Exemplo n.º 1
0
        public override void Update()
        {
            DB db = new DB("travox_global"); 

            RequestBuilder doExchange = new RequestBuilder("127.0.0.1:3000/API-v3/exchange-rate/");
            doExchange.By = RequestBuilder.Method.POST;
            doExchange.ContentType = "application/x-www-form-urlencoded";
            doExchange.AddHeader("Token-Auth", "ZHNnc2RmaCxrZXIgbmFsZ25zIGRmZ2RzZmc");

            doExchange.AddBody("from", db.GetField("SELECT ISNULL(currency,'') FROM currency FOR XML PATH('')"));
            doExchange.AddBody("to", "THB");
            doExchange.AddBody("amt", "1");

            XHR rate = new XHR().AsyncSend(doExchange).Wait();

            try
            {
                foreach (RateAPI item in JsonConvert.DeserializeObject<List<RateAPI>>(rate.ToString()))
                {
                    SQLCollection param = new SQLCollection();
                    param.Add("@to", DbType.String, item.currency);
                    param.Add("@rate", DbType.Decimal, item.rate);
                    param.Add("@date", DbType.DateTime, DateTime.Parse(item.updated).ToString("dd-MM-yyyy HH:mm:ss"));

                    db.Execute("UPDATE currency SET currency_rate=@rate, last_update=@date WHERE currency = @to", param);
                }
                db.Apply();
            }
            catch (Exception e)
            {
                db.Rollback();
                throw e;
            }
            base.Update();
        }
Exemplo n.º 2
0
        public override void Update()
        {
            if (State.CompanyCode == "mos")
            {
                DB db = new DB("travox_global");

                RequestBuilder doExchange = new RequestBuilder("https://api.travox.com/API-v3/exchange-rate/")
                {
                    Method      = RequestBuilder.By.POST,
                    ContentType = "application/x-www-form-urlencoded"
                };

                doExchange.Headers.Add("Token-Auth", "ZHNnc2RmaCxrZXIgbmFsZ25zIGRmZ2RzZmc");

                doExchange.AddBody("from", db.GetField("SELECT ISNULL(currency,'') FROM currency FOR XML PATH('')"));
                doExchange.AddBody("to", "THB");
                doExchange.AddBody("amt", "1");

                try
                {
                    String res = XHR.Request(doExchange, true);

                    foreach (RateAPI item in JsonConvert.DeserializeObject <List <RateAPI> >(res.ToString()))
                    {
                        SQLCollection param = new SQLCollection
                        {
                            { "@to", DbType.String, item.currency },
                            { "@rate", DbType.Decimal, item.rate },
                            { "@date", DbType.DateTime, DateTime.Parse(item.updated).ToString("dd-MM-yyyy HH:mm:ss") }
                        };
                        db.Execute("UPDATE currency SET currency_rate=@rate, last_update=@date WHERE currency = @to", param);
                    }
                    db.Apply();
                    base.Update();
                }
                catch (Exception e)
                {
                    db.Rollback();
                    base.Update();
                    throw new Exception(base.DBName, e);
                }
            }
        }
