diff options
| author | Roy <roy.mail.net@gmail.com> | 2017-12-24 02:27:16 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2017-12-24 02:27:16 +0200 |
| commit | 53db041e636bb3802dbe3cb911de6ef6ef41446c (patch) | |
| tree | 9be0b0961a31fea4a60f5a9c1741363fa313a13b /Software/Visual_Studio/Tango.Integration | |
| parent | ceac40d058a8554638aa3fa39d4697f3fbfe62f8 (diff) | |
| download | Tango-53db041e636bb3802dbe3cb911de6ef6ef41446c.tar.gz Tango-53db041e636bb3802dbe3cb911de6ef6ef41446c.zip | |
Continue for last commit.
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration')
7 files changed, 308 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Tango.Integration/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..161c5a04e --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Tango - Logging Library")] +[assembly: ComVisible(false)]
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeClient.cs b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeClient.cs new file mode 100644 index 000000000..1cbb6982a --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeClient.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.DAL.Observables; +using Tango.PMR.Integration; +using Tango.Settings; +using Tango.Transport; +using Tango.Transport.Adapters; +using Tango.Transport.Transporters; + +namespace Tango.Integration.Services +{ + public class ExternalBridgeClient : ProtoTransporter, IExternalBridgeClient + { + private String _serialNumber; + + public String SerialNumber + { + get { return _serialNumber; } + internal set + { + _serialNumber = value; + RaisePropertyChangedAuto(); + + var org = ObservablesEntitiesAdapter.Instance.Organizations.SingleOrDefault(x => x.Machines.ToList().Exists(y => y.SerialNumber == SerialNumber)); + Organization = org != null ? org.Name : "Unknown"; + } + } + + private String _ipAddress; + + public String IPAddress + { + get { return _ipAddress; } + set { _ipAddress = value; RaisePropertyChangedAuto(); } + } + + private String _organization; + + public String Organization + { + get { return _organization; } + private set { _organization = value; RaisePropertyChangedAuto(); } + } + + public override async Task Connect() + { + await Disconnect(); + Adapters.Clear(); + Adapters.Add(new TcpTransportAdapter(IPAddress, SettingsManager.Default.Integration.ExternalBridgeServicePort)); + await base.Connect(); + } + + public async Task<bool> Authenticate() + { + var response = await SendRequest<ExternalClientLoginRequest, ExternalClientLoginResponse>(new ExternalClientLoginRequest() { Key = "1234" }); + return response.Authenticated; + } + + public ExternalBridgeClient(String serialNumber,String ipAddress) + { + SerialNumber = serialNumber; + IPAddress = ipAddress; + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs new file mode 100644 index 000000000..fe7260a02 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Net; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Core.Helpers; +using Tango.Logging; +using Tango.PMR; +using Tango.PMR.Common; +using Tango.PMR.Integration; +using Tango.Settings; +using Tango.Transport.Adapters; + +namespace Tango.Integration.Services +{ + public class ExternalBridgeScanner : ExtendedObject + { + private Thread _discoveryThread; + + private ObservableCollection<IExternalBridgeClient> _availableMachines; + /// <summary> + /// Gets or sets the available services. + /// </summary> + public ObservableCollection<IExternalBridgeClient> AvailableMachines + { + get { return _availableMachines; } + private set { _availableMachines = value; RaisePropertyChangedAuto(); } + } + + private bool _isStarted; + /// <summary> + /// Gets or sets a value indicating whether this instance is started. + /// </summary> + public bool IsStarted + { + get { return _isStarted; } + private set { _isStarted = value; RaisePropertyChangedAuto(); } + } + + /// <summary> + /// Initializes a new instance of the <see cref="ExternalBridgeScanner"/> class. + /// </summary> + public ExternalBridgeScanner() + { + AvailableMachines = new ObservableCollection<IExternalBridgeClient>(); + } + + /// <summary> + /// Starts this instance. + /// </summary> + public void Start() + { + if (!IsStarted) + { + _discoveryThread = new Thread(DiscoveryThreadMethod); + _discoveryThread.IsBackground = true; + _discoveryThread.Start(); + } + } + + private void DiscoveryThreadMethod() + { + var Server = new UdpClient(8888); + + while (!IsStarted) + { + var ClientEp = new IPEndPoint(IPAddress.Any, 0); + var ClientRequestData = Server.Receive(ref ClientEp); + + ExternalBridgeUdpDiscoveryPacket packet = ExternalBridgeUdpDiscoveryPacket.Parser.ParseFrom(ClientRequestData); + + ExternalBridgeClient newMachine = new ExternalBridgeClient(packet.SerialNumber, ClientEp.Address.ToString()); + if (!AvailableMachines.ToList().Exists(x => x.SerialNumber == packet.SerialNumber)) + { + ThreadsHelper.InvokeUINow(() => + { + AvailableMachines.Add(newMachine); + }); + } + + Thread.Sleep(1000); + } + + Server.Close(); + } + + /// <summary> + /// Stops this instance. + /// </summary> + public void Stop() + { + if (IsStarted) + { + IsStarted = false; + } + } + + private void Client_StateChanged(object sender, Transport.TransportComponentState e) + { + if (e == Transport.TransportComponentState.Failed || e == Transport.TransportComponentState.Disposed) + { + AvailableMachines.Remove(sender as IExternalBridgeClient); + } + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeClient.cs b/Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeClient.cs new file mode 100644 index 000000000..6eb0ac5f9 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Services/IExternalBridgeClient.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport; +using Tango.Transport.Transporters; + +namespace Tango.Integration.Services +{ + public interface IExternalBridgeClient : ITransporter + { + String SerialNumber { get; } + + String Organization { get; } + + String IPAddress { get; set; } + + Task<bool> Authenticate(); + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj new file mode 100644 index 000000000..e07c5a90d --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{4206AC58-3B57-4699-8835-90BF6DB01A61}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Tango.Integration</RootNamespace> + <AssemblyName>Tango.Integration</AssemblyName> + <TargetFrameworkVersion>v4.6</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>..\Build\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Google.Protobuf, Version=3.4.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL"> + <HintPath>..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="..\Versioning\GlobalVersionInfo.cs"> + <Link>GlobalVersionInfo.cs</Link> + </Compile> + <Compile Include="Services\ExternalBridgeClient.cs" /> + <Compile Include="Services\ExternalBridgeScanner.cs" /> + <Compile Include="Services\IExternalBridgeClient.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\Tango.Core\Tango.Core.csproj"> + <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> + <Name>Tango.Core</Name> + </ProjectReference> + <ProjectReference Include="..\Tango.DAL.Observables\Tango.DAL.Observables.csproj"> + <Project>{0ecd6da8-7aa6-48d9-8b65-279d176ad9af}</Project> + <Name>Tango.DAL.Observables</Name> + </ProjectReference> + <ProjectReference Include="..\Tango.Logging\Tango.Logging.csproj"> + <Project>{bc932dbd-7cdb-488c-99e4-f02cf441f55e}</Project> + <Name>Tango.Logging</Name> + </ProjectReference> + <ProjectReference Include="..\Tango.PMR\Tango.PMR.csproj"> + <Project>{E4927038-348D-4295-AAF4-861C58CB3943}</Project> + <Name>Tango.PMR</Name> + </ProjectReference> + <ProjectReference Include="..\Tango.Settings\Tango.Settings.csproj"> + <Project>{d8f1ad85-526a-4f50-b6dc-d437af63d8d8}</Project> + <Name>Tango.Settings</Name> + </ProjectReference> + <ProjectReference Include="..\Tango.Transport\Tango.Transport.csproj"> + <Project>{74e700b0-1156-4126-be40-ee450d3c3026}</Project> + <Name>Tango.Transport</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <None Include="app.config" /> + <None Include="packages.config" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> +</Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Integration/app.config b/Software/Visual_Studio/Tango.Integration/app.config new file mode 100644 index 000000000..cacd4cd77 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/app.config @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="System.Reactive.Core" publicKeyToken="94bc3704cddfc263" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" /> + </dependentAssembly> + </assemblyBinding> + </runtime> +</configuration>
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Integration/packages.config b/Software/Visual_Studio/Tango.Integration/packages.config new file mode 100644 index 000000000..6d9929c06 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Google.Protobuf" version="3.4.1" targetFramework="net46" /> +</packages>
\ No newline at end of file |
