not working
This commit is contained in:
14
Vector3Visualizer/DebugVisualizer/DebugVisualizer.csproj
Normal file
14
Vector3Visualizer/DebugVisualizer/DebugVisualizer.csproj
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\NamedPipes\NamedPipes.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
2
Vector3Visualizer/DebugVisualizer/Program.cs
Normal file
2
Vector3Visualizer/DebugVisualizer/Program.cs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
var pipeServer = new NamedPipes.Receiver();
|
||||||
|
pipeServer.Start();
|
||||||
7
Vector3Visualizer/NamedPipes/NamedPipes.csproj
Normal file
7
Vector3Visualizer/NamedPipes/NamedPipes.csproj
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
23
Vector3Visualizer/NamedPipes/ReadFileToStream.cs
Normal file
23
Vector3Visualizer/NamedPipes/ReadFileToStream.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace NamedPipes
|
||||||
|
{
|
||||||
|
// Contains the method executed in the context of the impersonated user
|
||||||
|
public class ReadFileToStream
|
||||||
|
{
|
||||||
|
private readonly string fn;
|
||||||
|
private readonly StreamString ss;
|
||||||
|
|
||||||
|
public ReadFileToStream(StreamString str, string filename)
|
||||||
|
{
|
||||||
|
fn = filename;
|
||||||
|
ss = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
string contents = File.ReadAllText(fn);
|
||||||
|
ss.WriteString(contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
65
Vector3Visualizer/NamedPipes/Receiver.cs
Normal file
65
Vector3Visualizer/NamedPipes/Receiver.cs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Pipes;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace NamedPipes
|
||||||
|
{
|
||||||
|
|
||||||
|
public class Receiver
|
||||||
|
{
|
||||||
|
public readonly static string PipeName = "testpipe";
|
||||||
|
public Receiver()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~Receiver()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var pipeServer = new NamedPipeServerStream(PipeName, PipeDirection.InOut);
|
||||||
|
int threadId = Thread.CurrentThread.ManagedThreadId;
|
||||||
|
|
||||||
|
// Wait for a client to connect
|
||||||
|
pipeServer.WaitForConnection();
|
||||||
|
Console.WriteLine($"Client connected on thread[{threadId}].");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Read the request from the client. Once the client has
|
||||||
|
// written to the pipe its security token will be available.
|
||||||
|
|
||||||
|
StreamString stream = new StreamString(pipeServer);
|
||||||
|
|
||||||
|
// Verify our identity to the connected client using a
|
||||||
|
// string that the client anticipates.
|
||||||
|
|
||||||
|
stream.WriteString("I am the one true server!");
|
||||||
|
string message = stream.ReadString();
|
||||||
|
Console.WriteLine($"Received: {message}");
|
||||||
|
|
||||||
|
|
||||||
|
// Read in the contents of the file while impersonating the client.
|
||||||
|
//ReadFileToStream fileReader = new ReadFileToStream(ss, filename);
|
||||||
|
|
||||||
|
// Display the name of the user we are impersonating.
|
||||||
|
//Console.WriteLine($"Reading file: {filename} on thread[{threadId}] as user: {pipeServer.GetImpersonationUserName()}.");
|
||||||
|
//pipeServer.RunAsClient(fileReader.Start);
|
||||||
|
}
|
||||||
|
// Catch the IOException that is raised if the pipe is broken
|
||||||
|
// or disconnected.
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"ERROR: {e.Message}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
pipeServer.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
40
Vector3Visualizer/NamedPipes/Sender.cs
Normal file
40
Vector3Visualizer/NamedPipes/Sender.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO.Pipes;
|
||||||
|
using System.Security.Principal;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
|
||||||
|
namespace NamedPipes
|
||||||
|
{
|
||||||
|
public class Sender
|
||||||
|
{
|
||||||
|
public Sender() { }
|
||||||
|
public void SendMessage(string message)
|
||||||
|
{
|
||||||
|
var pipeClient = new NamedPipeClientStream(".", Receiver.PipeName, PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation);
|
||||||
|
Console.WriteLine("Connecting to server...\n");
|
||||||
|
pipeClient.Connect(5000);
|
||||||
|
Console.WriteLine("Connected.\n");
|
||||||
|
|
||||||
|
var ss = new StreamString(pipeClient);
|
||||||
|
// Validate the server's signature string.
|
||||||
|
if (ss.ReadString() == "I am the one true server!")
|
||||||
|
{
|
||||||
|
// The client security token is sent with the first write.
|
||||||
|
// Send the name of the file whose contents are returned
|
||||||
|
// by the server.
|
||||||
|
ss.WriteString(message);
|
||||||
|
|
||||||
|
// Print the file to the screen.
|
||||||
|
Console.Write(ss.ReadString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Server could not be verified.");
|
||||||
|
}
|
||||||
|
pipeClient.Dispose();
|
||||||
|
// Give the client process some time to display results before exiting.
|
||||||
|
Thread.Sleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
47
Vector3Visualizer/NamedPipes/StreamString.cs
Normal file
47
Vector3Visualizer/NamedPipes/StreamString.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
|
||||||
|
namespace NamedPipes
|
||||||
|
{
|
||||||
|
// Defines the data protocol for reading and writing strings on our stream.
|
||||||
|
public class StreamString
|
||||||
|
{
|
||||||
|
private readonly Stream ioStream;
|
||||||
|
private readonly UnicodeEncoding streamEncoding;
|
||||||
|
|
||||||
|
public StreamString(Stream ioStream)
|
||||||
|
{
|
||||||
|
this.ioStream = ioStream;
|
||||||
|
streamEncoding = new UnicodeEncoding();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ReadString()
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
len = ioStream.ReadByte() * 256;
|
||||||
|
len += ioStream.ReadByte();
|
||||||
|
var inBuffer = new byte[len];
|
||||||
|
ioStream.Read(inBuffer, 0, len);
|
||||||
|
|
||||||
|
return streamEncoding.GetString(inBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int WriteString(string outString)
|
||||||
|
{
|
||||||
|
byte[] outBuffer = streamEncoding.GetBytes(outString);
|
||||||
|
int len = outBuffer.Length;
|
||||||
|
if (len > UInt16.MaxValue)
|
||||||
|
{
|
||||||
|
len = (int)UInt16.MaxValue;
|
||||||
|
}
|
||||||
|
ioStream.WriteByte((byte)(len / 256));
|
||||||
|
ioStream.WriteByte((byte)(len & 255));
|
||||||
|
ioStream.Write(outBuffer, 0, len);
|
||||||
|
ioStream.Flush();
|
||||||
|
|
||||||
|
return outBuffer.Length + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
<Solution>
|
<Solution>
|
||||||
|
<Folder Name="/NamedPipes/">
|
||||||
|
<Project Path="DebugVisualizer/DebugVisualizer.csproj" Id="c81154ef-d854-4f1e-9d14-2cf674885291" />
|
||||||
|
<Project Path="NamedPipes/NamedPipes.csproj" Id="8d7b1151-8b57-4411-a361-47ed9c504a22" />
|
||||||
|
</Folder>
|
||||||
<Project Path="Vector3Visualizer/Vector3Visualizer.csproj" />
|
<Project Path="Vector3Visualizer/Vector3Visualizer.csproj" />
|
||||||
<Project Path="Vector3VisualizerSource/Vector3VisualizerSource.csproj" />
|
<Project Path="Vector3VisualizerSource/Vector3VisualizerSource.csproj" />
|
||||||
<Project Path="Vector3VisualizerTest/Test.csproj" />
|
<Project Path="Vector3VisualizerTest/Test.csproj" />
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using Microsoft.VisualStudio.Extensibility.DebuggerVisualizers;
|
using Microsoft.VisualStudio.Extensibility.DebuggerVisualizers;
|
||||||
using Microsoft.VisualStudio.RpcContracts.RemoteUI;
|
using Microsoft.VisualStudio.RpcContracts.RemoteUI;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="$(RepoRootPath)bin\Vector3VisualizerSource\$(Configuration)\netstandard2.0\Vector3VisualizerSource.dll" Link="netstandard2.0\Vector3VisualizerSource.dll" CopyToOutputDirectory="PreserveNewest" />
|
<Content Include="$(RepoRootPath)bin\Vector3VisualizerSource\$(Configuration)\netstandard2.0\Vector3VisualizerSource.dll" Link="netstandard2.0\Vector3VisualizerSource.dll" CopyToOutputDirectory="PreserveNewest" />
|
||||||
|
<Content Include="$(RepoRootPath)bin\NamedPipes\$(Configuration)\netstandard2.0\NamedPipes.dll" Link="netstandard2.0\NamedPipes.dll" CopyToOutputDirectory="PreserveNewest" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Vector3VisualizerUserControl.xaml" />
|
<EmbeddedResource Include="Vector3VisualizerUserControl.xaml" />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.VisualStudio.DebuggerVisualizers;
|
using Microsoft.VisualStudio.DebuggerVisualizers;
|
||||||
|
using NamedPipes;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -9,6 +10,12 @@ namespace Vector3VisualizerSource;
|
|||||||
|
|
||||||
public class Vector3ObjectSource : VisualizerObjectSource
|
public class Vector3ObjectSource : VisualizerObjectSource
|
||||||
{
|
{
|
||||||
|
public static void Send(Vector3Model vector3Model)
|
||||||
|
{
|
||||||
|
var pipeClient = new Sender();
|
||||||
|
|
||||||
|
pipeClient.SendMessage($"Hello from {nameof(Vector3ObjectSource)}");
|
||||||
|
}
|
||||||
public Vector3ObjectSource():base()
|
public Vector3ObjectSource():base()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("new Vector3ObjectSource");
|
Debug.WriteLine("new Vector3ObjectSource");
|
||||||
@@ -29,6 +36,7 @@ public class Vector3ObjectSource : VisualizerObjectSource
|
|||||||
{
|
{
|
||||||
vector3Model.Quaternion = quaternion.ToString();
|
vector3Model.Quaternion = quaternion.ToString();
|
||||||
}
|
}
|
||||||
|
Send(vector3Model);
|
||||||
SerializeAsJson(outgoingData, vector3Model);
|
SerializeAsJson(outgoingData, vector3Model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,4 +11,8 @@
|
|||||||
<PackageReference Include="System.Numerics.Vectors" Version="4.6.1" />
|
<PackageReference Include="System.Numerics.Vectors" Version="4.6.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\NamedPipes\NamedPipes.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user