Exemplo n.º 1
0
        protected virtual void OnMessage(IAvaloniaRemoteTransportConnection transport, object obj)
        {
            lock (_lock)
            {
                if (obj is FrameReceivedMessage lastFrame)
                {
                    lock (_lock)
                    {
                        _lastReceivedFrame = lastFrame.SequenceId;
                    }
                    Dispatcher.UIThread.Post(RenderIfNeeded);
                }
                if (obj is ClientRenderInfoMessage renderInfo)
                {
                    lock (_lock)
                    {
                        _dpi         = new Vector(renderInfo.DpiX, renderInfo.DpiY);
                        _invalidated = true;
                    }

                    Dispatcher.UIThread.Post(RenderIfNeeded);
                }
                if (obj is ClientSupportedPixelFormatsMessage supportedFormats)
                {
                    lock (_lock)
                        _supportedFormats = supportedFormats.Formats;
                    Dispatcher.UIThread.Post(RenderIfNeeded);
                }
                if (obj is MeasureViewportMessage measure)
                {
                    Dispatcher.UIThread.Post(() =>
                    {
                        var m = Measure(new Size(measure.Width, measure.Height));
                        _transport.Send(new MeasureViewportMessage
                        {
                            Width  = m.Width,
                            Height = m.Height
                        });
                    });
                }
                if (obj is ClientViewportAllocatedMessage allocated)
                {
                    lock (_lock)
                    {
                        if (_pendingAllocation == null)
                        {
                            Dispatcher.UIThread.Post(() =>
                            {
                                ClientViewportAllocatedMessage allocation;
                                lock (_lock)
                                {
                                    allocation         = _pendingAllocation;
                                    _pendingAllocation = null;
                                }
                                _dpi       = new Vector(allocation.DpiX, allocation.DpiY);
                                ClientSize = new Size(allocation.Width, allocation.Height);
                                RenderIfNeeded();
                            });
                        }

                        _pendingAllocation = allocated;
                    }
                }
                if (obj is PointerMovedEventMessage pointer)
                {
                    Dispatcher.UIThread.Post(() =>
                    {
                        Input?.Invoke(new RawMouseEventArgs(
                                          MouseDevice,
                                          0,
                                          InputRoot,
                                          RawMouseEventType.Move,
                                          new Point(pointer.X, pointer.Y),
                                          GetAvaloniaInputModifiers(pointer.Modifiers)));
                    }, DispatcherPriority.Input);
                }
                if (obj is PointerPressedEventMessage pressed)
                {
                    Dispatcher.UIThread.Post(() =>
                    {
                        Input?.Invoke(new RawMouseEventArgs(
                                          MouseDevice,
                                          0,
                                          InputRoot,
                                          GetAvaloniaEventType(pressed.Button, true),
                                          new Point(pressed.X, pressed.Y),
                                          GetAvaloniaInputModifiers(pressed.Modifiers)));
                    }, DispatcherPriority.Input);
                }
                if (obj is PointerPressedEventMessage released)
                {
                    Dispatcher.UIThread.Post(() =>
                    {
                        Input?.Invoke(new RawMouseEventArgs(
                                          MouseDevice,
                                          0,
                                          InputRoot,
                                          GetAvaloniaEventType(released.Button, false),
                                          new Point(released.X, released.Y),
                                          GetAvaloniaInputModifiers(released.Modifiers)));
                    }, DispatcherPriority.Input);
                }
                if (obj is ScrollEventMessage scroll)
                {
                    Dispatcher.UIThread.Post(() =>
                    {
                        Input?.Invoke(new RawMouseWheelEventArgs(
                                          MouseDevice,
                                          0,
                                          InputRoot,
                                          new Point(scroll.X, scroll.Y),
                                          new Vector(scroll.DeltaX, scroll.DeltaY),
                                          GetAvaloniaInputModifiers(scroll.Modifiers)));
                    }, DispatcherPriority.Input);
                }
                if (obj is KeyEventMessage key)
                {
                    Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1);

                    Dispatcher.UIThread.Post(() =>
                    {
                        Input?.Invoke(new RawKeyEventArgs(
                                          KeyboardDevice,
                                          0,
                                          key.IsDown ? RawKeyEventType.KeyDown : RawKeyEventType.KeyUp,
                                          (Key)key.Key,
                                          GetAvaloniaInputModifiers(key.Modifiers)));
                    }, DispatcherPriority.Input);
                }
                if (obj is TextInputEventMessage text)
                {
                    Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1);

                    Dispatcher.UIThread.Post(() =>
                    {
                        Input?.Invoke(new RawTextInputEventArgs(
                                          KeyboardDevice,
                                          0,
                                          text.Text));
                    }, DispatcherPriority.Input);
                }
            }
        }
