/// <summary> /// Submits the job. /// </summary> public void SubmitJob(string user, string password, List <string> urls) { Properties[KEY_USER] = user; Properties[KEY_PWD] = password; Properties[KEY_URLS] = urls; Schedule = new SPOneTimeSchedule(DateTime.Now); Update(); }
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { var app = properties.Feature.Parent as SPWebApplication; RemoveJobIfRegistered(app); var clientAccessPolicyJob = new ClientAccessPolicyDeploymentJob(JobName, app); var schedule = new SPOneTimeSchedule(DateTime.Now); clientAccessPolicyJob.Schedule = schedule; clientAccessPolicyJob.Update(); app.JobDefinitions.Add(clientAccessPolicyJob); app.Update(); clientAccessPolicyJob.RunNow(); }
private void CreateWorkItem(SPWeb web, string fullClass, string fullAssembly) { //SPSite tsite = properties.Feature.Parent as SPSite; Guid siteId = web.Site.ID; Guid webId = web.ID; string _modulename = fullClass; string _assembly = fullAssembly; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerModuleWorkItem.WorkItemTypeId, webId, siteId, 1, true, Guid.Empty, Guid.Empty, site.SystemAccount.ID, null, _modulename + ";" + _assembly, Guid.Empty ); } }); try { WebSiteControllerModuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerModuleWorkItem(WebSiteControllerModuleWorkItem.WorkItemJobDisplayName + "HomePage", web.Site.WebApplication); SPOneTimeSchedule oneTimeSchedule = new SPOneTimeSchedule(DateTime.Now); WebSiteControllerModuleJob.Schedule = oneTimeSchedule; WebSiteControllerModuleJob.Update(); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWebApplication adminWebApplication = properties.Feature.Parent as SPWebApplication; foreach (SPJobDefinition job in adminWebApplication.JobDefinitions) { if (job.Name == tJobName) { job.Delete(); } } if (((SPWebApplication)properties.Feature.Parent).IsAdministrationWebApplication) { STSSyncMonitor newTimerJob = new STSSyncMonitor(tJobName, adminWebApplication); var jobSchedule = new SPOneTimeSchedule(); newTimerJob.Schedule = jobSchedule; newTimerJob.Update(); } }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { var site = properties.Feature.Parent as SPWebApplication; RemoveJobIfRegistered(site); var clientAccessPolicyJob = new ClientAccessPolicyDeploymentJob(JobName, site); var schedule = new SPOneTimeSchedule(DateTime.Now); clientAccessPolicyJob.Schedule = schedule; #if SP2013 clientAccessPolicyJob.FeatureCompatibilityLevel = properties.Definition.CompatibilityLevel; #endif clientAccessPolicyJob.Update(); site.JobDefinitions.Add(clientAccessPolicyJob); site.Update(); //Disabled running this job for now, the administrator can choose to run it or copy the file manually //there are considerations with deploying this file, what if one exists already, does the administrator approve of it without seeing it //clientAccessPolicyJob.RunNow(); }
protected void okButton_Click(object sender, EventArgs e) { var application = GetApplication(); try { var xDocument = XDocument.Parse(configuration.Text); } catch (Exception) { LabelErrorMessage.Text = "Invalid XML configuration"; return; } if (application.Properties.ContainsKey(Constants.PulsusConfigKey)) application.Properties[Constants.PulsusConfigKey] = configuration.Text; else application.Properties.Add(Constants.PulsusConfigKey, configuration.Text); var configDeploymentJob = new ConfigDeploymentJob(Constants.ConfigDeploymentJobName, application); var schedule = new SPOneTimeSchedule(DateTime.Now); configDeploymentJob.Schedule = schedule; configDeploymentJob.Update(); foreach (SPJobDefinition job in application.JobDefinitions) if (job.Title == Constants.ConfigDeploymentJobName) job.Delete(); application.JobDefinitions.Add(configDeploymentJob); application.Update(); configDeploymentJob.RunNow(); ReloadPulsusFeature(application); base.EndOperation(0); }
/// <summary> /// Submits the job and schedules it to run on every server in the Farm. /// </summary> public void SubmitJob() { Schedule = new SPOneTimeSchedule(DateTime.Now); Title = "Update Layouts Sitemap (" + _uniqueID + ")"; Update(); }
private void CreateErrorWorkItem(SPWeb web, HttpStatusCode code) { try { Guid siteId = web.Site.ID; Guid webId = web.ID; bool disabled = false; WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None; bool appliesToSSL = true; int sequence = 1; String pricipal = string.Empty; StringBuilder builder = new StringBuilder(); builder.Append("Error/" + code.ToString() + ".aspx;"); builder.Append(disabled.ToString() + ";"); builder.Append(appliesToSSL.ToString() + ";"); builder.Append(sequence.ToString() + ";"); builder.Append(principalType.ToString() + ";"); builder.Append(pricipal + ";"); builder.Append("#"); builder.Append(String.Format("{0}:{1};", "ErrorPage", "Error/" + code.ToString() + ".aspx;")); builder.Append(String.Format("{0}:{1};", "ErrorCode", ((int)code).ToString())); string full = builder.ToString(); ErrorModule mod = new ErrorModule(); IWebSiteControllerModule imod = null; //WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType); while (imod == null) { System.Threading.Thread.Sleep(1000); try { imod = WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } } //Guid itemGuid = new Guid("17A3219B-049F-4056-9566-37590122BE8E"); int item = -1; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerRuleWorkItem.WorkItemTypeId, webId, siteId, item, true, imod.Id, Guid.Empty, site.SystemAccount.ID, null, builder.ToString(), Guid.Empty ); } }); try { WebSiteControllerRuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerRuleWorkItem(WebSiteControllerRuleWorkItem.WorkItemJobDisplayName + code.ToString(), web.Site.WebApplication); SPOneTimeSchedule oneTimeSchedule = new SPOneTimeSchedule(DateTime.Now); WebSiteControllerModuleJob.Schedule = oneTimeSchedule; WebSiteControllerModuleJob.Update(); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); } }
/// <summary> /// Submits the job. /// </summary> public void SubmitJob(string user, string password, List<string> urls) { Properties[KEY_USER] = user; Properties[KEY_PWD] = password; Properties[KEY_URLS] = urls; Schedule = new SPOneTimeSchedule(DateTime.Now); Update(); }
private void CreateWorkItem(WebSiteControllerRule rule, string url) { Guid siteId = SPContext.Current.Site.ID; Guid webId = SPContext.Current.Web.ID; if (url.StartsWith("/")) { url = url.TrimStart('/'); } StringBuilder builder = new StringBuilder(); builder.Append(SPContext.Current.Web.ServerRelativeUrl + ";"); builder.Append(rule.IsDisabled.ToString() + ";"); builder.Append(rule.AppliesToSsl.ToString() + ";"); builder.Append(rule.Sequence.ToString() + ";"); builder.Append(rule.PrincipalType + ";"); builder.Append(rule.Principal + ";"); builder.Append("#"); builder.Append(String.Format("{0}:{1};", "OriginalUrl", "/" + url)); int item = 2; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerRuleWorkItem.WorkItemTypeId, webId, siteId, item, true, rule.Id, Guid.Empty, site.SystemAccount.ID, null, builder.ToString(), Guid.Empty ); } }); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(siteId))//, SPUserToken.SystemAccount)) { try { WebSiteControllerRuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerRuleWorkItem(WebSiteControllerRuleWorkItem.WorkItemJobDisplayName + "HomePage", site.WebApplication); SPOneTimeSchedule oneTimeSchedule = new SPOneTimeSchedule(DateTime.Now); WebSiteControllerModuleJob.Schedule = oneTimeSchedule; WebSiteControllerModuleJob.Update(); } catch { }; } }); }
private void CreateWorkItem(string url) { Guid siteId = SPContext.Current.Site.ID; Guid webId = SPContext.Current.Web.ID; bool disabled = false; WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None; bool appliesToSSL = true; int sequence = 1; String pricipal = string.Empty; StringBuilder builder = new StringBuilder(); builder.Append(SPContext.Current.Web.ServerRelativeUrl + ";"); builder.Append(disabled.ToString() + ";"); builder.Append(appliesToSSL.ToString() + ";"); builder.Append(sequence.ToString() + ";"); builder.Append(principalType.ToString() + ";"); builder.Append(pricipal + ";"); builder.Append("#"); builder.Append(String.Format("{0}:{1};", "OriginalUrl", url)); string full = builder.ToString(); SemanticModule mod = new SemanticModule(); IWebSiteControllerModule imod = null;// WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType); while (imod == null) { System.Threading.Thread.Sleep(1000); try { imod = WebSiteControllerConfig.GetModule(SPContext.Current.Site.WebApplication, mod.RuleType); } catch (Exception ex) { ex.ToString(); } } int item = -1; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerRuleWorkItem.WorkItemTypeId, webId, siteId, item, true, imod.Id, Guid.Empty, site.SystemAccount.ID, null, builder.ToString(), Guid.Empty ); } }); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(siteId))//, SPUserToken.SystemAccount)) { try { WebSiteControllerRuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerRuleWorkItem(WebSiteControllerRuleWorkItem.WorkItemJobDisplayName + "HomePage", site.WebApplication); SPOneTimeSchedule oneTimeSchedule = new SPOneTimeSchedule(DateTime.Now); WebSiteControllerModuleJob.Schedule = oneTimeSchedule; WebSiteControllerModuleJob.Update(); } catch { }; } }); }
protected void OK_Click(object sender, EventArgs e) { try { SPContext.Current.Web.AllowUnsafeUpdates = true; SPAdministrationWebApplication caWebApp = SPAdministrationWebApplication.Local; AppData.Local.Entries[AppData.SELECTED_INDEX] = lstSchedule.SelectedIndex.ToString(); AppData.Local.Update(); //Delete any existing jobs string jobName = "SiteMap Ping"; foreach (SPJobDefinition job in caWebApp.JobDefinitions) { if (job.Name.ToUpper().Equals(jobName.ToUpper())) { job.Delete(); } } //Schedule new job switch (lstSchedule.SelectedIndex) { case 1: //Immediate SPOneTimeSchedule schedule1 = new SPOneTimeSchedule(DateTime.Now); Worker newJob1 = new Worker(jobName, caWebApp); newJob1.Schedule = schedule1; newJob1.Update(); break; case 2: //Daily SPDailySchedule schedule2 = new SPDailySchedule(); schedule2.BeginHour = 2; schedule2.EndHour = 6; Worker newJob2 = new Worker(jobName, caWebApp); newJob2.Schedule = schedule2; newJob2.Update(); break; case 3: //Weekly SPWeeklySchedule schedule3 = new SPWeeklySchedule(); schedule3.BeginDayOfWeek = DayOfWeek.Saturday; schedule3.EndDayOfWeek = DayOfWeek.Saturday; schedule3.BeginHour = 2; schedule3.EndHour = 6; Worker newJob3 = new Worker(jobName, caWebApp); newJob3.Schedule = schedule3; newJob3.Update(); break; case 4: //Monthly SPMonthlySchedule schedule4 = new SPMonthlySchedule(); schedule4.BeginDay = 1; schedule4.EndDay = 1; schedule4.BeginHour = 2; schedule4.EndHour = 6; Worker newJob4 = new Worker(jobName, caWebApp); newJob4.Schedule = schedule4; newJob4.Update(); break; } SPUtility.Redirect(caWebApp.Sites[0].Url, SPRedirectFlags.Default, HttpContext.Current); } catch (Exception x) { lblMessages.Text = x.Message; } }
private void CreateWorkItem(SPWeb web, string pagename, string url) { Guid siteId = web.Site.ID; Guid webId = web.ID; //string url = properties.ServerRelativeUrl; /* * if (url.StartsWith("/")) * { * url = url.TrimStart('/'); * } */ bool disabled = false; WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None; bool appliesToSSL = true; int sequence = 1; String pricipal = string.Empty; StringBuilder builder = new StringBuilder(); builder.Append(url + ";"); builder.Append(disabled.ToString() + ";"); builder.Append(appliesToSSL.ToString() + ";"); builder.Append(sequence.ToString() + ";"); builder.Append(principalType.ToString() + ";"); builder.Append(pricipal + ";"); builder.Append("#"); //builder.Append(String.Format("{0}:{1};", "OriginalUrl", url)); //string full = builder.ToString(); if (url.EndsWith("/")) { if (!pagename.EndsWith(".aspx")) { builder.Append(String.Format("{0}:{1};", "OriginalUrl", pagename + ".aspx")); } else { builder.Append(String.Format("{0}:{1};", "OriginalUrl", pagename)); } } else { if (!url.EndsWith(".aspx")) { builder.Append(String.Format("{0}:{1};", "OriginalUrl", url + pagename + ".aspx")); } else { builder.Append(String.Format("{0}:{1};", "OriginalUrl", url + pagename)); } } string full = builder.ToString(); //Guid itemGuid = new Guid("386577D9-0777-4AD3-A90A-C240D8B0A49E"); SemanticModule mod = new SemanticModule(); IWebSiteControllerModule imod = null;// WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType); while (imod == null) { System.Threading.Thread.Sleep(1000); try { imod = WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType); } catch (Exception ex) { ex.ToString(); } } int item = -1; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerRuleWorkItem.WorkItemTypeId, webId, siteId, item, true, imod.Id, Guid.Empty, site.SystemAccount.ID, null, builder.ToString(), Guid.Empty ); } }); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(siteId, SPUserToken.SystemAccount)) { try { WebSiteControllerRuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerRuleWorkItem(WebSiteControllerRuleWorkItem.WorkItemJobDisplayName + "HomePage", site.WebApplication); SPOneTimeSchedule oneTimeSchedule = new SPOneTimeSchedule(DateTime.Now); WebSiteControllerModuleJob.Schedule = oneTimeSchedule; WebSiteControllerModuleJob.Update(); } catch { }; } /* * if (SPContext.Current != null) * { * SPJobDefinitionCollection jobs = SPContext.Current.Site.WebApplication.JobDefinitions; * * int _seconds = 0; * * foreach (SPJobDefinition job in jobs) * { * if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName) * { * DateTime next = job.Schedule.NextOccurrence(job.LastRunTime); * _seconds = next.Second; * break; * } * } * } */ }); /* * SPSecurity.RunWithElevatedPrivileges(() => * { * using (SPSite site = new SPSite(siteId)) * { * site.AddWorkItem( * Guid.NewGuid(), * DateTime.Now.ToUniversalTime(), * WebSiteControllerRuleWorkItem.WorkItemTypeId, * webId, * siteId, * item, * true, * imod.Id, * Guid.Empty, * site.SystemAccount.ID, * null, * builder.ToString(), * Guid.Empty * ); * * try * { * * WebSiteControllerRuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerRuleWorkItem(WebSiteControllerRuleWorkItem.WorkItemJobDisplayName + "HomePage", site.WebApplication); * SPOneTimeSchedule oneTimeSchedule = new SPOneTimeSchedule(DateTime.Now); * * WebSiteControllerModuleJob.Schedule = oneTimeSchedule; * WebSiteControllerModuleJob.Update(); * } * catch (Exception ex) * { * SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); * //ex.ToString(); * } * * } * * SPJobDefinitionCollection jobs = SPContext.Current.Site.WebApplication.JobDefinitions; * * int _seconds = 0; * * foreach (SPJobDefinition job in jobs) * { * if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName) * { * DateTime next = job.Schedule.NextOccurrence(job.LastRunTime); * _seconds = next.Second; * break; * } * } * }); */ }