Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net5.0 update #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
Binary file added .vs/NamedPipeWrapper/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
6 changes: 4 additions & 2 deletions NamedPipeWrapper/IO/PipeStreamReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
Expand Down Expand Up @@ -68,7 +69,8 @@ private T ReadObject(int len)
BaseStream.Read(data, 0, len);
using (var memoryStream = new MemoryStream(data))
{
return (T) _binaryFormatter.Deserialize(memoryStream);
return Serializer.Deserialize<T>(memoryStream);
//return (T) _binaryFormatter.Deserialize(memoryStream);
}
}

Expand Down
6 changes: 4 additions & 2 deletions NamedPipeWrapper/IO/PipeStreamWriter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -41,11 +42,12 @@ private byte[] Serialize(T obj)
{
using (var memoryStream = new MemoryStream())
{
_binaryFormatter.Serialize(memoryStream, obj);
Serializer.Serialize(memoryStream, obj);
//_binaryFormatter.Serialize(memoryStream, obj);
return memoryStream.ToArray();
}
}
catch
catch (Exception ex)
{
//if any exception in the serialize, it will stop named pipe wrapper, so there will ignore any exception.
return null;
Expand Down
7 changes: 5 additions & 2 deletions NamedPipeWrapper/NamedPipeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public NamedPipeClient(string pipeName,string serverName)
AutoReconnect = true;
}



/// <summary>
/// Connects to the named pipe server asynchronously.
/// This method returns immediately, possibly before the connection has been established.
Expand All @@ -89,9 +91,10 @@ public void Start()
_closedExplicitly = false;
var worker = new Worker();
worker.Error += OnError;
worker.DoWork(ListenSync);
worker.DoWork(ListenSync, CancellationToken.None);
}


/// <summary>
/// Sends a message to the server over a named pipe.
/// </summary>
Expand Down Expand Up @@ -225,7 +228,7 @@ public static NamedPipeClientStream CreateAndConnectPipe(string pipeName, string

private static NamedPipeClientStream CreatePipe(string pipeName,string serverName)
{
return new NamedPipeClientStream(serverName, pipeName, PipeDirection.InOut, PipeOptions.Asynchronous | PipeOptions.WriteThrough);
return new NamedPipeClientStream(serverName, pipeName, PipeDirection.InOut, PipeOptions.Asynchronous | PipeOptions.WriteThrough, System.Security.Principal.TokenImpersonationLevel.None);
}
}
}
4 changes: 2 additions & 2 deletions NamedPipeWrapper/NamedPipeConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public void Open()
var readWorker = new Worker();
readWorker.Succeeded += OnSucceeded;
readWorker.Error += OnError;
readWorker.DoWork(ReadPipe);
readWorker.DoWork(ReadPipe, CancellationToken.None);

var writeWorker = new Worker();
writeWorker.Succeeded += OnSucceeded;
writeWorker.Error += OnError;
writeWorker.DoWork(WritePipe);
writeWorker.DoWork(WritePipe, CancellationToken.None);
}

/// <summary>
Expand Down
42 changes: 32 additions & 10 deletions NamedPipeWrapper/NamedPipeServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
using System;
using System.Collections.Generic;
using System.IO.Pipes;

using System.Threading;

namespace NamedPipeWrapper
{
/// <summary>
Expand All @@ -27,7 +28,8 @@ public NamedPipeServer(string pipeName)
/// <param name="pipeName">Name of the pipe to listen on</param>
public NamedPipeServer(string pipeName, PipeSecurity pipeSecurity)
: base(pipeName, pipeSecurity)
{
{

}
}

Expand Down Expand Up @@ -84,11 +86,20 @@ public Server(string pipeName, PipeSecurity pipeSecurity)
/// This method returns immediately.
/// </summary>
public void Start()
{
Start(CancellationToken.None);
}

/// <summary>
/// Begins listening for client connections in a separate background thread.
/// This method returns immediately.
/// </summary>
public void Start(CancellationToken stoppingToken)
{
_shouldKeepRunning = true;
var worker = new Worker();
worker.Error += OnError;
worker.DoWork(ListenSync);
worker.DoWork(() => ListenSync(stoppingToken), stoppingToken);
}

/// <summary>
Expand Down Expand Up @@ -139,6 +150,7 @@ public void Stop()
}
}


// If background thread is still listening for a client to connect,
// initiate a dummy connection that will allow the thread to exit.
//dummy connection will use the local server name.
Expand All @@ -151,11 +163,14 @@ public void Stop()

#region Private methods

