public string extractData(BANK bank)
        {
            string result = "";

            try
            {
                string replacestring = ConfigurationManager.AppSettings["ReplaceString"];
                string bankLink      = bank.BankLink;
                string str           = "";
                if (bank.BankLink.Contains(replacestring))
                {
                    str = DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString();
                }
                bankLink = bankLink.Replace(replacestring, str);
                if (bank.BankCode == "OCB")
                {
                    OCBHttpClient httpOCBclient = new OCBHttpClient();
                    result = httpOCBclient.getData(@"https://www.ocb.com.vn/");
                    result = Utilities.RemoveWhitespace(Regex.Replace(result, @"\t|\n|\r", "").Replace("            ", ""));
                }
                else
                {
                    HttpClient httpclient = new HttpClient();
                    result = httpclient.getData(bankLink);
                    result = Utilities.RemoveWhitespace(Regex.Replace(result, @"\t|\n|\r", "").Replace("            ", ""));
                }
            }
            catch (Exception ex)
            {
                ErrorUtil.logError(ex, bank.BankCode);
            }
            return(result);
        }
        public string SubmitLogin(string url, CookieCollection cookies)
        {
            string result = "";

            try
            {
                HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                myHttpWebRequest.ServicePoint.Expect100Continue = false;
                //   myHttpWebRequest.Timeout = Timeout.Infinite;
                myHttpWebRequest.Method = "POST";
                myHttpWebRequest.Accept = @"*/*";
                myHttpWebRequest.Headers.Add("Accept-Encoding", @"gzip, deflate, br");
                myHttpWebRequest.Headers.Add("Accept-Language", @"en-US,en;q=0.5");
                myHttpWebRequest.Headers.Add("Cache-Control", @"max-age=0");
                myHttpWebRequest.ContentLength = 67;
                myHttpWebRequest.ContentType   = @"application / x - www - form - urlencoded; charset = UTF - 8";
                myHttpWebRequest.UserAgent     = @"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0";
                myHttpWebRequest.Host          = @"www.ocb.com.vn";
                myHttpWebRequest.Referer       = @"https://www.ocb.com.vn/vi-VN/Khach-hang-ca-nhan/Lai-suat/ocb.htm";
                myHttpWebRequest.Headers.Add("X-Requested-With", @"XMLHttpRequest");
                Cookie cookie1 = new Cookie();
                cookie1.Name  = "_gat";
                cookie1.Value = "1";
                cookies.Add(cookie1);
                myHttpWebRequest.CookieContainer = new CookieContainer();
                foreach (Cookie cookie in cookies)
                {
                    myHttpWebRequest.CookieContainer.Add(new Cookie(cookie.Name, cookie.Value)
                    {
                        Domain = myHttpWebRequest.Host
                    });
                }
                string       postString    = string.Format("flag={0}&lang={1}&type={2}&formatdate={3}&flag_dn={4}", "1", "vi-VN", "VN%C4%90", "dd%2FMM%2Fyyyy", "0");
                StreamWriter requestWriter = new StreamWriter(myHttpWebRequest.GetRequestStream());
                requestWriter.Write(postString);
                requestWriter.Close();


                //// Sends the HttpWebRequest and waits for a response.
                HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
                if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
                {
                    foreach (Cookie cook in myHttpWebResponse.Cookies)
                    {
                    }
                    using (Stream stream = myHttpWebResponse.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            result = reader.ReadToEnd();
                        }
                }
            }
            catch (Exception ex)
            {
                ErrorUtil.logError(ex, "");
            }
            return(result);
        }
