Пример #1
0
 public void PushEvent(BaseEvent baseEvent)
 {
     try {
         if (clk.nextDay()) {
             InstantLogger.log("", "To be continued...", InstantLogger.TypeMessage.important);
             InstantLogger.LogFileInit();
             InstantLogger.log("", "...Continuing", InstantLogger.TypeMessage.important);
         }
         baseEvent.Time = DateTime.Now;
         //if (Core.Instance.Module != null)
         //{
         //    Core.Instance.Module.PushEvent(baseEvent);
         //}
         //else
         //{
         //    InstantLogger.log(baseEvent.ToString(), "Fail to transfer to Core.Instance.Module",
         //                      InstantLogger.TypeMessage.error);
         //}
         if (PushEventToClients(baseEvent))
             InstantLogger.log("", "Done processing", InstantLogger.TypeMessage.normal);
         else {
             InstantLogger.log(baseEvent.ToString(), "No listeners for admission",
                               InstantLogger.TypeMessage.error);
         }
     }
     catch (Exception e) {
         InstantLogger.log(string.Format("Exception:\n{0}\nProcessing:\n{1}", e, baseEvent.ToString()),
                           "Exception caught while processing", InstantLogger.TypeMessage.death);
     }
     return;
 }
        public void OnEvent(BaseEvent newEvent)
        {
            try
            {
                if (form.Status == MainForm.StatusEnum.Recorded)
                {
                    (form.Controls["tbMessages"] as System.Windows.Forms.TextBox).AppendText(newEvent.ToString() + "\n");
                }
            }

            catch { }

            if (newEvent is ConverterBaseEvent)
            {
                ConverterBaseEvent cbEvent = newEvent as ConverterBaseEvent;
                if (cbEvent is HeatChangeEvent && CurrentHeatNumber != (cbEvent as HeatChangeEvent).HeatNumber)
                {
                    SaveEvents(CurrentHeatNumber, AllEvents);
                    CurrentHeatNumber = (cbEvent as HeatChangeEvent).HeatNumber;
                    (form.Controls["tbMessages"] as System.Windows.Forms.TextBox).Clear();
                }
                if (CurrentHeatNumber != 0)
                {
                    AllEvents.Add(cbEvent);
                    WriteLog(CurrentHeatNumber, cbEvent);
                }
            }
        }
 public void OnEvent(BaseEvent newEvent)
 {
     if (newEvent is comAdditionsEvent) {
         InstantLogger.log(newEvent.ToString(), "receive message", InstantLogger.TypeMessage.important);
         Program.OPCCon.Send(newEvent as comAdditionsEvent);
     }
 }