Exemplo n.º 2
0
 public PreviewerWindowImpl(IAvaloniaRemoteTransportConnection transport) : base(transport)
 {
     _transport = transport;
     ClientSize = new Size(1, 1);
 }
Exemplo n.º 3
0
 public RemoteServerTopLevelImpl(IAvaloniaRemoteTransportConnection transport)
 {
     _transport            = transport;
     _transport.OnMessage += OnMessage;
 }
Exemplo n.º 4
0
 private static void OnTransportMessage(IAvaloniaRemoteTransportConnection transport, object obj) => Dispatcher.UIThread.Post(() =>
 {
     if (obj is ClientSupportedPixelFormatsMessage formats)
Exemplo n.º 5
0
 private void OnSignalTransportMessage(IAvaloniaRemoteTransportConnection signal, object message) => _onMessage?.Invoke(this, message);
Exemplo n.º 6
0
 private void OnSignalTransportException(IAvaloniaRemoteTransportConnection arg1, Exception ex)
 {
     _onException?.Invoke(this, ex);
 }
Exemplo n.º 7
0
 public RemoteServer(IAvaloniaRemoteTransportConnection transport)
 {
     _topLevel = new EmbeddableControlRoot(new EmbeddableRemoteServerTopLevelImpl(transport));
     _topLevel.Prepare();
     //TODO: Somehow react on closed connection?
 }
Exemplo n.º 8
0
 private void OnTransportException(IAvaloniaRemoteTransportConnection conn, Exception e)
 {
     Log.Message("Transport exception:" + e);
 }
Exemplo n.º 9
0
 public EmbeddableRemoteServerTopLevelImpl(IAvaloniaRemoteTransportConnection transport) : base(transport)
 {
 }
 public void FireOnMessage(IAvaloniaRemoteTransportConnection transport, object obj) => OnMessage?.Invoke(transport, obj);
 public DetachableTransportConnection(IAvaloniaRemoteTransportConnection inner)
 {
     _inner            = inner;
     _inner.OnMessage += FireOnMessage;
 }
Exemplo n.º 12
0
        public void Start(string targetExe, string xaml, string sourceAssembly)
        {
            _xaml = new UpdateXamlMessage {
                Xaml = xaml, AssemblyPath = sourceAssembly
            };
            if (_proc != null)
            {
                _proc.Exited -= OnExited;
                try
                {
                    _conn?.Dispose();
                    _conn = null;
                    _proc.Kill();
                }
                catch { }
                HandleExited();
                State = "Restarting...";
            }

            var netCore    = false;
            var targetDir  = Path.GetDirectoryName(targetExe);
            var targetBase = Path.Combine(targetDir,
                                          Path.GetFileNameWithoutExtension(targetExe));

            var depsJsonPath = targetBase + ".deps.json";

            netCore = File.Exists(depsJsonPath) &&
                      DepsJson.Load(depsJsonPath)?.RuntimeTarget?.Name?.Contains("NETCoreApp") == true;
            var sessionId = Guid.NewGuid().ToString();

            DesignerTcpListener.Register(this, sessionId);
            var cmdline =
                $"--transport tcp-bson://127.0.0.1:{DesignerTcpListener.Port}/ --session-id {sessionId} --method win32 \"{targetExe}\"";

            if (netCore)
            {
                cmdline =
                    $"exec --runtimeconfig \"{targetBase}.runtimeconfig.json\" --depsfile \"{depsJsonPath}\" \"{_config.NetCoreAppHostPath}\" " +
                    cmdline;
            }
            var exe = netCore ? "dotnet" : _config.NetFxAppHostPath;

            _proc = new Process()
            {
                StartInfo = new ProcessStartInfo(exe, cmdline)
                {
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true,
                    WorkingDirectory       = targetDir
                },
                EnableRaisingEvents = true
            };

            _proc.Exited += OnExited;
            try
            {
                _proc.Start();
                SpawnedProcess?.Invoke(_proc);
                State = "Launching designer process: " + Environment.NewLine
                        + exe + " " + cmdline + Environment.NewLine + "from directory " + targetDir;
                StartReaders(_proc);
            }
            catch (Exception e)
            {
                State = e.ToString();
                HandleExited();
            }
            IsAlive = true;
        }
 public void Dispose()
 {
     if (_inner != null)
         _inner.OnMessage -= FireOnMessage;
     _inner = null;
 }