示例#3
0
        public static void mainProcess()
        {
            string bankrule = "";

            try
            {
                BankService     bs  = new BankService();
                TenorService    ts  = new TenorService();
                BankRuleService brs = new BankRuleService();

                List <BANK> bankList  = bs.findAll();
                string      groupCode = Guid.NewGuid().ToString();



                List <TENOR> tenorList = ts.findAll();
                foreach (BANK b in bankList)
                {
                    if (DataExtractorFactory.getDataExtractor(b) != null)
                    {
                        string bankData = DataExtractorFactory.getDataExtractor(b).extractData(b);
                        foreach (TENOR t in tenorList)
                        {
                            BANK_RULES br = brs.find(b.BankCode, t.TenorCode);
                            bankrule = br.BankRule;
                            if (br != null)
                            {
                                string rule = br.BankRule;

                                string             result      = RuleProcessor.process(bankData, rule, b.BankCode);
                                RATE_HISTORY       rateHistory = new RATE_HISTORY();
                                RateHistoryService rhs         = new RateHistoryService();

                                rateHistory.BankCode  = b.BankCode;
                                rateHistory.TenorCode = t.TenorCode;
                                rateHistory.InsRate   = result;
                                rateHistory.GroupCode = groupCode;
                                rateHistory.Timestamp = DateTime.Now;

                                rhs.addRateHistory(rateHistory);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorUtil.logError(ex, bankrule);
            }
        }
示例#4
0
        public string extractData(BANK bank)
        {
            string result = "";

            try
            {
                HttpClient httpclient = new HttpClient();
                result = httpclient.getData(bank.BankLink);
                result = Regex.Replace(result, @"\t|\n|\r", "").Replace("            ", "");
            }
            catch (Exception ex)
            {
                ErrorUtil.logError(ex);
            }
            return(result);
        }
示例#5
0
        public static CommandProcessor getCommandProcessor(Command command)
        {
            CommandProcessor obj = null;

            try
            {
                Type t = Type.GetType("Library." + command.keywork + "CommandProcessor");

                obj = (CommandProcessor)Activator.CreateInstance(t);
            }
            catch (Exception ex)
            {
                ErrorUtil.logError(ex, "");
            }
            return(obj);
        }
        public static DataExtractor getDataExtractor(BANK bank)
        {
            DataExtractor obj = null;

            try
            {
                Type t = Type.GetType("Library." + bank.DataExtractor.Trim());
                if (t != null)
                {
                    obj = (DataExtractor)Activator.CreateInstance(t);
                }
            }
            catch (Exception ex)
            {
                ErrorUtil.logError(ex, "");
            }
            return(obj);
        }
        public static string DownloadFile(string url)
        {
            string fileLocation = ConfigurationManager.AppSettings["downloadLocation"];
            string fileName     = DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
            string fullFileName = fileLocation + @"\" + fileName + ".pdf";
            string result       = "";

            try
            {
                using (WebClient client = new WebClient())
                {
                    client.DownloadFile(url, fullFileName);
                }



                PDFParser pdfParser = new PDFParser();
                pdfParser.ExtractText(fullFileName, System.IO.Path.GetFileNameWithoutExtension(fullFileName) + ".txt");
                try
                {
                    //using (StreamReader sr = new StreamReader(System.IO.Path.GetFileNameWithoutExtension(fullFileName) + ".txt"))
                    //{
                    //    // Read the stream to a string, and write the string to the console.
                    //    result = sr.ReadToEnd();

                    //}
                    //string output=    System.IO.Path.GetFileNameWithoutExtension(fullFileName) + ".txt";
                    //    var bytes = File.ReadAllBytes(fullFileName);
                    //    File.WriteAllText(output, ConvertToText(bytes), Encoding.UTF8);
                    var bytes = File.ReadAllBytes(fullFileName);
                    result = ConvertToText(bytes);
                }
                catch (Exception ex)
                {
                    ErrorUtil.logError(ex, "");
                }
            }
            catch (Exception ex)
            {
                ErrorUtil.logError(ex, "");
            }

            return(result);
        }
        public string getData(string url)
        {
            string result = "";

            try
            {
                CookieCollection cookies = new CookieCollection();

                cookies = getAllCookie(url);
                if (cookies.Count > 0)
                {
                    result = SubmitLogin("https://www.ocb.com.vn/Web/ocb_submit_load_laisuat_page.aspx", cookies);
                }
            }
            catch (Exception ex)
            {
                ErrorUtil.logError(ex, "");
            }
            return(result);
        }
        public static string process(String input, String rule, string bank)
        {
            string result = input;

            try {
                char     delimiter       = Convert.ToChar(ConfigurationManager.AppSettings["delimiter"]);
                string[] commandTextList = rule.Split(delimiter);
                foreach (string commandText in commandTextList)
                {
                    Command command = CommandParser.parse(commandText);

                    CommandProcessor commandProcessor = CommandProcessorFactory.getCommandProcessor(command);
                    result = commandProcessor.process(result, command, bank).Trim();
                }
            }

            catch (Exception e) {
                ErrorUtil.logError(e, rule + " " + bank);
            }
            return(result);
        }
示例#10
0
        public static Command parse(string commandText)
        {
            Command cmd = new Command();

            try
            {
                string[] elements = commandText.Split(',');

                cmd.keywork = elements[0];
                List <string> str = new List <string>();
                for (int i = 1; i < elements.Length; i++)
                {
                    str.Add(elements[i]);
                }
                cmd.parameters = str;
            }
            catch (Exception ex)
            {
                ErrorUtil.logError(ex, commandText);
            }
            return(cmd);
        }