Beispiel #1
0
        private async Task <WagahighOperator> CreateWagahighOperatorAsync()
        {
            if (this.ToaHost != null)
            {
                this.Logger.Info($"Toa サーバー {this.ToaHost}:{this.ToaPort} に接続します。");
                var remoteOperator = new GrpcRemoteWagahighOperator(this.ToaHost, this.ToaPort);
                await remoteOperator.ConnectAsync().ConfigureAwait(false);

                return(remoteOperator);
            }
            else
            {
                this.Logger.Info("ワガママハイスペックを起動します。");
                var display = DisplayIdentifier.Parse(Environment.GetEnvironmentVariable("DISPLAY"));
                return(await LocalWagahighOperator.StartProcessAsync(this.Directory ?? "", display).ConfigureAwait(false));
            }
        }
Beispiel #2
0
        private async void btnConnect_Click(object sender, RoutedEventArgs e)
        {
            if (this._logSubscription != null)
            {
                this._logSubscription.Dispose();
                this._logSubscription = null;
            }

            if (this._connection != null)
            {
                this._connection.Dispose();
                this._connection = null;
            }

            var host = this.txtRemoteAddr.Text;
            int port;

            try
            {
                var colonIndex = host.LastIndexOf(':');
                if (colonIndex >= 0)
                {
                    port = int.Parse(host.Substring(colonIndex + 1));
                    host = host.Remove(colonIndex);
                }
                else
                {
                    port = GrpcToaServer.DefaultPort;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "接続先エラー", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            this.btnConnect.IsEnabled = false;

            try
            {
                var conn = new GrpcRemoteWagahighOperator(host, port);
                this._connection = conn;
                await conn.ConnectAsync();

                this._logSubscription = conn.LogStream
                                        .ObserveOn(this.Dispatcher)
                                        .Subscribe(
                    this.OnNextLog,
                    ex =>
                {
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                    MessageBox.Show(this, ex.ToString(), "ログエラー", MessageBoxButton.OK, MessageBoxImage.Error);
                },
                    () => MessageBox.Show(this, "ログストリームが終了しました。", "ログエラー", MessageBoxButton.OK, MessageBoxImage.Error)
                    );
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }

                MessageBox.Show(this, ex.ToString(), "接続失敗", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            finally
            {
                this.btnConnect.IsEnabled = true;
            }

            if (this._timer == null)
            {
                // 0.1 秒ごとに画面を更新
                this._timer = new DispatcherTimer(
                    new TimeSpan(100 * TimeSpan.TicksPerMillisecond),
                    DispatcherPriority.Normal,
                    this.TimerTick,
                    this.Dispatcher
                    );
            }
        }