Exemplo n.º 3
0
        public override void Update()
        {
            base.Update();
            const String CrawlerPath = @"D:\ip1\travox.com\www\crawler\documents\";
            const String ViewerPath = @"C:\ip1\travox.com\www\mos\mos_demo\report_viewer\";

            SecretaryEvent Period = SecretaryEvent.Unknow;

            SQLCollection param = new SQLCollection("@id", DbType.Int32, base.State.CompanyID);
            List<HandlerItem> EventEmail = new List<HandlerItem>();

            foreach (DataRow Row in new DB("travox_system").GetTable(base.GetResource("secretary_report.sql"), param).Rows)
            {
                ParameterDate SystemDate;

                switch(Row["period"].ToString())
                {
                    case "Daily": Period = SecretaryEvent.Daily; break;
                    case "Weekly": Period = SecretaryEvent.Weekly; break;
                    case "Monthly": Period = SecretaryEvent.Monthly; break;
                }

                SystemDate.From = DateTime.Now.Date;
                SystemDate.To = DateTime.Now.Date;
                DateTime DateEndMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(-1);
                String PeriodDate = "";
                String OutputEmailType = Row["output_email"].ToString().Trim();
                String OutputPrinter = Row["output_printer"].ToString().Trim();

                if (Period == SecretaryEvent.Monthly && DateTime.Now.Date == DateEndMonth)
                {
                    PeriodDate = SystemDate.From.ToString("yyyy");
                    SystemDate.From  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                    SystemDate.To  = DateEndMonth;
                }
                else if (Period == SecretaryEvent.Weekly && DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                {
                    PeriodDate = SystemDate.From.ToString("MM-yyyy");
                    SystemDate.From = SystemDate.From.AddDays(-7);
                }
                else if (Period == SecretaryEvent.Daily)
                {
                    PeriodDate = SystemDate.From.ToString("dd-MM-yyyy");
                }
                else
                {
                    Period = SecretaryEvent.Unknow;
                }

                if ((!MBOS.Null(OutputEmailType) || MBOS.Bool(OutputPrinter)) && Period != SecretaryEvent.Unknow)
                {
                    RequestBuilder ReportViewer = new RequestBuilder((!App.DebugMode) ? "mos.travox.com/mos_v2/report_viewer/default.aspx" : "localhost:8026/Default.aspx");
                    ReportViewer.By = RequestBuilder.Method.POST;
                    ReportViewer.SetCookie("ASP.NET_SessionId", "xxxxxxxxxxxxxxxxxxxxxxxx");
                    ReportViewer.SetCookie("COMPANY_ACCESS", base.State.CompanyCode);
                    ReportViewer.SetCookie("ID", "-4");
                    ReportViewer.SetCookie("Code", "TX");
                    ReportViewer.SetCookie("Name", "Travox Sentinel");

                    //ReportViewer.POST("ItemType", JSON.Serialize<ItemType>(new ItemType { ExportType = OutputEmailType }));
                    //ReportViewer.POST("Report", JSON.Serialize<ItemReport>(new ItemReport { Name = Row["report_key"].ToString(), Filename = Row["report_key"].ToString() + ".rpt" }));
                    ReportViewer.AddBody("period_begin", SystemDate.From.ToString("dd-MM-yyyy"));
                    ReportViewer.AddBody("period_end", SystemDate.To.ToString("dd-MM-yyyy"));

                    param.Add("@s_id", DbType.Int32, Row["secretary_id"].ToString());
                    param.Add("@name", DbType.String, Row["report_name"].ToString());
                    param.Add("@email", DbType.String, Row["email"].ToString());
                    param.Add("@code", DbType.String, base.State.CompanyCode);
                    param.Add("@file", DbType.String, null);

                    String[] ArgsString = { Row["period"].ToString(), PeriodDate, Row["report_name"].ToString() };
                    HandlerItem Item = new HandlerItem();
                    Item.Subject = String.Format("Secretary({0} {1}) Report of \"{2}\"", ArgsString);
                    Item.OnEmail = !MBOS.Null(OutputEmailType);
                    Item.OnPrinter = MBOS.Bool(OutputPrinter);
                    Item.Mail = Row["email"].ToString();
                    Item.Ajax = ReportViewer;
                    EventEmail.Add(Item);
                }
            }

            foreach (HandlerItem Item in EventEmail)
            {
                //CallbackException data = JSON.Deserialize<CallbackException>(XHR.Connect(Item.Ajax));
                CallbackException data = new CallbackException();
                String getItems = Regex.Match(data.getItems, @"[\\|/]Temp[\\|/](?<path>.*)").Groups["path"].Value;
                String AttachFile = null;
                if (!data.onError)
                {
                    String FolderName = Path.GetDirectoryName(CrawlerPath + getItems) + "\\";
                    String FileName = Path.GetFileName(getItems);
                    if (!App.DebugMode)
                    {
                        if (Directory.Exists(FolderName)) Directory.CreateDirectory(FolderName);
                        File.Copy(ViewerPath + data.getItems, FolderName + FileName);
                        File.Delete(ViewerPath + data.getItems);
                        AttachFile = FolderName + FileName;
                    }
                    else
                    {
                        AttachFile = @"D:\Travox Mid-Back\TravoxViewer\TravoxViewer\Temp\" + getItems;
                    }
                }

                if (Item.OnEmail)
                {
                    DB db = new DB("travox_system");
                    NameValueCollection MailParam = new NameValueCollection();
                    TypeMAIL ReportSecretary = new TypeMAIL("*****@*****.**", Item.Subject, false);
                    ReportSecretary.Add(Item.Mail);
                    ReportSecretary.Body(base.GetResource("MailTemplate.html"));

                    String SQL = db.Execute("INSERT INTO crawler.secretary_email (secretary_id, company_code, report_name, email) VALUES (@s_id, @code, @name, @email)", param);

                    MailParam.Add("message_email", data.exMessage);
                    MailParam.Add("print_date", DateTime.Now.Date.ToString("dd-MM-yyyy"));
                    if (!data.onError && data.exTitle != "ManualException")
                    {
                        ReportSecretary.Attach(AttachFile);
                        param["@file"].DefaultValue = getItems;
                    }
                    else
                    {
                        param["@file"].DefaultValue = data.exMessage;
                    }
                    param.Add("@e_id", DbType.Int32, SQL);
                    db.Execute("UPDATE crawler.secretary_email SET filename=@file WHERE email_id=@e_id", param);

                    ReportSecretary.DataSource(MailParam);
                    if (!ReportSecretary.Sending())
                    {
                        param["@file"].DefaultValue = ReportSecretary.ErrorMessage;
                        db.Execute("UPDATE crawler.secretary_email SET filename=@file WHERE email_id=@e_id", param);
                    }
                    db.Apply();
                }

                if (Item.OnPrinter)
                {

                }
            }
            param = null;
            EventEmail = null;
            Console.WriteLine("{0} Updated", base.State.DatabaseName);

        }
Exemplo n.º 4
-1
        public override void Start()
        {
            // LOGIN 
            
            RequestBuilder doLogin = new RequestBuilder("forum.tirkx.com/main/login.php?do=login");
            doLogin.By = RequestBuilder.Method.POST;
            doLogin.CacheControl = "max-age=0";
            doLogin.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
            doLogin.Origin = "http://forum.tirkx.com";
            doLogin.ContentType = "application/x-www-form-urlencoded";
            doLogin.Referer = "http://forum.tirkx.com/main/forum.php";

            doLogin.AddBody("vb_login_username", Username);
            doLogin.AddBody("vb_login_password", "");
            doLogin.AddBody("vb_login_password_hint", "Password");
            doLogin.AddBody("cookieuser", "1");
            doLogin.AddBody("s", "");
            doLogin.AddBody("securitytoken", "guest");
            doLogin.AddBody("do", "login");
            doLogin.AddBody("vb_login_md5password", Password);
            doLogin.AddBody("vb_login_md5password_utf", Password);

            Trikx = new XHR();
            //Trikx.AsyncSend(doLogin, true);

            //Trikx.AsyncReceive();
            //Trikx.WaitResponse();

            doLogin.Clear();

            base.Start();
        }