Пример #4
0
 public void CustomOnEvent(BaseEvent newEvent)
 {
     using (var l = new Logger("ConnectionProvider.PrimaryListener.EventProc")) {
         if (Client.protectedMode) {
             try {
                 m_EventListener.OnEvent(newEvent);
             }
             catch (Exception e) {
                 l.err("Event {0} exception {1}::{2} returned:\n{3} ", newEvent.ToString(), e.Source,
                       e.TargetSite, e.Message);
             }
         }
         else
             m_EventListener.OnEvent(newEvent);
     }
 }
        public void OnEvent(BaseEvent newEvent)
        {
            // System.Threading.Thread.Sleep(3000);
            // InstantLogger.log(newEvent.GetType().GetCustomAttributesData()[5].ToString());
            //if (!(newEvent is SteelMakingPatternEvent))
            if ((newEvent is visAdditionTotalEvent))
                InstantLogger.log(newEvent.ToString(), "Received", InstantLogger.TypeMessage.error);
            if (newEvent is visSpectrluksEvent)
                InstantLogger.log(newEvent.ToString(), "Received", InstantLogger.TypeMessage.error);

            if (newEvent is FlexEvent) {
                var flx = newEvent as FlexEvent;
                if (flx.Operation.StartsWith("TestComplex")) {
                    var fxe = new FlexHelper(flx);
                    var dimm = (int[]) fxe.GetComplexArg("dimm", typeof (int[]));
                    Console.WriteLine("Receive:");
                    foreach (var i in dimm)
                        Console.Write((i + ", "));
                }
            }
            //var v = (PLCGroup)newEvent.GetType().GetCustomAttributes(false).Where(x => x.GetType().Name == "PLCGroup").FirstOrDefault();
            //object first = null;
            /*         InstantLogger.log(newEvent.GetType().FullName);
            var plcg = new PLCGroup();
            foreach (object x in newEvent.GetType().GetCustomAttributes(false))
            {
                if (x.GetType().Name == "PLCGroup")
                {
                    plcg = (PLCGroup)x;
                    InstantLogger.log("    " + plcg.Location + " -- " + plcg.Destination);
                }
            }
            var plcp = new PLCPoint();
            foreach (var prop in newEvent.GetType().GetProperties())
            {
                foreach (object x in prop.GetCustomAttributes(false))
                {
                    if (x.GetType().Name == "PLCPoint")
                    {

                        if (((PLCPoint)x).IsWritable)
                        {

                            plcp = (PLCPoint)x;
                            //prop.GetValue(newEvent, null);
                            //prop.GetValue(newEvent);
                            InstantLogger.log("        " + prop.Name + " = " + prop.GetValue(newEvent, null).ToString());
                            InstantLogger.log("            IsWritable = " + plcp.IsWritable.ToString());
                            InstantLogger.log("            " + plcp.Location);
                           // break;
                        }

                    }
                }
            }
             */

            //if (
            //    (newEvent is cntBlowingSchemaEvent) ||
            //    (newEvent is comBlowingSchemaEvent) ||
            //    (newEvent is cntWatchDogPLC01Event) ||
            //    (newEvent is cntWatchDogPLC1Event) ||
            //    (newEvent is cntWatchDogPLC2Event) ||
            //    (newEvent is cntWatchDogPLC3Event) ||
            //    (newEvent is comO2FlowRateEvent) ||
            //   (newEvent is cntO2FlowRateEvent)
            //    )
            //{

            //   // SteelMakingPatternEvent steelMakingPatternEvent = newEvent as SteelMakingPatternEvent;
            //    InstantLogger.log(newEvent.ToString(), "Received", InstantLogger.TypeMessage.death);
            //}
            //if(
            //    (newEvent is comAdditionsEvent) ||
            //    (newEvent is comAdditionsSchemaEvent)
            //   )
            //{
            //    InstantLogger.log(newEvent.ToString(), "Received", InstantLogger.TypeMessage.terror);
            //}

            //if (newEvent is HeatSchemaStepEvent)
            //{
            //    InstantLogger.log("step = " + newEvent.ToString(), "Received", InstantLogger.TypeMessage.caution);
            //}
            //if ((newEvent is cntWeigher3JobReadyEvent) ||
            //    (newEvent is cntWeigher4JobReadyEvent)||
            //    (newEvent is cntWeigher5JobReadyEvent)||
            //    (newEvent is cntWeigher6JobReadyEvent)||
            //    (newEvent is cntWeigher7JobReadyEvent))
            //{
            //    InstantLogger.log("step = " + newEvent.ToString(), "Received", InstantLogger.TypeMessage.normal);
            //}
            /*if (newEvent is SteelMakingPatternEvent)
            {

                SteelMakingPatternEvent steelMakingPatternEvent = newEvent as SteelMakingPatternEvent;
                InstantLogger.log(steelMakingPatternEvent.steps[0].Period.ToString(), "Received", InstantLogger.TypeMessage.important);
            }*/
            // lock (Program.consoleLock)
            //{
            /* Console.BackgroundColor = ConsoleColor.Blue;
               Console.ForegroundColor = ConsoleColor.White;
               Console.WriteLine(" " + newEvent.ToString() + "\n");
               Console.BackgroundColor = ConsoleColor.DarkBlue;
               Console.ForegroundColor = ConsoleColor.Gray;

               logFile.Write(newEvent.ToString() + "\n");*/
            // InstantLogger.log(newEvent.ToString(), "Received", InstantLogger.TypeMessage.unimportant);

            //logFile.Close();
            //}

            //MessageBox.Show("ll", "ll");
        }
 public void OnEvent(BaseEvent newEvent)
 {
     Console.WriteLine(newEvent.ToString());
 }
Пример #7
0
        public bool PushEventToClients(BaseEvent baseEvent)
        {
            bool result = false;
            subscribers.ForEach(delegate(IMainGateCallback callback) {
                                    if (((ICommunicationObject) callback).State != CommunicationState.Opened) {
                                        InstantLogger.log(
                                            callback.ToString() + " is \"" +
                                            ((ICommunicationObject) callback).State.ToString() + "\"",
                                            "Dead callback is removed", InstantLogger.TypeMessage.warning);
                                        subscribers.Remove(callback);
                                    }
                                });
            try {
                bool firstLoop = true;
                foreach (var callback in subscribers) {
                    if (((ICommunicationObject) callback).State == CommunicationState.Opened) {
                        TaskInfo ti = new TaskInfo(baseEvent, callback);
                        result = System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(OnEventTask), ti);
                        if (firstLoop) {
                            InstantLogger.log(baseEvent.ToString(),
                                              "message is delivered -- OnEvent processing initiated",
                                              InstantLogger.TypeMessage.unimportant);
                            firstLoop = false;
                        }
                        //callback.OnEvent(baseEvent);
                        result = true;
                    }
                    else {
                        InstantLogger.log(baseEvent.ToString(), "message is not delivered",
                                          InstantLogger.TypeMessage.important);
                        //subscribers.Remove(callback);
                    }
                }
            }
            catch (Exception e) {
                InstantLogger.err("source exception:\n{0}", e.ToString());
                result = false;
            }
            //subscribers.ForEach(delegate(IMainGateCallback callback)
            //{
            //    if (((ICommunicationObject)callback).State == CommunicationState.Opened)
            //    {
            //        InstantLogger.log(baseEvent.ToString(), "message is delivered", InstantLogger.TypeMessage.unimportant);
            //        callback.OnEvent(baseEvent);
            //        result = true;
            //    }
            //    else
            //    {
            //        InstantLogger.log(baseEvent.ToString(), "message is not delivered", InstantLogger.TypeMessage.important);
            //        //subscribers.Remove(callback);
            //    }

            //});

            return result;
        }