예제 #1
0
        public void SendLog(List<string> symbols, DataAdminMessageFactory.LogMessage.Log logtype, string groupName,
            string timeFrame, bool started, bool finished, bool failed = false, string comments = "")
        {
            var status = started
                ? DataAdminMessageFactory.LogMessage.Status.Started
                : DataAdminMessageFactory.LogMessage.Status.Finished;

            if (symbols.Count > 0)
            {
                var logMsg = new DataAdminMessageFactory.LogMessage(_client.UserID, DateTime.Now, "",
                    logtype, groupName, status)
                {
                    IsByDataNetBusy = true,
                    IsDataNetClient = true,
                    IsTickNetClient = false,
                    TimeFrame = timeFrame,
                    Comments = comments

                };
                if (failed) logMsg.OperationStatus = DataAdminMessageFactory.LogMessage.Status.Aborted;

                var symb = symbols.Aggregate("", (current, symbol) => current + (symbol + ","));
                var index = symb.Count() - 1;
                symb = symb.Remove(index);
                logMsg.Symbol = symb;
                if (started)
                {
                    var tries = 0;
                    var errorHappened = false;
                    do
                    {
                        errorHappened = false;

                        try
                        {
                            Task.Factory.StartNew(() => _logClientService.ServiceProxy.SendStartedOperationLog(
                                logMsg)).Wait();

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            errorHappened = true;
                            tries++;
                        }

                    } while (tries < 3 && errorHappened);

                }
                else if (finished)
                {
                    logMsg.IsByDataNetBusy = false;
                    Task.Factory.StartNew(() => _logClientService.ServiceProxy.SendFinishedOperationLog(logMsg)).Wait();
                }

            }
            else
            {
                var logMsg = new DataAdminMessageFactory.LogMessage(_client.UserID, DateTime.Now, "", logtype, groupName,
                    status);
                if (started)
                {
                    logMsg.IsByDataNetBusy = true;
                    logMsg.IsDataNetClient = true;
                    logMsg.TimeFrame = timeFrame;
                    Task.Factory.StartNew(() => _logClientService.ServiceProxy.SendStartedOperationLog(logMsg)).Wait();

                }
                else if (finished)
                {
                    logMsg.IsByDataNetBusy = false;
                    logMsg.IsDataNetClient = true;
                    logMsg.TimeFrame = timeFrame;
                    _logClientService.ServiceProxy.SendFinishedOperationLog(logMsg);
                }
            }
        }
예제 #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();

            _serverHost = host;
            _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, 't');
            try
            {
                _clientService.ServiceProxy.Login(loginMsg);

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
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();
        }
예제 #4
0
파일: FormMain.cs 프로젝트: ruslanlyalko/DA
        private void RefreshDaBusySymbols(string username)
        {
            var symbols = from items in _busySymbols
                          where items.TimeFrames.Exists(oo => oo.UserId == _users.Find(o => o.Name == username).Id)
                          select items;

              //  var listS = symbols.Select(item => item.ID).ToList();
            var smbols = new List<DataAdminService.BusySymbol>(symbols);
            var logMSg = new DataAdminMessageFactory.LogMessage
                             {

                                 Time = DateTime.Now,
                                 Group = "",
                                 UserID = (from user in _users where user.Name == username select user.Id).First(),
                                 IsDataNetClient = true,
                                 OperationStatus = DataAdminMessageFactory.LogMessage.Status.Aborted,
                                 TimeFrame = "",
                                 LogType = DataAdminMessageFactory.LogMessage.Log.CollectSymbol
                             };

            foreach(var symbol in smbols)
            {
                logMSg.Symbol =  _symbols.Find(o => o.SymbolId == symbol.ID).SymbolName;
                var timeFr = from items in symbol.TimeFrames
                             where
                                 items.UserId == logMSg.UserID
                             select new {items.TimeFrame};

             logMSg.TimeFrame = timeFr.First().TimeFrame;
                    DataNetFinishedCollect(logMSg);

               }
        }
