Ejemplo n.º 1
0
        public static EAPOutput Send <T>(CommonInput inputObj) where T : CommonInput
        {
            EAPOutput output = new EAPOutput();

            try
            {
                lock (SyncObj)
                {
                    EAPInput input = new EAPInput();

                    input.InputMessage = inputObj.GetInputMessage <T>((T)inputObj);

                    Log.Logger.Info(String.Format("[ATS Request]:{0}", input.InputMessage));

                    output = _MessageExchangeServiceClient.EAPRequest(input);
                    XDocument xdoc;
                    try
                    {
                        Log.Logger.DebugFormat("[MES Reply]::ErrorCode: {0}, CnErrorText: {1}, EnErrorText: {2}", output.ErrCode, output.CNErrMsg, output.ENErrMsg);

                        if (String.IsNullOrEmpty(output.OutputMessage))
                        {
                            throw new MessageIsEmptyException();
                        }

                        xdoc = XDocument.Parse(output.OutputMessage);
                        var formattedXml = (xdoc.Declaration != null ? xdoc.Declaration + "\r\n" : "") + xdoc.ToString();
                        Log.Logger.InfoFormat("[MES Reply]:Message:{0}", formattedXml.ToString());
                    }
                    catch (Exception e)
                    {
                        Log.Logger.DebugFormat("[MES Reply]: OutputMessage: {0}", output.OutputMessage);

                        throw e;
                    }

                    String equipmentId   = xdoc.Root.Element("EquipmentId").Value;
                    String transactionId = xdoc.Root.Element("TransactionId").Value;

                    if (xdoc.Root.Name.Equals(inputObj.GetReplyRootName))
                    {
                        throw new MesReplyMisMatchException();
                    }
                    if (!inputObj.EquipmentId.Equals(equipmentId))
                    {
                        throw new EquipmentIdMisMatchException();
                    }
                    if (!inputObj.TransactionId.Equals(transactionId))
                    {
                        throw new TransactionIdMisMatchException();
                    }

                    return(output);
                }
            }
            catch (MessageIsEmptyException ex)
            {
                Log.Logger.Error(ex.Message);
                LogShown.RecordLog((String)Application.Current.FindResource("WariningMessage_TrackInToMesOutputMessageIsEmpty"), LogLevel.Warn);
                output.ErrCode  = "2000";
                output.ENErrMsg = (String)CommonParameter.EnLangResourceDictionary["WariningMessage_TrackInToMesOutputMessageIsEmpty"];
            }
            catch (EquipmentIdMisMatchException ex)
            {
                Log.Logger.Error(ex.Message);
                LogShown.RecordLog((String)Application.Current.FindResource("WariningMessage_TrackInToMesEquipmentIdMisMatch"), LogLevel.Warn);
                output.ErrCode  = "2001";
                output.ENErrMsg = (String)CommonParameter.EnLangResourceDictionary["WariningMessage_TrackInToMesEquipmentIdMisMatch"];
            }
            catch (TransactionIdMisMatchException ex)
            {
                Log.Logger.Error(ex.Message);
                LogShown.RecordLog((String)Application.Current.FindResource("WariningMessage_TrackInToMesTransactionIdMisMatch"), LogLevel.Warn);
                output.ErrCode  = "2002";
                output.ENErrMsg = (String)CommonParameter.EnLangResourceDictionary["WariningMessage_TrackInToMesTransactionIdMisMatch"];
            }
            catch (EndpointNotFoundException ex)
            {
                Log.Logger.Error(ex.Message);
                LogShown.RecordLog((String)Application.Current.FindResource("WariningMessage_TrackInToMesEndpointNotFound"), LogLevel.Warn);
                output.ErrCode  = "2003";
                output.ENErrMsg = (String)CommonParameter.EnLangResourceDictionary["WariningMessage_TrackInToMesEndpointNotFound"];
            }
            catch (TimeoutException ex)
            {
                Log.Logger.Error(ex.Message);
                LogShown.RecordLog((String)Application.Current.FindResource("WariningMessage_TrackInToMesTimeout"), LogLevel.Warn);
                output.ErrCode  = "2004";
                output.ENErrMsg = (String)CommonParameter.EnLangResourceDictionary["WariningMessage_TrackInToMesTimeout"];
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex);
                LogShown.RecordLog(String.Format((String)Application.Current.FindResource("ErrorMessage_TrackInToMesUnknownError"), ex.Message), LogLevel.Error);
                output.ErrCode  = "2999";
                output.ENErrMsg = "[ATS] TrackIn to MES Unkown Error";
            }
            return(output);
        }