Ejemplo n.º 1
0
        /// <summary>
        /// Processing of input queue
        /// </summary>
        public void OnSenderTimer(object sender, System.Timers.ElapsedEventArgs args)
        {
            SenderMonitorEvent.SendMonitorEvent(EventLog, "Monitoring the send command activity", EventLogEntryType.Information, 3);
            m_SenderTimer.Stop();

            string lLastError         = string.Empty;
            int    CountJobsToProcess = 0;

            try
            {
                KEPSSenderdbData senderDbData  = new KEPSSenderdbData(OdataServiceUrl);
                JobOrders        jobsToProcess = senderDbData.GetJobsToProcess();
                CountJobsToProcess = jobsToProcess.JobOrdersObj.Count;
                SenderMonitorEvent.SendMonitorEvent(EventLog, "Jobs to process: " + CountJobsToProcess, EventLogEntryType.Information, 3);

                string sendState = string.Empty;
                if (CountJobsToProcess > 0)
                {
                    // Step 1 -- Connect to UA server
                    SenderMonitorEvent.SendMonitorEvent(EventLog, "Step 1 -- Connect to OPC server", EventLogEntryType.Information, 4);
                    //string discoveryUrl = "opc.tcp://127.0.0.1:49320";
                    using (Session AMSession = ClientUtils.CreateSession(OPCServerUrl, "ArcelorMittal.UA.SenderCommand"))
                    {
                        SenderMonitorEvent.SendMonitorEvent(EventLog, "Loop through jobs", EventLogEntryType.Information, 4);
                        foreach (JobOrders.JobOrdersValue jobVal in jobsToProcess.JobOrdersObj)
                        {
                            try
                            {
                                SenderMonitorEvent.SendMonitorEvent(EventLog, "new SenderJobProps", EventLogEntryType.Information, 4);
                                SenderJobProps job = new SenderJobProps(jobVal.ID,
                                                                        jobVal.Command,
                                                                        (string)(jobVal.CommandRule));
                                SenderMonitorEvent.SendMonitorEvent(EventLog, "WriteToKEPServer", EventLogEntryType.Information, 4);
                                if (WriteToKEPServer(AMSession, job))
                                {
                                    sendState = "Done";
                                    if (wmiProductInfo != null)
                                    {
                                        wmiProductInfo.LastActivityTime = DateTime.Now;
                                    }
                                }
                                else
                                {
                                    sendState = "Failed";
                                }
                                lLastError = string.Format("JobOrderID: {0}. Send to KEP Server element {1} = {2}. Status: {3}", job.JobOrderID, job.Command, job.CommandRule, sendState);

                                if (sendState == "Done")
                                {
                                    Requests.UpdateJobStatus(OdataServiceUrl, job.JobOrderID, sendState);
                                }
                                else if (sendState == "Failed")
                                {
                                    if (wmiProductInfo != null)
                                    {
                                        wmiProductInfo.LastServiceError = string.Format("{0}. On {1}", lLastError, DateTime.Now);
                                    }
                                }
                                SenderMonitorEvent.SendMonitorEvent(EventLog, lLastError, EventLogEntryType.Information, 5);
                            }
                            catch (Exception ex)
                            {
                                lLastError = "Error sending command: " + ex.ToString();
                                SenderMonitorEvent.SendMonitorEvent(EventLog, lLastError, EventLogEntryType.Error, 4);
                                lLastError = "Reconecting...";
                                SenderMonitorEvent.SendMonitorEvent(EventLog, lLastError, EventLogEntryType.Information, 4);
                                AMSession.Reconnect();
                            }
                        }
                        // Step 3 -- Clean up
                        //AMSession.Close();
                        AMSession.KeepAlive -= ClientUtils.Session_KeepAlive;
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    string details = string.Empty;
                    if (ex is System.Net.WebException)
                    {
                        var resp = new System.IO.StreamReader((ex as System.Net.WebException).Response.GetResponseStream()).ReadToEnd();

                        try
                        {
                            dynamic obj = Newtonsoft.Json.JsonConvert.DeserializeObject(resp);
                            details = obj.error.message;
                        }
                        catch
                        {
                            details = resp;
                        }
                    }
                    lLastError = "Error getting jobs: " + ex.ToString() + " Details: " + details;
                    SenderMonitorEvent.SendMonitorEvent(EventLog, lLastError, EventLogEntryType.Error, 4);
                    if (wmiProductInfo != null)
                    {
                        wmiProductInfo.LastServiceError = string.Format("{0}. On {1}", lLastError, DateTime.Now);
                    }
                }
                catch (Exception exc)
                {
                    SenderMonitorEvent.SendMonitorEvent(EventLog, exc.Message, EventLogEntryType.Error, 4);
                }
            }
            if (wmiProductInfo != null)
            {
                wmiProductInfo.SendCommandsCount += CountJobsToProcess;
                wmiProductInfo.PublishInfo();
            }
            SenderMonitorEvent.SendMonitorEvent(EventLog, string.Format("Send command is done. {0} tasks", CountJobsToProcess), EventLogEntryType.Information, 3);

            m_SenderTimer.Start();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processing of input queue
        /// </summary>
        public void OnSenderTimer(object sender, System.Timers.ElapsedEventArgs args)
        {
            SenderMonitorEvent.sendMonitorEvent(vpEventLog, "Monitoring the send command activity", EventLogEntryType.Information);
            m_SenderTimer.Stop();

            string lLastError         = string.Empty;
            int    CountJobsToProcess = 0;

            try
            {
                KEPSSenderdbData senderDbData  = new KEPSSenderdbData(OdataServiceUrl);
                JobOrders        jobsToProcess = senderDbData.getJobsToProcess();
                CountJobsToProcess = jobsToProcess.JobOrdersObj.Count;
                SenderMonitorEvent.sendMonitorEvent(vpEventLog, "Jobs to process: " + CountJobsToProcess, EventLogEntryType.Information);

                string sendState = string.Empty;
                if (CountJobsToProcess > 0)
                {
                    // Step 1 -- Connect to UA server
                    //string discoveryUrl = "opc.tcp://127.0.0.1:49320";
                    using (Session AMSession = ClientUtils.CreateSession(OPCServerUrl, "ArcelorMittal.UA.SenderCommand"))
                    {
                        foreach (JobOrders.JobOrdersValue jobVal in jobsToProcess.JobOrdersObj)
                        {
                            try
                            {
                                SenderJobProps job = new SenderJobProps(jobVal.ID,
                                                                        jobVal.Command,
                                                                        (string)(jobVal.CommandRule));

                                if (WriteToKEPServer(AMSession, job))
                                {
                                    sendState = "Done";
                                    wmiProductInfo.LastActivityTime = DateTime.Now;
                                }
                                else
                                {
                                    sendState = "Failed";
                                }
                                lLastError = String.Format("JobOrderID: {0}. Send to KEP Server element {1} = {2}. Status: {3}", job.JobOrderID, job.Command, job.CommandRule, sendState);

                                if (sendState == "Done")
                                {
                                    Requests.updateJobStatus(OdataServiceUrl, job.JobOrderID, sendState);
                                }
                                else if (sendState == "Failed")
                                {
                                    wmiProductInfo.LastServiceError = string.Format("{0}. On {1}", lLastError, DateTime.Now);
                                }
                            }
                            catch (Exception ex)
                            {
                                lLastError = "Error sending command: " + ex.ToString();
                                SenderMonitorEvent.sendMonitorEvent(vpEventLog, lLastError, EventLogEntryType.Error);
                                lLastError = "Reconecting...";
                                SenderMonitorEvent.sendMonitorEvent(vpEventLog, lLastError, EventLogEntryType.Information);
                                AMSession.Reconnect();
                            }
                        }
                        // Step 3 -- Clean up
                        AMSession.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                lLastError = "Error getting jobs: " + ex.ToString();
                SenderMonitorEvent.sendMonitorEvent(vpEventLog, lLastError, EventLogEntryType.Error);
                wmiProductInfo.LastServiceError = string.Format("{0}. On {1}", lLastError, DateTime.Now);
            }
            wmiProductInfo.SendCommandsCount += CountJobsToProcess;
            wmiProductInfo.PublishInfo();
            SenderMonitorEvent.sendMonitorEvent(vpEventLog, string.Format("Send command is done. {0} tasks", CountJobsToProcess), EventLogEntryType.Information);

            m_SenderTimer.Start();
        }