private void ProcessSQLRow(BaseRequest baseRequest, string messageText, Guid messageLogId, TREntities entitiesModel)
 {
     WFMHelper wfmHelper = new WFMHelper(wfmUser, wfmPassword, baseRequest.BusinessUnitID, entitiesModel);
     if (wfmHelper.AuthenticationResultSuccessful)
     {
         if (baseRequest.RequestType == RequestTypes.RequestTypeEnum.Person)
         {
             PersonRequest personRequest = xmlHelper.ProcessInputXMLPerson(messageText);
             if (personRequest.XMLReturnCode == 0)
             {
                 try
                 {
                     var res1 = entitiesModel.fsp_MessageLog_WFMBeginUpdate(messageLogId, 0).FirstOrDefault();
                     personRequest = wfmHelper.ProcessPersonRequest(personRequest);
                     var res2 =
                         entitiesModel.fsp_MessageLog_WFMUpdate(messageLogId, personRequest.WFMReturnCode,
                             personRequest.WFMReturnMessage, 0).FirstOrDefault();
                 }
                 catch (Exception ex)
                 {
                     Utilities.WriteExceptionMessageToLog(ex);
                 }
             }
             personRequest.ReturnCode = personRequest.WFMReturnCode;
             personRequest.ReturnMessage = personRequest.WFMReturnMessage;
             consumer.MessageSend(messageLogId, personRequest);
         }
         else if (baseRequest.RequestType == RequestTypes.RequestTypeEnum.Report)
         {
             ReportRequest reportRequest = xmlHelper.ProcessInputXMLReport(messageText);
             if (reportRequest.XMLReturnCode == 0)
             {
                 var res1 = entitiesModel.fsp_MessageLog_WFMBeginUpdate(messageLogId, 0).FirstOrDefault();
                 reportRequest = wfmHelper.ProcessReportRequest(reportRequest);
                 var res2 =
                     entitiesModel.fsp_MessageLog_WFMUpdate(messageLogId,
                         reportRequest.WFMReturnCode,
                         reportRequest.WFMReturnMessage, 0).FirstOrDefault();
             }
             consumer.MessageSend(messageLogId, reportRequest);
         }
     }
     else // неудачная идентификация
     {
         baseRequest.ReturnCode = -1;
         baseRequest.ReturnMessage = @"Неудачная авторизация в WFM";
         baseRequest.ReturnType = ReturnTypes.ReturnTypeEnum.SystemError;
         consumer.MessageSend(messageLogId, baseRequest);
     }
 }
 public PersonRequest Base2PersonRequest(BaseRequest baseRequest)
 {
     PersonRequest personRequest = new PersonRequest();
     personRequest.BusinessUnitID = baseRequest.BusinessUnitID;
     personRequest.MessageLogId = baseRequest.MessageLogId;
     personRequest.RequestAction = baseRequest.RequestAction;
     personRequest.RequestID = baseRequest.RequestID;
     personRequest.RequestType = baseRequest.RequestType;
     personRequest.ReturnType = baseRequest.ReturnType;
     personRequest.ReturnCode = baseRequest.ReturnCode;
     personRequest.ReturnMessage = baseRequest.ReturnMessage;
     personRequest.WFMReturnCode = baseRequest.WFMReturnCode;
     personRequest.WFMReturnMessage = baseRequest.WFMReturnMessage;
     personRequest.XMLReturnCode = baseRequest.XMLReturnCode;
     personRequest.XMLReturnMessage = baseRequest.XMLReturnMessage;
     return personRequest;
 }
        public string OutputXMLMessageGenerate(Guid MessageLogId, BaseRequest baseRequest)
        {
            //<? xml version = "1.0" ?>
            //< PersonCreate.response xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" >
            //< RequestID > 13B77B73 - A80D - 4E65 - BCC1 - B045867CE038 </ RequestID >
            //< PersonID > FFD9C2F7 - 70C4 - 4EBF - 90F4 - A30600FFF235 </ PersonID >
            //< ReturnCode > 0 </ ReturnCode >
            //< ReturnMessage > OK </ ReturnMessage >
            //</ PersonCreate.response >
            string newPersonID = @"";
            var personRequest = baseRequest as PersonRequest;
            if (personRequest != null)
            {
                newPersonID = personRequest.NewPersonID;
            }

            XElement result = null;

            if (!string.IsNullOrEmpty(newPersonID))
            {
                result = new XElement(baseRequest.RequestType.ToString() + @"." + baseRequest.RequestAction + @".response",
                new XElement("MessageLogId", MessageLogId),
                new XElement("RequestID", baseRequest.RequestID.ToString()),
                new XElement("BusinessUnitID", baseRequest.BusinessUnitID),
                new XElement("NewPersonID", newPersonID),
                new XElement("ReturnType", baseRequest.ReturnType.ToString()),
                new XElement("ReturnCode", baseRequest.ReturnCode),
                new XElement("ReturnMessage", baseRequest.ReturnMessage)
                );
            }
            else
            {
                result = new XElement(baseRequest.RequestType.ToString() + @"." + baseRequest.RequestAction + @".response",
                new XElement("MessageLogId", MessageLogId),
                new XElement("RequestID", baseRequest.RequestID.ToString()),
                new XElement("BusinessUnitID", baseRequest.BusinessUnitID),
                new XElement("ReturnType", baseRequest.ReturnType.ToString()),
                new XElement("ReturnCode", baseRequest.ReturnCode),
                new XElement("ReturnMessage", baseRequest.ReturnMessage)
                );
            }

            return result.ToString();
        }
 public BaseRequest ParseInputXmlBase(string messageText)
 {
     BaseRequest baseRequest = new BaseRequest();
     try
     {
         XmlDocument doc = new XmlDocument();
         doc.LoadXml(messageText);
         string docElementName = doc.DocumentElement.Name;
         var parsedDocElementName = docElementName.Split('.');
         var requestType = parsedDocElementName[0];
         var requestAction = parsedDocElementName[1];
         var requestMark = parsedDocElementName[2];
         baseRequest.RequestAction = requestAction;
         if (requestType == @"Person")
         {
             baseRequest.RequestType = RequestTypes.RequestTypeEnum.Person;
         }
         else if (requestType == @"Report")
         {
             baseRequest.RequestType = RequestTypes.RequestTypeEnum.Report;
         }
         else
         {
             baseRequest.RequestType = RequestTypes.RequestTypeEnum.None;
         }
         Guid requestGuid = Guid.Empty;
         Guid.TryParse(ProcessNode(doc, "RequestID"), out requestGuid);
         baseRequest.RequestID = requestGuid;
         baseRequest.BusinessUnitID = ProcessNode(doc, "BusinessUnitID");
         baseRequest.XMLReturnCode = 0;
         baseRequest.XMLReturnMessage = @"OK";
     }
     catch (Exception ex)
     {
         Utilities.WriteLog(String.Format(ex.Message + " " + ex.StackTrace));
         baseRequest.XMLReturnCode = -1;
         baseRequest.XMLReturnMessage = ex.Message;
     }
     return baseRequest;
 }
 public ReportRequest Base2ReportRequest(BaseRequest baseRequest)
 {
     ReportRequest reportRequest = new ReportRequest();
     reportRequest.BusinessUnitID = baseRequest.BusinessUnitID;
     reportRequest.MessageLogId = baseRequest.MessageLogId;
     reportRequest.RequestAction = baseRequest.RequestAction;
     reportRequest.RequestID = baseRequest.RequestID;
     reportRequest.RequestType = baseRequest.RequestType;
     reportRequest.ReturnType = baseRequest.ReturnType;
     reportRequest.ReturnCode = baseRequest.ReturnCode;
     reportRequest.ReturnMessage = baseRequest.ReturnMessage;
     reportRequest.WFMReturnCode = baseRequest.WFMReturnCode;
     reportRequest.WFMReturnMessage = baseRequest.WFMReturnMessage;
     reportRequest.XMLReturnCode = baseRequest.XMLReturnCode;
     reportRequest.XMLReturnMessage = baseRequest.XMLReturnMessage;
     return reportRequest;
 }
 private void ProcessSQLRow(BaseRequest baseRequest, string messageText, Guid messageLogId)
 {
     WFMHelper wfmHelper = new WFMHelper(wfmUser, wfmPassword, baseRequest.BusinessUnitID, entitiesModel);
     if (wfmHelper.AuthenticationResultSuccessful)
     {
         if (baseRequest.RequestType == RequestTypes.RequestTypeEnum.Person)
         {
             PersonRequest personRequest = xmlHelper.ProcessInputXMLPerson(messageText);
             if (personRequest.XMLReturnCode == 0)
             {
                 personRequest = wfmHelper.ProcessPersonRequest(personRequest);
                 var resUpdateWFMResult =
                     entitiesModel.fsp_MessageLog_WFMUpdate(messageLogId,
                         personRequest.WFMReturnCode,
                         personRequest.WFMReturnMessage, 0).FirstOrDefault();
             }
             MessageSend(messageLogId, personRequest);
         }
         else if (baseRequest.RequestType == RequestTypes.RequestTypeEnum.Report)
         {
             ReportRequest reportRequest = xmlHelper.ProcessInputXMLReport(messageText);
             if (reportRequest.XMLReturnCode == 0)
             {
                 reportRequest = wfmHelper.ProcessReportRequest(reportRequest);
                 var resUpdateWFMResult =
                     entitiesModel.fsp_MessageLog_WFMUpdate(messageLogId,
                         reportRequest.WFMReturnCode,
                         reportRequest.WFMReturnMessage, 0).FirstOrDefault();
             }
             reportRequest.ReturnMessage = reportRequest.ReportResultXML;
             MessageSend(messageLogId, reportRequest);
         }
     }
     else // неудачная идентификация
     {
         baseRequest.ReturnCode = -1;
         baseRequest.ReturnMessage = @"Неудачная авторизация в WFM";
         baseRequest.ReturnType = ReturnTypes.ReturnTypeEnum.SystemError;
         MessageSend(messageLogId, baseRequest);
     }
 }
 public void MessageSend(Guid MessageLogId, BaseRequest baseRequest)
 {
     try
     {
         var xmlMessage = xmlHelper.OutputXMLMessageGenerate(MessageLogId, baseRequest);
         entitiesModel.fsp_MessageLog_OutputMessageUpdate(MessageLogId, xmlMessage, 0);
         Message msg = new TextMessage(emsSession, xmlMessage);
         msgProducer.Send(destination, msg, completionListener);
     }
     catch (Exception ex)
     {
         Utilities.WriteExceptionMessageToLog(ex);
     }
 }