Beispiel #1
0
 private void MonitoringStringAutoUpdating(Object source, ElapsedEventArgs e)
 {
     Dispatcher.BeginInvoke(new ThreadStart(delegate
     {
         MonitoringString.Text = ClientMaintaining.GetMonitoringInfo();
     }));
 }
Beispiel #2
0
 private void TbChatMessageSend_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter && ClientMaintaining.isConnected)
     {
         ClientMaintaining.SendMessage(tbChatMessage.Text.Trim());
         tbChatMessage.Text = string.Empty;
         tbChatMessage.Focus();
     }
 }
Beispiel #3
0
        private void ServerStop()
        {
            if (ClientMaintaining.IsRunningAsLocalAdmin() &&
                ServerMaintaining.host.State != CommunicationState.Closed &&
                ServerMaintaining.host.State != CommunicationState.Closing &&
                ServerMaintaining.host.State != CommunicationState.Created)

            {
                ServerMaintaining.ServerStop();
            }
        }
        private async Task ListUsersUpdate(List <BookMyFood.ServiceChat.ServerUser> users)
        {
            if (!updating)
            {
                updating = true;

                ClientMaintaining.Update()
                ;

                try
                {
                    var me = users[users.FindIndex(x => x.ID == ClientMaintaining.ID)];
                    users.Remove(me);
                    users.Insert(0, me);
                }
                catch (Exception e)
                {
                    Log.Instance.W(this, e.Message);
                    updating = false;
                    return;
                }


                var cp = new SequenceEqualityComparer <UserItem>(new UserComparer());

                TempUsersList.Clear();
                //await Task.Run(async () => { Thread.Sleep(3000); });
                foreach (var user in users)
                {
                    TempUsersList.Add(new UserItem(user));
                    //await Task.Run(async () => { TempUsersList.Add(new UserItem(user)); });
                    //await
                    //    Task.Run( () = {

                    //    TempUsersList.Add(new UserItem(user));
                    //}
                }



                if (!cp.Equals(TempUsersList, UsersList) || Math.Abs(ClientMaintaining.CurrentDiscount - discount) > 0)
                {
                    UsersList.Clear();
                    foreach (var user in users)
                    {
                        UsersList.Add(new UserItem(user));
                    }
                    ;
                }

                updating = false;
            }
        }
Beispiel #5
0
        private void BtJoin_Click(object sender, RoutedEventArgs e)
        {
            uint port = 0;

            LeaderServer.Leader.ServerDNSName = tbLeaderName.Text.Trim();
            LeaderServer.Leader.VisibleName   = tbYourName.Text.Trim();
            LeaderServer.Leader.Port          = uint.TryParse(tbPort.Text.Trim(), out port) ? port : 0;
            LeaderServer.Leader.ServerIP      = Miscelanious.ResolveIP(tbLeaderName.Text.Trim()).FirstOrDefault();

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

            imgCircleArrows.RenderTransform = new RotateTransform();

            ServerStop();
            if (ClientMaintaining.isConnected)
            {
                ClientMaintaining.Disconnect();
            }
            ClientMaintaining.Join(tbYourName.Text);

            if (ClientMaintaining.isConnected)
            {
                expander.IsExpanded = false;
                Expander_Collapsed(this, null);
                //ChatClientHandler.ChatMessageCame += (string s) =>
                //{
                //    Dispatcher.BeginInvoke(new ThreadStart(delegate
                //    {
                //        lbChatMessages.ItemsSource = new List<string>();
                //        lbChatMessages.ItemsSource = ChatClientHandler.ChatBoxContainment;
                //        lbChatMessages.ScrollIntoView(lbChatMessages.Items[lbChatMessages.Items.Count - 1]);
                //    }));
                //};
                GridContainerForUC.Children.Clear();
                GridContainerForUC.Children.Add(new ucSelector());
            }
            //var u = ClientMaintaining.GetUsers();
        }
Beispiel #6
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     ClientMaintaining.Disconnect();
     ServerStop();
 }
