Esempio n. 1
0
        private void LoginToServer(string username, string password, string host, bool isMaster)
        {
            _logonThread = new Thread(
                () =>
                {
                    _pingTimer.Enabled = false;
                    _client = new DataClientClass(username);
                    _logClient = new DataNetLogService();
                    _logClientService =
                        ScsServiceClientBuilder.CreateClient<IDataNetLogService>(new ScsTcpEndPoint(host, 443),
                            _logClient);
                    _clientService =
                        ScsServiceClientBuilder.CreateClient<IDataAdminService>(new ScsTcpEndPoint(host, 443), _client);
                    _clientService.Connected += ScsClient_Connected;

                    try
                    {
                        _clientService.Connect();
                        _logClientService.Connect();

                        _client.login += LoggedIn;
                        _client.block += BlockedByAdmin;
                        _client.loginFailed += LoginFailed;
                        _client.changePrivilages += ChangedPrivileges;
                        _client.logout += DeletedClient;
                        _client.symblolListRecieved += GroupSymbolChange;
                        _client.symbolListChanged += RefreshSymbols;
                        _client.groupChanged += RefreshGroups;
                        //_client.logoutServer += ServerStatusChanged;
                        _client.busySymbolListReceived += BusySymbolChanged;
                        _client.symbolPermissionChanged += RefreshSymbols;
                        _clientService.Disconnected += OnServerCrashed;

                        var logmsg = new DataAdminMessageFactory.LogMessage
                        {
                            Symbol = username,
                            LogType = DataAdminMessageFactory.LogMessage.Log.Login,
                            Group = ""
                        };

                        _logClientService.ServiceProxy.SendSimpleLog(logmsg);
                        Settings.Default.scHost = _startControl.ui_textBox_ip.Text;
                        Settings.Default.scHostSlave = _startControl.ui_textBox_ip_slave.Text;
                        Invoke((Action) (() =>
                        {
                            labelItem_server.Text = isMaster ? "Master" : "Slave";
                            styleManager1.MetroColorParameters = new MetroColorGeneratorParameters(Color.White,
                                isMaster ? Color.Green : Color.YellowGreen);

                            metroStatusBar1.Refresh();
                        }));

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        if (_startControl != null)
                            _startControl.Invoke((Action) (() =>
                            {
                                if (isMaster)
                                {
                                    ToastNotification.Show(_startControl, "Can't connect. IP is incorrect");
                                    _startControl.ui_buttonX_logon.Enabled = true;
                                }
                                else
                                {
                                    Logout();
                                }
                            }
                                ));

                        return;
                    }
                    var loginMsg = new DataAdminMessageFactory.LoginMessage(username, password, 'd');
                    try
                    {
                        _clientService.ServiceProxy.Login(loginMsg);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        MessageBox.Show(ex.Message);
                    }
                }) {Name = "LogonThread", IsBackground = true};

            _logonThread.Start();
        }
Esempio n. 2
0
        private void Logout()
        {
            if (!_logined) return;
            _logined = false;

            if (_serverStatusMaster)
                if (_clientService != null && _clientService.ServiceProxy != null)
                    _clientService.ServiceProxy.Logout("d", _client.UserName);

            if (_logonThread != null) _logonThread.Abort();

            ClientDatabaseManager.CloseConnectionToDbSystem();

            Invoke((Action) delegate
            {
                metroTabItem2.Visible = false;
                metroTabItem3.Visible = false;
                metroShell1.SelectedTab = metroTabItem1;

                ClientDatabaseManager.CloseConnectionToDbSystem();
                RefreshGroups();
                RefreshSymbols();
                _client = null;
                _startControl.Dispose();
                _startControl = new StartControl {Commands = _commands};
                Controls.Add(_startControl);
                _startControl.BringToFront();
                _startControl.SlideSide = DevComponents.DotNetBar.Controls.eSlideSide.Right;
                UpdateControlsSizeAndLocation();
                _startControl.ui_textBox_ip.Text = Settings.Default.scHost;
                _pingTimer.Enabled = true;
            });
        }
Esempio n. 3
0
        private void LoginToServer(string username, string password, string host)
        {
            _pingTimer.Enabled = false;
            _client = new DataClientClass(username);
            _logClient = new DataNetLogService();
            _logClientService = ScsServiceClientBuilder.CreateClient<IDataNetLogService>(new ScsTcpEndPoint(host, 443), _logClient);
            _clientService = ScsServiceClientBuilder.CreateClient<IDataAdminService>(new ScsTcpEndPoint(host, 443), _client);
            _clientService.Connected += ScsClient_Connected;
            try
            {
                _clientService.Connect();
                _logClientService.Connect();

                _client.login += LoggedIn;
                _client.block += BlockedByAdmin;
                _client.loginFailed += LoginFailed;
                _client.changePrivilages += ChangedPrivileges;
                _client.logout += DeletedClient;
                _client.symblolListRecieved += GroupSymbolChange;
                _client.symbolListChanged += RefreshSymbols;
                _client.groupChanged += RefreshGroups;
                _client.logoutServer += ServerStatusChanged;
                _client.busySymbolListReceived += BusySymbolChanged;
                _client.symbolPermissionChanged += RefreshSymbols;
                _clientService.Disconnected += OnServerCrashed;

                var logmsg = new DataAdminMessageFactory.LogMessage
                                 {Symbol = username, LogType = DataAdminMessageFactory.LogMessage.Log.Login, Group = ""};

                _logClientService.ServiceProxy.SendSimpleLog(logmsg);
                Settings.Default.connectionHost = _startControl.ui_textBox_ip.Text;

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (_startControl!=null)
                _startControl.Invoke((Action)(() =>
                                                  {
                                                      ToastNotification.Show(_startControl, "Can't connect. IP is incorrect");
                                                      _startControl.ui_buttonX_logon.Enabled = true;
                                                  }
                    ));

                return;
            }
            var loginMsg = new DataAdminMessageFactory.LoginMessage(username, password, 'd');
            try
            {
                _clientService.ServiceProxy.Login(loginMsg);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show(ex.Message);
            }
        }