-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial code commit, forked from: https://github.com/Konard/LinksPlat…
- Loading branch information
Showing
11 changed files
with
460 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Description>LinksPlatform's Platform.Communication Class Library</Description> | ||
<Copyright>Konstantin Diachenko</Copyright> | ||
<AssemblyTitle>Platform.Communication</AssemblyTitle> | ||
<VersionPrefix>0.1.0</VersionPrefix> | ||
<Authors>Konstantin Diachenko</Authors> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<AssemblyName>Platform.Communication</AssemblyName> | ||
<PackageId>Platform.Communication</PackageId> | ||
<PackageTags>Communication;Protocols;Gexf;Udp;UdpSender;UdpReceiver</PackageTags> | ||
<PackageIconUrl>https://raw.githubusercontent.com/linksplatform/Documentation/18469f4d033ee9a5b7b84caab9c585acab2ac519/doc/Avatar-rainbow-icon-64x64.png</PackageIconUrl> | ||
<PackageProjectUrl>https://github.com/linksplatform/Communication</PackageProjectUrl> | ||
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>git://github.com/linksplatform/Communication</RepositoryUrl> | ||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Platform.Threading" Version="0.0.3" /> | ||
<PackageReference Include="Platform.Helpers" Version="0.1.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29102.190 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Platform.Communication", "Platform.Communication.csproj", "{8B98EB46-0A79-45F7-AD16-CA7C17F1452C}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{8B98EB46-0A79-45F7-AD16-CA7C17F1452C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8B98EB46-0A79-45F7-AD16-CA7C17F1452C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8B98EB46-0A79-45F7-AD16-CA7C17F1452C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8B98EB46-0A79-45F7-AD16-CA7C17F1452C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {98DDC0A8-01B8-4DF5-8EB7-74AA61EADDCE} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Globalization; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
|
||
namespace Platform.Communication.Protocol.Gexf | ||
{ | ||
public class Edge | ||
{ | ||
public const string ElementName = "edge"; | ||
public const string IdAttributeName = "id"; | ||
public const string SourceAttributeName = "source"; | ||
public const string TargetAttributeName = "target"; | ||
public const string LabelAttributeName = "label"; | ||
|
||
[XmlAttribute(AttributeName = IdAttributeName)] | ||
public long Id { get; set; } | ||
|
||
[XmlAttribute(AttributeName = SourceAttributeName)] | ||
public long Source { get; set; } | ||
|
||
[XmlAttribute(AttributeName = TargetAttributeName)] | ||
public long Target { get; set; } | ||
|
||
[XmlAttribute(AttributeName = LabelAttributeName)] | ||
public string Label { get; set; } | ||
|
||
public void WriteXml(XmlWriter writer) => WriteXml(writer, Id, Source, Target, Label); | ||
|
||
public static void WriteXml(XmlWriter writer, long id, long sourceNodeId, long targetNodeId, string label = null) | ||
{ | ||
// <edge id="0" source="0" target="0" label="..." /> | ||
writer.WriteStartElement(ElementName); | ||
|
||
writer.WriteAttributeString(IdAttributeName, id.ToString(CultureInfo.InvariantCulture)); | ||
writer.WriteAttributeString(SourceAttributeName, sourceNodeId.ToString(CultureInfo.InvariantCulture)); | ||
writer.WriteAttributeString(TargetAttributeName, targetNodeId.ToString(CultureInfo.InvariantCulture)); | ||
if (!string.IsNullOrWhiteSpace(label)) | ||
writer.WriteAttributeString(LabelAttributeName, label); | ||
|
||
writer.WriteEndElement(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Xml.Serialization; | ||
|
||
namespace Platform.Communication.Protocol.Gexf | ||
{ | ||
public enum GraphMode | ||
{ | ||
[XmlEnum(Name = "static")] | ||
Static, | ||
|
||
[XmlEnum(Name = "dynamic")] | ||
Dynamic | ||
} | ||
|
||
public enum GraphDefaultEdgeType | ||
{ | ||
[XmlEnum(Name = "directed")] | ||
Directed | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
|
||
namespace Platform.Communication.Protocol.Gexf | ||
{ | ||
[XmlRoot(ElementName = ElementName, Namespace = Namespace)] | ||
public class Gexf | ||
{ | ||
public const string ElementName = "gexf"; | ||
public const string Namespace = "http://www.gexf.net/1.2draft"; | ||
public const string VersionAttributeName = "version"; | ||
public const string GraphElementName = "graph"; | ||
public const string CurrentVersion = "1.2"; | ||
|
||
[XmlAttribute(AttributeName = VersionAttributeName)] | ||
public string Version { get; set; } | ||
|
||
[XmlElement(ElementName = GraphElementName)] | ||
public Graph Graph { get; set; } | ||
|
||
public Gexf() | ||
{ | ||
Version = CurrentVersion; | ||
Graph = new Graph(); | ||
} | ||
|
||
public void WriteXml(XmlWriter writer) | ||
{ | ||
void writeGraph() => Graph.WriteXml(writer); | ||
|
||
WriteXml(writer, writeGraph, Version); | ||
} | ||
|
||
public static void WriteXml(XmlWriter writer, Action writeGraph, string version = CurrentVersion) | ||
{ | ||
writer.WriteStartDocument(); | ||
writer.WriteStartElement(ElementName, Namespace); | ||
writer.WriteAttributeString(VersionAttributeName, version); | ||
|
||
writeGraph(); | ||
|
||
writer.WriteEndElement(); | ||
writer.WriteEndDocument(); | ||
} | ||
|
||
public static void WriteXml(XmlWriter writer, Action writeNodes, Action writeEdges, string version = CurrentVersion, | ||
GraphMode mode = GraphMode.Static, GraphDefaultEdgeType defaultEdgeType = GraphDefaultEdgeType.Directed) | ||
{ | ||
WriteXml(writer, () => Graph.WriteXml(writer, writeNodes, writeEdges, mode, defaultEdgeType), version); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
|
||
namespace Platform.Communication.Protocol.Gexf | ||
{ | ||
public class Graph | ||
{ | ||
public const string ElementName = "graph"; | ||
public const string ModeAttributeName = "mode"; | ||
public const string DefaultEdgeTypeAttributeName = "defaultedgetype"; | ||
public const string NodesElementName = "nodes"; | ||
public const string NodeElementName = "node"; | ||
public const string EdgesElementName = "edges"; | ||
public const string EdgeElementName = "edge"; | ||
|
||
[XmlAttribute(AttributeName = ModeAttributeName)] | ||
public GraphMode Mode { get; set; } | ||
|
||
[XmlAttribute(AttributeName = DefaultEdgeTypeAttributeName)] | ||
public GraphDefaultEdgeType DefaultEdgeType { get; set; } | ||
|
||
[XmlArray(ElementName = NodesElementName)] | ||
[XmlArrayItem(ElementName = NodeElementName)] | ||
public List<Node> Nodes { get; set; } | ||
|
||
[XmlArray(ElementName = EdgesElementName)] | ||
[XmlArrayItem(ElementName = EdgeElementName)] | ||
public List<Edge> Edges { get; set; } | ||
|
||
public Graph() | ||
{ | ||
Nodes = new List<Node>(); | ||
Edges = new List<Edge>(); | ||
} | ||
|
||
public void WriteXml(XmlWriter writer) | ||
{ | ||
void writeNodes() | ||
{ | ||
for (var i = 0; i < Nodes.Count; i++) | ||
Nodes[i].WriteXml(writer); | ||
} | ||
|
||
void writeEdges() | ||
{ | ||
for (var i = 0; i < Edges.Count; i++) | ||
Edges[i].WriteXml(writer); | ||
} | ||
|
||
WriteXml(writer, writeNodes, writeEdges, Mode, DefaultEdgeType); | ||
} | ||
|
||
public static void WriteXml(XmlWriter writer, Action writeNodes, Action writeEdges, GraphMode mode = GraphMode.Static, GraphDefaultEdgeType defaultEdgeType = GraphDefaultEdgeType.Directed) | ||
{ | ||
writer.WriteStartElement(ElementName); | ||
|
||
writer.WriteAttributeString(ModeAttributeName, mode.ToString().ToLower()); | ||
writer.WriteAttributeString(DefaultEdgeTypeAttributeName, defaultEdgeType.ToString().ToLower()); | ||
|
||
writer.WriteStartElement(NodesElementName); | ||
|
||
writeNodes(); | ||
|
||
writer.WriteEndElement(); | ||
|
||
writer.WriteStartElement(EdgesElementName); | ||
|
||
writeEdges(); | ||
|
||
writer.WriteEndElement(); | ||
|
||
writer.WriteEndElement(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Globalization; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
|
||
namespace Platform.Communication.Protocol.Gexf | ||
{ | ||
public class Node | ||
{ | ||
public const string ElementName = "node"; | ||
public const string IdAttributeName = "id"; | ||
public const string LabelAttributeName = "label"; | ||
|
||
[XmlAttribute(AttributeName = IdAttributeName)] | ||
public long Id { get; set; } | ||
|
||
[XmlAttribute(AttributeName = LabelAttributeName)] | ||
public string Label { get; set; } | ||
|
||
public void WriteXml(XmlWriter writer) => WriteXml(writer, Id, Label); | ||
|
||
public static void WriteXml(XmlWriter writer, long id, string label) | ||
{ | ||
// <node id="0" label="..." /> | ||
writer.WriteStartElement(ElementName); | ||
|
||
writer.WriteAttributeString(IdAttributeName, id.ToString(CultureInfo.InvariantCulture)); | ||
writer.WriteAttributeString(LabelAttributeName, label); | ||
|
||
writer.WriteEndElement(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using Platform.Threading; | ||
using Platform.Helpers; | ||
|
||
namespace Platform.Communication.Protocol.Udp | ||
{ | ||
public static class UdpClientExtensions | ||
{ | ||
private static readonly Encoding DefaultEncoding = Singleton.Get(() => Encoding.GetEncoding(0)); | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static int SendString(this UdpClient udp, IPEndPoint ipEndPoint, string message) | ||
{ | ||
var bytes = DefaultEncoding.GetBytes(message); | ||
return udp.SendAsync(bytes, bytes.Length, ipEndPoint).AwaitResult(); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static string ReceiveString(this UdpClient udp) => DefaultEncoding.GetString(udp.ReceiveAsync().AwaitResult().Buffer); | ||
} | ||
} |
Oops, something went wrong.