public CustomerGroupImporterWorker( LogWriter logger, ILogin login, TaskSchedule task, ApplicationControl appControl, DataExpression expression) : base(logger, login, task, appControl, expression) { var difinition = new CustomerGroupFileDefinition(expression); difinition.GetCustomerDictionary = val => Screen.Util.ConvertToDictionary(Screen.Util.GetCustomerList(Login, val), x => x.Code); difinition.GetDbCsutomerGroups = () => Task.Run(async() => await Screen.Util.GetCustomerGroupListAsync(Login)).Result; var importer = difinition.CreateImporter(x => new { x.ParentCustomerId, x.ChildCustomerId }); importer.UserId = Login.UserId; importer.UserCode = Login.UserCode; importer.CompanyId = Login.CompanyId; importer.CompanyCode = Login.CompanyCode; importer.LoadAsync = async() => await Screen.Util.GetCustomerGroupListAsync(Login); importer.RegisterAsync = async unitOfWork => await Screen.Util.ImportCustomerGroupAsync(Login, unitOfWork); importer.ErrorLogPath = logger.GetOutputPath(); Importer = importer; }
public static IEnumerable <NodeTotals> FromSchedule(TaskSchedule schedule) { if (schedule == null || String.IsNullOrEmpty(schedule.ResourceName) || schedule.Nodes == null || !schedule.Nodes.Any()) { return(null); } IEnumerable <NodeTotals> totals = null; try { var resource = ResourceBase.GetResourceByName(schedule.ResourceName); var res = schedule.Nodes.Select(nodeConf => new NodeTotals() { NodeName = nodeConf.NodeName, NodeAddress = resource.Nodes.First(n => n.NodeName == nodeConf.NodeName).NodeAddress, CoresUsed = (int)nodeConf.Cores, SupportedArchitectures = resource.Nodes.First(n => n.NodeName == nodeConf.NodeName).SupportedArchitectures, }); totals = res.ToArray(); } catch (Exception e) { Log.Warn("Can't make NodeTotals: " + e.ToString()); totals = null; } return(totals); }
public WorkerBase(LogWriter logger, ILogin login, TaskSchedule task, ApplicationControl appControl = null, DataExpression expression = null) { this.logger = logger; Login = login; Setting = task; if (appControl != null) { AppControl = appControl; } if (expression != null) { DataExpression = expression; } History = new TaskScheduleHistory { CompanyId = login.CompanyId, ImportType = task.ImportType, ImportSubType = task.ImportSubType, StartAt = DateTime.Now /* get DB Server timestamp */ }; }
public static ResourceTotals FromSchedule(TaskSchedule schedule) { if (schedule == null || String.IsNullOrEmpty(schedule.ResourceName)) { return(null); } ResourceTotals totals = null; try { var resource = ResourceBase.GetResourceByName(schedule.ResourceName); totals = new ResourceTotals() { ProviderName = resource.Controller.Type, // resource.ProviderName, ResourceName = resource.ResourceName, ResourceDescription = resource.ResourceDescription, Location = resource.Location, NodesTotal = resource.Nodes.Length, SupportedArchitectures = resource.SupportedArchitectures, }; } catch (Exception e) { Log.Warn("Can't make ResourceTotals: " + e.ToString()); totals = null; } return(totals); }
public async Task <IActionResult> PostSchedule([FromBody] TaskSchedule taskSchedule) { int tokenUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); DateTime thisDay = DateTime.Now; string NowDate = thisDay.ToString("g"); taskSchedule.userLastEditId = tokenUserId; taskSchedule.taskCreatedDate = Convert.ToDateTime(NowDate); taskSchedule.userLastEditDate = Convert.ToDateTime(NowDate); if (taskSchedule.Notes != null) { taskSchedule.Notes[0].DateCreated = Convert.ToDateTime(NowDate); taskSchedule.Notes[0].UserId = tokenUserId; } if (taskSchedule.Start > taskSchedule.End) { return(BadRequest("start time is not less than end time")); } else if (taskSchedule.userCurrentAssignedId == tokenUserId || User.IsInRole("Admin")) { var taskScheduleRepo = await _repo.Add(taskSchedule); var taskReturn = _mapper.Map <getTaskScheduleIdDto>(taskScheduleRepo); return(Ok(taskReturn)); } else { return(Unauthorized()); } }
/// <summary> /// Updates the task schedule. /// </summary> /// <param name="systemJobId">The system job identifier.</param> public void UpdateTaskSchedule(string systemJobId) { var repository = _repositoryFactory(); using (SqlDbConfiguration.ExecutionStrategySuspension) using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { var job = repository.SystemJobs.FirstOrDefault(sj => sj.SystemJobId == systemJobId); var task = repository.TaskSchedules.SingleOrDefault(ts => ts.SystemJobId == systemJobId); if (task != null) { repository.Remove(task); } if (job != null && job.IsEnabled && job.Period > 0) { var startedDateTime = DateTime.UtcNow; var originalFrequency = PeriodToFrequency(job.Period); var newTaskSchedule = new TaskSchedule { Frequency = originalFrequency, NextScheduledStartTime = startedDateTime.AddMinutes(originalFrequency), SystemJobId = systemJobId }; repository.Add(newTaskSchedule); } repository.UnitOfWork.Commit(); transaction.Complete(); } }
public static DateTime NextRun(TaskSchedule ts, Usertask ut, User u) { //this could be used to populate the next run of a grouptaskschedule //Get last run time, will need to add to correct data later var lastRunTime = DateTime.Now; if (ut.SendNow) { lastRunTime = ts.TimeOverride ? ts.Time : u.ContactTime; } else { lastRunTime = ut.SendTime; } //need to figure out the next x of when it should send based off of taskschedule or somehow from the last scheduled switch (ts.Frequency) { case Enums.Frequency.Daily: return(lastRunTime.AddDays(1)); case Enums.Frequency.Weekly: return(lastRunTime.AddDays(7)); case Enums.Frequency.Monthly: return(lastRunTime.AddMonths(1)); default: break; } return(DateTime.Now); }
public ReceiptImporterWorker(LogWriter logger, ILogin login, TaskSchedule task, ApplicationControl applicationControl) : base(logger, login, task) { Importer = new ReceiptImporter(login, applicationControl); Importer.ImporterSettingId = task.ImportSubType; }
//updating new tasks public ActionResult <TaskSchedule> PutScheduleM(int id, [FromBody] TaskSchedule taskSchedule) { if (taskSchedule.Start < taskSchedule.End || taskSchedule.Start == null && taskSchedule.End == null) { TaskSchedule taskSchedulePut = _repo.Update(id, taskSchedule); return(taskSchedulePut); } return(BadRequest("start time is not less than end time")); }
public CustomerImporterWorker( LogWriter logger, ILogin login, TaskSchedule task, ApplicationControl appControl) : base(logger, login, task, appControl) { Importer = new CustomerImporter(Login, appControl); }
public EBDataImporterWorker( LogWriter logger, ILogin login, TaskSchedule task) : base(logger, login, task) { Importer = new EbDataImporter(); Importer.Login = Login; Importer.Year = DateTime.Today.Year; /* get database timestamp */ }
public TaskScheduleViewModel(TaskSchedule schedule) { this.Schedule = new TaskSchedule(); if (schedule != null) { this.Schedule.Time = schedule.Time; this.Schedule.IsEnabled = schedule.IsEnabled; } }
//add new data to the database // public Task<IActionResult> Add<T>(T entity) where T : class public async Task <TaskSchedule> Add(TaskSchedule entity) { await _context.TaskSchedules.AddAsync(entity); _context.SaveChanges(); int id = entity.Id; return(entity); }
private void GetImages() { WriteLog("获取商品图片"); List <string> xpaths = new List <string>() { ".//*[@id='altImages']/ul/li/span/span/span/span/img", ".//*[@id='altImages']/ul/li/span/span/span/span/span/img" }; Regex RegexImage = new Regex(@"L\..*?.jpg"); string imageSize = "L._SX450_SY450_CR,0,0,450,450_.jpg"; foreach (string xpath in xpaths) { HtmlNodeCollection htmlNodes = htmlDocument.DocumentNode.SelectNodes(xpath); if (htmlNodes != null && htmlNodes.Count > 0) { var count = 1; lock (insertData) { foreach (var htmlNode in htmlNodes) { if (count > 2) { break; } string imageSrc = htmlNode.GetAttributeValue("src", "").Trim(); imageSrc = RegexImage.Replace(imageSrc, imageSize); var pi = ProductImage.AddOrUpdate(new ProductImage() { Asin = product.Asin, Number = count, Status = 0, Url = imageSrc }); if (pi.Id > 0) { TaskSchedule.AddOrUpdate(new TaskSchedule() { PlayerAccountId = pi.Id, RunDateTime = DateTime.Now.GetTimestamp(), PlayerType = "Amazonspider.ProductImageDownload.Download", PlayerStep = "1" }); } count++; } } break; } } }
/// <summary> /// 初始化一个<c>TopicTask</c>实例 /// </summary> /// <param name="topicId">主题 Id</param> /// <param name="taskSchedule">任务的执行计划</param> /// <param name="month">指定执行的时间:月 [1-12]</param> /// <param name="week">指定执行的时间:周几 [0-6]</param> /// <param name="day">指定执行的时间:天 [1-31]</param> /// <param name="hour">指定执行的时间:小时 [0-23]</param> /// <param name="minute">指定执行的时间:分钟 [0-59]</param> public TopicTask(Guid topicId, TaskSchedule taskSchedule, int?month, DayOfWeek?week, int?day, int?hour, int?minute) { TopicId = topicId; TaskSchedule = taskSchedule; Month = month; Week = week; Day = day; Hour = hour; Minute = minute; this.GenerateNewIdentity(); }
public static void MarkAsPendingTask(int taskId, int aux = 0) { using (ctaDBEntities entities = new ctaDBEntities()) { TaskSchedule task = entities.TaskSchedules.Where(t => t.Id == taskId).FirstOrDefault(); if (task != null) { task.Status = aux == 0 ? (int)TaskScheduleStatus.InProcess : aux; entities.SaveChanges(); } } }
private void GetMoreProducts() { WriteLog("获取更多商品"); var descNodes = htmlDocument.GetElementbyId("sp_detail"); //GetHtmlNodesByCss("div[data-a-carousel-options*='ajax']"); if (descNodes != null) { //foreach (var item in descNodes) //{ string more = descNodes.GetAttributeValue("data-a-carousel-options", "").Replace(""", "\"").Trim() + "\r\n"; JObject jb = (JObject)JsonConvert.DeserializeObject(more); JArray jarr = null; if (more.IndexOf("initialSeenAsins") > -1) { jarr = jb["initialSeenAsins"].ToObject <JArray>(); } else if (more.IndexOf("id_list") > -1 && more.IndexOf("ajax") > -1) { jarr = jb["ajax"]["id_list"].ToObject <JArray>(); } if (jarr != null) { lock (insertData) { for (int i = 0; i < jarr.Count; i++) { string id = jarr[i].Value <string>().Trim(':'); var p = Product.AddOrUpdate(new Product() { Id = -2, Asin = id, Price = 0, Desc = "", Title = "", Time = DateTime.Now.GetTimestamp(), }); if (p.Id > -1) { TaskSchedule.AddOrUpdate(new TaskSchedule() { PlayerAccountId = p.Id, PlayerStep = "2", PlayerType = this.GetType().ToString(), RunDateTime = DateTime.Now.GetTimestamp() }); } } } //} } } }
public static void RemoveTask(int taskId) { using (ctaDBEntities entities = new ctaDBEntities()) { TaskSchedule task = entities.TaskSchedules.Where(t => t.Id == taskId).FirstOrDefault(); if (task != null) { entities.TaskSchedules.Remove(task); entities.SaveChanges(); } } }
public PaymentScheduleImporterWorker(LogWriter logger, ILogin login, TaskSchedule task, ApplicationControl applicationControl) : base(logger, login, task) { Importer = new PaymentScheduleImporter(login, applicationControl); Importer.ImporterSettingId = task.ImportSubType; Importer.DoReplaceAmount = task.BillingAmount == 0; Importer.DoTargetNotMatchedData = task.TargetBillingAssignment == 0; Importer.DoIgnoreSameCustomerGroup = task.UpdateSameCustomer == 0; }
public static void ScheduleTask(TaskScheduleType taskType, string data, DateTime nextTime) { using (ctaDBEntities entities = new ctaDBEntities()) { entities.Database.Connection.Open(); TaskSchedule task = new TaskSchedule() { Type = (int)taskType, Data = data, Status = (int)TaskScheduleStatus.Pending, Description = Enum.GetName(typeof(TaskScheduleType), taskType), ExecTime = nextTime }; entities.TaskSchedules.Add(task); entities.SaveChanges(); } }
public ActionResult <TaskSchedule> PutSchedule(int id, [FromBody] TaskSchedule taskSchedule) { int tokenUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); taskSchedule.userLastEditId = tokenUserId; DateTime thisDay = DateTime.Now; string NowDate = thisDay.ToString("g"); taskSchedule.userLastEditDate = Convert.ToDateTime(NowDate); var updateTask = PutScheduleM(id, taskSchedule); return(updateTask); }
public async Task <TaskScheduleResult> SaveAsync(string SessionKey, TaskSchedule TaskSchedule) { return(await authorizationProcessor.DoAuthorizeAsync(SessionKey, async token => { var result = await taskScheduleProcessor.SaveAsync(TaskSchedule); return new TaskScheduleResult { ProcessResult = new ProcessResult { Result = true }, TaskSchedule = result, }; }, logger)); }
private void AddTaskSchedule() { var taskSchedule = new TaskSchedule { IntervalFrequency = IntervalFrequencies.FirstOrDefault(f => f.Name == IntervalFrequency.Day), InspectionDateTime = StartDate, Interval = 1, Task = SelectedTask }; TaskSchedules.Add(taskSchedule); SelectedTaskSchedule = taskSchedule; CalculateInspectionDates(); CanEditStartDate = false; }
public static Task Run() { while (true) { var status = TaskSchedule.Prop(); if (status.Value != null) { CommandExcute commandExcute = new CommandExcute("task1.sh", "sh", status.Value.InFastqPath, status.Value.InRefFaPath, "0", status.Key); Console.WriteLine("开始执行任务:" + status.Key); commandExcute.Excute(); } else { Console.WriteLine("没有任务 "); } Thread.Sleep(10000); } }
public static string GetCronString(TaskSchedule taskSchedule) { //Set Cron strings for common settings switch (taskSchedule.Frequency) { case Enums.Frequency.Daily: return(string.Format("{1} {0} * * 0-6", taskSchedule.Time.Hour.ToString(), taskSchedule.Time.Minute.ToString())); case Enums.Frequency.Weekly: var ds = taskSchedule.DayOfWeek.Select(s => s.ToString().ToUpper().Substring(0, 3)); return(string.Format("{1} {0} * * {2}", taskSchedule.Time.Hour.ToString(), taskSchedule.Time.Minute.ToString(), string.Join(',', ds))); case Enums.Frequency.Monthly: return(string.Format("{1} {0} {2} * *", taskSchedule.Time.Hour.ToString(), taskSchedule.Time.Minute.ToString(), taskSchedule.DayOfMonth)); default: return(""); } }
public Task(Task otherTask) : base(otherTask) { if (otherTask.OutputParams != null) { OutputParams = new Dictionary <string, string>(otherTask.OutputParams); } if (otherTask.PackageEngineState != null) { this.PackageEngineState = (PackageEngineState)otherTask.PackageEngineState.Clone(); } Time = new TaskTimeMeasurement(otherTask.Time); Incarnation = new IncarnationParams(otherTask.Incarnation); if (otherTask.Estimations != null) { Estimations = new Dictionary <string, double>(otherTask.Estimations); } CurrentSchedule = null; if (otherTask.CurrentSchedule != null) { CurrentSchedule = new TaskSchedule(otherTask.CurrentSchedule); // immutable: this.AssignedResource = otherTask.AssignedResource; this.AssignedNodes = otherTask.AssignedNodes; } State = otherTask.State; _inputsProcessed = otherTask._inputsProcessed; _inputsProcessingError = otherTask._inputsProcessingError; _failReason = otherTask._failReason; if (otherTask._lastEvent != null && otherTask._lastEvent.HasValue) { _lastEvent = otherTask._lastEvent.Value; } }
public void PrepareTaskSchedule(string systemJobId, bool allowMultipleInstances) { lock (keylock) { var job = SystemJobs.FirstOrDefault(sj => sj.SystemJobId == systemJobId); var taskSchedule = TaskSchedules.SingleOrDefault(ts => ts.SystemJobId == systemJobId); if (taskSchedule == null) { var startedDateTime = DateTime.UtcNow; var originalFrequency = SchedulerDbContext.PeriodToFrequency(job.Period); var newTaskSchedule = new TaskSchedule { Frequency = originalFrequency, NextScheduledStartTime = startedDateTime.AddMinutes(originalFrequency), SystemJobId = systemJobId }; TaskSchedules.Add(newTaskSchedule); } } }
// update database public TaskSchedule Update(int Id, TaskSchedule taskSchedule) { var TaskScheduleDb = _context.TaskSchedules.SingleOrDefault(s => s.Id == Id); TaskScheduleDb.Title = taskSchedule.Title; TaskScheduleDb.Start = taskSchedule.Start; TaskScheduleDb.End = taskSchedule.End; TaskScheduleDb.userCurrentAssignedId = taskSchedule.userCurrentAssignedId; TaskScheduleDb.userLastEditId = taskSchedule.userLastEditId; TaskScheduleDb.highPriority = taskSchedule.highPriority; TaskScheduleDb.isClosed = taskSchedule.isClosed; TaskScheduleDb.hasTimeLimit = taskSchedule.hasTimeLimit; TaskScheduleDb.Attachments = taskSchedule.Attachments; TaskScheduleDb.customerId = taskSchedule.customerId; TaskScheduleDb.userLastEditDate = taskSchedule.userLastEditDate; _context.SaveChanges(); return(TaskScheduleDb); }
private IWorker CreateConcreteWorker(LogWriter logger, TaskSchedule task) { ApplicationControl appControl = null; DataExpression expression = null; try { appControl = Screen.Util.GetApplicationControl(Login); } catch (Exception ex) { logger.Log(ex); } if (appControl == null) { return(null); } else { expression = new DataExpression(appControl); } switch (task.ImportType) { case (int)BatchType.Customer: return(new ConcreteWorker.CustomerImporterWorker(logger, Login, task, appControl)); case (int)BatchType.CustomerGroup: return(new ConcreteWorker.CustomerGroupImporterWorker(logger, Login, task, appControl, expression)); case (int)BatchType.Billing: return(new ConcreteWorker.BillingImporterWorker(logger, Login, task, appControl)); case (int)BatchType.EbData: return(new ConcreteWorker.EBDataImporterWorker(logger, Login, task)); case (int)BatchType.Receipt: return(new ConcreteWorker.ReceiptImporterWorker(logger, Login, task, appControl)); case (int)BatchType.PaymentSchedule: return(new ConcreteWorker.PaymentScheduleImporterWorker(logger, Login, task, appControl)); } return(null); }
private void btnAddAsin_Click(object sender, EventArgs e) { var product = Product.AddOrUpdate(new Product() { Asin = txtAsin.Text, Status = 0, Desc = "", Title = "", Price = 0, Time = DateTime.Now.GetTimestamp() }); if (product.Id > -1) { TaskSchedule.AddOrUpdate(new TaskSchedule() { PlayerAccountId = product.Id, PlayerStep = "download", RunDateTime = DateTime.Now.GetTimestamp(), PlayerType = new Amazonspider.ProductDownload.Download().GetType().ToString() }); } }
/// <summary> /// 初始化一个<c>TopicTask</c>实例 /// </summary> /// <param name="topicId">主题 Id</param> /// <param name="taskSchedule">任务的执行计划</param> /// <param name="month">指定执行的时间:月 [1-12]</param> /// <param name="week">指定执行的时间:周几 [0-6]</param> /// <param name="day">指定执行的时间:天 [1-31]</param> /// <param name="hour">指定执行的时间:小时 [0-23]</param> /// <param name="minute">指定执行的时间:分钟 [0-59]</param> public TopicTask(Guid topicId, TaskSchedule taskSchedule, int? month, DayOfWeek? week, int? day, int? hour, int? minute) { TopicId = topicId; TaskSchedule = taskSchedule; Month = month; Week = week; Day = day; Hour = hour; Minute = minute; this.GenerateNewIdentity(); }
/// <summary> /// 初始化一个<c>TopicTask</c>实例。其中默认执行的分钟为 00 /// </summary> /// <param name="topicId">主题 Id</param> /// <param name="taskSchedule">任务的执行计划</param> /// <param name="month">指定执行的时间:月 [1-12]</param> /// <param name="week">指定执行的时间:周几 [0-6]</param> /// <param name="day">指定执行的时间:天 [1-31]</param> /// <param name="hour">指定执行的时间:小时 [0-23]</param> public TopicTask(Guid topicId, TaskSchedule taskSchedule, int? month, DayOfWeek? week, int? day, int? hour) : this(topicId, taskSchedule, month, week, day, hour, 0) { }