Added crude debug pipes

This commit is contained in:
Joshua Askharoun
2021-04-27 11:48:43 -05:00
parent 1b199adc28
commit 5d7546edaf
9 changed files with 134 additions and 36 deletions
+2
View File
@@ -133,6 +133,8 @@ namespace Microsoft.Iris
get => DllResources.StaticDllResourcesOnly;
}
public static bool IsDebug { get; set; }
public static void Initialize()
{
if (IsInitialized)
+57
View File
@@ -5,6 +5,8 @@
// Assembly location: C:\Program Files\Zune\UIX.dll
using System;
using System.IO;
using System.IO.Pipes;
using System.Threading;
namespace Microsoft.Iris.Queues
@@ -14,6 +16,9 @@ namespace Microsoft.Iris.Queues
private static Interconnect s_interconnect = new Interconnect();
[ThreadStatic]
private static Dispatcher s_threadDispatcher;
private static NamedPipeClientStream _debugPipe;
private static BinaryWriter _debugPipeWriter;
private static BinaryReader _debugPipeReader;
private Thread _owningThread;
private uint _enterCount;
private Feeder _feeder;
@@ -66,7 +71,10 @@ namespace Microsoft.Iris.Queues
{
QueueItem nextItem = queue.GetNextItem();
if (nextItem != null)
{
SendDebugMessage(nextItem.ToDebugPacketString());
nextItem.Dispatch();
}
else
break;
}
@@ -132,5 +140,54 @@ namespace Microsoft.Iris.Queues
}
return flag;
}
private static NamedPipeClientStream DebugPipe
{
get
{
if (_debugPipe == null && Application.IsDebug)
{
_debugPipe = new NamedPipeClientStream(System.Reflection.Assembly.GetExecutingAssembly().FullName);
_debugPipe.Connect();
}
return _debugPipe;
}
}
private static BinaryWriter DebugPipeWriter
{
get
{
if (_debugPipe != null && _debugPipeWriter == null)
_debugPipeWriter = new BinaryWriter(DebugPipe);
return _debugPipeWriter;
}
}
private static BinaryReader DebugPipeReader
{
get
{
if (_debugPipe != null && _debugPipeReader == null)
_debugPipeReader = new BinaryReader(DebugPipe);
return _debugPipeReader;
}
}
/// <summary>
/// Sends a message via <see cref="debugPipe"/>
/// </summary>
/// <param name="message"></param>
public static void SendDebugMessage(string message)
{
if (Application.IsDebug && DebugPipe.IsConnected && DebugPipe.CanWrite)
{
DebugPipe.WriteByte(0x01);
byte[] buffer = System.Text.Encoding.Unicode.GetBytes(message);
DebugPipe.Write(BitConverter.GetBytes(buffer.Length), 0, sizeof(int));
DebugPipe.Write(buffer, 0, buffer.Length);
DebugPipe.Flush();
}
}
}
}
+2
View File
@@ -20,6 +20,8 @@ namespace Microsoft.Iris.Queues
public override string ToString() => GetType().Name;
public virtual string ToDebugPacketString() => ToString();
internal class Chain
{
public virtual void Dispose()
@@ -158,6 +158,36 @@ namespace Microsoft.Iris.Session
UIDispatcher.Post(thread, priority, queueItem);
}
public override string ToDebugPacketString()
{
string packetString = string.Empty; ;
switch (_callType)
{
case CallType.Simple:
var simpleCallback = (SimpleCallback)_target;
packetString = simpleCallback.Target.ToString() + "." + simpleCallback.Method.Name;
break;
case CallType.OneParam:
var deferredHandler = (DeferredHandler)_target;
string targetStr = deferredHandler.Target?.ToString();
if (!string.IsNullOrEmpty(targetStr))
packetString += targetStr + ".";
packetString += $"{deferredHandler.Method.Name}({_param})";
break;
case CallType.Event:
var eventHandler = (EventHandler)_target;
packetString = $"{eventHandler.Target}.{eventHandler.Method.Name}({_param}, {_args})";
break;
case CallType.RenderItem:
var deferredInvokeItem = (IDeferredInvokeItem)_param;
packetString = deferredInvokeItem.ToString();
break;
default:
throw new InvalidOperationException();
}
return packetString;
}
private enum CallType
{
None,
+1 -1
View File
@@ -190,7 +190,7 @@ namespace Microsoft.Iris.ViewItems
char ch1 = value[value.Length - 1];
char ch2 = value[value.Length - 2];
if (ch1 == ' ' && ch2 != ' ')
_content += (string)(object)ch1;
_content += ch1;
}
else
_content = value;