示例#1
0
 public static int AcquireServer(string ipAddress)
 {
     // ToDo: Which result do you expect? You need a proper approval/confirmation handling!
     HubProxy.Invoke <bool>("ShutDownServer", ipAddress, Server.Port);
     if (UacHelper.IsElevated() == false)
     {
         if (UacHelper.RestartWithAdminRights("serverRole") == false)
         {
             return(0);
         }
         Process.GetCurrentProcess().Kill();
     }
     return(1);
 }
            public DisconnectMessageBox()
            {
                this.reconnectButton.Text    = @"Erneut verbinden";
                this.getServerButton.Text    = @"Server werden";
                this.connectOtherButton.Text = @"Mit anderem Server verbinden";

                this.reconnectButton.Click += async(a, b) =>
                {
                    this.ChangeButtonIsEnabled(false);
                    var success = await CommunicationProxy.ConnectToServer(BsaContext.GetURL(), 8081);

                    if (success)
                    {
                        this.Close();
                    }

                    this.ChangeButtonIsEnabled(true);
                };

                this.getServerButton.Click += (a, b) =>
                {
                    this.ChangeButtonIsEnabled(false);
                    if (UacHelper.RestartWithAdminRights("") == false)
                    {
                        this.ChangeButtonIsEnabled(true);
                        return;
                    }

                    Process.GetCurrentProcess().Kill();
                };

                this.connectOtherButton.Click += async(a, b) =>
                {
                    this.ChangeButtonIsEnabled(false);
                    var success = await this.ConnectToServerAsync();

                    if (success == false)
                    {
                        this.ChangeButtonIsEnabled(true);
                    }
                    else
                    {
                        this.Close();
                    }
                };

                var l = new Label {
                    Text = @"Die Verbindung zum Server ist getrennt. Was möchten Sie jetzt tun?"
                };

                l.SetBounds(100, 30, 450, 50);
                this.reconnectButton.SetBounds(50, 100, 150, 50);
                this.getServerButton.SetBounds(250, 100, 150, 50);
                this.connectOtherButton.SetBounds(450, 100, 150, 50);

                this.connectOtherButton.Anchor = this.connectOtherButton.Anchor | AnchorStyles.Right;
                this.reconnectButton.Anchor    = AnchorStyles.Bottom | AnchorStyles.Right;
                this.getServerButton.Anchor    = AnchorStyles.Bottom | AnchorStyles.Right;
                this.Text       = @"Fehler";
                this.ClientSize = new Size(650, 200);
                this.Controls.AddRange(new Control[] { l, this.reconnectButton, this.getServerButton, this.connectOtherButton });
                this.FormBorderStyle = FormBorderStyle.FixedDialog;
                this.StartPosition   = FormStartPosition.CenterScreen;
                this.MinimizeBox     = false;
                this.MaximizeBox     = false;

                this.ShowDialog();
            }