public AvaloniaDesigner(DesignerConfiguration config)
        {
            _host = new ProcessHost(config);
            _host.SpawnedProcess += proc => SpawnedProcess?.Invoke(proc);
            InitializeComponent();
            BindingOperations.SetBinding(State, TextBox.TextProperty,
                                         new Binding(nameof(ProcessHost.State))
            {
                Source = _host, Mode = BindingMode.OneWay
            });

            _host.PropertyChanged   += _host_PropertyChanged;
            DesignerView.DataContext = new HostedAppModel(_host);
        }
Пример #2
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;
        }