Beispiel #7
0
        public MainWindow()
        {
            const string WINDOWS_FIREWALL_SERVICE = "MpsSvc";


            using (var sc = new ServiceController(WINDOWS_FIREWALL_SERVICE))
            {
                if ((sc.Status == ServiceControllerStatus.Running))
                {
                    Log.Instance.W(this, "Found working Windows Firewall Service");
                    MessageBoxResult result = MessageBox.Show(ClientUIPresenter.GetString("FoundworkingWindowsFirewallServiceWouldyouliketostopit")
                                                              , ClientUIPresenter.GetString("Question")
                                                              , MessageBoxButton.YesNo);
                    switch (result)
                    {
                    case MessageBoxResult.Yes:
                        if (ClientMaintaining.IsRunningAsLocalAdmin())
                        {
                            Log.Instance.W(this, ClientUIPresenter.GetString("Tryingtostop")
                                           );
                            try
                            {
                                sc.Stop();
                                ServiceHelper.ChangeStartMode(sc, ServiceStartMode.Disabled);
                                System.Windows.MessageBox.Show(
                                    ClientUIPresenter.GetString("WindowsFirewallServicehasbeenstopped")
                                    ,
                                    ClientUIPresenter.GetString("Success")
                                    , MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                            }
                            catch (Exception e)
                            {
                                Log.Instance.W(this, ClientUIPresenter.GetString("Errorwhilestoptrying")

                                               + e.Message);
                                System.Windows.MessageBox.Show(
                                    "Error while stop trying: " + e.Message,
                                    "Attention", MessageBoxButton.OK,
                                    MessageBoxImage.Warning);
                            }
                            //sc.sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(30));
                            if (sc.Status == ServiceControllerStatus.Stopped)
                            {
                                Console.WriteLine("Service '{0}' has been stopped", sc.DisplayName);
                            }
                        }
                        else
                        {
                            System.Windows.MessageBox.Show(
                                ClientUIPresenter.GetString("TostoptheWindowsFirewallServiceyoumustRunthisappasAdministrator")
                                ,
                                ClientUIPresenter.GetString("Insufficientrightstostoptheservice")
                                , MessageBoxButton.OK,
                                MessageBoxImage.Warning);
                        }
                        break;

                    case MessageBoxResult.No:
                        System.Windows.MessageBox.Show(
                            ClientUIPresenter.GetString("Youmayencountersomeproblemswhensearchingforotherpeoplesservers")
                            ,
                            ClientUIPresenter.GetString("Attention")
                            , MessageBoxButton.OK,
                            MessageBoxImage.Warning);
                        break;
                    }
                }
            }

            settings.LocaleChanged += ChangeFormLocale;
            ClientMaintaining.ClientStateChanged += ClientEventsHandler;
            InitializeComponent();
            cbLanguage.ItemsSource = new List <string> {
                "ru-RU", "en-US", "ms-MY"
            };
            FillUpTextFields();
            ChatGrid.Width = 0;
            SetDefaultValues();

            ChatClientHandler.ChatMessageCame += (string s) =>
            {
                Dispatcher.BeginInvoke(new ThreadStart(delegate
                {
                    lbChatMessages.ItemsSource = new List <string>();
                    lbChatMessages.ItemsSource = ChatClientHandler.ChatBoxContainment;
                    lbChatMessages.ScrollIntoView(lbChatMessages.Items[lbChatMessages.Items.Count - 1]);
                }));
            };

            void SetDefaultValues()
            {
                tbLeaderName.Text = ClientMaintaining.IsRunningAsLocalAdmin() ? Miscelanious.GetComputerName() : string.Empty;
                tbPort.Text       = ClientMaintaining.IsRunningAsLocalAdmin() ? "666" : string.Empty;
                tbYourName.Text   = Miscelanious.GetComputerName();
            }

            void ChangeFormLocale(string locale)
            {
                FillUpTextFields();
            }

            void FillUpTextFields()
            {
                ClientUIPresenter presenter = new ClientUIPresenter(this);

                presenter.FillUpTextFields();
            }

            StartupManual manual = new StartupManual();

            if (!File.Exists(Path.Combine(Assembly.GetExecutingAssembly().Location
                                          .Replace(Assembly.GetExecutingAssembly().ManifestModule.Name, "") +
                                          "firstrun")))
            {
                manual.ShowDialog();
                File.Create(Path.Combine(Assembly.GetExecutingAssembly().Location
                                         .Replace(Assembly.GetExecutingAssembly().ManifestModule.Name, "") +
                                         "firstrun"));
            }


            // Create a timer with a two second interval.
            aTimer = new System.Timers.Timer(2000);
            // Hook up the Elapsed event for the timer.
            aTimer.Elapsed  += MonitoringStringAutoUpdating;
            aTimer.AutoReset = true;
            aTimer.Enabled   = true;
        }
Beispiel #8
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);
            }
        }