Ejemplo n.º 1
0
 private void Secs1Port_OnSECS1Event(SECSEventType eventtype, SECSTransaction trans, SECSErrors err, string errmsg)
 {
     if (this.s9FxMonitor.PreHandleSECSEvent(eventtype, trans, err))
     {
         this.CallSECSEvent(eventtype, trans, err, errmsg);
     }
 }
Ejemplo n.º 2
0
 private void HandleWriteError(SECSEventType type, SECSTransaction t, string errmsg)
 {
     if (this.OnHSMSEvent != null)
     {
         this.OnHSMSEvent(SECSEventType.Error, t, SECSErrors.WriteError, string.Format("{0} {1}", type.ToString(), errmsg));
     }
 }
Ejemplo n.º 3
0
 private void RemoveConversationTimeout(SECSEventType eventtype, SECSTransaction trans, SECSErrors err)
 {
     if (eventtype == SECSEventType.PrimaryRcvd && trans != null && trans.Primary != null && err == SECSErrors.None)
     {
         string str = string.Format("S{0}F{1}", trans.Primary.Stream, trans.Primary.Function);
         if (this.conversactionReflect.ContainsKey(str))
         {
             lock (this.syncConversation)
             {
                 int num = -1;
                 for (int i = 0; i < this.conversationList.Count; i++)
                 {
                     if (this.conversationList[i].Transaction1 == this.conversactionReflect[str])
                     {
                         num = i;
                         break;
                     }
                 }
                 if (num != -1)
                 {
                     this.conversationList.RemoveAt(num);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 private void eventExecutor_OnSECS1Event(SECSEventType eventtype, SECSTransaction trans, SECSErrors err, string errmsg)
 {
     if (this.OnSECS1Event != null)
     {
         this.OnSECS1Event(eventtype, trans, err, errmsg);
     }
 }
Ejemplo n.º 5
0
 private void UpdateMatchedSecondary(SECSEventType eventtype, SECSTransaction trans)
 {
     if (eventtype == SECSEventType.PrimaryRcvd && trans != null && trans.Primary != null && this.secsPort.Library != null && trans.Primary.WBit)
     {
         SECSTransaction transaction = this.secsPort.Library.FindTransaction(string.Format("S{0}F{1}", trans.Primary.Stream, trans.Primary.Function));
         if (transaction != null)
         {
             trans.Secondary = transaction.Secondary;
         }
     }
 }
Ejemplo n.º 6
0
 internal void CallSECSEvent(SECSEventType type, SECSTransaction trans, SECSErrors err, string errmsg)
 {
     if (type == SECSEventType.Error || type == SECSEventType.Warn)
     {
         this.logger.Error(string.Format("SystemBytes: {0}, ERRCODE: {1}, ERRDESC: {2}.", (trans != null) ? trans.SystemBytes.ToString() : "null", err, errmsg));
     }
     if (this.OnSECSEvent != null)
     {
         this.OnSECSEvent(this, type, trans, err, errmsg);
     }
 }
Ejemplo n.º 7
0
 private void AddConversationTimeout(SECSEventType eventtype, SECSTransaction trans, SECSErrors err)
 {
     if (eventtype == SECSEventType.SecondarySent && err == SECSErrors.None && trans != null && trans.Secondary != null)
     {
         string str = string.Format("S{0}F{1}", trans.Secondary.Stream, trans.Secondary.Function);
         if (this.conversactionConfigure.ContainsKey(str))
         {
             if (str == "S3F12")
             {
                 if (trans.Secondary.Root.Item(2).IsEmpty)
                 {
                     return;
                 }
                 if ((int)trans.Secondary.Root.Item(2).Value != 2)
                 {
                     return;
                 }
             }
             else
             {
                 if (trans.Secondary.Root.IsEmpty)
                 {
                     return;
                 }
                 if ((int)trans.Secondary.Root.Value != 0)
                 {
                     return;
                 }
             }
             SECSS9FxMonitor.ConversactionItem item = new SECSS9FxMonitor.ConversactionItem
             {
                 Transaction1 = this.conversactionConfigure[str].Transaction1,
                 Transaction2 = this.conversactionConfigure[str].Transaction2,
                 Transaction  = trans
             };
             try
             {
                 item.EDID = trans.Primary.Root.Item(1).Value.ToString();
                 item.EDID = this.conversactionConfigure[str].EDID + ": " + item.EDID;
             }
             catch (Exception)
             {
                 item.EDID = this.conversactionConfigure[str].EDID;
             }
             lock (this.syncConversation)
             {
                 item.DeadLine = DateTime.Now.AddSeconds(45.0);
                 this.conversationList.Add(item);
             }
         }
     }
 }
Ejemplo n.º 8
0
 internal void NotifyEVENT(SECSEventType type, SECSTransaction trans, SECSErrors err)
 {
     lock (this.syncObject)
     {
         SECS1EventArgs args = new SECS1EventArgs
         {
             EventType = type,
             ErrorCode = err,
             ErrorMsg  = SECSErrorsMessage.GetSECSErrorMessage(err),
             Trans     = trans
         };
         this.eventQueue.Enqueue(args);
     }
 }
Ejemplo n.º 9
0
 private void HsmsPort_OnHSMSEvent(SECSEventType eventtype, SECSTransaction trans, SECSErrors err, string errmsg)
 {
     if (eventtype == SECSEventType.HSMSConnected)
     {
         this.isConnected = true;
     }
     else if (eventtype == SECSEventType.HSMSDisconnected)
     {
         this.isConnected = false;
     }
     if (this.s9FxMonitor.PreHandleSECSEvent(eventtype, trans, err))
     {
         this.CallSECSEvent(eventtype, trans, err, errmsg);
     }
 }
Ejemplo n.º 10
0
 private bool CheckS9F1Exception(SECSEventType eventtype, SECSTransaction trans)
 {
     if (eventtype == SECSEventType.PrimaryRcvd && trans != null && trans.Primary != null && trans.Primary.DeviceIdID != this.secsPort.DeviceID)
     {
         this.SendS9Fx(1, trans.Primary.Header);
         this.secsPort.CallSECSEvent(SECSEventType.Error, trans, SECSErrors.UnrecognizedDeviceID, SECSErrorsMessage.GetSECSErrorMessage(SECSErrors.UnrecognizedDeviceID));
         return(false);
     }
     if (eventtype == SECSEventType.SecondaryRcvd && trans != null && trans.Secondary != null && trans.Secondary.DeviceIdID != this.secsPort.DeviceID)
     {
         this.SendS9Fx(1, trans.Secondary.Header);
         this.secsPort.CallSECSEvent(SECSEventType.Error, trans, SECSErrors.UnrecognizedDeviceID, SECSErrorsMessage.GetSECSErrorMessage(SECSErrors.UnrecognizedDeviceID));
         return(false);
     }
     return(true);
 }
Ejemplo n.º 11
0
 public bool PreHandleSECSEvent(SECSEventType eventtype, SECSTransaction trans, SECSErrors err)
 {
     this.UpdateMatchedSecondary(eventtype, trans);
     if (!this.IsHost)
     {
         if (!this.CheckS9F1Exception(eventtype, trans))
         {
             return(false);
         }
         if (!this.CheckS9F357Exception(eventtype, trans))
         {
             return(false);
         }
         if (eventtype == SECSEventType.Error && err == SECSErrors.T3TimeOut)
         {
             this.SendS9Fx(9, trans.Primary.Header);
             return(true);
         }
         this.AddConversationTimeout(eventtype, trans, err);
         this.RemoveConversationTimeout(eventtype, trans, err);
     }
     return(true);
 }
Ejemplo n.º 12
0
        private bool CheckS9F357Exception(SECSEventType eventtype, SECSTransaction trans)
        {
            SECSMessage msg = null;

            if (eventtype == SECSEventType.PrimaryRcvd)
            {
                msg = trans.Primary;
            }
            else if (eventtype == SECSEventType.SecondaryRcvd)
            {
                msg = trans.Secondary;
            }
            if (this.secsPort.Library != null && msg != null)
            {
                if (!this.secsPort.Library.FindStream(msg.Stream))
                {
                    this.SendS9Fx(3, msg.Header);
                    this.secsPort.CallSECSEvent(SECSEventType.Error, trans, SECSErrors.UnrecognizedStreamType, SECSErrorsMessage.GetSECSErrorMessage(SECSErrors.UnrecognizedStreamType));
                    return(false);
                }
                if (!this.secsPort.Library.FindFunction(msg.Stream, msg.Function))
                {
                    this.SendS9Fx(5, msg.Header);
                    this.secsPort.CallSECSEvent(SECSEventType.Error, trans, SECSErrors.UnrecognizedFunctionType, SECSErrorsMessage.GetSECSErrorMessage(SECSErrors.UnrecognizedFunctionType));
                    return(false);
                }
                List <SECSMessage> list = this.secsPort.Library.FindMessage(msg.Stream, msg.Function);
                if (!this.CheckMsgFormat(msg, list))
                {
                    this.SendS9Fx(7, msg.Header);
                    this.secsPort.CallSECSEvent(SECSEventType.Error, trans, SECSErrors.IllegalData, SECSErrorsMessage.GetSECSErrorMessage(SECSErrors.IllegalData));
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 13
0
        async private void OnSECSEventHandler(SECSPort secsPort, SECSEventType type, SECSTransaction trans, SECSErrors err, string errmsg)
        {
            try
            {
                XElement xmlMessage = secsPort.Library.TransToXElement(trans);
                switch (type)
                {
                case SECSEventType.PrimaryRcvd:
                    if (err == SECSErrors.None)
                    {
                        if (secsPortList.Count < 1)
                        {
                            xmlMessage.Element("Primary").Add(new XElement("UnitName", _unitID));
                        }
                        else
                        {
                            xmlMessage.Element("Primary").Add(new XElement("UnitName", secsPortList.First(j => j.Value.DeviceID == secsPort.DeviceID).Key));
                        }
                        await Task.Factory.StartNew(() => DispatchPrimaryInGEMMessage(secsPort.Name, trans, xmlMessage));
                    }
                    //else
                    //_logWriter.Write(String.Format("Error Code: {0}. {1}", trans.Name, errmsg), "ApplicationException", 0, 8000, System.Diagnostics.TraceEventType.Error, "Primary Recvd Error!");
                    //BOE_CIS20EventSource.Log.ReceiveSECSIIMessage(trans.Name, xmlMessage.Element("Primary").ToString());
                    //_logWriter.Write(xmlMessage.Element("Primary"), "SECSII", 0, 7000, System.Diagnostics.TraceEventType.Information, "Rcvd " + trans.Name);
                    break;

                case SECSEventType.SecondaryRcvd:
                    string transName = ParseMessageName(trans.Primary.Stream, trans.Secondary.Function);
                    //S9F* SecsDriver 会自动恢复,不用自己处理
                    //if (err == SECSErrors.T3TimeOut && trans.Name == "S1F14")
                    //{
                    //    _dispatchGEMMessage.CommunicationFailure("S1F14", null);
                    //}

                    await Task.Factory.StartNew(() => DispatchSecondaryInGEMMessage(transName, xmlMessage));

                    //_logWriter.Write(xmlMessage.Element("Secondary"), "SECSII", 0, 7000, System.Diagnostics.TraceEventType.Information, "Rcvd " + transName);
                    break;

                case SECSEventType.PrimarySent:
                    //_logWriter.Write(xmlMessage.Element("Primary"), "SECSII", 0, 7000, System.Diagnostics.TraceEventType.Information, "Sent " + trans.Name);
                    break;

                case SECSEventType.SecondarySent:
                    //_logWriter.Write(xmlMessage.Element("Secondary"), "SECSII", 0, 7000, System.Diagnostics.TraceEventType.Information, "Reply " + ParseMessageName(trans.Primary.Stream, trans.Secondary.Function));
                    break;

                case SECSEventType.HSMSDisconnected:
                    DispatchSecondaryInGEMMessage("S99F1", null);
                    //_logWriter.Write("HSMS is Disconnected", "SECSII");
                    break;

                case SECSEventType.HSMSConnected:
                    DispatchSecondaryInGEMMessage("S1F13", null);
                    //_logWriter.Write("HSMS is Connected", "SECSII");
                    break;

                case SECSEventType.Error:
                    if (err == SECSErrors.T3TimeOut && trans.Name == "S1F13")
                    {
                        DispatchSecondaryInGEMMessage("S1F14", xmlMessage);
                    }
                    if (err == SECSErrors.ReadError || err == SECSErrors.WriteError)
                    {
                        DispatchSecondaryInGEMMessage("S99F2", null);
                    }
                    string name = "";
                    if (trans != null)
                    {
                        //if (err == SECSErrors.T3TimeOut)
                        //    name = ParseMessageName(trans.Primary.Stream, trans.Secondary.Function);
                        //else
                        name = trans.Name;
                    }
                    //_logWriter.Write(String.Format(" ErrorCode: {0} {1}", err, errmsg), "ApplicationException", 0, 8000, System.Diagnostics.TraceEventType.Error, name + ": SECSDriver Error!");
                    break;
                }
            }
            catch (NullReferenceException n)
            {
            }
            catch (Exception e)
            {
            }
            //Logging
        }