private void ProcessMessageLogRow(Guid messageLogId, string messageText, TREntities entitiesModel)
        {
            Utilities.WriteLog("MessageLog Row is processing...");
            var baseRequest = xmlHelper.ParseInputXmlBase(messageText);
            businessUnitID = baseRequest.BusinessUnitID;

            ProcessSQLRow(baseRequest, messageText, messageLogId, entitiesModel);

            Thread.Sleep(2 * sleepMs);
            Utilities.WriteLog("MessageLog Row has been processed...");
        }
 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 WFMHelper(string user, string password, string businessUnitId, TREntities _entitiesModel)
 {
     entitiesModel = _entitiesModel;
     _businessUnitID = businessUnitId;
     try
     {
         wfmServiceApplication = new ServiceApplication(user, password, _businessUnitID);
         SetBusinessUnit(_businessUnitID);
         authenticationResultSuccessful = wfmServiceApplication.AuthenticationSuccessful;
         authenticationResultMessage = @"Authorized: OK;";
     }
     catch (Exception ex)
     {
         authenticationResultSuccessful = false;
         authenticationResultMessage = ex.Message;
     }
 }
 private void start()
 {
     started = true;
     try
     {
         Utilities.WriteLog("MessageLog has been started...");
         int i = 0;
         while (true)
         {
             using (TREntities entitiesModel = new TREntities())
             {
                 entitiesModel.Database.Connection.Open();
                 var list = entitiesModel.fsp_MessageLogUnprocessedList(1000, 0).ToList();
                 foreach (var rowItem in list)
                 {
                     var messageLogId = rowItem.MessageLogId;
                     var messageText = rowItem.InputMessageText;
                     ProcessMessageLogRow(messageLogId, messageText, entitiesModel);
                 }
                 Thread.Sleep(sleepMs);
                 if (i == 10)
                 {
                     Utilities.WriteLog("MessageLog has been scanned 10 times...");
                     i = 0;
                 }
                 else
                 {
                     i++;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         var message = String.Format(@"Message Log Exception {0};", ex.Message);
         Utilities.WriteLog(message);
         started = false;
     }
 }
 public csAsyncMsgConsumer(string _emsServer, string _emsUser, string _emsPassword,string _emsInputQueue,string _emsOutputQueue, string _wfmUser, string _wfmPassword)
 {
     emsServerUrl = _emsServer;
     emsUserName = _emsUser;
     emsUserPassword = _emsPassword;
     _emsInputQueueName = _emsInputQueue;
     _emsOutputQueueName = _emsOutputQueue;
     wfmUser = _wfmUser;
     wfmPassword = _wfmPassword;
     entitiesModel = new TREntities();
     entitiesModel.Database.Connection.Open();
 }
 public EMSCompletionListener(TREntities model)
 {
     _model = model;
     xmlHelper = new XMLHelper();
 }