public ActionResult ScheduleTaskEvt(int[] Id, string Action) { // You have your books IDs on the deleteInputs array switch (Action.ToLower()) { case "delete": if (Id != null && Id.Length > 0) { int length = Id.Length; ScheduleTask objItem; for (int i = 0; i <= length - 1; i++) { objItem = ScheduleTaskManager.GetById(Id[i], CurrentUser.CompanyID); if (objItem != null) { ScheduleTaskManager.Delete(objItem); } } return(View(ViewFolder + "list.cshtml", ScheduleTaskManager.GetAll(CurrentUser.CompanyID))); } break; } return(View("PostFrm")); }
public ContentResult Save(string objdata, string value) { JsonObject js = new JsonObject(); js.StatusCode = 200; js.Message = "Upload Success"; try { ScheduleTask obj = JsonConvert.DeserializeObject <ScheduleTask>(objdata); obj = ScheduleTaskManager.Update(obj); if (obj.Id == 0) { js.StatusCode = 400; js.Message = "Has Errors. Please contact Admin for more information"; } else { js.Data = obj; } } catch (Exception objEx) { js.StatusCode = 400; js.Message = objEx.Message; } return(Content(JsonConvert.SerializeObject(js), "application/json")); }
public ContentResult Search(SearchFilter SearchKey) { SearchKey.OrderBy = string.IsNullOrEmpty(SearchKey.OrderBy) ? "Id" : SearchKey.OrderBy; ScheduleTaskCollection collection = ScheduleTaskManager.Search(SearchKey); return(Content(JsonConvert.SerializeObject(collection), "application/json")); }
/// <summary> /// use for setting up default value /// </summary> /// <returns></returns> public ActionResult Update(int Id, string TargetID = "ScheduleTasklist") { ScheduleTask objItem = ScheduleTaskManager.GetById(Id, CurrentUser.CompanyID); objItem.TargetDisplayID = TargetID; return(View(ViewFolder + "Create.cshtml", objItem)); }
/// <summary> /// use for scrolling page /// </summary> /// <returns></returns> public ContentResult GetPg(int page, int pagesize) { string condition = ""; SearchFilter SearchKey = SearchFilter.SearchPG(CurrentUser.CompanyID, page, pagesize, "Id", "Id", "Desc", condition); ScheduleTaskCollection objItem = ScheduleTaskManager.Search(SearchKey); return(Content(JsonConvert.SerializeObject(objItem), "application/json")); }
/// <summary> /// Initializes the task manager /// </summary> public void Initialize() { this._taskThreads.Clear(); //var taskService = EngineContext.Current.Resolve<IScheduleTaskService>(); var scheduleTasks = ScheduleTaskManager.GetAll(1); //taskService //.GetAllTasks() //.OrderBy(x => x.Seconds) //.ToList(); //group by threads with the same seconds foreach (var scheduleTaskGrouped in scheduleTasks.GroupBy(x => x.Seconds)) { //create a thread var taskThread = new TaskThread { Seconds = scheduleTaskGrouped.Key }; foreach (var scheduleTask in scheduleTaskGrouped) { var task = new Task(scheduleTask); taskThread.AddTask(task); } this._taskThreads.Add(taskThread); } //sometimes a task period could be set to several hours (or even days). //in this case a probability that it'll be run is quite small (an application could be restarted) //we should manually run the tasks which weren't run for a long time var notRunTasks = scheduleTasks //find tasks with "run period" more than 30 minutes .Where(x => x.Seconds >= _notRunTasksInterval) .Where(x => !x.LastStartUtc.HasValue || x.LastStartUtc.Value.AddSeconds(x.Seconds) < DateTime.UtcNow) .ToList(); //create a thread for the tasks which weren't run for a long time if (notRunTasks.Any()) { var taskThread = new TaskThread { RunOnlyOnce = true, Seconds = 60 * 5 //let's run such tasks in 5 minutes after application start }; foreach (var scheduleTask in notRunTasks) { var task = new Task(scheduleTask); taskThread.AddTask(task); } this._taskThreads.Add(taskThread); } }
public JsonResult GetGata([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel) { SearchFilter SearchKey = SearchFilter.SearchData(CurrentUser.CompanyID, requestModel, "Id", "Id"); ScheduleTaskCollection collection = ScheduleTaskManager.Search(SearchKey); int TotalRecord = 0; if (collection.Count > 0) { TotalRecord = collection[0].TotalRecord; } //ScheduleTaskCollection data = ScheduleTaskManager.GetAll(CurrentUser.CompanyID); return(Json(new DataTablesResponse(requestModel.Draw, collection, TotalRecord, TotalRecord), JsonRequestBehavior.AllowGet)); }
public JsonResult GetSearchData([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel, string searchprm) { SearchFilter SearchKey = BindSearch(searchprm); SearchKey = SearchFilter.SearchData(SearchKey, requestModel); ScheduleTaskCollection collection = ScheduleTaskManager.Search(SearchKey); int TotalRecord = 0; if (collection.Count > 0) { TotalRecord = collection[0].TotalRecord; } return(Json(new DataTablesResponse(requestModel.Draw, collection, TotalRecord, TotalRecord), JsonRequestBehavior.AllowGet)); }
// PUT api/<controller>/5 /// <summary> /// Puts the specified identifier. /// </summary> /// <param name="id">The identifier.</param> /// <param name="value">The value.</param> /// <returns></returns> /// <exception cref="HttpResponseException"></exception> public ScheduleTask Put(string id, [FromBody] ScheduleTask value) { ScheduleTask objItem = new ScheduleTask(); try { objItem = ScheduleTaskManager.UpdateItem(value); } catch (Exception ObjEx) { IfindLogManager.AddItem(new IfindLog() { LinkUrl = Request.RequestUri.AbsoluteUri, Exception = ObjEx.Message, Message = ObjEx.StackTrace }); } return(objItem); }
/// <summary> /// ExportExcel File /// </summary> /// <returns></returns> public string ExportExcel() { ScheduleTaskCollection collection = ScheduleTaskManager.GetAll(CurrentUser.CompanyID); DataTable dt = collection.ToDataTable <ScheduleTask>(); string fileName = "ScheduleTask_" + SystemConfig.CurrentDate.ToString("MM-dd-yyyy"); string[] RemoveColumn = { "CompanyID", "TargetDisplayID", "ReturnDisplay", "TotalRecord", "CreatedUser", "CreatedDate" }; for (int i = 0; i < RemoveColumn.Length; i++) { if (dt.Columns.Contains(RemoveColumn[i])) { dt.Columns.Remove(RemoveColumn[i]); } } FileInputHelper.ExportExcel(dt, fileName, "ScheduleTask List", false); return(fileName); }
public ActionResult Update(ScheduleTask model) { try { if (ModelState.IsValid) { // TODO: Add insert logic here ScheduleTaskManager.Update(model); //return RedirectToAction("Index"); } return(View(model)); } catch { return(View(model)); } }
public ContentResult SaveExcel(string item) { //string b = Request["item"]; IEnumerable <ScheduleTask> objItemList = JsonConvert.DeserializeObject <IEnumerable <ScheduleTask> >(item); JsonObject obj = new JsonObject(); obj.StatusCode = 200; obj.Message = "The process is sucessed"; foreach (ScheduleTask objitem in objItemList) { //default value objitem.CreatedUser = CurrentUser.EmployeeCode; objitem.CreatedDate = SystemConfig.CurrentDate; objitem.CompanyID = CurrentUser.CompanyID; ScheduleTaskManager.Add(objitem); } return(Content(JsonConvert.SerializeObject(obj), "application/json")); }
public ActionResult Create(ScheduleTask model) { try { if (ModelState.IsValid) { model.CompanyID = CurrentUser.CompanyID; if (model.Id != 0) { //get default value ScheduleTask objOldScheduleTask = ScheduleTaskManager.GetById(model.Id, CurrentUser.CompanyID); if (objOldScheduleTask != null) { model.CreatedDate = objOldScheduleTask.CreatedDate; model.CreatedUser = objOldScheduleTask.CreatedUser; } ScheduleTaskManager.Update(model); } else { // TODO: Add insert logic here model.CreatedUser = CurrentUser.EmployeeCode; model.CreatedDate = SystemConfig.CurrentDate; ScheduleTaskManager.Add(model); } return(View(ViewFolder + "list.cshtml", ScheduleTaskManager.GetAll(CurrentUser.CompanyID))); } } catch (Exception ObjEx) { //LogHelper.AddLog(new IfindLog() {LinkUrl=Request.Url.AbsoluteUri,Exception= ObjEx.Message,Message = ObjEx.StackTrace}); return(View(model)); } return(View(model)); }
public ActionResult Get(int Id, string action) { ScheduleTask objItem = ScheduleTaskManager.GetById(Id, CurrentUser.CompanyID); return(Content(JsonConvert.SerializeObject(objItem), "application/json")); }
public ActionResult Get(int Id) { ScheduleTask objItem = ScheduleTaskManager.GetById(Id, CurrentUser.CompanyID); return(View(objItem)); }
public ScheduleTask GetbyType(string Type, int CompanyID) { return(ScheduleTaskManager.GetbyType(Type, CompanyID)); }
public ActionResult list() { ScheduleTaskCollection collection = ScheduleTaskManager.GetAll(CurrentUser.CompanyID); return(View(ViewFolder + "list.cshtml", collection)); }
// GET api/<controller>/5 /// <summary> /// Gets the specified COM group identifier. /// </summary> /// <param name="ScheduleTaskId">The COM group identifier.</param> /// <returns></returns> public ScheduleTask Get(int Id, int CompanyID) { return(ScheduleTaskManager.GetItemByID(Id, CompanyID)); }
public ScheduleTaskCollection Get(int CompanyID) { return(ScheduleTaskManager.GetAllItem(CompanyID)); }
// GET api/<controller> /// <summary> /// Gets this instance. /// </summary> /// <returns></returns> public ScheduleTaskCollection Post(string method, [FromBody] SearchFilter value) { return(ScheduleTaskManager.Search(value)); }
/// <summary> /// Executes the task /// </summary> /// <param name="throwException">A value indicating whether exception should be thrown if some error happens</param> /// <param name="dispose">A value indicating whether all instances should be disposed after task run</param> /// <param name="ensureRunOnOneWebFarmInstance">A value indicating whether we should ensure this task is run on one farm node at a time</param> public void Execute(bool throwException = false, bool dispose = true, bool ensureRunOnOneWebFarmInstance = true) { //background tasks has an issue with Autofac //because scope is generated each time it's requested //that's why we get one single scope here //this way we can also dispose resources once a task is completed var scope = EngineContext.Current.ContainerManager.Scope(); // var scheduleTaskService = EngineContext.Current.ContainerManager.Resolve<IScheduleTaskService>("", scope); //var scheduleTask = ScheduleTaskManager.GetByType(this.Type, Biz.Core.Security.CustomerAuthorize.CurrentUser.CompanyID); var scheduleTask = ScheduleTaskManager.GetByType(this.Type, 1); // scheduleTaskService.GetTaskByType(this.Type); //Example Type = App.Services.Messages.QueuedMessagesSendTask, App.Services try { //flag that task is already executed var taskExecuted = false; //task is run on one farm node at a time? if (ensureRunOnOneWebFarmInstance) { //is web farm enabled (multiple instances)? var DNHConfig = EngineContext.Current.ContainerManager.Resolve <AppConfig>("", scope); if (DNHConfig.MultipleInstancesEnabled) { var machineNameProvider = new DefaultMachineNameProvider();// EngineContext.Current.ContainerManager.Resolve<IMachineNameProvider>("", scope); var machineName = machineNameProvider.GetMachineName(); if (String.IsNullOrEmpty(machineName)) { throw new Exception("Machine name cannot be detected. You cannot run in web farm."); //actually in this case we can generate some unique string (e.g. Guid) and store it in some "static" (!!!) variable //then it can be used as a machine name } //if (scheduleTask != null) //{ // if (DNHConfig.RedisCachingEnabled) // { // //get expiration time // var expirationInSeconds = scheduleTask.Seconds <= 300 ? scheduleTask.Seconds - 1 : 300; // var executeTaskAction = new Action(() => // { // //execute task // taskExecuted = true; // var task = this.CreateTask(scope); // if (task != null) // { // //update appropriate datetime properties // scheduleTask.LastStartUtc = DateTime.UtcNow; // scheduleTaskService.UpdateTask(scheduleTask); // task.Execute(); // this.LastEndUtc = this.LastSuccessUtc = DateTime.UtcNow; // } // }); // ////execute task with lock just use if we have redis server // //var redisWrapper = EngineContext.Current.ContainerManager.Resolve<IRedisConnectionWrapper>(scope: scope); // //if (!redisWrapper.PerformActionWithLock(scheduleTask.Type, TimeSpan.FromSeconds(expirationInSeconds), executeTaskAction)) // // return; // } // else // { // //lease can't be acquired only if for a different machine and it has not expired // if (scheduleTask.LeasedUntilUtc.HasValue && // scheduleTask.LeasedUntilUtc.Value >= DateTime.UtcNow && // scheduleTask.LeasedByMachineName != machineName) // return; // //lease the task. so it's run on one farm node at a time // scheduleTask.LeasedByMachineName = machineName; // scheduleTask.LeasedUntilUtc = DateTime.UtcNow.AddMinutes(30); // scheduleTaskService.UpdateTask(scheduleTask); // } //} } } //execute task in case if is not executed yet if (!taskExecuted) { //initialize and execute var task = this.CreateTask(scope); if (task != null) { this.LastStartUtc = DateTime.UtcNow; if (scheduleTask != null) { //update appropriate datetime properties scheduleTask.LastStartUtc = this.LastStartUtc; ScheduleTaskManager.Update(scheduleTask); // scheduleTaskService.UpdateTask(scheduleTask); } task.Execute(); this.LastEndUtc = this.LastSuccessUtc = DateTime.UtcNow; } } } catch (Exception exc) { this.Enabled = !this.StopOnError; this.LastEndUtc = DateTime.UtcNow; //log error // var logger = EngineContext.Current.ContainerManager.Resolve<ILogger>("", scope); // logger.Error(string.Format("Error while running the '{0}' schedule task. {1}", this.Name, exc.Message), exc); if (throwException) { throw; } } if (scheduleTask != null) { //update appropriate datetime properties scheduleTask.LastEndUtc = this.LastEndUtc; scheduleTask.LastSuccessUtc = this.LastSuccessUtc; ScheduleTaskManager.Update(scheduleTask); //scheduleTaskService.UpdateTask(scheduleTask); } //dispose all resources if (dispose) { scope.Dispose(); } }
// DELETE api/<controller>/5 /// <summary> /// Deletes the specified identifier. /// </summary> /// <param name="id">The identifier.</param> public void Delete(int id, int CompanyID) { ScheduleTaskManager.DeleteItem(id, CompanyID); }