Пример #1
0
 public void Run()
 {
     try
     {
         AgentServiceClient agentClient = new AgentServiceClient();
         IsRunning = true;
         while (IsRunning)
         {
             lock (OpcCommunication.GetLockObject(serverUrl))
             {
                 if (!IsRunning)
                 {
                     break;
                 }
                 if (OpcCommunication.ServerIsConnected(serverUrl))
                 {
                     agentClient.PostResult(DecisionsAgent.SessionUserContext, DecisionsAgent.AGENT_ID, InstructionId, new AgentInstructionsResult());
                 }
             }
             Thread.Sleep(5000);
         }
     }
     catch
     {
         IsRunning = false;
     }
 }
        public CancellationTokenSource CreateTask( long agentId )
        {
            CancellationTokenSource source = new CancellationTokenSource();
            var task = new Task( async () =>
            {
                while( !source.Token.IsCancellationRequested )
                {
                    try
                    {
                        using( AgentServiceClient client = new AgentServiceClient() )
                        {
                            await client.HandshakeAsync( agentId );
                            while( !source.Token.IsCancellationRequested )
                            {
                                Thread.Sleep( 1000 );
                                await client.DoOperationAsync();
                            }
                        }
                    }
                    catch
                    {
                        Thread.Sleep( 1000 );
                    }
                }

                source.Dispose();
            }, source.Token );
            task.Start();
            return source;
        }
Пример #3
0
        public Controller()
        {
            YSize = 12;
            XSize = 8;

            this.AgentCollection = new ObservableCollection<MapRow>();

            for (int i = 0; i < YSize; i++)
            {
                this.AgentCollection.Add(new MapRow(XSize));

                for (int j = 0; j < XSize; j++)
                {
                    this.AgentCollection[i].Column[j] = '?';
                }
            }

            this.callback.ClientCallback += Update;
            this.remoteService = new AgentServiceClient(this.callback.ClientInstanceContext);
            this.remoteService.RegisterClient();

            //ThreadPool.QueueUserWorkItem(TestThread);
            ThreadPool.QueueUserWorkItem(ReaderThread);
            ThreadPool.QueueUserWorkItem(CleanerThread);
        }
Пример #4
0
        public string TestAgentConnection(string ipAddress)
        {
            string ret            = "";
            string clientEndpiont = "";

            try
            {
                var asc = new AgentServiceClient();
                clientEndpiont       = ConfigurationManager.AppSettings["RMS.NetTcpBinding_AgentService"];
                clientEndpiont       = clientEndpiont.Replace("client_ip_address", ipAddress);
                asc.Endpoint.Address = new EndpointAddress(clientEndpiont);

                NetTcpBinding myBinding = new NetTcpBinding();
                myBinding.Security.Mode = SecurityMode.None;
                myBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
                myBinding.OpenTimeout = new TimeSpan(0, 5, 0);
                asc.Endpoint.Binding  = myBinding;

                var ar = asc.InnerChannel.BeginOpen(null, null);
                if (!ar.AsyncWaitHandle.WaitOne(asc.Endpoint.Binding.OpenTimeout, true))
                {
                    throw new CommunicationException(ipAddress + " Monitoring Agent is not available.");
                }
                asc.InnerChannel.EndOpen(ar);

                asc.TestConnection();
            }
            catch (Exception ex)
            {
                new RMSWebException(this, "0500", "TestAgentConnection failed (" + clientEndpiont + "). " + ex.Message, ex, true);

                return("<br/>" + ex.Message);
            }
            return(ret);
        }
        public CancellationTokenSource CreateTask(long agentId)
        {
            CancellationTokenSource source = new CancellationTokenSource();
            var task = new Task(async() =>
            {
                while (!source.Token.IsCancellationRequested)
                {
                    try
                    {
                        using (AgentServiceClient client = new AgentServiceClient())
                        {
                            await client.HandshakeAsync(agentId);
                            while (!source.Token.IsCancellationRequested)
                            {
                                Thread.Sleep(1000);
                                await client.DoOperationAsync();
                            }
                        }
                    }
                    catch
                    {
                        Thread.Sleep(1000);
                    }
                }

                source.Dispose();
            }, source.Token);

            task.Start();
            return(source);
        }
Пример #6
0
        public DbVersionsDiffForm()
        {
            InitializeComponent();

            _agentServiceClient = new AgentServiceClient();
        }