예제 #5
0
        /// <summary>
        /// This method is called when a client calls
        /// the Logout method of service or a client
        /// connection fails.
        /// </summary>
        /// <param name="clientId">Unique Id of client that is logged out</param>
        /// <param name="clientType"> </param>
        private void ClientLogout(long clientId, string clientType)
        {
            var client = Clients[clientId];
            var isdnetClient = false;
            var istnetclient = false;
            if (client == null)
            {
                return;
            }

            switch (clientType)
            {
                case "d":
                    isdnetClient = true;
                    if (!(client.IsDexportConnected || client.IsTickNetConnected))
                    {

                        DClientCrashed(client.UserName);
                        Clients.Remove(client.IndexInAdminList);
                    }
                    else
                    {
                        DClientCrashed(client.UserName);
                        client.IsDatanetConnected = false;
                        client.DnetClient = null;
                        client.DClientProxy = null;
                    }
                    break;

                case "t":
                    istnetclient = true;
                    if (!(client.IsDexportConnected || client.IsDatanetConnected))
                    {
                        TClientCrashed(client.UserName);
                        Clients.Remove(client.IndexInAdminList);
                    }
                    else
                    {
                        TClientCrashed(client.UserName);
                        client.IsTickNetConnected = false;

                        client.TClientProxy = null;
                        client.TnetClient = null;
                    }
                    break;

                case "e":
                    if (!(client.IsDatanetConnected || client.IsDatanetConnected))
                    {
                        Clients.Remove(client.IndexInAdminList);
                    }
                    else
                    {
                        client.IsDexportConnected = false;
                        client.DexportProxy = null;
                        client.DexportClient = null;
                    }
                    break;
            }

            if (OnloggedOutLog != null)
            {
                var msg = new DataAdminMessageFactory.LogMessage
                              {
                                  OperationStatus = DataAdminMessageFactory.LogMessage.Status.Finished,
                                  LogType = DataAdminMessageFactory.LogMessage.Log.Logout,
                                  UserID = client.DBId,
                                  Time = DateTime.Now,
                                  IsDataNetClient = isdnetClient,
                                  IsTickNetClient = istnetclient

                              };
                var msgMain = "Client " + client.UserName + " disconected.";
                OnloggedOutLog(msg, msgMain, client.UserName);
            }
            Task.Factory.StartNew(OnUserListChanged);
        }
예제 #6
0
 public void TickNetClientLogin(DataAdminMessageFactory.LoginMessage loginParams, UserModel tempUser)
 {
     if (!(Clients.GetAllItems().Exists(a => a.UserName == loginParams.UsernameMD5)))
     {
         AddClient(CurrentClient, loginParams.NetType, tempUser);
         return;
     }
     var clientInList = Clients.GetAllItems().Find(a => a.UserName == loginParams.UsernameMD5);
     if (clientInList.IsTickNetConnected == false)
     {
         clientInList.IsTickNetConnected = true;
         clientInList.TClientProxy = CurrentClient.GetClientProxy<IDataAdminService>();
         clientInList.TnetClient = CurrentClient;
         var usrModel = new UserModel();
         if (OnloggedInLog != null)
         {
             var msg = new DataAdminMessageFactory.LogMessage
                           {
                               OperationStatus = DataAdminMessageFactory.LogMessage.Status.Finished,
                               LogType = DataAdminMessageFactory.LogMessage.Log.Login,
                               Time = DateTime.Now,
                               UserID = tempUser.Id,
                               IsTickNetClient = true
                           };
             var msgMain = "Client " + usrModel.Name + " connected from " +
                           CurrentClient.RemoteEndPoint;
             OnloggedInLog(msg, msgMain);
         }
         CurrentLoginTypeDnet = false;
         CurrentLoginTypeTnet = true;
         CurrentLoginTypeDexp = false;
       OnClientLogon(tempUser);
     }
 }
