public static DataTable GetUpdateServiceSchedule(ServiceSchedule servicedetails) { try { var ServiceOutDate = "1900-01-01"; if (servicedetails.ServiceOutDate != "" && servicedetails.ServiceOutDate != null && servicedetails.ServiceOutDate != "string") { ServiceOutDate = servicedetails.ServiceOutDate; } //else //{ // ServiceOutDate = Convert.ToDateTime("1900-01-01"); //} string ConnectionString = Common.GetConnectionString(); List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter("@ScheduleID", servicedetails.ScheduleID)); // parameters.Add(new SqlParameter("@ServiceID", servicedetails.ServiceID)); parameters.Add(new SqlParameter("@RequestedServiceDate", Convert.ToDateTime(servicedetails.RequestedServiceDate))); //parameters.Add(new SqlParameter("@ActualServiceDate", Convert.ToDateTime(servicedetails.ActualServiceDate))); parameters.Add(new SqlParameter("@ServiceOutDate", Convert.ToDateTime(ServiceOutDate))); parameters.Add(new SqlParameter("@Status", servicedetails.Status)); parameters.Add(new SqlParameter("@Comments", servicedetails.Comments)); //Execute the query using (DataTable dt = SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure, "spUpdateServiceSchedule", parameters.ToArray()).Tables[0]) { return(dt); } } catch (Exception e) { throw e; } }
public ActionResult Create(ServiceScheduleViewModel model) { var urlRefer = Request["UrlReferrer"]; if (ModelState.IsValid) { var serviceSchedule = new ServiceSchedule(); AutoMapper.Mapper.Map(model, serviceSchedule); serviceSchedule.IsDeleted = false; serviceSchedule.CreatedUserId = WebSecurity.CurrentUserId; serviceSchedule.ModifiedUserId = WebSecurity.CurrentUserId; serviceSchedule.AssignedUserId = WebSecurity.CurrentUserId; serviceSchedule.CreatedDate = DateTime.Now; serviceSchedule.ModifiedDate = DateTime.Now; serviceSchedule.Status = "pending"; ServiceScheduleRepository.InsertServiceSchedule(serviceSchedule); string prefix = Erp.BackOffice.Helpers.Common.GetSetting("prefixOrderNo_ServiceSchedule"); serviceSchedule.Code = Erp.BackOffice.Helpers.Common.GetCode(prefix, serviceSchedule.Id); ServiceScheduleRepository.UpdateServiceSchedule(serviceSchedule); TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess; if (Request["IsPopup"] == "true" || Request["IsPopup"] == "True") { TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess; ViewBag.closePopup = "true"; model.Id = serviceSchedule.Id; ViewBag.urlRefer = urlRefer; return(View(model)); } return(Redirect(urlRefer)); } return(View(model)); }
public static void Advance(this ServiceSchedule self) { /* * switch (self.Interval) * { * case ScheduleType.Weekly: * self.TimeOfDay = self.TimeOfDay.AddDays(7); * break; * case ScheduleType.Monthly: * self.TimeOfDay = self.TimeOfDay.AddMonths(1); * break; * case ScheduleType.WorkDays: * self.TimeOfDay = self.TimeOfDay.AddWorkdays(1); * break; * //case ScheduleType.Daily: * default: * self.TimeOfDay = self.TimeOfDay.AddDays(1); * break; * }//*/ }
public static void Normalize(this ServiceSchedule result) { // Compute TimeOfDay (the date of first occurance) based on StartAt try { /* * switch (result.Interval) * { * case ScheduleType.WorkDays: * // If it's the weekend get monday * if (!result.TimeOfDay.IsWorkday()) * result.Advance(); * break; * case ScheduleType.Weekly: * result.TimeOfDay = result.TimeOfDay.SetDayOfWeek((DayOfWeek)result.StartAt); * break; * case ScheduleType.Monthly: * if (result.StartAt >= 31) * { * // End of month * result.TimeOfDay = result.TimeOfDay.SetDayOfMonth(1); * * result.TimeOfDay = result.TimeOfDay.AddMonths(1); * result.TimeOfDay = result.TimeOfDay.AddDays(-1); * } * else if (result.StartAt > 0) * result.TimeOfDay = result.TimeOfDay.SetDayOfMonth(result.StartAt); * break; * default: * break; * } * while (result.TimeOfDay < DateTime.Now) * result.Advance(); * //*/ } catch { } }
public static void DoTasks(string ExecuteMethods, ServiceSchedule schedule) { DoTasks(ExecuteMethods, new object[] { schedule }); }
private string VerifyPolicy() { if (string.IsNullOrEmpty(_policy.Name)) { return("The Policy's Name Is Not Valid."); } if (string.IsNullOrEmpty(_policy.Guid)) { return("The Policy's Guid Is Not Valid."); } if (_policy.Frequency != EnumPolicy.Frequency.OncePerComputer && _policy.Frequency != EnumPolicy.Frequency.OncePerDay && _policy.Frequency != EnumPolicy.Frequency.OncePerMonth && _policy.Frequency != EnumPolicy.Frequency.OncePerUserPerComputer && _policy.Frequency != EnumPolicy.Frequency.OncePerWeek && _policy.Frequency != EnumPolicy.Frequency.Ongoing && _policy.Frequency != EnumPolicy.Frequency.EveryXdays && _policy.Frequency != EnumPolicy.Frequency.EveryXhours) { return("The Policy's Frequency Is Not Valid."); } if (_policy.Trigger != EnumPolicy.Trigger.Checkin && _policy.Trigger != EnumPolicy.Trigger.Login && _policy.Trigger != EnumPolicy.Trigger.Startup && _policy.Trigger != EnumPolicy.Trigger.StartupOrCheckin) { return("The Policy's Trigger Is Not Valid."); } if (_policy.RunInventory != EnumPolicy.InventoryAction.After && _policy.RunInventory != EnumPolicy.InventoryAction.Before && _policy.RunInventory != EnumPolicy.InventoryAction.Both && _policy.RunInventory != EnumPolicy.InventoryAction.Disabled) { return("The Policy's Run Inventory Is Not Valid."); } int value; if (!int.TryParse(_policy.SubFrequency.ToString(), out value)) { return("The Policy's Sub Frequency Is Not Valid."); } if (_policy.CompletedAction != EnumPolicy.CompletedAction.DoNothing && _policy.CompletedAction != EnumPolicy.CompletedAction.Reboot && _policy.CompletedAction != EnumPolicy.CompletedAction.RebootIfNoLogins) { return("The Policy's Completed Action Is Not Valid."); } if (_policy.ExecutionType != EnumPolicy.ExecutionType.Cache && _policy.ExecutionType != EnumPolicy.ExecutionType.Install) { return("The Policy's Execution Type Is Not Valid."); } if (_policy.ErrorAction != EnumPolicy.ErrorAction.AbortCurrentPolicy && _policy.ErrorAction != EnumPolicy.ErrorAction.AbortRemainingPolicies && _policy.ErrorAction != EnumPolicy.ErrorAction.Continue) { return("The Policy's Error Action Is Not Valid"); } if (_policy.MissedAction != EnumPolicy.FrequencyMissedAction.NextOpportunity && _policy.MissedAction != EnumPolicy.FrequencyMissedAction.ScheduleDayOnly) { return("The Policy's Frequency Missed Action Is Not Valid."); } if (_policy.LogLevel != EnumPolicy.LogLevel.Full && _policy.LogLevel != EnumPolicy.LogLevel.HiddenArguments && _policy.LogLevel != EnumPolicy.LogLevel.None) { return("The Policy's Log Level Is Not Valid."); } if (_policy.WuType != EnumPolicy.WuType.Disabled && _policy.WuType != EnumPolicy.WuType.Microsoft && _policy.WuType != EnumPolicy.WuType.MicrosoftSkipUpgrades && _policy.WuType != EnumPolicy.WuType.Wsus && _policy.WuType != EnumPolicy.WuType.WsusSkipUpgrades) { return("The Policy's Windows Update Type Is Not Valid."); } if (_policy.AutoArchiveType != EnumPolicy.AutoArchiveType.AfterXdays && _policy.AutoArchiveType != EnumPolicy.AutoArchiveType.None && _policy.AutoArchiveType != EnumPolicy.AutoArchiveType.WhenComplete) { return("The Policy's Auto Archive Type Is Not Valid."); } if (_policy.AutoArchiveType == EnumPolicy.AutoArchiveType.AfterXdays) { int autoArchiveSub; if (!int.TryParse(_policy.AutoArchiveSub, out autoArchiveSub)) { return("The Policy's Auto Archive Sub Is Not Valid."); } } if (_policy.WindowStartScheduleId != -1) { var schedule = new ServiceSchedule().GetSchedule(_policy.WindowStartScheduleId); if (schedule == null) { return("The Policy's Start Schedule Id Is Not Valid."); } } if (_policy.WindowEndScheduleId != -1) { var schedule = new ServiceSchedule().GetSchedule(_policy.WindowEndScheduleId); if (schedule == null) { return("The Policy's End Schedule Id Is Not Valid."); } } if (_policy.PolicyComCondition != EnumPolicy.PolicyComCondition.Any && _policy.PolicyComCondition != EnumPolicy.PolicyComCondition.Selective) { return("The Policy's Com Server Condition Is Not Valid"); } if (_policy.PolicyComCondition == EnumPolicy.PolicyComCondition.Selective) { var policyComServers = _policyService.GetPolicyComServers(_policy.Id); if (policyComServers == null) { return("The Policy's Selected Com Servers Are Not Valid"); } if (policyComServers.Count == 0) { return("The Policy's Selected Com Servers Are Not Valid. At Least One Server Must Be Selected."); } foreach (var policyComServer in policyComServers) { var comServer = new ServiceClientComServer().GetServer(policyComServer.ComServerId); if (comServer == null) { return("The Policy's Selected Com Servers Are Not Valid. A Specified Com Server Does Not Exist"); } } } if (_policy.ConditionId != -1) // -1 = disabled { var conditionScript = new ServiceScriptModule().GetModule(_policy.ConditionId); if (conditionScript == null) { return($"Condition Script For {_policy.Name} Does Not Exist"); } if (!conditionScript.IsCondition) { return($"The Condition Script For {_policy.Name} Is Not Currently Set As A Condition"); } if (string.IsNullOrEmpty(conditionScript.Name)) { return($"A Condition Script For {_policy.Name} Has An Invalid Name"); } if (conditionScript.Archived) { return($"A Condition Script For {_policy.Name} Is Archived"); } if (string.IsNullOrEmpty(conditionScript.ScriptContents)) { return("Condition Script: " + conditionScript.Name + " Has An Invalid Script. It Cannot Be Empty."); } if (string.IsNullOrEmpty(conditionScript.Guid)) { return("Condition Script: " + conditionScript.Name + " Has An Invalid GUID"); } if (conditionScript.ScriptType != EnumScriptModule.ScriptType.Batch && conditionScript.ScriptType != EnumScriptModule.ScriptType.Powershell && conditionScript.ScriptType != EnumScriptModule.ScriptType.VbScript) { return("Condition Script: " + conditionScript.Name + " Has An Invalid Type"); } if (!int.TryParse(conditionScript.Timeout.ToString(), out value)) { return("Condition Script: " + conditionScript.Name + " Has An Invalid Timeout"); } List <string> successCodes = new List <string>(); foreach (var successCode in conditionScript.SuccessCodes.Split(',')) { successCodes.Add(successCode); } if (successCodes.Count == 0) { return("Condition Script: " + conditionScript.Name + " Has An Invalid Success Code"); } if (successCodes.Any(code => !int.TryParse(code, out value))) { return("Condition Script: " + conditionScript.Name + " Has An Invalid Success Code"); } if (!string.IsNullOrEmpty(conditionScript.WorkingDirectory)) { try { Path.GetFullPath(conditionScript.WorkingDirectory); } catch { return("Condition Script: " + conditionScript.Name + " Has An Invalid Working Directory"); } } if (conditionScript.ImpersonationId != -1) { var impAccount = new ServiceImpersonationAccount().GetAccount(conditionScript.ImpersonationId); if (impAccount == null) { return("Condition Script: " + conditionScript.Name + " Has An Invalid Impersonation Account"); } } if (_policy.ConditionFailedAction != EnumCondition.FailedAction.MarkFailed && _policy.ConditionFailedAction != EnumCondition.FailedAction.MarkNotApplicable && _policy.ConditionFailedAction != EnumCondition.FailedAction.MarkSkipped && _policy.ConditionFailedAction != EnumCondition.FailedAction.MarkSuccess) { return($"The Condition Failed Action For {_policy.Name} Is Not Valid"); } } return(null); }
public ScheduleController() { _scheduleService = new ServiceSchedule(); }
public IActionResult UpdateServiceSchedule([FromBody] ServiceSchedule servicedetails) { //string GetConnectionString = ServicesController.GetConnectionString(); //string GetConnectionString = configuration.GetSection("ConnectionString").GetSection("DefaultConnection").Value; List <ServiceDetails> serviceDetails = new List <ServiceDetails>(); try { if (servicedetails.ScheduleID <= 0 || servicedetails.ScheduleID == null) { return(StatusCode((int)HttpStatusCode.BadRequest, new { error = new { message = "Please enter ScheduleID" } })); } else if (servicedetails.RequestedServiceDate == "" || servicedetails.RequestedServiceDate == "string" || servicedetails.RequestedServiceDate == null) { return(StatusCode((int)HttpStatusCode.BadRequest, new { error = new { message = "Please enter RequestedServiceDate" } })); } else { DataTable dt = Data.Services.GetUpdateServiceSchedule(servicedetails); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ServiceDetails service = new ServiceDetails(); service.ServiceID = (dt.Rows[i]["ServiceID"] == DBNull.Value ? 0 : (int)dt.Rows[i]["ServiceID"]); //service.ServicePlanID = (dt.Rows[i]["ServicePlanID"] == DBNull.Value ? 0 : (int)dt.Rows[i]["ServicePlanID"]); // service.ServicePriceChartId = (dt.Rows[i]["ServicePriceChartId"] == DBNull.Value ? 0 : (int)dt.Rows[i]["ServicePriceChartId"]); service.PlanType = (dt.Rows[i]["PlanType"] == DBNull.Value ? "-" : dt.Rows[i]["PlanType"].ToString()); service.Price = (dt.Rows[i]["Price"] == DBNull.Value ? 0 : (decimal)dt.Rows[i]["Price"]); service.VehicleId = (dt.Rows[i]["VehicleId"] == DBNull.Value ? 0 : (int)dt.Rows[i]["VehicleId"]); service.UserId = (dt.Rows[i]["UserId"] == DBNull.Value ? 0 : (int)dt.Rows[i]["UserId"]); //service.RemainderMinutes = (dt.Rows[i]["RemainderMinutes"] == DBNull.Value ? 0 : (int)dt.Rows[i]["RemainderMinutes"]); //service.LocationID = (dt.Rows[i]["LocationID"] == DBNull.Value ? 0 : (int)dt.Rows[i]["LocationID"]); //service.IsTeamsandConditionsAccepted = (dt.Rows[i]["IsTeamsandConditionsAccepted"] == DBNull.Value ? false : (bool)dt.Rows[i]["IsTeamsandConditionsAccepted"]); service.PromoCodeApplied = (dt.Rows[i]["PromoCodeApplied"] == DBNull.Value ? false : (bool)dt.Rows[i]["PromoCodeApplied"]); service.Status = (dt.Rows[i]["Status"] == DBNull.Value ? "-" : dt.Rows[i]["Status"].ToString()); service.Comments = (dt.Rows[i]["Comments"] == DBNull.Value ? "-" : dt.Rows[i]["Comments"].ToString()); service.ScheduleID = (dt.Rows[i]["ScheduleID"] == DBNull.Value ? 0 : (int)dt.Rows[i]["ScheduleID"]); service.RequestedServiceDate = (dt.Rows[i]["RequestedServiceDate"] == DBNull.Value ? "-" : dt.Rows[i]["RequestedServiceDate"].ToString()); service.ActualServiceDate = (dt.Rows[i]["ActualServiceDate"] == DBNull.Value ? "-" : dt.Rows[i]["ActualServiceDate"].ToString()); service.ServiceOutDate = (dt.Rows[i]["ServiceOutDate"] == DBNull.Value ? "-" : dt.Rows[i]["ServiceOutDate"].ToString()); service.ServiceName = (dt.Rows[i]["ServiceName"] == DBNull.Value ? "-" : dt.Rows[i]["ServiceName"].ToString()); // service.Description = (dt.Rows[i]["Description"] == DBNull.Value ? "-" : dt.Rows[i]["Description"].ToString()); // service.IsAvailable = (dt.Rows[i]["IsAvailable"] == DBNull.Value ? false : (bool)dt.Rows[i]["IsAvailable"]); serviceDetails.Add(service); } return(StatusCode((int)HttpStatusCode.OK, serviceDetails)); } else { return(StatusCode((int)HttpStatusCode.OK, new { })); } } } catch (Exception e) { string SaveErrorLog = Data.Common.SaveErrorLog("UpdateServiceSchedule", e.Message); return(StatusCode((int)HttpStatusCode.InternalServerError, new { error = new { message = e.Message } })); } }
public DtoTriggerResponse Execute(DtoPolicyRequest policyRequest) { var triggerResponse = new DtoTriggerResponse(); var list = new List <DtoClientPolicy>(); var computer = _uow.ComputerRepository.GetFirstOrDefault(x => x.Guid == policyRequest.ClientIdentity.Guid); if (computer == null) { return(null); } if (string.IsNullOrEmpty(policyRequest.CurrentComServer)) { Logger.Debug("Could Not Determine The Client's Policy. A Com Server Was Not Provided."); return(null); } //without this, viewing the computer's effective policy, clears these values if (!string.IsNullOrEmpty(policyRequest.ClientVersion) && !string.IsNullOrEmpty(policyRequest.PushURL)) { computer.LastCheckinTime = DateTime.Now; computer.ClientVersion = policyRequest.ClientVersion; computer.PushUrl = policyRequest.PushURL; computer.LastIp = IpServices.GetIPAddress(); new ServiceComputer().UpdateComputer(computer); } var groupMemberships = _uow.GroupRepository.GetMembershipsForClientPolicy(computer.Id); if (policyRequest.UserLogins != null) { var userLoginsResult = new ServiceUserLogins().AddOrUpdate(policyRequest.UserLogins, computer.Id); if (userLoginsResult != null) { triggerResponse.UserLoginsSubmitted = userLoginsResult.Success; } } if (policyRequest.AppMonitors != null) { var appMonitorResult = new ServiceAppMonitor().AddOrUpdate(policyRequest.AppMonitors, computer.Id); if (appMonitorResult != null) { triggerResponse.AppMonitorSubmitted = appMonitorResult.Success; } } foreach (var membership in groupMemberships) { var clientPoliciesJson = new ServiceGroup().GetActiveGroupPolicy(membership.GroupId); if (clientPoliciesJson == null) { continue; } if (policyRequest.Trigger == EnumPolicy.Trigger.Startup) { list.AddRange(JsonConvert.DeserializeObject <List <DtoClientPolicy> >(clientPoliciesJson.PolicyJson).Where(x => x.StartDate <= DateTime.UtcNow && (x.Trigger == EnumPolicy.Trigger.Startup || x.Trigger == EnumPolicy.Trigger.StartupOrCheckin))); } else if (policyRequest.Trigger == EnumPolicy.Trigger.Checkin) { list.AddRange(JsonConvert.DeserializeObject <List <DtoClientPolicy> >(clientPoliciesJson.PolicyJson).Where(x => x.StartDate <= DateTime.UtcNow && (x.Trigger == EnumPolicy.Trigger.Checkin || x.Trigger == EnumPolicy.Trigger.StartupOrCheckin))); } else { list.AddRange(JsonConvert.DeserializeObject <List <DtoClientPolicy> >(clientPoliciesJson.PolicyJson).Where(x => x.StartDate <= DateTime.UtcNow && x.Trigger == policyRequest.Trigger)); } } var distinctList = list.GroupBy(dto => dto.Guid).Select(y => y.First()).ToList(); var toRemoveByComServer = new List <DtoClientPolicy>(); //refine list to only designated com servers foreach (var p in distinctList) { if (p.PolicyComCondition == EnumPolicy.PolicyComCondition.Any) { continue; } var policyComServers = _uow.PolicyRepository.GetPolicyComServerUrls(p.Id); if (!policyComServers.Contains(policyRequest.CurrentComServer.ToLower())) { toRemoveByComServer.Add(p); } } foreach (var p in toRemoveByComServer) { distinctList.Remove(p); } //refine list to designated schedules var currentDayOfWeek = (int)DateTime.Now.DayOfWeek; var currentTimeOfDay = DateTime.Now.TimeOfDay; var serviceSchedule = new ServiceSchedule(); var toRemoveBySchedule = new List <DtoClientPolicy>(); foreach (var p in distinctList.Where(x => x.StartWindowScheduleId != -1 && x.EndWindowScheduleId != -1 && x.Trigger != EnumPolicy.Trigger.Login)) { //items in here have a more refined schedule. Check if they should be removed from the current run list. var start = serviceSchedule.GetSchedule(p.StartWindowScheduleId); var end = serviceSchedule.GetSchedule(p.EndWindowScheduleId); if (start == null || end == null) { continue; } if (!start.IsActive || !end.IsActive) { continue; } if (p.Frequency != EnumPolicy.Frequency.OncePerWeek && p.Frequency != EnumPolicy.Frequency.OncePerMonth) //day of week is already defined in weekly frequency and day of month is already defined { if (currentDayOfWeek == 0 && !start.Sunday) { toRemoveBySchedule.Add(p); } else if (currentDayOfWeek == 1 && !start.Monday) { toRemoveBySchedule.Add(p); } else if (currentDayOfWeek == 2 && !start.Tuesday) { toRemoveBySchedule.Add(p); } else if (currentDayOfWeek == 3 && !start.Wednesday) { toRemoveBySchedule.Add(p); } else if (currentDayOfWeek == 4 && !start.Thursday) { toRemoveBySchedule.Add(p); } else if (currentDayOfWeek == 5 && !start.Friday) { toRemoveBySchedule.Add(p); } else if (currentDayOfWeek == 6 && !start.Saturday) { toRemoveBySchedule.Add(p); } } try { var startMinute = start.Minute == 0 ? "00" : start.Minute.ToString(); var endMinute = end.Minute == 0 ? "00" : end.Minute.ToString(); var startTimeOfDay = DateTime.ParseExact(start.Hour + " " + startMinute, "H mm", CultureInfo.InvariantCulture).TimeOfDay; var endTimeOfDay = DateTime.ParseExact(end.Hour + " " + endMinute, "H mm", CultureInfo.InvariantCulture).TimeOfDay; if (currentTimeOfDay >= startTimeOfDay && currentTimeOfDay <= endTimeOfDay) { //ignored } else { toRemoveBySchedule.Add(p); } } catch (Exception ex) { Logger.Error("Could Not Parse Schedule Times For " + start.Name + " " + end.Name); Logger.Error(ex.Message); continue; } } foreach (var p in toRemoveBySchedule) { distinctList.Remove(p); } triggerResponse.Policies = distinctList; triggerResponse.CheckinTime = Convert.ToInt32(ServiceSetting.GetSettingValue(SettingStrings.CheckinInterval)); triggerResponse.ShutdownDelay = Convert.ToInt32(ServiceSetting.GetSettingValue(SettingStrings.ShutdownDelay)); return(triggerResponse); }