private void PopulateSchedule(SPSchedule schedule) { if (schedule is SPMinuteSchedule) { PopulateMinuteSchedule(schedule); ScheduleField.Value = "Minutes"; } else if (schedule is SPHourlySchedule) { PopulateHourlySchedule(schedule); ScheduleField.Value = "Hourly"; } else if (schedule is SPDailySchedule) { PopulateDailySchedule(schedule); ScheduleField.Value = "Daily"; } else if (schedule is SPWeeklySchedule) { PopulateWeeklySchedule(schedule); ScheduleField.Value = "Weekly"; } else if (schedule is SPMonthlySchedule) { PopulateMonthlySchedule(schedule); ScheduleField.Value = "Monthly"; } else if (schedule is SPYearlySchedule) { PopulateYearlySchedule(schedule); ScheduleField.Value = "Yearly"; } }
private void PopulateHourlySchedule(SPSchedule currentSchedule) { var schedule = (SPHourlySchedule)currentSchedule; BeginMinuteTextBox.Text = schedule.BeginMinute.ToString(); EndMinuteTextBox.Text = schedule.EndMinute.ToString(); }
protected virtual void MapProperties(SPJobDefinition currentJobInstance, JobDefinition jobDefinition) { if (!string.IsNullOrEmpty(jobDefinition.ScheduleString)) { currentJobInstance.Schedule = SPSchedule.FromString(jobDefinition.ScheduleString); } if (!string.IsNullOrEmpty(jobDefinition.Title)) { currentJobInstance.Title = jobDefinition.Title; } foreach (var prop in jobDefinition.Properties) { var key = prop.Key; var value = prop.Value; if (currentJobInstance.Properties.ContainsKey(key)) { currentJobInstance.Properties[key] = value; } else { currentJobInstance.Properties.Add(key, value); } } }
public void SetSchedule(SPSchedule schedule) { if (schedule == null) { schedule = DefaultValues.GetSchedule(); } this.Timerjob.Schedule = schedule; }
private void PopulateMinuteSchedule(SPSchedule currentSchedule) { var schedule = (SPMinuteSchedule)currentSchedule; BeginSecondTextBox.Text = schedule.BeginSecond.ToString(); EndSecondTextBox.Text = schedule.EndSecond.ToString(); MinutesIntervalTextBox.Text = schedule.Interval.ToString(); }
private void PopulateDailySchedule(SPSchedule currentSchedule) { var schedule = (SPDailySchedule)currentSchedule; BeginDHourTextBox.Text = schedule.BeginHour.ToString(); BeginDMinuteTextBox.Text = schedule.BeginMinute.ToString(); BeginDSecondTextBox.Text = schedule.BeginSecond.ToString(); EndDHourTextBox.Text = schedule.EndHour.ToString(); EndDMinuteTextBox.Text = schedule.EndMinute.ToString(); EndDSecondTextBox.Text = schedule.EndSecond.ToString(); }
private void PopulateWeeklySchedule(SPSchedule currentSchedule) { var schedule = (SPWeeklySchedule)currentSchedule; BeginWDayDropDownList.SelectedValue = schedule.BeginDayOfWeek.ToString(); BeginWHourTextBox.Text = schedule.BeginHour.ToString(); BeginWMinuteTextBox.Text = schedule.BeginMinute.ToString(); BeginWSecondTextBox.Text = schedule.BeginSecond.ToString(); EndWDayDropDownList.SelectedValue = schedule.EndDayOfWeek.ToString(); EndWHourTextBox.Text = schedule.EndHour.ToString(); EndWMinuteTextBox.Text = schedule.EndMinute.ToString(); EndWSecondTextBox.Text = schedule.EndSecond.ToString(); }
private void PopulateMonthlySchedule(SPSchedule currentSchedule) { var schedule = (SPMonthlySchedule)currentSchedule; BeginMDayTextBox.Text = schedule.BeginDay.ToString(); BeginMHourTextBox.Text = schedule.BeginHour.ToString(); BeginMMinuteTextBox.Text = schedule.BeginMinute.ToString(); BeginMSecondTextBox.Text = schedule.BeginSecond.ToString(); EndMDayTextBox.Text = schedule.EndDay.ToString(); EndMHourTextBox.Text = schedule.EndHour.ToString(); EndMMinuteTextBox.Text = schedule.EndMinute.ToString(); EndMSecondTextBox.Text = schedule.EndSecond.ToString(); }
private void PopulateYearlySchedule(SPSchedule currentSchedule) { var schedule = (SPYearlySchedule)currentSchedule; BeginYMonthTextBox.Text = schedule.BeginMonth.ToString(); BeginYDayTextBox.Text = schedule.BeginDay.ToString(); BeginYHourTextBox.Text = schedule.BeginHour.ToString(); BeginYMinuteTextBox.Text = schedule.BeginMinute.ToString(); BeginYSecondTextBox.Text = schedule.BeginSecond.ToString(); EndYMonthTextBox.Text = schedule.EndMonth.ToString(); EndYDayTextBox.Text = schedule.EndDay.ToString(); EndYHourTextBox.Text = schedule.EndHour.ToString(); EndYMinuteTextBox.Text = schedule.EndMinute.ToString(); EndYSecondTextBox.Text = schedule.EndSecond.ToString(); }
public override void DeployModel(object modelHost, DefinitionBase model) { var webAppModelHost = modelHost.WithAssertAndCast <WebApplicationModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <JobDefinition>("model", value => value.RequireNotNull()); var spObject = FindWebApplicationJob(modelHost, webAppModelHost.HostWebApplication, definition); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.Name, o => o.Name) .ShouldBeEqual(m => m.Title, o => o.Title); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.JobType); var jobType = ResolveJobType(definition); var spJobType = spObject.GetType(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = jobType == spJobType }); }); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ScheduleString); var spSchedule = SPSchedule.FromString(definition.ScheduleString); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = spSchedule.Equals(spObject.Schedule) }); }); }
private void DeployWebApplicationJob(object modelHost, SPWebApplication webApp, JobDefinition jobDefinition) { var currentJobInstance = FindWebApplicationJob(modelHost, webApp, jobDefinition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentJobInstance, ObjectType = typeof(SPJobDefinition), ObjectDefinition = jobDefinition, ModelHost = modelHost }); if (currentJobInstance == null) { // install one var jobType = ResolveJobType(jobDefinition); // expecting only as timerjob is under web application //public cstr(string jobName, SPWebApplication webapp) if (jobDefinition.ConstructorParams.Count() == 0) { currentJobInstance = (SPJobDefinition)Activator.CreateInstance(jobType); } else { var parameters = new List <object>(); foreach (var param in jobDefinition.ConstructorParams) { switch (param) { case JobDefinitionCtorParams.JobName: parameters.Add(jobDefinition.Name); break; case JobDefinitionCtorParams.WebApplication: parameters.Add(webApp); break; default: throw new SPMeta2NotImplementedException(string.Format("Job cstr parameter [{0}] is not supported yet.", param)); } } currentJobInstance = (SPJobDefinition)Activator.CreateInstance(jobType, parameters.ToArray()); } if (!string.IsNullOrEmpty(jobDefinition.ScheduleString)) { currentJobInstance.Schedule = SPSchedule.FromString(jobDefinition.ScheduleString); } currentJobInstance.Title = jobDefinition.Title; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentJobInstance, ObjectType = typeof(SPJobDefinition), ObjectDefinition = jobDefinition, ModelHost = modelHost }); currentJobInstance.Update(); } else { if (!string.IsNullOrEmpty(jobDefinition.ScheduleString)) { currentJobInstance.Schedule = SPSchedule.FromString(jobDefinition.ScheduleString); } currentJobInstance.Title = jobDefinition.Title; InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentJobInstance, ObjectType = typeof(SPJobDefinition), ObjectDefinition = jobDefinition, ModelHost = modelHost }); currentJobInstance.Update(); } }
public override void DeployModel(object modelHost, DefinitionBase model) { var webAppModelHost = modelHost.WithAssertAndCast <WebApplicationModelHost>("modelHost", value => value.RequireNotNull()); var definition = model.WithAssertAndCast <JobDefinition>("model", value => value.RequireNotNull()); var spObject = FindWebApplicationJob(modelHost, webAppModelHost.HostWebApplication, definition); var assert = ServiceFactory.AssertService .NewAssert(definition, spObject) .ShouldNotBeNull(spObject) .ShouldBeEqual(m => m.Name, o => o.Name) .ShouldBeEqual(m => m.Title, o => o.Title); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.JobType); var jobType = ResolveJobType(definition); var spJobType = spObject.GetType(); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = jobType == spJobType }); }); assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.ScheduleString); var spSchedule = SPSchedule.FromString(definition.ScheduleString); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = spSchedule.Equals(spObject.Schedule) }); }); if (definition.Properties.Any()) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.Properties); var isValid = true; foreach (var prop in s.Properties) { if (!d.Properties.ContainsKey(prop.Key)) { isValid = false; break; } var currentSrcProp = prop.Value; var currentDstProp = d.Properties[prop.Key]; if (currentDstProp is string) { isValid = (string)currentDstProp == (string)currentSrcProp; } else if (currentDstProp is int) { isValid = (int)currentDstProp == (int)currentSrcProp; } else if (currentDstProp is double) { isValid = (double)currentDstProp == (double)currentSrcProp; } else { throw new Exception(string.Format("Type [{0}] is not supported yet", currentDstProp.GetType())); } if (!isValid) { break; } } return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = null, IsValid = isValid }); }); } else { assert.SkipProperty(p => p.Properties, "Properties are empty. Skiping."); } }
public static void Create(string assamblyName, string className, object[] TJCtorParams, SPJobDefinitionCollection jobsCollection, Hashtable properties, SPSchedule schedule = null) { TimerJobBuilder TJBuilder = new TimerJobBuilder(); TJBuilder.CreateJob(assamblyName, className, TJCtorParams); TJBuilder.DeleteOldVersion(jobsCollection); TJBuilder.SetSchedule(schedule); TJBuilder.SetProperties(properties); TJBuilder.UpdateJob(); }
public void SubmitButton_Click(object sender, EventArgs e) { SPJobDefinition jobDefinition = GetJobDefinition(); if (jobDefinition != null) { string str = ScheduleField.Value; SPSchedule schedule = null; string str2 = str; if (str2 != null) { if (!(str2 == "Minutes")) { if (str2 == "Hourly") { schedule = BuildHourlySchedule(); } else if (str2 == "Daily") { schedule = BuildDailySchedule(); } else if (str2 == "Weekly") { schedule = BuildWeeklySchedule(); } else if (str2 == "Monthly") { schedule = BuildMonthlySchedule(); } else if (str2 == "Yearly") { schedule = BuildYearlySchedule(); } } else { schedule = BuildMinuteSchedule(); } } bool flag = true; if ((jobDefinition.Schedule != null) && jobDefinition.Schedule.Equals(schedule)) { flag = false; } if (flag) { jobDefinition.Schedule = schedule; if (jobDefinition.IsDisabled) { jobDefinition.IsDisabled = false; } jobDefinition.Update(); } var child = WebAppSelector.CurrentItem.GetChild <JobSettings>(jobDefinition.Name); if (child == null) { child = new JobSettings(jobDefinition.Name, WebAppSelector.CurrentItem, Guid.NewGuid()); } else { child.SiteCollectionsEnabled.Clear(); } if (SomeSiteCollectionsRadioButton.Checked) { foreach (RepeaterItem item in SiteCollectionRepeater.Items) { var box = item.FindControl("SiteCollectionCheckBox") as CheckBox; if ((box != null) && box.Checked) { var label = item.FindControl("SiteCollectionIDLabel") as Label; if (label != null) { var guid = new Guid(label.Text); child.SiteCollectionsEnabled.Add(guid); } } } } child.Update(); } SPUtility.Redirect(SPContext.Current.Web.Url + "/_admin/operations.aspx", SPRedirectFlags.DoNotEncodeUrl, HttpContext.Current); }