private void ListenSync()
private void ListenSync(CancellationToken stoppingToken)
{
_isRunning = true;
while (_shouldKeepRunning)
{
if (stoppingToken.IsCancellationRequested)
Stop();

WaitForConnection(_pipeName, _pipeSecurity);
}
_isRunning = false;
Expand Down Expand Up @@ -276,11 +291,18 @@ public static NamedPipeServerStream CreateAndConnectPipe(string pipeName, PipeSe
var pipe = CreatePipe(pipeName, pipeSecurity);
pipe.WaitForConnection();
return pipe;
}
}


public static NamedPipeServerStream CreatePipe(string pipeName, PipeSecurity pipeSecurity)
{
return new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, 0, 0, pipeSecurity);
}
}
}
{
//return new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, 0, 0, pipeSecurity);

// NOTE: we use the old framework version package to call into the NamedPipeServerStream constructor that allows
// PipeSecurity to be passed in. It is a known issue that .net core does not support the pipesecurity param
// as it's based upon native windows functionality and is not supported cross platform. Using the package
// is a successful workaround to set the pipe's security.
return NamedPipeServerStreamConstructors.New(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, 0, 0, pipeSecurity);
}
}
}
26 changes: 26 additions & 0 deletions NamedPipeWrapper/NamedPipeWrapper - Backup.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<OutputType>Library</OutputType>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DocumentationFile>bin\Debug\NamedPipeWrapper.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<Reference Include="System.IO.Pipes.AccessControl" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="NamedPipeServerStream.NetFrameworkVersion">
<Version>1.0.2</Version>
</PackageReference>
<PackageReference Include="System.IO.Pipes.AccessControl">
<Version>4.5.1</Version>
</PackageReference>
</ItemGroup>

</Project>
80 changes: 19 additions & 61 deletions NamedPipeWrapper/NamedPipeWrapper.csproj
Original file line number Diff line number Diff line change
@@ -1,62 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{73152691-3CDE-46DF-8D04-7117747DFFE7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NamedPipeWrapper</RootNamespace>
<AssemblyName>NamedPipeWrapper</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</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>
<DocumentationFile>bin\Debug\NamedPipeWrapper.XML</DocumentationFile>
</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="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="NamedPipeClient.cs" />
<Compile Include="NamedPipeConnection.cs" />
<Compile Include="IO\PipeStreamReader.cs" />
<Compile Include="IO\PipeStreamWrapper.cs" />
<Compile Include="IO\PipeStreamWriter.cs" />
<Compile Include="PipeExceptionEventHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="NamedPipeServer.cs" />
<Compile Include="Threading\Worker.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<OutputType>Library</OutputType>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DocumentationFile>bin\Debug\NamedPipeWrapper.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NamedPipeServerStream.NetFrameworkVersion" Version="1.0.8" />
<PackageReference Include="protobuf-net" Version="3.0.101" />
<PackageReference Include="System.IO.Pipes.AccessControl" Version="5.0.0" />
</ItemGroup>
<Import Project="$(SolutionDir)\BuildCommon.targets" />
</Project>
62 changes: 62 additions & 0 deletions NamedPipeWrapper/NamedPipeWrapper.csproj.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{73152691-3CDE-46DF-8D04-7117747DFFE7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NamedPipeWrapper</RootNamespace>
<AssemblyName>NamedPipeWrapper</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</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>
<DocumentationFile>bin\Debug\NamedPipeWrapper.XML</DocumentationFile>
</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="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="NamedPipeClient.cs" />
<Compile Include="NamedPipeConnection.cs" />
<Compile Include="IO\PipeStreamReader.cs" />
<Compile Include="IO\PipeStreamWrapper.cs" />
<Compile Include="IO\PipeStreamWriter.cs" />
<Compile Include="PipeExceptionEventHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="NamedPipeServer.cs" />
<Compile Include="Threading\Worker.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
6 changes: 6 additions & 0 deletions NamedPipeWrapper/NamedPipeWrapper.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>E:\git\undigital\named-pipe-wrapper\NamedPipeWrapper\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
10 changes: 3 additions & 7 deletions NamedPipeWrapper/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Named Pipe Wrapper library")]
[assembly: AssemblyDescription("A simple, easy to use, strongly-typed wrapper around .NET named pipes.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NamedPipeWrapper")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyCopyright("Copyright © 2019 - 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +28,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
//[assembly: AssemblyVersion("1.4.0.0")]
//[assembly: AssemblyFileVersion("1.4.0.0")]
12 changes: 12 additions & 0 deletions NamedPipeWrapper/Properties/PublishProfiles/FolderProfile.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net472\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
Loading