public override void Update() { String DNS = (App.DebugMode) ? "db9.ns.co.th" : "db2.ns.co.th"; mres = new ManualResetEventSlim[Idx + 1]; for (var i = 0; i < mres.Length; i++) { mres[i] = new ManualResetEventSlim(false); } if (!MBOS.Null(DBNameB2C)) { Task.Factory.StartNew(GetPNR, new StateTask() { ID = Idx--, DB = DBNameB2C, DNS = DNS, Type = Business.B2C }); } if (!MBOS.Null(DBNameB2B)) { Task.Factory.StartNew(GetPNR, new StateTask() { ID = Idx--, DB = DBNameB2B, DNS = DNS, Type = Business.B2B }); } WaitHandle.WaitAll((from x in mres select x.WaitHandle).ToArray()); foreach (ManualResetEventSlim t in mres) { t.Reset(); } base.Update(); }
public override void Start() { if (!MBOS.Null(DBNameB2C)) { Idx++; } if (!MBOS.Null(DBNameB2B)) { Idx++; } base.Start(); }
private static void Task_OutputCMD(object sender, DataReceivedEventArgs e) { App.WebCrawlerRestarted = true; if (!MBOS.Null(e.Data)) { Match Node = Regex.Match(e.Data, @"^CRAWLER >> \[(?<command>.*?)\]$"); if (Node.Success) { switch (Node.Groups["command"].Value.ToUpper()) { case "START": App.WebCrawlerConnected = true; break; default: break; } } else { } } }
private void WorkSentinelServices(object sender, DoWorkEventArgs e) { // this.WriteLineConsoleCheck(); BackgroundWorker init = sender as BackgroundWorker; init.ReportProgress(0, StateTravox.InitReadConfig); Config = new Configuration(); if (!Config.Load()) { Config.Default(); } String IP = null; //XHR.Connect("checkip.dyndns.com"); if (MBOS.Null(IP)) { IP = "IP Address: 127.0.0.1"; } Configuration.InternetIP = IPAddress.Parse(Regex.Match(IP, @"IP Address:.*?(?<ip>[\d|\.]+)").Groups["ip"].Value); if (App.DebugMode) { TravoxIP = Configuration.NetworkIP; } else { TravoxIP = Configuration.InternetIP; } TravoxPort = Config.SentinelPort; IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); TcpListener.Create(TravoxPort).Stop(); foreach (TcpConnectionInformation tcpi in ipGlobalProperties.GetActiveTcpConnections()) { if (tcpi.LocalEndPoint.Port == TravoxPort) { throw new Exception("Port is Unavailable."); } } Config.Save(); init.ReportProgress(0, StateTravox.InitStartServer); // Crawler Sentinel for Client Connected //Console.WriteLine("{0} Server Starting...", TravoxIP.ToString()); //Listen = new TcpListener(new IPEndPoint(TravoxIP, TravoxPort)); //Listen.Start(); //TaskListen = new Task() //App.ServerConnected = true; //while (App.ServerConnected) //{ // if (!Listen.Pending()) continue; // TcpClient client = Listen.AcceptTcpClient(); // Thread clientThread = new Thread(new ParameterizedThreadStart(OnClientConnect)); // clientThread.Start(client.GetStream()); // client.Close(); //} }
public override void Update() { base.Update(); const String ViewerPath = @"C:\inetpub\wwwroot\travox.com\viewer\"; SecretaryEvent Period = SecretaryEvent.Unknow; SQLCollection param = new SQLCollection("@id", DbType.Int32, base.State.CompanyID); foreach (DataRow Row in new DB("travox_system").GetTable(@" SELECT secretary_id, period, output_email, output_printer, email, report_name, report_key, template_name FROM crawler.secretary s LEFT JOIN document.report r ON r.report_id = s.report_id WHERE s.status = 'ACTIVE' AND (site_customer_id = @id OR site_customer_id IS NULL) ", 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 OutputEmailType = Row["output_email"].ToString().Trim(); String OutputPrinter = Row["output_printer"].ToString().Trim(); if (Period == SecretaryEvent.Monthly && (DateTime.Now.Date == DateEndMonth || App.DebugMode)) { SystemDate.From = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); SystemDate.To = DateEndMonth; } else if (Period == SecretaryEvent.Weekly && (DateTime.Now.DayOfWeek == DayOfWeek.Sunday || App.DebugMode)) { SystemDate.From = SystemDate.To.AddDays(-7); } else if (Period == SecretaryEvent.Daily) { } else { Period = SecretaryEvent.Unknow; } if ((!MBOS.Null(OutputEmailType) || MBOS.Bool(OutputPrinter)) && Period != SecretaryEvent.Unknow) { RequestBuilder ReportViewer = new RequestBuilder(App.DebugMode ? "https://viewer.travox.com/default.aspx" : "http://localhost:8026/Default.aspx") { Method = RequestBuilder.By.POST, ContentType = "application/json" }; ReportViewer.Headers.Add("Travox-Sentinel", "true"); ReportViewer.SetCookie("ASP.NET_SessionId", SessionID); ReportViewer.SetCookie("DATABASE_NAME", base.State.DatabaseName); ReportViewer.SetCookie("CUSTOMER_CODE", base.State.CompanyCode); ReportViewer.SetCookie("STAFF_ID", "-4"); ReportViewer.SetCookie("STAFF_CODE", "TX"); ReportViewer.SetCookie("REMEMBER", "true"); ReportViewer.RawBody.Append(JsonConvert.SerializeObject(new HandlerItem { OnEmail = !MBOS.Null(OutputEmailType), OnPrinter = MBOS.Bool(OutputPrinter), ID = Row["secretary_id"].ToString(), Email = Row["email"].ToString(), Period = Row["period"].ToString(), TemplateName = Row["template_name"].ToString(), PeriodDate = SystemDate, ItemType = new ItemType { ExportType = OutputEmailType }, Report = new ItemReport { Name = Row["report_key"].ToString(), Filename = Row["report_key"].ToString() + ".rpt" } })); String ex = XHR.Request(ReportViewer, true); if (!MBOS.Null(ex)) { Console.WriteLine(base.State.CompanyCode + " --- " + Row["template_name"].ToString()); Console.WriteLine(ex); } } } }