Example #1
0
        private void ServerStop()
        {
            if (ClientMaintaining.IsRunningAsLocalAdmin() &&
                ServerMaintaining.host.State != CommunicationState.Closed &&
                ServerMaintaining.host.State != CommunicationState.Closing &&
                ServerMaintaining.host.State != CommunicationState.Created)

            {
                ServerMaintaining.ServerStop();
            }
        }
Example #2
0
        private async void BtHost_Click(object sender, RoutedEventArgs e)
        {
            LeaderServer.Leader.ServerDNSName = tbLeaderName.Text.Trim();
            LeaderServer.Leader.VisibleName   = tbYourName.Text.Trim();
            LeaderServer.Leader.ServerIP      = Miscelanious.ResolveIP(tbLeaderName.Text.Trim()).FirstOrDefault();


            if (ClientMaintaining.IsRunningAsLocalAdmin())
            {
                if (ServerMaintaining.host.State != CommunicationState.Opened &&
                    ServerMaintaining.host.State != CommunicationState.Opening)
                {
                    imgCircleArrows.RenderTransform = new RotateTransform();

                    IsScanningForServers = false;
                    ClientMaintaining.scan.ScanCancel();

                    bool ServerSuccessfullyStarted = false;

                    try
                    {
                        ServerSuccessfullyStarted =
                            await Task.Run(async() =>
                        {
                            ServerMaintaining.ServerStart();
                            return(true);
                        });
                    }
                    catch (InvalidOperationException exception)
                    {
                        System.Windows.MessageBox.Show(
                            ClientUIPresenter.GetString("ThehostnameandportarealreadyinuseWaitforalittle")
                            + exception.Message,
                            ClientUIPresenter.GetString("Error")
                            , MessageBoxButton.OK,
                            MessageBoxImage.Error);
                        ClientMaintaining.Disconnect();
                    }
                    catch (AddressAlreadyInUseException exception)
                    {
                        System.Windows.MessageBox.Show(
                            ClientUIPresenter.GetString("Thehostnameandportarealreadyinuse")
                            ,
                            ClientUIPresenter.GetString("Error")
                            , MessageBoxButton.OK,
                            MessageBoxImage.Error);
                        ClientMaintaining.Disconnect();
                    }

                    if (ServerSuccessfullyStarted)
                    {
                        ClientMaintaining.isSelfServer = true;
                        expander.IsExpanded            = false;
                        Expander_Collapsed(this, null);


                        LeaderServer.Leader.ServerState = ServerStates.DelivererSet;
                        //ServerStatus.Current.ServerState = ServerStates.DelivererSet;


                        GridContainerForUC.Children.Clear();
                        GridContainerForUC.Children.Add(new ucSelector());



                        Log.Instance.W(this, "Server is launched now trying to connect to ourselves");
                        ClientMaintaining.Join(tbYourName.Text, true);

                        //if (ClientMaintaining.GetConnectionStatus())
                        //{
                        //    ClientMaintaining.SendMessage("Hello to Everyone!");
                        //}
                    }
                }
                else
                {
                    string infoString = ClientUIPresenter.GetString("Yourserverisalreadystarted")
                    ;
                    if (LeaderServer.Leader.ServerDNSName != string.Empty)
                    {
                        infoString += Environment.NewLine + ClientUIPresenter.GetString("Itiscalled")
                                      + LeaderServer.Leader.VisibleName +
                                      Environment.NewLine + ClientUIPresenter.GetString("Theotherusersoughttolookfor")
                                      +
                                      LeaderServer.Leader.ServerDNSName;
                        foreach (var ip in NetworkComputers.ResolveIP(LeaderServer.Leader.ServerDNSName).Select(x => x.ToString()).Distinct())
                        {
                            infoString += Environment.NewLine + ClientUIPresenter.GetString("or")
                                          + ip;
                        }
                    }

                    System.Windows.MessageBox.Show(infoString
                                                   , "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                System.Windows.MessageBox.Show(ClientUIPresenter.GetString("TolaunchyourownserveryouneedtoRunthisappasAdministrator")
                                               ,
                                               ClientUIPresenter.GetString("Insufficientrightstolaunchaserver")
                                               , MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }