Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions MTApiService/MtServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ private bool InitHosts(int port)
return false;
}

// currently not supported with CoreWCF
////init local pipe host
//var localPipeUrl = CreateConnectionAddress(null, port, true);
//var localPipeServiceHost = CreateServiceHost(localPipeUrl, true);
//if (localPipeServiceHost != null)
//{
// _hosts.Add(localPipeServiceHost);
//}
//init local pipe host
var localPipeUrl = CreateConnectionAddress(null, port, true);
var localPipeServiceHost = CreateServiceHost(localPipeUrl, true);
if (localPipeServiceHost != null)
{
_hosts.Add(localPipeServiceHost);
}

//init localhost
var localUrl = CreateConnectionAddress("localhost", port, false);
Expand All @@ -78,24 +77,23 @@ private bool InitHosts(int port)
_hosts.Add(localServiceHost);
}

// currently not required for CoreWCF
////init network hosts
//var dnsHostName = Dns.GetHostName();
//var ips = Dns.GetHostEntry(dnsHostName);

//foreach (var ipAddress in ips.AddressList)
//{
// if (ipAddress?.AddressFamily == AddressFamily.InterNetwork)
// {
// var ip = ipAddress.ToString();
// var networkUrl = CreateConnectionAddress(ip, port, false);
// var serviceHost = CreateServiceHost(networkUrl, false);
// if (serviceHost != null)
// {
// _hosts.Add(serviceHost);
// }
// }
//}
//init network hosts
var dnsHostName = Dns.GetHostName();
var ips = Dns.GetHostEntry(dnsHostName);

foreach (var ipAddress in ips.AddressList)
{
if (ipAddress?.AddressFamily == AddressFamily.InterNetwork)
{
var ip = ipAddress.ToString();
var networkUrl = CreateConnectionAddress(ip, port, false);
var serviceHost = CreateServiceHost(networkUrl, false);
if (serviceHost != null)
{
_hosts.Add(serviceHost);
}
}
}

count = _hosts.Count;
}
Expand Down Expand Up @@ -124,7 +122,7 @@ private ServiceHost CreateServiceHost(string serverUrlAdress, bool local)
serviceHost.AddServiceEndpoint(typeof(IMtApi), binding, serverUrlAdress);
serviceHost.Open();
}
catch(Exception e)
catch (Exception e)
{
Log.ErrorFormat("CreateServiceHost: Error! {0}", e.Message);
serviceHost = null;
Expand Down
2 changes: 1 addition & 1 deletion MtApi5/MtApi5.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
Expand Down
7 changes: 4 additions & 3 deletions MtApiServiceNetCore/MtApiServiceNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
Expand Down Expand Up @@ -44,8 +44,9 @@
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.ServiceModel.Duplex" Version="4.10.0" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.10.0" />
<PackageReference Include="System.ServiceModel.Duplex" Version="6.0.0-preview1.23060.3" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="6.0.0-preview1.23060.3" />
<PackageReference Include="System.ServiceModel.NetNamedPipe" Version="6.0.0-preview1.23060.3" />
</ItemGroup>
<PropertyGroup />
</Project>
47 changes: 39 additions & 8 deletions MtApiServiceNetCore/MtClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ public sealed class MtClient : IMtApiCallback, IDisposable
#endregion

#region ctor
public MtClient(string host, int port)

private MtClient()
{
var quoteScheduler = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.AttachedToParent);
var eventScheduler = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.AttachedToParent);
lastQuoteTask = quoteScheduler.StartNew(() => { });
lastEventTask = eventScheduler.StartNew(() => { });
}

public MtClient(string host, int port): this()
{
if (string.IsNullOrEmpty(host))
throw new ArgumentNullException(nameof(host), "host is null or empty");
Expand Down Expand Up @@ -54,17 +63,39 @@ public MtClient(string host, int port)
}
};

var quoteScheduler = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.AttachedToParent);
var eventScheduler = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.AttachedToParent);
lastQuoteTask = quoteScheduler.StartNew(() => { });
lastEventTask = eventScheduler.StartNew(() => { });

_proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
_proxy.Faulted += ProxyFaulted;
}

public MtClient(int port) : this("localhost", port)
{ }
public MtClient(int port): this()
{
if (port < 0 || port > 65536)
throw new ArgumentOutOfRangeException(nameof(port), "port value is invalid");

Port = port;

var urlService = $"net.pipe://localhost/{ServiceName}_{port}";

var bind = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None)
{
MaxReceivedMessageSize = 2147483647,
MaxBufferSize = 2147483647,
MaxBufferPoolSize = 2147483647,
SendTimeout = new TimeSpan(12, 0, 0),
ReceiveTimeout = new TimeSpan(12, 0, 0),
ReaderQuotas =
{
MaxArrayLength = 2147483647,
MaxBytesPerRead = 2147483647,
MaxDepth = 2147483647,
MaxStringContentLength = 2147483647,
MaxNameTableCharCount = 2147483647
}
};

_proxy = new MtApiProxy(new InstanceContext(this), bind, new EndpointAddress(urlService));
_proxy.Faulted += ProxyFaulted;
}

#endregion

Expand Down
2 changes: 1 addition & 1 deletion MtApiServiceTest/MtApiServiceTest.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>

<IsPackable>false</IsPackable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Platforms>AnyCPU;x64</Platforms>
Expand Down
2 changes: 1 addition & 1 deletion TestClients/MtApi5TestClient/MtApi5TestClient.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Expand Down