/// <summary>
        /// Поиск по Id или по ApplicationId
        /// </summary>
        public static ApplicationResponse GetByIdOrApplicationId(int id, Guid applicationId)
        {
            SqlParameter        par;
            ApplicationResponse entity        = null;
            SqlConnection       sqlConnection = new SqlConnection(Const.cs);
            SqlDataReader       reader        = null;
            //SqlCommand sqlCommand = new SqlCommand("GetCreditServiceBybaseServicesYaId", sqlConnection);
            SqlCommand sqlCommand = new SqlCommand("GetByIdOrApplicationId", sqlConnection);

            sqlCommand.CommandType = CommandType.StoredProcedure;

            try
            {
                //SqlParameter par = new SqlParameter("@YaId", SqlDbType.Int);
                //par.Value = yaId;
                //sqlCommand.Parameters.Add(par);

                if (id != 0)
                {
                    par       = new SqlParameter("@Id", SqlDbType.Int);
                    par.Value = id;
                    sqlCommand.Parameters.Add(par);
                }
                else
                {
                    par       = new SqlParameter("@ApplicationId", SqlDbType.UniqueIdentifier);
                    par.Value = applicationId;
                    sqlCommand.Parameters.Add(par);
                }
                par       = new SqlParameter("@Table", SqlDbType.NVarChar, 50);
                par.Value = TableName;
                sqlCommand.Parameters.Add(par);

                sqlConnection.Open();
                reader = sqlCommand.ExecuteReader();
                reader.Read();
                if (reader.HasRows)
                {
                    entity = new ApplicationResponse(reader);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} Exception caught.", ex);
                Logs.ErrorLog(ex.ToString());
            }
            finally
            {
                sqlConnection.Close();
                sqlConnection = null;
            }
            return(entity);
        }
Example #2
0
        public static XmlDocument GetResponce(XMLRequestsEnterpriseService xmlRequests, string url)
        {
            HttpStatusCode      code;
            XmlDocument         responseXml         = null;
            ApplicationResponse applicationResponce = null;

            try
            {
                responseXml = SoapCaller.CallWebService(xmlRequests.RequestXML, url, out code);
                if (code == HttpStatusCode.OK)
                {
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine("{0} Exception caught.", ex);
                //Logs.ErrorLog(ex.ToString());
            }
            //return responseXml;
            return(responseXml);
        }
Example #3
0
        public static XmlDocument GetResponce(XMLRequestsProductService xmlRequests, string url)
        {
            HttpStatusCode      code;
            XmlDocument         responseXml         = null;
            ApplicationResponse applicationResponce = null;

            try
            {
                responseXml = SoapCaller.CallWebService(xmlRequests.RequestXML, url, out code);
                if (code == HttpStatusCode.OK)
                {
                }
            }
            catch (Exception ex)
            {
                //TODO: сделать обработку ошибок
                //TODO: сделать сохранение остатков если получена ошибка о недостаточности количества
                Console.WriteLine("{0} Exception caught.", ex);
                Logs.ErrorLog(ex.ToString());
            }
            //return responseXml;
            return(responseXml);
        }
Example #4
0
 public static ApplicationResponse GetResponce(XMLRequests xmlRequests, string url, string fileName = "")
 {
     #region var
     HttpStatusCode      code;
     XmlDocument         responseXml         = null;
     ApplicationRequest  applicationRequest  = null;
     ApplicationResponse applicationResponce = null;
     int requestCount = 1;
     #endregion var
     if (fileName == "")
     {
         fileName = Guid.NewGuid().ToString();
     }
     try
     {
         responseXml = SoapCaller.CallWebService(xmlRequests.RequestXML, url, out code);
         if (code == HttpStatusCode.OK)
         {
             applicationRequest = new ApplicationRequest(fileName, xmlRequests, responseXml);
             applicationRequest.Save();
             applicationResponce = new ApplicationResponse(responseXml);
             //applicationResponce.Save();
             //if (applicationResponce.Status == Enum.ApplicationStatus.ACCEPTED)
             if (applicationResponce.Status != Enum.ApplicationStatus.REJECTED)
             {
                 xmlRequests = new XMLRequests(applicationResponce.ApplicationId);
                 while (applicationResponce.Status != Enum.ApplicationStatus.COMPLETED)
                 {
                     TimeSpan i = applicationResponce.RcvDate - applicationResponce.IssueDate;
                     Thread.Sleep(1000); //Thread.Sleep(3000);
                     if (i.Seconds > 0)
                     {
                         Thread.Sleep((i.Seconds + 1) * 1000); //сколько секунд ждать, для минут 60000
                     }
                     responseXml = SoapCaller.CallWebService(xmlRequests.RequestXML, url, out code);
                     requestCount++;
                     applicationResponce = new ApplicationResponse(responseXml);
                     applicationResponce.RequestCount = requestCount;
                     //TODO: определить количество повторов до выхода и подумать о вынесении в Const
                     //if (requestCount > 100)
                     //{
                     //    applicationResponce.ErrorList.Add(new Error("Превышено допустимое число повторных запросов", "Подозрение на зависание запроса в статусе IN_PROCESS"));
                     //    applicationResponce.Status = Enum.ApplicationStatus.REJECTED;
                     //}
                     if (applicationResponce.Status == Enum.ApplicationStatus.COMPLETED || applicationResponce.Status == Enum.ApplicationStatus.REJECTED)
                     {
                         applicationResponce.Save();
                     }
                     if (applicationResponce.Status == Enum.ApplicationStatus.REJECTED)
                     {
                         break;
                     }
                 }
                 XmlNodeList xmlNodeList = responseXml.GetElementsByTagName("merc:stockEntry");
                 if (xmlNodeList == null || xmlNodeList.Count == 0)
                 {
                     xmlNodeList = responseXml.GetElementsByTagName("vd:stockEntry");
                 }
                 if (xmlNodeList != null)
                 {
                     foreach (XmlNode xmlNode in xmlNodeList)
                     {
                         //StockEntrys.Save(XTO.StockEntry(xmlNode));
                     }
                 }
             }
             else
             {
                 //TODO: сделать обработку ошибок
             }
         }
     }
     catch (Exception ex)
     {
         //TODO: сделать сохранение остатков если получена ошибка о недостаточности количества
         if (ex.Message != Const.ErrorThrow)
         {
             Console.WriteLine("{0} Exception caught.", ex);
             Logs.ErrorLog(ex.ToString());
         }
         else
         {
             throw;
         }
     }
     finally
     {
         #region var = null
         responseXml        = null;
         applicationRequest = null;
         //applicationResponce = null;
         #endregion var = null
     }
     //return responseXml;
     return(applicationResponce);
 }