public void Execute(IJobExecutionContext context) { Log.Info("SetKeywordsCostJob запущен!"); Console.WriteLine("SetKeywordsCostJob was started! " + DateTime.Now); IQueryable <Client> clients = _clientRep.GetAll(); DateTime StartDate = new DateTime(); DateTime FinishDate = new DateTime(); JobsInfo JobsInfoQuery = _jobsinfoRep.GetLastActionDateForJob(Constants.SetKeywordsCostJob); if (JobsInfoQuery != null) { StartDate = JobsInfoQuery.lastactiondate.AddDays(-1); //AddDays(-1) для учета часовых поясов FinishDate = DateTime.Now.ToUniversalTime().AddDays(2); //AddDays(1) для учета часовых поясов } else { if (_visitsRep.GetAll().Count() > 0) { StartDate = DateTime.Parse("2013-04-28"); FinishDate = DateTime.Now.ToUniversalTime().AddDays(2);//AddDays(1) для учета часовых поясов } } foreach (Client item in clients) { Console.WriteLine("SetKeywordsCostJob Клиент " + item.Name + " Время старта: " + DateTime.Now); Execute_KeywordsCost_Query(StartDate, FinishDate, item.LoginGoogleAnalitics, item.PasswordGoogleAnalitics, item.ids.ToString(), item.Id); Console.WriteLine("SetKeywordsCostJob Клиент " + item.Name + " Время финиша: " + DateTime.Now); } _jobsinfoRep.Add(new JobsInfo() { jobId = Constants.SetKeywordsCostJob, lastactiondate = DateTime.Now.AddDays(-1).ToUniversalTime(), status = true }); _jobsinfoRep.Save(); Console.WriteLine("SetKeywordsCostJob is finished! " + DateTime.Now); }
public void Execute(IJobExecutionContext context) { try { // Log.Info("GetGoogleAnalyticsDataJob запущен!"); Console.WriteLine("GetGoogleAnalyticsDataJob is started....." + DateTime.Now.ToString()); IQueryable <Client> clients = _clientRep.GetAll(); DateTime StartDate = new DateTime(); DateTime FinishDate = new DateTime(); JobsInfo JobsInfoQuery = _jobsinfoRep.GetLastActionDateForJob(Constants.GetGoogleAnalyticsDataJob); if (JobsInfoQuery != null) { StartDate = /*DateTime.Parse("2013-04-01");*/ JobsInfoQuery.lastactiondate.AddDays(-1); //AddDays(-1) для учета часовых поясов FinishDate = DateTime.Now.ToUniversalTime().AddDays(2); //AddDays(1) для учета часовых поясов } else { if (_visitsRep.GetAll().Count() > 0) { StartDate = DateTime.Parse("2012-05-01"); FinishDate = DateTime.Now.ToUniversalTime().AddDays(2);//AddDays(1) для учета часовых поясов } } foreach (Client item in clients) { Console.WriteLine("GetGoogleAnalyticsDataJob Клиент " + item.Name + " Время старта: " + DateTime.Now); if (item.Id != 6) { if (!(String.IsNullOrEmpty(item.LoginGoogleAnalitics)) && (!String.IsNullOrEmpty(item.PasswordGoogleAnalitics)) && (!String.IsNullOrEmpty(item.ids.ToString())) && (item.ids != 0)) { Execute_NonPaidSearchTraffic_Query(StartDate, FinishDate, item.LoginGoogleAnalitics, item.PasswordGoogleAnalitics, item.ids.ToString(), item.Id); Execute_PaidSearchTraffic_Query(StartDate, FinishDate, item.LoginGoogleAnalitics, item.PasswordGoogleAnalitics, item.ids.ToString(), item.Id); Execute_ReferralTraffic_Query(StartDate, FinishDate, item.LoginGoogleAnalitics, item.PasswordGoogleAnalitics, item.ids.ToString(), item.Id); Execute_DirectTraffic_Query(StartDate, FinishDate, item.LoginGoogleAnalitics, item.PasswordGoogleAnalitics, item.ids.ToString(), item.Id); } } else { if (StartDate >= DateTime.Parse("2013-05-25")) //для клиента 6 выполняем после 25-го числа { if (!(String.IsNullOrEmpty(item.LoginGoogleAnalitics)) && (!String.IsNullOrEmpty(item.PasswordGoogleAnalitics)) && (!String.IsNullOrEmpty(item.ids.ToString())) && (item.ids != 0)) { Execute_NonPaidSearchTraffic_Query(StartDate, FinishDate, item.LoginGoogleAnalitics, item.PasswordGoogleAnalitics, item.ids.ToString(), item.Id); Execute_PaidSearchTraffic_Query(StartDate, FinishDate, item.LoginGoogleAnalitics, item.PasswordGoogleAnalitics, item.ids.ToString(), item.Id); Execute_ReferralTraffic_Query(StartDate, FinishDate, item.LoginGoogleAnalitics, item.PasswordGoogleAnalitics, item.ids.ToString(), item.Id); Execute_DirectTraffic_Query(StartDate, FinishDate, item.LoginGoogleAnalitics, item.PasswordGoogleAnalitics, item.ids.ToString(), item.Id); } } } Console.WriteLine("GetGoogleAnalyticsDataJob Клиент " + item.Name + " Время финиша: " + DateTime.Now); } _jobsinfoRep.Add(new JobsInfo() { jobId = Constants.GetGoogleAnalyticsDataJob, lastactiondate = DateTime.Now.AddDays(-1).ToUniversalTime(), status = true }); _jobsinfoRep.Save(); // Log.Info("GetGoogleAnalyticsDataJob успешно выполнен!"); Console.WriteLine("GetGoogleAnalyticsDataJob is finished....." + DateTime.Now.ToString()); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } //Log.Error(String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace)); // Console.WriteLine("GetGoogleAnalyticsDataJob is running with error....." + DateTime.Now.ToString()); // Console.WriteLine(String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace)); throw ex; } }
///<Summary> /// Gets the answer ///</Summary> public void Execute(IJobExecutionContext context) { try { using (CallTrackingDBContext _db = new CallTrackingDBContext()) { Log.Info("SetCallInfoJob запущен!"); //получаем дату и время последнего запуска Job-а string date = ""; JobsInfo JobsInfoQuery = _jobsinfoRep.GetLastActionDateForJob(Constants.SetCallInfoJob);//_db.jobsInfo.FirstOrDefault(t => t.job.Id == Constants.SetCallInfoJob); if (JobsInfoQuery != null) { //date = JobsInfoQuery.lastactiondate.ToString("YYYY-M-dd hh:"); date = JobsInfoQuery.lastactiondate.Year + "-" + JobsInfoQuery.lastactiondate.Month + "-" + JobsInfoQuery.lastactiondate.Day + " " + JobsInfoQuery.lastactiondate.Hour + ":" + JobsInfoQuery.lastactiondate.Minute + ":" + JobsInfoQuery.lastactiondate.Second; } else //если Job не запускался, то делаем работу за весь период { DateTime calldate = DateTime.Parse("2012-05-01"); date = calldate.Year + "-" + calldate.Month + "-" + calldate.Day + " " + calldate.Hour + ":" + calldate.Minute + ":" + calldate.Second; } // using (MySqlConnection objConn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CallTrackingDBContext"].ConnectionString)) { objConn.Open(); MySqlCommand objSetCallInfo = new MySqlCommand("SetCallInfo", objConn); objSetCallInfo.CommandType = CommandType.StoredProcedure; objSetCallInfo.CommandTimeout = int.MaxValue; objSetCallInfo.Parameters.Add("@date_", MySqlDbType.Datetime).Value = DateTime.Parse(date); objSetCallInfo.ExecuteNonQuery(); objConn.Close(); } /*_db.Database.ExecuteSqlCommand(String.Format(@"update Cdr c, Visits v * set c.VisitsId=v.Id * where * c.VisitsId is null * and * c.calldate>Date('{0}') * and * c.dcontext='frw_in' * and * c.dst=v.UserNumber * and * c.calldate between v.datetime and v.lastupdate", date));// + interval 3 minute */ JobsInfo new_jobs_info = new JobsInfo() { status = true, lastactiondate = DateTime.Now.ToUniversalTime(), jobId = Constants.SetCallInfoJob }; //поставить еще jobId! ( также в классе JobsInfo ) _jobsinfoRep.Add(new_jobs_info); _jobsinfoRep.Save(); Console.WriteLine("SetCallInfoJob is running....." + DateTime.Now.ToString()); Log.Info("SetCallInfoJob успешно выполнен!"); } } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } //JobsInfo new_jobs_info = new JobsInfo() { status = false, lastactiondate = DateTime.Now.ToUniversalTime(), ExceptionText = String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace) };//поставить еще jobId! ( также в классе JobsInfo ) // _jobsinfoRep.Add(new_jobs_info); // _jobsinfoRep.Save(); Log.Error(String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace)); Console.WriteLine("SetCallInfoJob is running with error....." + DateTime.Now.ToString()); Console.WriteLine(String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace)); } }
public void Execute(IJobExecutionContext context) { try { Console.WriteLine("RemoveMoneyJob is starting....." + DateTime.Now.ToString()); Log.Info("RemoveMoneyJob запущен!"); List <GetBillsecForClientInfo> BillsecForClientInfoList_Curent = new List <GetBillsecForClientInfo>(); List <GetPhonesCountForClientInfo> PhonesCountForClientInfoList_Curent = new List <GetPhonesCountForClientInfo>(); ////выбираем дату последнего успешного запуска Job-а ( Начало ) DateTime lastactiondate = new DateTime(); JobsInfo JobsInfoQuery = _jobsinfoRep.GetLastActionDateForJob(Constants.RemoveMoneyJob); if (JobsInfoQuery != null) { lastactiondate = JobsInfoQuery.lastactiondate; } // выбираем дату последнего успешного запуска Job-а ( Конец ) else { lastactiondate = DateTime.Parse("2013-03-15"); } double numbercostforday = 0; DateTime FinishDate = /*GetDateFromFile()[1];*/ DateTime.Now.AddHours(-1).ToUniversalTime(); DateTime StartDate = /*GetDateFromFile()[0];*/ lastactiondate; DateTime CurentDate = StartDate; MinutesCost lastminutecostdate = null; NumberCost lastnumbercostdate = null; //StartDate = DateTime.Parse("29.04.2013 23:00:00"); //CurentDate = StartDate; //FinishDate = DateTime.Parse("30.04.2013 00:00:00").AddHours(-1); while (CurentDate <= FinishDate) //условие <= приводит к двойному выполнению Job-а для одного и того же клиента в сутки { string clients = GetClientsForRemoveMoney_(CurentDate /*DateTime.Parse("30.04.2013 0:00:00")*/); //получаем всех клиентов, для которых нужно списать деньги if (!String.IsNullOrEmpty(clients)) { Console.WriteLine("Диапазон между startdate и finishdate: " + StartDate.ToString() + " - " + FinishDate.ToString()); Console.WriteLine("Грабеж!!!!!!!!! Время грабежа: " + CurentDate.ToString() + " Клиенты: " + clients); List <BillSecForClientsInfo> billsecforclientsinfo = Call_GetBillSecForClients(CurentDate, clients); List <ActivedClientsNumbersCountInfo> activedclientsnumberscountinfo = Call_GetActivedClientsNumbers(CurentDate, clients); lastminutecostdate = _minutescostRep.GetAll().Where(t => t.lastupdate <= CurentDate).OrderByDescending(t => t.lastupdate).FirstOrDefault(); lastnumbercostdate = _numbercostRep.GetAll().Where(t => t.lastupdate <= CurentDate).OrderByDescending(t => t.lastupdate).FirstOrDefault(); List <InfoForPaymants> infoforpaymants = new List <InfoForPaymants>(); var commondata = from b in billsecforclientsinfo from a in activedclientsnumberscountinfo where b.date == a.date && b.ClientId == a.ClientId select new { ClientId = b.ClientId, date = b.date, count = a.count, codes_billsec = b.codes_billsec }; var differentdata = from a in activedclientsnumberscountinfo where !billsecforclientsinfo.Any(t => t.ClientId == a.ClientId && t.date == a.date) select a; if (commondata.Count() > 0) { foreach (var item in commondata) { infoforpaymants.Add(new InfoForPaymants() { codes_billsec = item.codes_billsec, ClientId = item.ClientId, count = item.count, date = item.date }); } } if (differentdata.Count() > 0) { foreach (var item in differentdata) { infoforpaymants.Add(new InfoForPaymants() { codes_billsec = null, count = item.count, date = item.date, ClientId = item.ClientId }); } } int allbillsec = 0; //общее колическво секунд разговоров для клиента для всех кодов if (infoforpaymants.Count() > 0) { foreach (InfoForPaymants item in infoforpaymants) { numbercostforday = _numbercostRep.GetLastNumberCostToThisDate(item.date); //последняя стоимость номера за день if (item.codes_billsec != null) { item.sum = Math.Round(GetCommonBillsecCostForAllCodes(item.codes_billsec) + item.count * numbercostforday, 2); } else { item.sum = Math.Round(item.count * numbercostforday, 2); } if (item.codes_billsec != null) { allbillsec = item.codes_billsec.Sum(t => t.billsec); } Paymant new_paymant = new Paymant() { ClientId = item.ClientId, date = item.date, Type = false, sum = -1 * item.sum, coment = "Снятие денег со счета. Время разговоров: " + allbillsec + " сек; Количество арендуемых номеров: " + item.count + " Время: " + DateTime.Now.ToString() }; _paymantsRep.Add(new_paymant); _paymantsRep.Save(); Client curent_client = _clientRep.Find(item.ClientId); if (curent_client != null) { string message_ = "Уважаемый " + curent_client.Name + ", " + item.date.ToShortDateString() + " с вашего счета было снято " + item.sum + " грн за " + allbillsec + " секунд разговоров и за аренду телефонов в количестве " + item.count + "."; _sendemailjobinfoRep.Add(new SendEmailJobInfo() { attemptcount = 0, date = DateTime.Now.ToUniversalTime(), message = message_, status = false, subject = "CallTracking Info", To = curent_client.Email }); _sendemailjobinfoRep.Save(); } allbillsec = 0; } } } CurentDate = CurentDate.AddHours(1); } // AddOneHourToDatesFromFile(); JobsInfo new_jobs_info = new JobsInfo() { status = true, lastactiondate = DateTime.Now.ToUniversalTime(), jobId = Constants.RemoveMoneyJob }; //поставить еще jobId! ( также в классе JobsInfo ) _jobsinfoRep.Add(new_jobs_info); _jobsinfoRep.Save(); Log.Info("RemoveMoneyJob успешно выполнен!"); Console.WriteLine("RemoveMoneyJob is finished....." + DateTime.Now.ToString()); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } /* JobsInfo new_jobs_info = new JobsInfo() { status = false, lastactiondate = DateTime.Now.ToUniversalTime(), jobId = Constants.RemoveMoneyJob, ExceptionText = String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace) };//поставить еще jobId! ( также в классе JobsInfo ) * _jobsinfoRep.Add(new_jobs_info); * _jobsinfoRep.Save(); * * Log.Error(String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace)); * Console.WriteLine("RemoveMoneyJob is running with error....." + DateTime.Now.ToString()); * Console.WriteLine(String.Format(@"Message: {0}, Source: {1}, TargetSite: {2}, Trace: {3} ", ex.Message, ex.Source, ex.TargetSite, ex.StackTrace));*/ throw ex; } }