public void Run(string[] args) { if (!Debugger.IsAttached) { shutdown.ShutdownRequested.Register(() => { var message = new Message { MessageType = MessageType.GuestShutdown }; hostBuffer.Write(ref message); }); } new Thread(ListenHostEvents) { Name = "Host Listener" }.Start(); var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof(IApplicationEnvironment)); var accessor = (IAssemblyLoadContextAccessor)serviceProvider.GetService(typeof(IAssemblyLoadContextAccessor)); var assembly = accessor.Default.Load(appEnv.ApplicationName); CallContextServiceLocator.Locator.ServiceProvider = this; EntryPointExecutor.Execute(assembly, args, this); }
private void OnMessage(ref Message message) { switch (message.MessageType) { case MessageType.HostWindow: parentWindow = message.Pointer; Debug.Assert(parentWindow != IntPtr.Zero); TryAttach(); break; case MessageType.HostResize: if (childWindow != IntPtr.Zero) { var msg = message; ThreadPool.QueueUserWorkItem(_ => { WindowHelper.Resize(childWindow, msg.Width, msg.Height); }); } break; } }
private void TryAttach() { if (parentWindow != IntPtr.Zero && childWindow != IntPtr.Zero && !childAttached) { childAttached = true; WindowHelper.EmbedWindow(childWindow, parentWindow); var message = new Message { MessageType = MessageType.GuestWindowAttached }; hostBuffer.Write(ref message); } }
public bool Remove(string name) { MemoryMappedFile mmf; if (mmfMap.TryRemove(name, out mmf)) { var message = new Message(MessageType.GuestRemoveSharedMemory).WithName(name); hostBuffer.Write(ref message); mmf.Dispose(); return true; } return false; }
public Stream Write(string name, int sizeInBytes) { var mmf = mmfMap.GetOrAdd(name, key => { if (sizeInBytes <= 0) { throw new ArgumentOutOfRangeException(nameof(sizeInBytes)); } var message = new Message(MessageType.GuestRequestSharedMemory).WithName(name); lock (mmfMap) { hostBuffer.Write(ref message); return MemoryMappedFile.CreateNew(channel + name, sizeInBytes); } }); return mmf.CreateViewStream(); }
private unsafe void OnMessage(ref Message message) { switch (message.MessageType) { case MessageType.GuestShutdown: StartGuestProcess(); break; case MessageType.GuestWindowAttached: SendHostResize(); reloadWatch.Stop(); var runtimeOptions = (IRuntimeOptions)serviceProvider.GetService(typeof(IRuntimeOptions)); if (runtimeOptions.CompilationServerPort.HasValue) { Console.WriteLine($"Application loaded in { reloadWatch.ElapsedMilliseconds }ms using compilation server port { runtimeOptions.CompilationServerPort }"); } else { Console.WriteLine($"Application loaded in { reloadWatch.ElapsedMilliseconds }ms"); } break; case MessageType.GuestRequestSharedMemory: mmfMap.GetOrAdd(channel + message.GetName(), MemoryMappedFile.OpenExisting); break; case MessageType.GuestRemoveSharedMemory: MemoryMappedFile mmf; if (mmfMap.TryRemove(channel + message.GetName(), out mmf)) mmf.Dispose(); break; } }
private void SendHostWindow() { if (guestProcess != null) { var message = new Message { MessageType = MessageType.HostWindow, Pointer = form.Handle }; guestBuffer.Write(ref message); } }
private void SendHostResize() { if (guestProcess != null) { var message = new Message { MessageType = MessageType.HostResize, Width = form.Width, Height = form.Height, }; guestBuffer.Write(ref message); } }