Permalink
Browse files

initial commit

  • Loading branch information...
cbries committed Sep 2, 2017
1 parent 0a89fd1 commit 9628e014c69060fd4c26ba84b72a287e028e2a52
Showing 696 changed files with 99,835 additions and 38 deletions.
@@ -0,0 +1,89 @@
<?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>{8C4A1922-3BAB-4F3E-B5A4-3FB906F97BC2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Communicator</RootNamespace>
<AssemblyName>Communicator</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>bin\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>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="LiteGuard, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LiteGuard.1.1.0\lib\net35\LiteGuard.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="Connector.cs" />
<Compile Include="ICommandStation.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="License.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Ecos2Core\Ecos2Core.csproj">
<Project>{5E022579-45A1-4E6F-94DB-1C88E089030D}</Project>
<Name>Ecos2Core</Name>
</ProjectReference>
<ProjectReference Include="..\RailwayEssentialCore\RailwayEssentialCore.csproj">
<Project>{b80cfecd-db0b-4533-aa42-784b2ebe85ff}</Project>
<Name>RailwayEssentialCore</Name>
</ProjectReference>
<ProjectReference Include="..\ThirdParty\Telnet-master\PrimS.Telnet.NetStandard\PrimS.Telnet.NetStandard.csproj">
<Project>{09c8914d-4e27-4f10-bc62-31a68484a661}</Project>
<Name>PrimS.Telnet.NetStandard</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
View
@@ -0,0 +1,161 @@
/*
* MIT License
*
* Copyright (c) 2017 Dr. Christian Benjamin Ries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
using System;
using System.Threading;
using System.Threading.Tasks;
using Ecos2Core;
using PrimS.Telnet;
using RailwayEssentialCore;
using ThreadState = System.Threading.ThreadState;
namespace Communicator
{
public delegate void StartedDelegator(object sender);
public delegate void FailedDelegator(object sender, string message);
public delegate void StoppedDelegator(object sender);
public delegate void MessageReceivedDelegator(object sender, string msg);
public class Connector
{
public event StartedDelegator Started;
public event FailedDelegator Failed;
public event StoppedDelegator Stopped;
public event MessageReceivedDelegator MessageReceived;
public ILogging Logger { get; set; }
public IConfiguration Cfg { get; set; }
private string IpAddr { get { return Cfg.IpAddress; } }
private UInt16 Port { get { return Cfg.Port; } }
private bool _run = false;
private Thread _thread = null;
private Client _clientConnection;
public async Task<bool> SendMessage(string msg)
{
if (string.IsNullOrEmpty(msg))
return false;
if (_clientConnection == null)
return false;
if (_clientConnection.IsConnected)
await _clientConnection.WriteLine(msg.Trim());
return false;
}
public bool Start()
{
if (_thread != null && _thread.IsAlive)
return true;
_thread = new Thread(async () =>
{
Thread.CurrentThread.IsBackground = true;
await StartHandler();
});
_thread.Start();
_run = _thread.ThreadState == ThreadState.Running || _thread.ThreadState == ThreadState.Background;
if(_run)
return true;
try
{
_thread.Abort(null);
_thread = null;
}
catch
{
// ignore
}
return false;
}
public bool Stop()
{
_run = false;
return true;
}
private async Task StartHandler()
{
string ipaddr = IpAddr;
int port = Port;
try
{
using (_clientConnection = new Client(new TcpByteStream(ipaddr, port), new CancellationToken()))
{
if (_clientConnection.IsConnected)
{
if (Logger != null)
Logger.Log("<Connector> Connection established\r\n");
if (Started != null)
Started(this);
}
else
{
if (Logger != null)
Logger.LogError("<Connector> Connection failed\r\n");
if (Failed != null)
Failed(this, "Connection failed");
}
while (_run)
{
var msg = await _clientConnection.TerminatedReadAsync("\r\n", TimeSpan.FromMilliseconds(2500));
if (!string.IsNullOrEmpty(msg))
{
if (Logger != null)
Logger.Log($"<Connector> Message received, Length: {msg.Length}\r\n");
if (MessageReceived != null)
MessageReceived(this, msg);
}
}
if (Stopped != null)
Stopped(this);
}
}
catch (Exception ex)
{
if (Failed != null)
Failed(this, ex.Message);
}
}
}
}
@@ -0,0 +1,41 @@
/*
* MIT License
*
* Copyright (c) 2017 Dr. Christian Benjamin Ries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Communicator
{
public delegate void ConnectedDelegator(object sender);
public delegate void DisconnectedDelegator(object sender);
public delegate void FailureDelegator(object sender);
interface ICommandStation
{
event ConnectedDelegator Connected;
event DisconnectedDelegator Disconnected;
event FailureDelegator Failure;
string Name { get; set; }
bool Connect();
bool Disconnect();
}
}
View
@@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright (c) Telnet contributors. (Telnet@prims.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Communicator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Dr. C.B.Ries")]
[assembly: AssemblyProduct("RailwayEssential")]
[assembly: AssemblyCopyright("Copyright © 2017 Dr. C.B.Ries")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("8c4a1922-3bab-4f3e-b5a4-3fb906f97bc2")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LiteGuard" version="1.1.0" targetFramework="net46" />
<package id="Telnet" version="0.8.0" targetFramework="net46" />
</packages>
Oops, something went wrong.

0 comments on commit 9628e01

Please sign in to comment.