Exemplo n.º 1
0
        public static void DeleteAsiiuTicketFromUTM()
        {
            List <UTM> utmList = WorkWithDB.GetActiveUTM();

            try
            {
                foreach (var utm in utmList)
                {
                    if (utm.IsActive & UTMDeleteTicketPossibility(utm.UTMId))
                    {
                        string pathToOutFilesFromUTM = ConfigurationManager.AppSettings.Get("pathToTicket");

                        int timeOut = Convert.ToInt32(ConfigurationManager.AppSettings.Get("HTTPTimeout")); // httpTimeout
                        if (timeOut == 0)
                        {
                            timeOut = 20000;
                        }

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

                        WorkWithXML     workWithXML       = new WorkWithXML();
                        List <UTM_Data> listTicketFromUtm = null; // all files on UTM

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

                        httpWebRequest = null;

                        foreach (var linkticket in listTicketFromUtm)
                        {
                            string Ticket = null;

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

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

                            httpWebRequestGetTicket = null;

                            linkticket.XMLContent = Ticket;
                            linkticket.UTMId      = utm.UTMId;

                            string docType = workWithXML.GetTicketDocType(linkticket.XMLContent);

                            if (!DocTypeDeletePossibility(docType))
                            {
                                DateTime TicketDate  = DateTime.Parse(WorkWithXML.GetDateFromXml(linkticket.XMLContent));
                                DateTime NowDateTime = DateTime.Now;
                                TimeSpan TicketOld   = NowDateTime.Subtract(TicketDate);

                                string ticketTimeSpan = ConfigurationManager.AppSettings.Get("ticketTimeSpan");

                                if (TicketOld > TimeSpan.Parse(ticketTimeSpan))
                                {
                                    HttpWebRequest  httpWebRequestDelete  = null;
                                    HttpWebResponse httpWebResponseDelete = null;

                                    try
                                    {
                                        httpWebRequestDelete        = (HttpWebRequest)WebRequest.Create(linkticket.URL);
                                        httpWebRequestDelete.Method = "DELETE";
                                        httpWebResponseDelete       = (HttpWebResponse)httpWebRequestDelete.GetResponse();
                                    }
                                    finally
                                    {
                                        httpWebRequestDelete  = null;
                                        httpWebResponseDelete = null;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log log = new Log(ex);
            }
        } // delete Asiiu's tickets from UTM
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);
            }
        }