예제 #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();
        }
예제 #2
0
파일: FormMain.cs 프로젝트: ruslanlyalko/DA
        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);
            }
        }