Пример #7
0
        private void BroadcastAliveMessage(RmsClient client, int refID)
        {
            try
            {
                var    asc            = new AgentServiceClient();
                string clientEndpiont = ConfigurationManager.AppSettings["RMS.NetTcpBinding_AgentService"];
                clientEndpiont       = clientEndpiont.Replace("client_ip_address", client.IpAddress);
                asc.Endpoint.Address = new EndpointAddress(clientEndpiont);

                NetTcpBinding myBinding = new NetTcpBinding();
                myBinding.Security.Mode = SecurityMode.None;
                myBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
                myBinding.OpenTimeout = new TimeSpan(0, 5, 0);
                asc.Endpoint.Binding  = myBinding;

                AddLogMonitoringClient(refID, client.ClientId, client.ClientCode, client.IpAddress, client.State, null);
                var result = asc.Monitoring(client.ClientCode);

                if (agentNotAliveHashtable.Contains(client.ClientCode))
                {
                    agentNotAliveHashtable.Remove(client.ClientCode);
                }
            }
            catch (Exception e)
            {
                try
                {
                    if (e.Message.IndexOf("AddLogMonitoringClient") > -1)
                    {
                        throw new RMSWebException(this, "0500", "BroadcastAliveMessage failed. " + e.Message, e, false);
                    }


                    // ถ้า Cleint State เป็น 1 (Normal) แสดงว่า Agent ผิดปกติ
                    if (client.State == 1)
                    {
                        using (var db = new MyDbContext())
                        {
                            var    rmsSystemConfig = db.RmsSystemConfigs.Find("AgentProcessName");
                            string agentProcessName;
                            if (rmsSystemConfig == null)
                            {
                                agentProcessName = "RMS.Agent.WPF";
                            }
                            else
                            {
                                agentProcessName = rmsSystemConfig.Value ?? rmsSystemConfig.DefaultValue;
                            }

                            rmsSystemConfig = db.RmsSystemConfigs.Find("DelayAlert.AgentNotAlive");
                            string dalayInSecond;
                            if (rmsSystemConfig == null)
                            {
                                dalayInSecond = "90";
                            }
                            else
                            {
                                dalayInSecond = rmsSystemConfig.Value ?? rmsSystemConfig.DefaultValue;
                            }

                            SqlParameter[] parameters = new SqlParameter[1];
                            SqlParameter   p1         = new SqlParameter("ClientID", client.ClientId);
                            parameters[0] = p1;

                            var lists = db.Database.SqlQuery <MonitoringProfileDeviceInfo>("RMS_GetMonitoringProfileDeviceByClientID "
                                                                                           + "@ClientID", parameters);
                            var device = lists.First(f => f.DeviceCode == "CLIENT" && f.DeviceTypeCode == Models.DeviceCode.Client &&
                                                     (string.IsNullOrEmpty(f.StringValue) || f.StringValue == agentProcessName));

                            if (device != null)
                            {
                                bool CanSendMessage = Convert.ToInt32(dalayInSecond) == 0;

                                if (agentNotAliveHashtable.Contains(client.ClientCode))
                                {
                                    DateTime a             = (DateTime)agentNotAliveHashtable[client.ClientCode];
                                    var      diffInSeconds = (DateTime.Now - a).TotalSeconds;
                                    if (diffInSeconds > Convert.ToInt32(dalayInSecond))
                                    {
                                        CanSendMessage = true;
                                    }
                                }
                                else
                                {
                                    agentNotAliveHashtable.Add(client.ClientCode, DateTime.Now);
                                }


                                if (CanSendMessage)
                                {
                                    var mp = new WebService.Proxy.MonitoringService().monitoringService;

                                    RmsReportMonitoringRaw rawMessage = new RmsReportMonitoringRaw
                                    {
                                        ClientCode                = client.ClientCode,
                                        DeviceCode                = "CLIENT",
                                        Message                   = "AGENT_NOT_ALIVE",
                                        MessageDateTime           = DateTime.Now,
                                        MonitoringProfileDeviceId = device.MonitoringProfileDeviceId
                                    };

                                    mp.AddMessage(rawMessage);

                                    if (agentNotAliveHashtable.Contains(client.ClientCode))
                                    {
                                        agentNotAliveHashtable.Remove(client.ClientCode);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new RMSWebException(this, "0500", "BroadcastAliveMessage failed. " + ex.Message, ex, false);
                }
            }
        }
Пример #8
0
        public DeploymentAuditForm()
        {
            InitializeComponent();

              _agentServiceClient = new AgentServiceClient();
        }
Пример #9
0
        public DbVersionsDiffForm()
        {
            InitializeComponent();

              _agentServiceClient = new AgentServiceClient();
        }
Пример #10
0
        public DeploymentAuditForm()
        {
            InitializeComponent();

            _agentServiceClient = new AgentServiceClient();
        }
Пример #11
0
 public AgentServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(AgentServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Пример #12
0
 public AgentServiceClient(EndpointConfiguration endpointConfiguration) :
     base(AgentServiceClient.GetBindingForEndpoint(endpointConfiguration), AgentServiceClient.GetEndpointAddress(endpointConfiguration))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }