Browse Source

Designer: fixed VS-embedded mode

pull/148/head
Nikita Tsukanov 11 years ago
parent
commit
25e56dc581
  1. 26
      src/Windows/Perspex.Designer/Comm/CommChannel.cs
  2. 3
      src/Windows/Perspex.Designer/Comm/ProcessHost.cs
  3. 1
      src/Windows/Perspex.Designer/Program.cs

26
src/Windows/Perspex.Designer/Comm/CommChannel.cs

@ -3,10 +3,12 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Threading;
namespace Perspex.Designer.Comm
@ -20,6 +22,7 @@ namespace Perspex.Designer.Comm
private BlockingCollection<byte[]> _outputQueue = new BlockingCollection<byte[]>();
public event Action<object> OnMessage;
public event Action Disposed;
public event Action<Exception> Exception;
public CommChannel(Stream input, Stream output)
{
_input = new BinaryReader(input);
@ -36,7 +39,7 @@ namespace Perspex.Designer.Comm
public void SendMessage(object message)
{
var fmt = new BinaryFormatter();
var fmt = GetFormatter();
var ms = new MemoryStream();
fmt.Serialize(ms, message);
_outputQueue.Add(ms.ToArray());
@ -57,6 +60,7 @@ namespace Perspex.Designer.Comm
}
catch (Exception e)
{
Exception?.Invoke(e);
Dispose();
}
}
@ -73,7 +77,8 @@ namespace Perspex.Designer.Comm
async void ReaderThread()
{
var fmt = new BinaryFormatter();
await Task.Delay(10).ConfigureAwait(false);
var fmt = GetFormatter();
while (!_terminating.Task.IsCompleted)
{
try
@ -87,15 +92,30 @@ namespace Perspex.Designer.Comm
var message = fmt.Deserialize(new MemoryStream(data));
_dispatcher.Post(_ => OnMessage?.Invoke(message), null);
}
catch
catch(Exception e)
{
Dispose();
Exception?.Invoke(e);
return;
}
}
}
sealed class BinderFix : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
return typeof (CommChannel).Assembly.GetType(typeName, false, true);
}
}
BinaryFormatter GetFormatter()
{
return new BinaryFormatter() {Binder = new BinderFix()};
}
public void Dispose()
{
if(_terminating.Task.IsCompleted)

3
src/Windows/Perspex.Designer/Comm/ProcessHost.cs

@ -103,7 +103,8 @@ namespace Perspex.Designer.Comm
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true
RedirectStandardError = true,
CreateNoWindow = true
},
EnableRaisingEvents = true
};

1
src/Windows/Perspex.Designer/Program.cs

@ -34,6 +34,7 @@ namespace Perspex.Designer
Console.SetOut(new NullTextWriter());
Console.SetError(new NullTextWriter());
comm.Disposed += () => Process.GetCurrentProcess().Kill();
comm.SendMessage(new StateMessage("Staying awhile and listening..."));
var service = new PerspexAppHost(comm);
service.Start();
Application.Run();

Loading…
Cancel
Save