convert VB to C#
This commit is contained in:
219
Pilz.Networking/ConnectionManagerBase.cs
Normal file
219
Pilz.Networking/ConnectionManagerBase.cs
Normal file
@@ -0,0 +1,219 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using global::System.IO;
|
||||
using System.Linq;
|
||||
using global::System.Net;
|
||||
using global::Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Pilz.Networking
|
||||
{
|
||||
public abstract class ConnectionManagerBase
|
||||
{
|
||||
private const int HEADER_LENGTH = 12;
|
||||
private bool listening = false;
|
||||
private readonly Dictionary<int, Dictionary<int, byte[]>> dicData = new Dictionary<int, Dictionary<int, byte[]>>();
|
||||
|
||||
public int Port { get; private set; }
|
||||
public bool UseAssemblyQualifiedName { get; set; } = false;
|
||||
|
||||
public event RetriveDataEventHandler RetriveData;
|
||||
|
||||
public delegate void RetriveDataEventHandler(ConnectionManagerBase manager, string senderIP, string cmd, object content);
|
||||
|
||||
public bool IsListening
|
||||
{
|
||||
get
|
||||
{
|
||||
return listening;
|
||||
}
|
||||
|
||||
protected set
|
||||
{
|
||||
listening = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectionManagerBase(int port)
|
||||
{
|
||||
Port = port;
|
||||
}
|
||||
|
||||
~ConnectionManagerBase()
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
public abstract void Start();
|
||||
public abstract void Stop();
|
||||
protected abstract void SendData(IPEndPoint endPoint, byte[] data);
|
||||
protected abstract int GetBufferSize();
|
||||
|
||||
public virtual void Send(string empfängerIP, string cmd)
|
||||
{
|
||||
Send(empfängerIP, cmd, string.Empty);
|
||||
}
|
||||
|
||||
public virtual void Send(string empfängerIP, string cmd, string info)
|
||||
{
|
||||
Send(empfängerIP, cmd, info);
|
||||
}
|
||||
|
||||
private void RaiseRetriveData(string senderIP, string cmd, object content)
|
||||
{
|
||||
RetriveData?.Invoke(this, senderIP, cmd, content);
|
||||
}
|
||||
|
||||
protected void ProcessRetrivedData(string senderIP, byte[] buf)
|
||||
{
|
||||
int readInteger(int index) => buf[index] << 24 | buf[index + 1] << 16 | buf[index + 2] << 8 | buf[index + 3];
|
||||
int dataID = readInteger(0);
|
||||
int packageID = readInteger(4);
|
||||
int packageCount = readInteger(8);
|
||||
bool resolveData = true;
|
||||
|
||||
// Remember data
|
||||
var data = buf.Skip(HEADER_LENGTH).ToArray();
|
||||
Dictionary<int, byte[]> dicMyData;
|
||||
if (dicData.ContainsKey(dataID))
|
||||
{
|
||||
dicMyData = dicData[dataID];
|
||||
if (dicMyData.ContainsKey(packageID))
|
||||
{
|
||||
dicMyData[packageID] = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
dicMyData.Add(packageID, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dicMyData = new Dictionary<int, byte[]>() { { packageID, data } };
|
||||
dicData.Add(dataID, dicMyData);
|
||||
}
|
||||
|
||||
if (dicMyData.Count < packageCount)
|
||||
{
|
||||
resolveData = false;
|
||||
}
|
||||
|
||||
// Resolve Data
|
||||
if (resolveData)
|
||||
{
|
||||
if (dicMyData is null)
|
||||
{
|
||||
dicMyData = dicData[dataID];
|
||||
}
|
||||
|
||||
var myData = new List<byte>();
|
||||
foreach (var kvp in dicMyData.OrderBy(n => n.Key))
|
||||
myData.AddRange(kvp.Value);
|
||||
dicMyData.Remove(dataID);
|
||||
object content = null;
|
||||
string cmd = string.Empty;
|
||||
try
|
||||
{
|
||||
var res = DecodeFromBytes(myData.ToArray());
|
||||
cmd = res.cmd;
|
||||
content = res.content;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
RaiseRetriveData(senderIP, cmd, content);
|
||||
}
|
||||
}
|
||||
|
||||
private Random send_Rnd = new Random();
|
||||
public void Send(string empfängerIP, string cmd, object content)
|
||||
{
|
||||
var ep = new IPEndPoint(NetworkFeatures.GetIPFromHost(empfängerIP).MapToIPv4(), Port);
|
||||
var finalBuffer = new List<byte>();
|
||||
int maxBufferSize = GetBufferSize();
|
||||
int maxDataSize = maxBufferSize - HEADER_LENGTH;
|
||||
var data = EncodeToBytes(cmd, content, UseAssemblyQualifiedName);
|
||||
int dataID = send_Rnd.Next();
|
||||
|
||||
// Some methods for later user
|
||||
void send() => SendData(ep, finalBuffer.ToArray());
|
||||
void addInteger(int value) => finalBuffer.AddRange(new byte[] { (byte)((value >> 24) & 0xFF), (byte)((value >> 16) & 0xFF), (byte)((value >> 8) & 0xFF), (byte)(value & 0xFF) });
|
||||
void addHeader(int packageID, int packagesCount)
|
||||
{
|
||||
addInteger(dataID); // Data ID
|
||||
addInteger(packageID); // Package ID
|
||||
addInteger(packagesCount); // Packages Count
|
||||
};
|
||||
|
||||
// Send data (this if statement and else content might be useless)
|
||||
if (data.Length > maxDataSize)
|
||||
{
|
||||
int curIndex = 0;
|
||||
int curID = 0;
|
||||
int packagesCount = (int)Math.Ceiling(data.Length / (double)maxDataSize);
|
||||
while (curIndex < data.Length)
|
||||
{
|
||||
finalBuffer.Clear();
|
||||
addHeader(curID, packagesCount);
|
||||
for (int i = 1, loopTo = maxDataSize; i <= loopTo; i++)
|
||||
{
|
||||
if (curIndex < data.Length)
|
||||
{
|
||||
finalBuffer.Add(data[curIndex]);
|
||||
curIndex += 1;
|
||||
}
|
||||
}
|
||||
|
||||
send();
|
||||
curID += 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
addHeader(0, 1);
|
||||
finalBuffer.AddRange(data);
|
||||
send();
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] EncodeToBytes(string cmd, object content, bool useAssemblyQualifiedName)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
var bw = new BinaryWriter(ms);
|
||||
var obj = new JObject();
|
||||
|
||||
// Write header
|
||||
obj["Cmd"] = cmd;
|
||||
obj["ContentType"] = useAssemblyQualifiedName ? content?.GetType()?.AssemblyQualifiedName : content?.GetType()?.ToString();
|
||||
|
||||
// Content
|
||||
obj["Content"] = JToken.FromObject(content);
|
||||
|
||||
// Write Json to MemoryStream
|
||||
bw.Write(System.Text.Encoding.Default.GetBytes(obj.ToString()));
|
||||
|
||||
// Get Buffer Bytes
|
||||
var buf = ms.ToArray();
|
||||
ms.Close();
|
||||
return buf;
|
||||
}
|
||||
|
||||
private static (string cmd, object content) DecodeFromBytes(byte[] buf)
|
||||
{
|
||||
string contentstring = System.Text.Encoding.Default.GetString(buf);
|
||||
object content = null;
|
||||
var contentobj = JObject.Parse(contentstring);
|
||||
string cmd = (string)contentobj["Cmd"];
|
||||
string contenttypestring = (string)contentobj["ContentType"];
|
||||
var contentlinq = contentobj["Content"];
|
||||
if (!string.IsNullOrEmpty(contenttypestring))
|
||||
{
|
||||
var contenttype = Type.GetType(contenttypestring);
|
||||
content = contentlinq.ToObject(contenttype);
|
||||
}
|
||||
|
||||
return (cmd, content);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
Imports System.IO
|
||||
Imports System.Net
|
||||
Imports Newtonsoft.Json.Linq
|
||||
|
||||
Public MustInherit Class ConnectionManagerBase
|
||||
|
||||
Private Const HEADER_LENGTH As Integer = 12
|
||||
|
||||
Private listening As Boolean = False
|
||||
Private ReadOnly dicData As New Dictionary(Of Integer, Dictionary(Of Integer, Byte()))
|
||||
|
||||
Public ReadOnly Property Port As Integer
|
||||
Public Property UseAssemblyQualifiedName As Boolean = False
|
||||
|
||||
Public Event RetriveData(manager As ConnectionManagerBase, senderIP As String, cmd As String, content As Object)
|
||||
|
||||
Public Property IsListening As Boolean
|
||||
Get
|
||||
Return listening
|
||||
End Get
|
||||
Protected Set(value As Boolean)
|
||||
listening = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Sub New(port As Integer)
|
||||
Me.Port = port
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Finalize()
|
||||
[Stop]()
|
||||
End Sub
|
||||
|
||||
Public MustOverride Sub Start()
|
||||
Public MustOverride Sub [Stop]()
|
||||
Protected MustOverride Sub SendData(endPoint As IPEndPoint, data As Byte())
|
||||
Protected MustOverride Function GetBufferSize() As Integer
|
||||
|
||||
Public Overridable Sub Send(empfängerIP As String, cmd As String)
|
||||
Send(empfängerIP, cmd, String.Empty)
|
||||
End Sub
|
||||
|
||||
Public Overridable Sub Send(empfängerIP As String, cmd As String, info As String)
|
||||
Send(empfängerIP, cmd, CObj(info))
|
||||
End Sub
|
||||
|
||||
Private Sub RaiseRetriveData(senderIP As String, cmd As String, content As Object)
|
||||
RaiseEvent RetriveData(Me, senderIP, cmd, content)
|
||||
End Sub
|
||||
|
||||
Protected Sub ProcessRetrivedData(senderIP As String, buf As Byte())
|
||||
Dim readInteger =
|
||||
Function(index As Integer) As Integer
|
||||
Return (CInt(buf(index)) << 24) Or (CInt(buf(index + 1)) << 16) Or (CInt(buf(index + 2)) << 8) Or buf(index + 3)
|
||||
End Function
|
||||
|
||||
Dim dataID As Integer = readInteger(0)
|
||||
Dim packageID As Integer = readInteger(4)
|
||||
Dim packageCount As Integer = readInteger(8)
|
||||
Dim resolveData As Boolean = True
|
||||
|
||||
'Remember data
|
||||
Dim data As Byte() = buf.Skip(HEADER_LENGTH).ToArray
|
||||
Dim dicMyData As Dictionary(Of Integer, Byte())
|
||||
|
||||
If dicData.ContainsKey(dataID) Then
|
||||
dicMyData = dicData(dataID)
|
||||
If dicMyData.ContainsKey(packageID) Then
|
||||
dicMyData(packageID) = data
|
||||
Else
|
||||
dicMyData.Add(packageID, data)
|
||||
End If
|
||||
Else
|
||||
dicMyData = New Dictionary(Of Integer, Byte()) From {{packageID, data}}
|
||||
dicData.Add(dataID, dicMyData)
|
||||
End If
|
||||
|
||||
If dicMyData.Count < packageCount Then
|
||||
resolveData = False
|
||||
End If
|
||||
|
||||
'Resolve Data
|
||||
If resolveData Then
|
||||
If dicMyData Is Nothing Then
|
||||
dicMyData = dicData(dataID)
|
||||
End If
|
||||
Dim myData As New List(Of Byte)
|
||||
For Each kvp In dicMyData.OrderBy(Function(n) n.Key)
|
||||
myData.AddRange(kvp.Value)
|
||||
Next
|
||||
dicMyData.Remove(dataID)
|
||||
|
||||
Dim content As Object = Nothing
|
||||
Dim cmd As String = String.Empty
|
||||
Try
|
||||
Dim res = DecodeFromBytes(myData.ToArray)
|
||||
cmd = res.cmd
|
||||
content = res.content
|
||||
Catch ex As Exception
|
||||
End Try
|
||||
|
||||
RaiseRetriveData(senderIP, cmd, content)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub Send(empfängerIP As String, cmd As String, content As Object)
|
||||
Static rnd As New Random
|
||||
Dim ep As New IPEndPoint(GetIPFromHost(empfängerIP).MapToIPv4, Port)
|
||||
Dim finalBuffer As New List(Of Byte)
|
||||
Dim maxBufferSize As Integer = GetBufferSize()
|
||||
Dim maxDataSize As Integer = maxBufferSize - HEADER_LENGTH
|
||||
Dim data As Byte() = EncodeToBytes(cmd, content, UseAssemblyQualifiedName)
|
||||
Dim dataID As Integer = rnd.Next
|
||||
|
||||
'Some methods for later user
|
||||
Dim send = Sub() SendData(ep, finalBuffer.ToArray)
|
||||
Dim addInteger =
|
||||
Sub(value As Integer)
|
||||
finalBuffer.AddRange({(value >> 24) And &HFF, (value >> 16) And &HFF, (value >> 8) And &HFF, value And &HFF})
|
||||
End Sub
|
||||
Dim addHeader =
|
||||
Sub(packageID As Integer, packagesCount As Integer)
|
||||
addInteger(dataID) 'Data ID
|
||||
addInteger(packageID) 'Package ID
|
||||
addInteger(packagesCount) 'Packages Count
|
||||
End Sub
|
||||
|
||||
'Send data (this if statement and else content might be useless)
|
||||
If data.Length > maxDataSize Then
|
||||
Dim curIndex As Integer = 0
|
||||
Dim curID As Integer = 0
|
||||
Dim packagesCount As Integer = Math.Ceiling(data.Length / maxDataSize)
|
||||
|
||||
Do While curIndex < data.Length
|
||||
finalBuffer.Clear()
|
||||
addHeader(curID, packagesCount)
|
||||
For i As Integer = 1 To maxDataSize
|
||||
If curIndex < data.Length Then
|
||||
finalBuffer.Add(data(curIndex))
|
||||
curIndex += 1
|
||||
End If
|
||||
Next
|
||||
send()
|
||||
curID += 1
|
||||
Loop
|
||||
Else
|
||||
addHeader(0, 1)
|
||||
finalBuffer.AddRange(data)
|
||||
send()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Shared Function EncodeToBytes(cmd As String, content As Object, useAssemblyQualifiedName As Boolean) As Byte()
|
||||
Dim ms As New MemoryStream()
|
||||
Dim bw As New BinaryWriter(ms)
|
||||
Dim obj As New JObject
|
||||
|
||||
'Write header
|
||||
obj("Cmd") = cmd
|
||||
obj("ContentType") = If(useAssemblyQualifiedName, content?.GetType?.AssemblyQualifiedName, content?.GetType?.ToString)
|
||||
|
||||
'Content
|
||||
obj("Content") = JToken.FromObject(content)
|
||||
|
||||
'Write Json to MemoryStream
|
||||
bw.Write(Text.Encoding.Default.GetBytes(obj.ToString))
|
||||
|
||||
'Get Buffer Bytes
|
||||
Dim buf As Byte() = ms.ToArray
|
||||
ms.Close()
|
||||
|
||||
Return buf
|
||||
End Function
|
||||
|
||||
Private Shared Function DecodeFromBytes(buf As Byte()) As (cmd As String, content As Object)
|
||||
Dim contentstring As String = Text.Encoding.Default.GetString(buf)
|
||||
Dim content As Object = Nothing
|
||||
Dim contentobj As JObject = JObject.Parse(contentstring)
|
||||
|
||||
Dim cmd As String = contentobj("Cmd")
|
||||
Dim contenttypestring As String = contentobj("ContentType")
|
||||
Dim contentlinq As JToken = contentobj("Content")
|
||||
|
||||
If Not String.IsNullOrEmpty(contenttypestring) Then
|
||||
Dim contenttype As Type = Type.GetType(contenttypestring)
|
||||
content = contentlinq.ToObject(contenttype)
|
||||
End If
|
||||
|
||||
Return (cmd, content)
|
||||
End Function
|
||||
|
||||
End Class
|
||||
11
Pilz.Networking/My Project/Application.Designer.cs
generated
Normal file
11
Pilz.Networking/My Project/Application.Designer.cs
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Dieser Code wurde von einem Tool generiert.
|
||||
// Laufzeitversion:4.0.30319.42000
|
||||
//
|
||||
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
// der Code erneut generiert wird.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
13
Pilz.Networking/My Project/Application.Designer.vb
generated
13
Pilz.Networking/My Project/Application.Designer.vb
generated
@@ -1,13 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' Dieser Code wurde von einem Tool generiert.
|
||||
' Laufzeitversion:4.0.30319.42000
|
||||
'
|
||||
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
' der Code erneut generiert wird.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
Imports System
|
||||
Imports System.Reflection
|
||||
Imports System.Runtime.InteropServices
|
||||
|
||||
' Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
' die einer Assembly zugeordnet sind.
|
||||
|
||||
' Werte der Assemblyattribute überprüfen
|
||||
|
||||
<Assembly: AssemblyTitle("Pilz.Networking")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("DRSN")>
|
||||
<Assembly: AssemblyProduct("Pilz.Networking")>
|
||||
<Assembly: AssemblyCopyright("Copyright © DRSN 2019")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird.
|
||||
<Assembly: Guid("467b9a06-75bf-4894-b88d-397eeb2bb0cc")>
|
||||
|
||||
' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
'
|
||||
' Hauptversion
|
||||
' Nebenversion
|
||||
' Buildnummer
|
||||
' Revision
|
||||
'
|
||||
' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
192
Pilz.Networking/My Project/MyNamespace.Static.1.Designer.cs
generated
Normal file
192
Pilz.Networking/My Project/MyNamespace.Static.1.Designer.cs
generated
Normal file
@@ -0,0 +1,192 @@
|
||||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualBasic;
|
||||
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */
|
||||
/* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia *//* TODO ERROR: Skipped DefineDirectiveTrivia */
|
||||
/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia */
|
||||
namespace Pilz.Networking.My
|
||||
{
|
||||
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia */
|
||||
[System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped ElifDirectiveTrivia */
|
||||
internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.ApplicationBase
|
||||
{
|
||||
/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
}
|
||||
|
||||
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia */
|
||||
[System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia */
|
||||
internal partial class MyComputer : Microsoft.VisualBasic.Devices.Computer
|
||||
{
|
||||
/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
[DebuggerHidden()]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public MyComputer() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
[HideModuleName()]
|
||||
[System.CodeDom.Compiler.GeneratedCode("MyTemplate", "11.0.0.0")]
|
||||
internal static class MyProject
|
||||
{
|
||||
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia */
|
||||
[System.ComponentModel.Design.HelpKeyword("My.Computer")]
|
||||
internal static MyComputer Computer
|
||||
{
|
||||
[DebuggerHidden()]
|
||||
get
|
||||
{
|
||||
return m_ComputerObjectProvider.GetInstance;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly static ThreadSafeObjectProvider<MyComputer> m_ComputerObjectProvider = new ThreadSafeObjectProvider<MyComputer>();
|
||||
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia */
|
||||
[System.ComponentModel.Design.HelpKeyword("My.Application")]
|
||||
internal static MyApplication Application
|
||||
{
|
||||
[DebuggerHidden()]
|
||||
get
|
||||
{
|
||||
return m_AppObjectProvider.GetInstance;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly static ThreadSafeObjectProvider<MyApplication> m_AppObjectProvider = new ThreadSafeObjectProvider<MyApplication>();
|
||||
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia */
|
||||
[System.ComponentModel.Design.HelpKeyword("My.User")]
|
||||
internal static Microsoft.VisualBasic.ApplicationServices.User User
|
||||
{
|
||||
[DebuggerHidden()]
|
||||
get
|
||||
{
|
||||
return m_UserObjectProvider.GetInstance;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly static ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.User> m_UserObjectProvider = new ThreadSafeObjectProvider<Microsoft.VisualBasic.ApplicationServices.User>();
|
||||
/* TODO ERROR: Skipped ElifDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia */
|
||||
[System.ComponentModel.Design.HelpKeyword("My.WebServices")]
|
||||
internal static MyWebServices WebServices
|
||||
{
|
||||
[DebuggerHidden()]
|
||||
get
|
||||
{
|
||||
return m_MyWebServicesObjectProvider.GetInstance;
|
||||
}
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
[MyGroupCollection("System.Web.Services.Protocols.SoapHttpClientProtocol", "Create__Instance__", "Dispose__Instance__", "")]
|
||||
internal sealed class MyWebServices
|
||||
{
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
[DebuggerHidden()]
|
||||
public override bool Equals(object o)
|
||||
{
|
||||
return base.Equals(o);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
[DebuggerHidden()]
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
[DebuggerHidden()]
|
||||
internal new Type GetType()
|
||||
{
|
||||
return typeof(MyWebServices);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
[DebuggerHidden()]
|
||||
public override string ToString()
|
||||
{
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
[DebuggerHidden()]
|
||||
private static T Create__Instance__<T>(T instance) where T : new()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
else
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerHidden()]
|
||||
private void Dispose__Instance__<T>(ref T instance)
|
||||
{
|
||||
instance = default;
|
||||
}
|
||||
|
||||
[DebuggerHidden()]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public MyWebServices() : base()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private readonly static ThreadSafeObjectProvider<MyWebServices> m_MyWebServicesObjectProvider = new ThreadSafeObjectProvider<MyWebServices>();
|
||||
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
[System.Runtime.InteropServices.ComVisible(false)]
|
||||
internal sealed class ThreadSafeObjectProvider<T> where T : new()
|
||||
{
|
||||
internal T GetInstance
|
||||
{
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia */
|
||||
[DebuggerHidden()]
|
||||
get
|
||||
{
|
||||
var Value = m_Context.Value;
|
||||
if (Value == null)
|
||||
{
|
||||
Value = new T();
|
||||
m_Context.Value = Value;
|
||||
}
|
||||
|
||||
return Value;
|
||||
}
|
||||
/* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
}
|
||||
|
||||
[DebuggerHidden()]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public ThreadSafeObjectProvider() : base()
|
||||
{
|
||||
}
|
||||
|
||||
/* TODO ERROR: Skipped IfDirectiveTrivia */
|
||||
private readonly Microsoft.VisualBasic.MyServices.Internal.ContextValue<T> m_Context = new Microsoft.VisualBasic.MyServices.Internal.ContextValue<T>();
|
||||
/* TODO ERROR: Skipped ElseDirectiveTrivia *//* TODO ERROR: Skipped DisabledTextTrivia *//* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
}
|
||||
}
|
||||
}
|
||||
/* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
||||
253
Pilz.Networking/My Project/MyNamespace.Static.2.Designer.cs
generated
Normal file
253
Pilz.Networking/My Project/MyNamespace.Static.2.Designer.cs
generated
Normal file
@@ -0,0 +1,253 @@
|
||||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
// See Compiler::LoadXmlSolutionExtension
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.VisualBasic;
|
||||
using Microsoft.VisualBasic.CompilerServices;
|
||||
|
||||
namespace Pilz.Networking.My
|
||||
{
|
||||
[Embedded()]
|
||||
[DebuggerNonUserCode()]
|
||||
[System.Runtime.CompilerServices.CompilerGenerated()]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal sealed class InternalXmlHelper
|
||||
{
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
private InternalXmlHelper()
|
||||
{
|
||||
}
|
||||
|
||||
public static string get_Value(IEnumerable<XElement> source)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
return item.Value;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void set_Value(IEnumerable<XElement> source, string value)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
{
|
||||
item.Value = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static string get_AttributeValue(IEnumerable<XElement> source, XName name)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
return Conversions.ToString(item.Attribute(name));
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void set_AttributeValue(IEnumerable<XElement> source, XName name, string value)
|
||||
{
|
||||
foreach (XElement item in source)
|
||||
{
|
||||
item.SetAttributeValue(name, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static string get_AttributeValue(XElement source, XName name)
|
||||
{
|
||||
return Conversions.ToString(source.Attribute(name));
|
||||
}
|
||||
|
||||
public static void set_AttributeValue(XElement source, XName name, string value)
|
||||
{
|
||||
source.SetAttributeValue(name, value);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public static XAttribute CreateAttribute(XName name, object value)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new XAttribute(name, value);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public static XAttribute CreateNamespaceAttribute(XName name, XNamespace ns)
|
||||
{
|
||||
var a = new XAttribute(name, ns.NamespaceName);
|
||||
a.AddAnnotation(ns);
|
||||
return a;
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public static object RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List<XAttribute> attributes, object obj)
|
||||
{
|
||||
if (obj is object)
|
||||
{
|
||||
XElement elem = obj as XElement;
|
||||
if (elem is object)
|
||||
{
|
||||
return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elem);
|
||||
}
|
||||
else
|
||||
{
|
||||
IEnumerable elems = obj as IEnumerable;
|
||||
if (elems is object)
|
||||
{
|
||||
return RemoveNamespaceAttributes(inScopePrefixes, inScopeNs, attributes, elems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public static IEnumerable RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List<XAttribute> attributes, IEnumerable obj)
|
||||
{
|
||||
if (obj is object)
|
||||
{
|
||||
IEnumerable<XElement> elems = obj as IEnumerable<XElement>;
|
||||
if (elems is object)
|
||||
{
|
||||
return elems.Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessXElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
return obj.Cast<object>().Select(new RemoveNamespaceAttributesClosure(inScopePrefixes, inScopeNs, attributes).ProcessObject);
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
[DebuggerNonUserCode()]
|
||||
[System.Runtime.CompilerServices.CompilerGenerated()]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
private sealed class RemoveNamespaceAttributesClosure
|
||||
{
|
||||
private readonly string[] m_inScopePrefixes;
|
||||
private readonly XNamespace[] m_inScopeNs;
|
||||
private readonly List<XAttribute> m_attributes;
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal RemoveNamespaceAttributesClosure(string[] inScopePrefixes, XNamespace[] inScopeNs, List<XAttribute> attributes)
|
||||
{
|
||||
m_inScopePrefixes = inScopePrefixes;
|
||||
m_inScopeNs = inScopeNs;
|
||||
m_attributes = attributes;
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal XElement ProcessXElement(XElement elem)
|
||||
{
|
||||
return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem);
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal object ProcessObject(object obj)
|
||||
{
|
||||
XElement elem = obj as XElement;
|
||||
if (elem is object)
|
||||
{
|
||||
return RemoveNamespaceAttributes(m_inScopePrefixes, m_inScopeNs, m_attributes, elem);
|
||||
}
|
||||
else
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public static XElement RemoveNamespaceAttributes(string[] inScopePrefixes, XNamespace[] inScopeNs, List<XAttribute> attributes, XElement e)
|
||||
{
|
||||
if (e is object)
|
||||
{
|
||||
var a = e.FirstAttribute;
|
||||
while (a is object)
|
||||
{
|
||||
var nextA = a.NextAttribute;
|
||||
if (a.IsNamespaceDeclaration)
|
||||
{
|
||||
var ns = a.Annotation<XNamespace>();
|
||||
string prefix = a.Name.LocalName;
|
||||
if (ns is object)
|
||||
{
|
||||
if (inScopePrefixes is object && inScopeNs is object)
|
||||
{
|
||||
int lastIndex = inScopePrefixes.Length - 1;
|
||||
for (int i = 0, loopTo = lastIndex; i <= loopTo; i++)
|
||||
{
|
||||
string currentInScopePrefix = inScopePrefixes[i];
|
||||
var currentInScopeNs = inScopeNs[i];
|
||||
if (prefix.Equals(currentInScopePrefix))
|
||||
{
|
||||
if (ns == currentInScopeNs)
|
||||
{
|
||||
// prefix and namespace match. Remove the unneeded ns attribute
|
||||
a.Remove();
|
||||
}
|
||||
|
||||
// prefix is in scope but refers to something else. Leave the ns attribute.
|
||||
a = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (a is object)
|
||||
{
|
||||
// Prefix is not in scope
|
||||
// Now check whether it's going to be in scope because it is in the attributes list
|
||||
|
||||
if (attributes is object)
|
||||
{
|
||||
int lastIndex = attributes.Count - 1;
|
||||
for (int i = 0, loopTo1 = lastIndex; i <= loopTo1; i++)
|
||||
{
|
||||
var currentA = attributes[i];
|
||||
string currentInScopePrefix = currentA.Name.LocalName;
|
||||
var currentInScopeNs = currentA.Annotation<XNamespace>();
|
||||
if (currentInScopeNs is object)
|
||||
{
|
||||
if (prefix.Equals(currentInScopePrefix))
|
||||
{
|
||||
if (ns == currentInScopeNs)
|
||||
{
|
||||
// prefix and namespace match. Remove the unneeded ns attribute
|
||||
a.Remove();
|
||||
}
|
||||
|
||||
// prefix is in scope but refers to something else. Leave the ns attribute.
|
||||
a = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (a is object)
|
||||
{
|
||||
// Prefix is definitely not in scope
|
||||
a.Remove();
|
||||
// namespace is not defined either. Add this attributes list
|
||||
attributes.Add(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
a = nextA;
|
||||
}
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Pilz.Networking/My Project/MyNamespace.Static.3.Designer.cs
generated
Normal file
14
Pilz.Networking/My Project/MyNamespace.Static.3.Designer.cs
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.VisualBasic
|
||||
{
|
||||
[Embedded()]
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Module | AttributeTargets.Assembly, Inherited = false)]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
[System.Runtime.CompilerServices.CompilerGenerated()]
|
||||
internal sealed class Embedded : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
63
Pilz.Networking/My Project/Resources.Designer.vb
generated
63
Pilz.Networking/My Project/Resources.Designer.vb
generated
@@ -1,63 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' Dieser Code wurde von einem Tool generiert.
|
||||
' Laufzeitversion:4.0.30319.42000
|
||||
'
|
||||
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
' der Code erneut generiert wird.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
Imports System
|
||||
|
||||
Namespace My.Resources
|
||||
|
||||
'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
|
||||
'-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
|
||||
'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
|
||||
'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
|
||||
'''<summary>
|
||||
''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
'''<summary>
|
||||
''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
|
||||
Get
|
||||
If Object.ReferenceEquals(resourceMan, Nothing) Then
|
||||
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Pilz.Networking.Resources", GetType(Resources).Assembly)
|
||||
resourceMan = temp
|
||||
End If
|
||||
Return resourceMan
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
73
Pilz.Networking/My Project/Settings.Designer.vb
generated
73
Pilz.Networking/My Project/Settings.Designer.vb
generated
@@ -1,73 +0,0 @@
|
||||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' Dieser Code wurde von einem Tool generiert.
|
||||
' Laufzeitversion:4.0.30319.42000
|
||||
'
|
||||
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
' der Code erneut generiert wird.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Partial Friend NotInheritable Class MySettings
|
||||
Inherits Global.System.Configuration.ApplicationSettingsBase
|
||||
|
||||
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings)
|
||||
|
||||
#Region "Automatische My.Settings-Speicherfunktion"
|
||||
#If _MyType = "WindowsForms" Then
|
||||
Private Shared addedHandler As Boolean
|
||||
|
||||
Private Shared addedHandlerLockObject As New Object
|
||||
|
||||
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Private Shared Sub AutoSaveSettings(sender As Global.System.Object, e As Global.System.EventArgs)
|
||||
If My.Application.SaveMySettingsOnExit Then
|
||||
My.Settings.Save()
|
||||
End If
|
||||
End Sub
|
||||
#End If
|
||||
#End Region
|
||||
|
||||
Public Shared ReadOnly Property [Default]() As MySettings
|
||||
Get
|
||||
|
||||
#If _MyType = "WindowsForms" Then
|
||||
If Not addedHandler Then
|
||||
SyncLock addedHandlerLockObject
|
||||
If Not addedHandler Then
|
||||
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
|
||||
addedHandler = True
|
||||
End If
|
||||
End SyncLock
|
||||
End If
|
||||
#End If
|
||||
Return defaultInstance
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||
Friend Module MySettingsProperty
|
||||
|
||||
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||
Friend ReadOnly Property Settings() As Global.Pilz.Networking.My.MySettings
|
||||
Get
|
||||
Return Global.Pilz.Networking.My.MySettings.Default
|
||||
End Get
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
||||
62
Pilz.Networking/NetworkFeatures.cs
Normal file
62
Pilz.Networking/NetworkFeatures.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Linq;
|
||||
using global::System.Net;
|
||||
using global::System.Net.NetworkInformation;
|
||||
using global::System.Net.Sockets;
|
||||
|
||||
namespace Pilz.Networking
|
||||
{
|
||||
public static class NetworkFeatures
|
||||
{
|
||||
public static IPAddress GetIPFromHost(string hostName)
|
||||
{
|
||||
return Dns.GetHostAddresses(hostName).FirstOrDefault(n => n.AddressFamily == AddressFamily.InterNetwork);
|
||||
}
|
||||
|
||||
public static object GetHostFromIP(string ip)
|
||||
{
|
||||
return Dns.GetHostEntry(ip)?.HostName;
|
||||
}
|
||||
|
||||
public static UnicastIPAddressInformation GetLocalIPInformations()
|
||||
{
|
||||
UnicastIPAddressInformation addr = null;
|
||||
foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces())
|
||||
{
|
||||
if (addr is null && adapter.OperationalStatus == OperationalStatus.Up && adapter.NetworkInterfaceType != NetworkInterfaceType.Tunnel && adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback)
|
||||
{
|
||||
foreach (UnicastIPAddressInformation uni in adapter.GetIPProperties().UnicastAddresses)
|
||||
{
|
||||
if (addr is null && uni.Address.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
addr = uni;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
public static IPAddress GetLocalIPAddress()
|
||||
{
|
||||
return GetLocalIPInformations()?.Address;
|
||||
}
|
||||
|
||||
public static IPAddress GetLocalIPv4Mask()
|
||||
{
|
||||
return GetLocalIPInformations()?.IPv4Mask;
|
||||
}
|
||||
|
||||
public static IPAddress GetLocalBoradcastIP(UnicastIPAddressInformation ipInfo)
|
||||
{
|
||||
IPAddress ip = null;
|
||||
var myIPBytes = ipInfo.Address.GetAddressBytes();
|
||||
var subnetBytes = ipInfo.IPv4Mask.GetAddressBytes();
|
||||
var broadcastBytes = new byte[myIPBytes.Length];
|
||||
for (int i = 0, loopTo = subnetBytes.Length - 1; i <= loopTo; i++)
|
||||
broadcastBytes[i] = (byte)(myIPBytes[i] | ~subnetBytes[i]);
|
||||
ip = new IPAddress(broadcastBytes);
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
Imports System.Net
|
||||
Imports System.Net.NetworkInformation
|
||||
Imports System.Net.Sockets
|
||||
|
||||
Public Module NetworkFeatures
|
||||
|
||||
Public Function GetIPFromHost(hostName As String) As IPAddress
|
||||
Return Dns.GetHostAddresses(hostName).FirstOrDefault(Function(n) n.AddressFamily = AddressFamily.InterNetwork)
|
||||
End Function
|
||||
|
||||
Public Function GetHostFromIP(ip As String)
|
||||
Return Dns.GetHostEntry(ip)?.HostName
|
||||
End Function
|
||||
|
||||
Public Function GetLocalIPInformations() As UnicastIPAddressInformation
|
||||
Dim addr As UnicastIPAddressInformation = Nothing
|
||||
|
||||
For Each adapter As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces
|
||||
If addr Is Nothing AndAlso adapter.OperationalStatus = OperationalStatus.Up AndAlso adapter.NetworkInterfaceType <> NetworkInterfaceType.Tunnel AndAlso adapter.NetworkInterfaceType <> NetworkInterfaceType.Loopback Then
|
||||
For Each uni As UnicastIPAddressInformation In adapter.GetIPProperties.UnicastAddresses
|
||||
If addr Is Nothing AndAlso uni.Address.AddressFamily = AddressFamily.InterNetwork Then
|
||||
addr = uni
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
Next
|
||||
|
||||
Return addr
|
||||
End Function
|
||||
|
||||
Public Function GetLocalIPAddress() As IPAddress
|
||||
Return GetLocalIPInformations()?.Address
|
||||
End Function
|
||||
|
||||
Public Function GetLocalIPv4Mask() As IPAddress
|
||||
Return GetLocalIPInformations()?.IPv4Mask
|
||||
End Function
|
||||
|
||||
Public Function GetLocalBoradcastIP(ipInfo As UnicastIPAddressInformation) As IPAddress
|
||||
Dim ip As IPAddress = Nothing
|
||||
Dim myIPBytes As Byte() = ipInfo.Address.GetAddressBytes
|
||||
Dim subnetBytes As Byte() = ipInfo.IPv4Mask.GetAddressBytes
|
||||
Dim broadcastBytes As Byte() = New Byte(myIPBytes.Length - 1) {}
|
||||
|
||||
For i As Integer = 0 To subnetBytes.Length - 1
|
||||
broadcastBytes(i) = myIPBytes(i) Or Not subnetBytes(i)
|
||||
Next
|
||||
|
||||
ip = New IPAddress(broadcastBytes)
|
||||
|
||||
Return ip
|
||||
End Function
|
||||
|
||||
End Module
|
||||
@@ -4,7 +4,7 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4584B121-09C6-40AC-849B-7E410125EF66}</ProjectGuid>
|
||||
<ProjectGuid>{F7A0304A-C59E-0F5D-06C3-B43F63B2DBC6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Pilz.Networking</RootNamespace>
|
||||
<AssemblyName>Pilz.Networking</AssemblyName>
|
||||
@@ -13,6 +13,8 @@
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);$(ProjectDir)**\*.vb</DefaultItemExcludes>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -45,6 +47,7 @@
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualBasic" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
@@ -65,43 +68,46 @@
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ConnectionManagerBase.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<Compile Include="My Project\MyNamespace.Static.1.Designer.cs" />
|
||||
<Compile Include="My Project\MyNamespace.Static.2.Designer.cs" />
|
||||
<Compile Include="My Project\MyNamespace.Static.3.Designer.cs" />
|
||||
<Compile Include="ConnectionManagerBase.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="My Project\Application.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Resources.Designer.vb">
|
||||
<Compile Include="Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Settings.Designer.vb">
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="NetworkFeatures.vb" />
|
||||
<Compile Include="TCPManager.vb" />
|
||||
<Compile Include="UDPManager.vb" />
|
||||
<Compile Include="NetworkFeatures.cs" />
|
||||
<Compile Include="TCPManager.cs" />
|
||||
<Compile Include="UDPManager.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<EmbeddedResource Include="Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<CustomToolNamespace>Pilz.Networking.My.Resources</CustomToolNamespace>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||
<LastGenOutput>Application.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Include="My Project\Settings.settings">
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>Pilz.Networking.My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -109,5 +115,5 @@
|
||||
<Version>12.0.3</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
35
Pilz.Networking/Properties/AssemblyInfo.cs
Normal file
35
Pilz.Networking/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using global::System;
|
||||
using global::System.Reflection;
|
||||
using global::System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die einer Assembly zugeordnet sind.
|
||||
|
||||
// Werte der Assemblyattribute überprüfen
|
||||
|
||||
[assembly: AssemblyTitle("Pilz.Networking")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyCompany("DRSN")]
|
||||
[assembly: AssemblyProduct("Pilz.Networking")]
|
||||
[assembly: AssemblyCopyright("Copyright © DRSN 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird.
|
||||
[assembly: Guid("467b9a06-75bf-4894-b88d-397eeb2bb0cc")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
26
Pilz.Networking/Properties/Settings.Designer.cs
generated
Normal file
26
Pilz.Networking/Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Dieser Code wurde von einem Tool generiert.
|
||||
// Laufzeitversion:4.0.30319.42000
|
||||
//
|
||||
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
// der Code erneut generiert wird.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Pilz.Networking.My {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
69
Pilz.Networking/Resources.Designer.cs
generated
Normal file
69
Pilz.Networking/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,69 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Dieser Code wurde von einem Tool generiert.
|
||||
// Laufzeitversion:4.0.30319.42000
|
||||
//
|
||||
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
// der Code erneut generiert wird.
|
||||
// </auto-generated>
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualBasic;
|
||||
|
||||
namespace Pilz.Networking.My.Resources
|
||||
{
|
||||
|
||||
// Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
|
||||
// -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
|
||||
// Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
|
||||
// mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
|
||||
/// <summary>
|
||||
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
/// </summary>
|
||||
[System.CodeDom.Compiler.GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
|
||||
[DebuggerNonUserCode()]
|
||||
[System.Runtime.CompilerServices.CompilerGenerated()]
|
||||
[HideModuleName()]
|
||||
internal static class Resources
|
||||
{
|
||||
private static System.Resources.ResourceManager resourceMan;
|
||||
private static System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
/// <summary>
|
||||
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
/// </summary>
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static System.Resources.ResourceManager ResourceManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ReferenceEquals(resourceMan, null))
|
||||
{
|
||||
var temp = new System.Resources.ResourceManager("Pilz.Networking.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
/// </summary>
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourceCulture;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
117
Pilz.Networking/Resources.resx
Normal file
117
Pilz.Networking/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
74
Pilz.Networking/TCPManager.cs
Normal file
74
Pilz.Networking/TCPManager.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using global::System.Net;
|
||||
using global::System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking
|
||||
{
|
||||
public class TCPManager : ConnectionManagerBase
|
||||
{
|
||||
private readonly TcpListener listener;
|
||||
|
||||
public int BufferSize { get; set; } = 10240;
|
||||
|
||||
public TCPManager(int port) : base(port)
|
||||
{
|
||||
listener = new TcpListener(IPAddress.Any, port);
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
if (!IsListening)
|
||||
{
|
||||
listener.Start();
|
||||
IsListening = true;
|
||||
Task.Run(CheckRetriveData);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
if (IsListening)
|
||||
{
|
||||
IsListening = false;
|
||||
listener.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
protected override int GetBufferSize()
|
||||
{
|
||||
return BufferSize;
|
||||
}
|
||||
|
||||
private void CheckRetriveData()
|
||||
{
|
||||
while (IsListening)
|
||||
{
|
||||
if (listener.Pending())
|
||||
{
|
||||
var tcp = listener.AcceptTcpClient();
|
||||
string ip = ((IPEndPoint)tcp.Client.RemoteEndPoint).Address.ToString();
|
||||
var Stream = tcp.GetStream();
|
||||
var buf = new byte[BufferSize];
|
||||
tcp.ReceiveBufferSize = BufferSize;
|
||||
Stream.Read(buf, 0, buf.Length);
|
||||
tcp.Close();
|
||||
ProcessRetrivedData(ip, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SendData(IPEndPoint ep, byte[] buf)
|
||||
{
|
||||
var tcp = new TcpClient();
|
||||
tcp.SendBufferSize = BufferSize;
|
||||
tcp.Connect(ep);
|
||||
var stream = tcp.GetStream();
|
||||
|
||||
// Send Data
|
||||
stream.Write(buf, 0, buf.Length);
|
||||
stream.Flush();
|
||||
tcp.Client.Shutdown(SocketShutdown.Both);
|
||||
tcp.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
Imports System.IO
|
||||
Imports System.Net
|
||||
Imports System.Net.NetworkInformation
|
||||
Imports System.Net.Sockets
|
||||
Imports Newtonsoft.Json.Linq
|
||||
|
||||
Public Class TCPManager
|
||||
Inherits ConnectionManagerBase
|
||||
|
||||
Private ReadOnly listener As TcpListener
|
||||
Public Property BufferSize As Integer = 10240
|
||||
|
||||
Public Sub New(port As Integer)
|
||||
MyBase.New(port)
|
||||
listener = New TcpListener(IPAddress.Any, port)
|
||||
End Sub
|
||||
|
||||
Public Overrides Sub Start()
|
||||
If Not IsListening Then
|
||||
listener.Start()
|
||||
IsListening = True
|
||||
Task.Run(AddressOf CheckRetriveData)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Overrides Sub [Stop]()
|
||||
If IsListening Then
|
||||
IsListening = False
|
||||
listener.Stop()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Protected Overrides Function GetBufferSize() As Integer
|
||||
Return BufferSize
|
||||
End Function
|
||||
|
||||
Private Sub CheckRetriveData()
|
||||
Do While IsListening
|
||||
If listener.Pending Then
|
||||
Dim tcp As TcpClient = listener.AcceptTcpClient()
|
||||
Dim ip As String = CType(tcp.Client.RemoteEndPoint, IPEndPoint).Address.ToString
|
||||
Dim Stream As NetworkStream = tcp.GetStream
|
||||
Dim buf As Byte() = New Byte(BufferSize - 1) {}
|
||||
|
||||
tcp.ReceiveBufferSize = BufferSize
|
||||
Stream.Read(buf, 0, buf.Length)
|
||||
|
||||
tcp.Close()
|
||||
|
||||
ProcessRetrivedData(ip, buf)
|
||||
End If
|
||||
Loop
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub SendData(ep As IPEndPoint, buf As Byte())
|
||||
Dim tcp As New TcpClient
|
||||
|
||||
tcp.SendBufferSize = BufferSize
|
||||
tcp.Connect(ep)
|
||||
|
||||
Dim stream As NetworkStream = tcp.GetStream()
|
||||
|
||||
'Send Data
|
||||
stream.Write(buf, 0, buf.Length)
|
||||
stream.Flush()
|
||||
|
||||
tcp.Client.Shutdown(SocketShutdown.Both)
|
||||
tcp.Close()
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
83
Pilz.Networking/UDPManager.cs
Normal file
83
Pilz.Networking/UDPManager.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using global::System.Net;
|
||||
using global::System.Net.Sockets;
|
||||
using global::System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking
|
||||
{
|
||||
public class UDPManager : ConnectionManagerBase
|
||||
{
|
||||
public UDPManager(int port) : base(port)
|
||||
{
|
||||
cancelToken = cancelTokenSource.Token;
|
||||
client = new UdpClient(port);
|
||||
}
|
||||
|
||||
private readonly UdpClient client;
|
||||
private Task listenTask = null;
|
||||
private readonly CancellationTokenSource cancelTokenSource = new CancellationTokenSource();
|
||||
private readonly CancellationToken cancelToken;
|
||||
|
||||
public int MaxBufferSize { get; private set; } = 8192;
|
||||
|
||||
~UDPManager()
|
||||
{
|
||||
client.Client.Shutdown(SocketShutdown.Both);
|
||||
client.Close();
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
if (!IsListening)
|
||||
{
|
||||
StartInternal();
|
||||
}
|
||||
}
|
||||
|
||||
private void StartInternal()
|
||||
{
|
||||
IsListening = true;
|
||||
listenTask = Task.Run(() => { try { RetriveAnyData(cancelToken); } catch (Exception ex) { IsListening = false; } });
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
if (IsListening)
|
||||
{
|
||||
IsListening = false;
|
||||
cancelTokenSource.Cancel();
|
||||
listenTask.Wait();
|
||||
}
|
||||
}
|
||||
|
||||
protected override int GetBufferSize()
|
||||
{
|
||||
return MaxBufferSize;
|
||||
}
|
||||
|
||||
private void RetriveAnyData(CancellationToken ct)
|
||||
{
|
||||
void doExit() => ct.ThrowIfCancellationRequested();
|
||||
var receiveTask = client.ReceiveAsync();
|
||||
|
||||
// Wait for the data and cancel if requested
|
||||
receiveTask.Wait(ct);
|
||||
var buf = receiveTask.Result.Buffer;
|
||||
string ip = receiveTask.Result.RemoteEndPoint.Address.ToString();
|
||||
doExit();
|
||||
ProcessRetrivedData(ip, buf);
|
||||
doExit();
|
||||
StartInternal();
|
||||
}
|
||||
|
||||
protected override void SendData(IPEndPoint ep, byte[] buf)
|
||||
{
|
||||
var udp = new UdpClient();
|
||||
udp.Connect(ep);
|
||||
udp.Send(buf, buf.Length);
|
||||
udp.Client.Shutdown(SocketShutdown.Both);
|
||||
udp.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
Imports System.IO
|
||||
Imports System.Net
|
||||
Imports System.Net.NetworkInformation
|
||||
Imports System.Net.Sockets
|
||||
Imports System.Threading
|
||||
Imports Newtonsoft.Json.Linq
|
||||
|
||||
Public Class UDPManager
|
||||
Inherits ConnectionManagerBase
|
||||
|
||||
Private ReadOnly client As UdpClient
|
||||
Private listenTask As Task = Nothing
|
||||
Private ReadOnly cancelTokenSource As New CancellationTokenSource
|
||||
Private ReadOnly cancelToken As CancellationToken = cancelTokenSource.Token
|
||||
Public ReadOnly Property MaxBufferSize As Integer = 8192
|
||||
|
||||
Public Sub New(port As Integer)
|
||||
MyBase.New(port)
|
||||
client = New UdpClient(port)
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Finalize()
|
||||
MyBase.Finalize()
|
||||
client.Client.Shutdown(SocketShutdown.Both)
|
||||
client.Close()
|
||||
End Sub
|
||||
|
||||
Public Overrides Sub Start()
|
||||
If Not IsListening Then
|
||||
StartInternal()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub StartInternal()
|
||||
IsListening = True
|
||||
listenTask = Task.Run(
|
||||
Sub()
|
||||
Try
|
||||
RetriveAnyData(cancelToken)
|
||||
Catch ex As Exception
|
||||
IsListening = False
|
||||
End Try
|
||||
End Sub)
|
||||
End Sub
|
||||
|
||||
Public Overrides Sub [Stop]()
|
||||
If IsListening Then
|
||||
IsListening = False
|
||||
cancelTokenSource.Cancel()
|
||||
listenTask.Wait()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Protected Overrides Function GetBufferSize() As Integer
|
||||
Return MaxBufferSize
|
||||
End Function
|
||||
|
||||
Private Sub RetriveAnyData(ct As CancellationToken)
|
||||
Dim doExit = Sub() ct.ThrowIfCancellationRequested()
|
||||
Dim receiveTask As Task(Of UdpReceiveResult) = client.ReceiveAsync()
|
||||
|
||||
'Wait for the data and cancel if requested
|
||||
receiveTask.Wait(ct)
|
||||
|
||||
Dim buf As Byte() = receiveTask.Result.Buffer
|
||||
Dim ip As String = receiveTask.Result.RemoteEndPoint.Address.ToString
|
||||
|
||||
doExit()
|
||||
|
||||
ProcessRetrivedData(ip, buf)
|
||||
|
||||
doExit()
|
||||
|
||||
StartInternal()
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub SendData(ep As IPEndPoint, buf As Byte())
|
||||
Dim udp As New UdpClient
|
||||
udp.Connect(ep)
|
||||
udp.Send(buf, buf.Length)
|
||||
udp.Client.Shutdown(SocketShutdown.Both)
|
||||
udp.Close()
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user