-
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.
- Loading branch information
MultiPlug Hub
committed
Jan 22, 2021
1 parent
800c04f
commit 59b6d5b
Showing
35 changed files
with
1,577 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,63 @@ | ||
############################################################################### | ||
# Set default behavior to automatically normalize line endings. | ||
############################################################################### | ||
* text=auto | ||
|
||
############################################################################### | ||
# Set default behavior for command prompt diff. | ||
# | ||
# This is need for earlier builds of msysgit that does not have it on by | ||
# default for csharp files. | ||
# Note: This is only used by command line | ||
############################################################################### | ||
#*.cs diff=csharp | ||
|
||
############################################################################### | ||
# Set the merge driver for project and solution files | ||
# | ||
# Merging from the command prompt will add diff markers to the files if there | ||
# are conflicts (Merging from VS is not affected by the settings below, in VS | ||
# the diff markers are never inserted). Diff markers may cause the following | ||
# file extensions to fail to load in VS. An alternative would be to treat | ||
# these files as binary and thus will always conflict and require user | ||
# intervention with every merge. To do so, just uncomment the entries below | ||
############################################################################### | ||
#*.sln merge=binary | ||
#*.csproj merge=binary | ||
#*.vbproj merge=binary | ||
#*.vcxproj merge=binary | ||
#*.vcproj merge=binary | ||
#*.dbproj merge=binary | ||
#*.fsproj merge=binary | ||
#*.lsproj merge=binary | ||
#*.wixproj merge=binary | ||
#*.modelproj merge=binary | ||
#*.sqlproj merge=binary | ||
#*.wwaproj merge=binary | ||
|
||
############################################################################### | ||
# behavior for image files | ||
# | ||
# image files are treated as binary by default. | ||
############################################################################### | ||
#*.jpg binary | ||
#*.png binary | ||
#*.gif binary | ||
|
||
############################################################################### | ||
# diff behavior for common document formats | ||
# | ||
# Convert binary document formats to text before diffing them. This feature | ||
# is only available from the command line. Turn it on by uncommenting the | ||
# entries below. | ||
############################################################################### | ||
#*.doc diff=astextplain | ||
#*.DOC diff=astextplain | ||
#*.docx diff=astextplain | ||
#*.DOCX diff=astextplain | ||
#*.dot diff=astextplain | ||
#*.DOT diff=astextplain | ||
#*.pdf diff=astextplain | ||
#*.PDF diff=astextplain | ||
#*.rtf diff=astextplain | ||
#*.RTF diff=astextplain |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# MultiPlug.Ext.Network.SSDP | ||
Network SSDP (Simple Service Discovery Protocol) Extension for the MultiPlug .Net Edge Computing Platform | ||
|
||
More information about the MultiPlug .Net Edge Computing Platform at https://www.multiplug.app |
Binary file not shown.
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,29 @@ | ||
<?xml version="1.0"?> | ||
<package > | ||
<metadata> | ||
<id>MultiPlug.Ext.Network.SSDP</id> | ||
<version>1.0.1</version> | ||
<title>Simple Service Discovery Protocol Extension for the MultiPlug .Net Edge Computing Platform</title> | ||
<authors>MultiPlugHub</authors> | ||
<owners>MultiPlugHub</owners> | ||
<projectUrl>https://github.com/multiplug-hub/MultiPlug.Ext.Network.SSDP</projectUrl> | ||
<icon>images\multiplugico.png</icon> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<description>Discover devices on a network using Simple Service Discovery Protocol with this MultiPlug Extension</description> | ||
<license type="expression">MIT</license> | ||
<releaseNotes>1.0.1 First Release based on MultiPlug.Ext.Networks</releaseNotes> | ||
<copyright>MultiPlug Community</copyright> | ||
<tags>MultiPlug Edge_Computing IoT</tags> | ||
<dependencies> | ||
<group targetFramework=".NETFramework4.7.2"> | ||
<dependency id="MultiPlug.Base" version="1.0.52" /> | ||
<dependency id="MultiPlug.Extension.Core" version="1.0.59" /> | ||
<dependency id="MultiPlug.Core" version="2.2.68" /> | ||
</group> | ||
</dependencies> | ||
</metadata> | ||
<files> | ||
<file src="images\multiplugico.png" target="images\" /> | ||
<file src="..\..\src\MultiPlug.Ext.Network.SSDP\bin\Release\MultiPlug.Ext.Network.SSDP.dll" target="lib\net472" /> | ||
</files> | ||
</package> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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 @@ | ||
nuget.exe pack Nuget/MultiPlug.Ext.Network.SSDP.nuspec |
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,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25420.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiPlug.Ext.Network.SSDP", "MultiPlug.Ext.Network.SSDP\MultiPlug.Ext.Network.SSDP.csproj", "{AA4D5B0A-F87E-49AF-AE66-0EE7FEEC5937}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{AA4D5B0A-F87E-49AF-AE66-0EE7FEEC5937}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{AA4D5B0A-F87E-49AF-AE66-0EE7FEEC5937}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{AA4D5B0A-F87E-49AF-AE66-0EE7FEEC5937}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AA4D5B0A-F87E-49AF-AE66-0EE7FEEC5937}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
118 changes: 118 additions & 0 deletions
118
src/MultiPlug.Ext.Network.SSDP/Components/SimpleServiceDiscoveryProtocol/SSDPComponent.cs
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,118 @@ | ||
using System; | ||
using MultiPlug.Base.Exchange; | ||
using MultiPlug.Base.Exchange.API; | ||
using MultiPlug.Ext.Network.SSDP.Models.Components; | ||
|
||
namespace MultiPlug.Ext.Network.SSDP.Components.SimpleServiceDiscoveryProtocol | ||
{ | ||
public class SSDPComponent : SSDPProperties | ||
{ | ||
|
||
internal event Action EventsUpdated; | ||
internal event Action SubscriptionsUpdated; | ||
|
||
readonly ILoggingService m_LoggingService; | ||
|
||
private SSDPWorker m_SSDPWorker; | ||
|
||
public SSDPComponent(string theGuid, ILoggingService theLoggingService) | ||
{ | ||
m_LoggingService = theLoggingService; | ||
|
||
Guid = theGuid; | ||
DiscoveryTarget = ""; | ||
SearchSubscription = new Subscription { Guid = theGuid, Id = "" }; | ||
|
||
m_SSDPWorker = new SSDPWorker(this); | ||
m_SSDPWorker.DeviceDiscovered += OnDeviceDiscovered; | ||
SearchSubscription.EventConsumer = m_SSDPWorker; | ||
|
||
DiscoveryEvent = new Event | ||
{ | ||
Guid = theGuid, | ||
Id = "", | ||
Description = "", | ||
Subjects = new string[] | ||
{ | ||
"Location", | ||
"DeviceType", | ||
"FriendlyName", | ||
"Manufacturer", | ||
"ManufacturerURL", | ||
"ModelDescription", | ||
"ModelName", | ||
"ModelNumber", | ||
"UDN", | ||
"SerialNumber", | ||
"PresentationURL" } | ||
}; | ||
} | ||
|
||
public void UpdateProperties(SSDPProperties theProperties) | ||
{ | ||
bool EventUpdatedFlag = false; | ||
bool SubscriptionUpdatedFlag = false; | ||
|
||
if (theProperties.DiscoveryEvent.Id != DiscoveryEvent.Id) | ||
{ | ||
DiscoveryEvent.Id = theProperties.DiscoveryEvent.Id; | ||
EventUpdatedFlag = true; | ||
} | ||
|
||
if (theProperties.DiscoveryEvent.Description != DiscoveryEvent.Description) | ||
{ | ||
DiscoveryEvent.Description = theProperties.DiscoveryEvent.Description; | ||
EventUpdatedFlag = true; | ||
} | ||
|
||
if (theProperties.DiscoveryTarget != DiscoveryTarget) | ||
{ | ||
DiscoveryTarget = theProperties.DiscoveryTarget; | ||
} | ||
|
||
if (theProperties.SearchSubscription != null && theProperties.SearchSubscription.Id != SearchSubscription.Id) | ||
{ | ||
SearchSubscription.Id = theProperties.SearchSubscription.Id; | ||
SubscriptionUpdatedFlag = true; | ||
} | ||
|
||
|
||
|
||
/// | ||
/// ... | ||
/// | ||
|
||
if (EventUpdatedFlag) | ||
{ | ||
EventsUpdated?.Invoke(); | ||
} | ||
|
||
if( SubscriptionUpdatedFlag) | ||
{ | ||
SubscriptionsUpdated?.Invoke(); | ||
} | ||
} | ||
|
||
public void OnDeviceDiscovered( string theIPAddress, Device theDeviceDesription) | ||
{ | ||
DiscoveryEvent.Fire(new Payload | ||
( | ||
DiscoveryEvent.Id, | ||
new [] | ||
{ | ||
new PayloadSubject( DiscoveryEvent.Subjects[0], theIPAddress ), | ||
new PayloadSubject( DiscoveryEvent.Subjects[1], string.IsNullOrEmpty(theDeviceDesription.DeviceType)? string.Empty: theDeviceDesription.DeviceType ), | ||
new PayloadSubject( DiscoveryEvent.Subjects[2], string.IsNullOrEmpty(theDeviceDesription.FriendlyName)? string.Empty: theDeviceDesription.FriendlyName ), | ||
new PayloadSubject( DiscoveryEvent.Subjects[3], string.IsNullOrEmpty(theDeviceDesription.Manufacturer)? string.Empty: theDeviceDesription.Manufacturer ), | ||
new PayloadSubject( DiscoveryEvent.Subjects[4], string.IsNullOrEmpty(theDeviceDesription.ManufacturerURL)? string.Empty: theDeviceDesription.ManufacturerURL ), | ||
new PayloadSubject( DiscoveryEvent.Subjects[5], string.IsNullOrEmpty(theDeviceDesription.ModelDescription)? string.Empty: theDeviceDesription.ModelDescription ), | ||
new PayloadSubject( DiscoveryEvent.Subjects[6], string.IsNullOrEmpty(theDeviceDesription.ModelName)? string.Empty: theDeviceDesription.ModelName ), | ||
new PayloadSubject( DiscoveryEvent.Subjects[7], string.IsNullOrEmpty(theDeviceDesription.ModelNumber)? string.Empty: theDeviceDesription.ModelNumber ), | ||
new PayloadSubject( DiscoveryEvent.Subjects[8], string.IsNullOrEmpty(theDeviceDesription.UDN)? string.Empty: theDeviceDesription.UDN ), | ||
new PayloadSubject( DiscoveryEvent.Subjects[9], string.IsNullOrEmpty(theDeviceDesription.SerialNumber)? string.Empty: theDeviceDesription.SerialNumber ), | ||
new PayloadSubject( DiscoveryEvent.Subjects[10], string.IsNullOrEmpty(theDeviceDesription.PresentationURL)? string.Empty: theDeviceDesription.PresentationURL ) | ||
} | ||
)); | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/MultiPlug.Ext.Network.SSDP/Components/SimpleServiceDiscoveryProtocol/SSDPReceive.cs
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,82 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml.Serialization; | ||
using MultiPlug.Ext.Network.SSDP.Models.Components; | ||
|
||
namespace MultiPlug.Ext.Network.SSDP.Components.SimpleServiceDiscoveryProtocol | ||
{ | ||
public class SSDPReceive | ||
{ | ||
private IPAddress m_IpAddress; | ||
private UdpClient m_UdpClient; | ||
|
||
internal event Action<string, Device> DeviceDiscovered; | ||
|
||
public SSDPReceive(UdpClient theUdpClient, IPAddress theIPAddress) | ||
{ | ||
m_UdpClient = theUdpClient; | ||
m_IpAddress = theIPAddress; | ||
} | ||
|
||
public void BeginReceive() | ||
{ | ||
m_UdpClient.BeginReceive(Response, null); | ||
} | ||
|
||
private void Response(IAsyncResult ar) | ||
{ | ||
var remote = new IPEndPoint(m_IpAddress, 0); | ||
var bytes = m_UdpClient.EndReceive(ar, ref remote); | ||
|
||
var payload = Encoding.UTF8.GetString(bytes); | ||
|
||
string[] Lines = payload.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
|
||
int index = Array.FindIndex(Lines, v => v.StartsWith("ST:")); | ||
|
||
if (index != -1) | ||
{ | ||
string SearchTarget = Lines[index].Replace("ST:", "").Trim(); | ||
|
||
index = Array.FindIndex(Lines, v => v.StartsWith("LOCATION:")); | ||
|
||
if (index != -1) | ||
{ | ||
string LocationUrl = Lines[index].Replace("LOCATION:", "").Trim(); | ||
|
||
Task.Run(() => | ||
{ | ||
Lookup(LocationUrl); | ||
}); | ||
} | ||
} | ||
|
||
BeginReceive(); | ||
} | ||
|
||
private void Lookup(string m_Url) | ||
{ | ||
WebRequest request = WebRequest.Create(m_Url); | ||
using (WebResponse response = request.GetResponse()) | ||
{ | ||
try | ||
{ | ||
Stream dataStream = response.GetResponseStream(); | ||
StreamReader reader = new StreamReader(dataStream); | ||
XmlSerializer serializer = new XmlSerializer(typeof(SSDPDeviceDescription)); | ||
SSDPDeviceDescription deserialized = (SSDPDeviceDescription)serializer.Deserialize(reader); | ||
|
||
DeviceDiscovered?.Invoke(m_Url, deserialized.Device); | ||
} | ||
catch (Exception) | ||
{ | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.