예제 #7
0
        public void AddClient(IScsServiceClient newClient, char listflag, UserModel usrModel)
        {
            var client = CurrentClient;

            //Get a proxy object to call methods of client when needed
            var clientProxy = CurrentClient.GetClientProxy<IDataAdminService>();
            //Create a DataClient and store it in a collection
            bool dnet = listflag == 'd';
            bool tnet = listflag == 't';
            bool dexp = listflag == 'e';
            var dataClient = new DataClient(usrModel.Name, usrModel.Id, dnet, tnet) {IsDexportConnected = dexp};

            if (dnet)
            {
                dataClient.DClientProxy = clientProxy;
                dataClient.DnetClient = CurrentClient;
                CurrentLoginTypeDnet = true;
                CurrentLoginTypeTnet = false;
                CurrentLoginTypeDexp = false;
                dataClient.DexportProxy = null;
                dataClient.TnetClient = null;

            }
            if (tnet)
            {
                dataClient.TClientProxy = clientProxy;
                dataClient.TnetClient = CurrentClient;
                CurrentLoginTypeTnet = true;
                CurrentLoginTypeDnet = false;
                CurrentLoginTypeDexp = false;
                dataClient.DnetClient = null;
                dataClient.DexportProxy = null;

            }
            if (dexp)
            {
                dataClient.DexportProxy = clientProxy;
                dataClient.DexportClient = CurrentClient;
                CurrentLoginTypeDexp = true;
                CurrentLoginTypeTnet = false;
                CurrentLoginTypeDnet = false;
                dataClient.DnetClient = null;
                dataClient.TnetClient = null;

            }

            dataClient.IndexInAdminList = (int) client.ClientId;
            Clients[client.ClientId] = dataClient;

            //Register to Disconnected event to know when user connection is closed
            client.Disconnected += Client_Disconnected;
            //Start a new task to send user list to mainform

            if (OnloggedInLog != null)
            {
                var msg = new DataAdminMessageFactory.LogMessage
                              {
                                  OperationStatus = DataAdminMessageFactory.LogMessage.Status.Finished,
                                  LogType = DataAdminMessageFactory.LogMessage.Log.Login,
                                  Time = DateTime.Now,
                                  UserID = usrModel.Id,
                                  IsDataNetClient = CurrentLoginTypeDnet,
                                  IsTickNetClient = CurrentLoginTypeTnet,
                              };
                var msgMain = "Client " + usrModel.Name + " connected from " + CurrentClient.RemoteEndPoint;
                OnloggedInLog(msg, msgMain);
            }
            OnClientLogon(usrModel);
            Task.Factory.StartNew(OnUserListChanged);
        }
예제 #8
0
파일: FormMain.cs 프로젝트: ruslanlyalko/DA
 public void SendLog(List<string> symbols, DataAdminMessageFactory.LogMessage.Log logtype, string groupName, bool started, bool finished)
 {
     var status = started ? DataAdminMessageFactory.LogMessage.Status.Started: DataAdminMessageFactory.LogMessage.Status.Finished;
     if (symbols.Count > 0)
     {
         foreach (var symbol in symbols)
         {
             var logMsg = new DataAdminMessageFactory.LogMessage(_client.UserID, DateTime.Now, symbol,
                                    logtype, groupName, status)
                 {
                     IsByDataNetBusy = true,
                     IsDataNetClient = true,
                     IsTickNetClient = false
                 };
             if (started)
                 _logClientService.ServiceProxy.SendStartedOperationLog(logMsg);
             else if (finished)
             {
                 logMsg.IsByDataNetBusy = false;
                _logClientService.ServiceProxy.SendFinishedOperationLog(logMsg);
             }
         }
     }
     else
     {
         var logMsg = new DataAdminMessageFactory.LogMessage(_client.UserID, DateTime.Now, "",
                      logtype, groupName, status);
         if (started)
             _logClientService.ServiceProxy.SendStartedOperationLog(logMsg);
         else if (finished)
             _logClientService.ServiceProxy.SendFinishedOperationLog(logMsg);
     }
 }