Exemplo n.º 1
0
 private static async Task AsyncGet(UTM utm, int timeOut)
 {
     await Task.Run(() => Get(utm, timeOut));
 }
Exemplo n.º 2
0
        public static void Get(UTM utm, int timeOut)
        {
            try
            {
                if (utm.IsActive)
                {
                    WorkWithXML     workWithXML = new WorkWithXML();
                    List <UTM_Data> listFromUtm = null; //all files from UTM

                    string pathToOutFilesFromUTM = ConfigurationManager.AppSettings.Get("pathToOutFilesFromUTM");
                    if (pathToOutFilesFromUTM == null || pathToOutFilesFromUTM == "")
                    {
                        pathToOutFilesFromUTM = "/opt/out";
                    }

                    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(utm.URL + pathToOutFilesFromUTM);
                    httpWebRequest.Method  = "GET";
                    httpWebRequest.Timeout = Convert.ToInt32(timeOut);

                    using (StreamReader streamReader = new StreamReader(httpWebRequest.GetResponse().GetResponseStream(), Encoding.UTF8))
                    {
                        string responseFromUTM = streamReader.ReadToEnd();               // xml with list of all tickets on UTM
                        listFromUtm = workWithXML.ParseResponseFromUTM(responseFromUTM); //get list all files on UTM
                        listFromUtm.Reverse();
                    }

                    httpWebRequest = null;

                    foreach (var y in listFromUtm)
                    {
                        string xmlContent = null;

                        HttpWebRequest httpWebRequestGetTicket = (HttpWebRequest)WebRequest.Create(y.URL);
                        httpWebRequestGetTicket.Method  = "GET";
                        httpWebRequestGetTicket.Timeout = Convert.ToInt32(timeOut);

                        using (StreamReader streamReader = new StreamReader(httpWebRequestGetTicket.GetResponse().GetResponseStream(), Encoding.UTF8))
                        {
                            xmlContent = streamReader.ReadToEnd();
                        }

                        httpWebRequestGetTicket = null;

                        y.XMLContent = xmlContent;
                        y.UTMId      = utm.UTMId;

                        string DocType = null;

                        if (y.ExchangeTypeCode.ToUpper() == "TICKET")
                        {
                            DocType = workWithXML.GetTicketDocType(y.XMLContent);
                        }
                        else
                        {
                            DocType = y.ExchangeTypeCode;
                        }


                        if (y.Error != 1 & DocTypeDeletePossibility(DocType))
                        {
                            y.InsertTicket();                                                                       // insert into UTM_Data

                            HttpWebRequest  httpWebRequestDeleteTicket  = (HttpWebRequest)WebRequest.Create(y.URL); //delete ticket from UTM
                            HttpWebResponse httpWebResponseDeleteTicket = null;

                            httpWebRequestDeleteTicket.Timeout = Convert.ToInt32(timeOut);
                            httpWebRequestDeleteTicket.Method  = "DELETE";
                            httpWebResponseDeleteTicket        = (HttpWebResponse)httpWebRequestDeleteTicket.GetResponse();

                            httpWebRequestDeleteTicket  = null;
                            httpWebResponseDeleteTicket = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log log = new Log(ex);
            }
        }