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(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(); 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) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //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 ); } SPJobDefinitionCollection jobs = SPContext.Current.Site.WebApplication.JobDefinitions; foreach (SPJobDefinition job in jobs) { if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName) { try { DateTime next = job.Schedule.NextOccurrence(job.LastRunTime); _seconds = next.Second; break; } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } } } }); }
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); } }
private void CreateWorkItem(SPWebEventProperties properties, string pagename, string url) { Guid siteId = properties.SiteId; Guid webId = properties.WebId; bool disabled = false; WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None; bool appliesToSSL = true; int sequence = 1; String pricipal = string.Empty; StringBuilder builder = new StringBuilder(); builder.Append(properties.Web.ServerRelativeUrl + 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", properties.Web.ServerRelativeUrl + pagename)); string full = builder.ToString(); IWebSiteControllerModule imod = null; SPSite parentsite = new SPSite(properties.SiteId); while (imod == null) { System.Threading.Thread.Sleep(1000); try { imod = WebSiteControllerConfig.GetModule(parentsite.WebApplication, "Hemrika.SharePoint.WebSite.Modules.SemanticModule.SemanticModule"); } 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 ); } }); }
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 { }; } }); }
private void CreateWorkItem(SPWeb web, string pagename, string url) { Guid siteId = web.Site.ID; Guid webId = web.ID; 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("#"); if (url.EndsWith("/")) { builder.Append(String.Format("{0}:{1};", "OriginalUrl", url + pagename + ".aspx")); } else { builder.Append(String.Format("{0}:{1};", "OriginalUrl", url + ".aspx")); } string full = builder.ToString(); SemanticModule mod = new SemanticModule(); IWebSiteControllerModule imod = null; while (imod == null) { try { imod = WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType); } catch (Exception ex) { ex.ToString(); } System.Threading.Thread.Sleep(1000); } 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 ); } }); }
private void CreateWorkItem(SPWebEventProperties properties) { Guid siteId = properties.SiteId; Guid webId = properties.WebId; string url = properties.ServerRelativeUrl; if (url.StartsWith("/")) { url = url.Remove(0, 1); } 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 + "/default.aspx")); string full = builder.ToString(); Guid itemGuid = new Guid("386577D9-0777-4AD3-A90A-C240D8B0A49E"); int item = -1; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerRuleWorkItem.WorkItemTypeId, webId, siteId, item, true, itemGuid, Guid.Empty, site.SystemAccount.ID, null, builder.ToString(), Guid.Empty ); } }); SPJobDefinitionCollection jobs = properties.Web.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.Millisecond; break; } } //System.Threading.Thread.Sleep(_seconds); }
private void CreateWorkItem() { Guid siteId = SPContext.Current.Site.ID; Guid webId = SPContext.Current.Web.ID; WebSiteControllerRuleControl control = (WebSiteControllerRuleControl)FindControlRecursive(this.Master, "moduleControl"); string url = this.pageTextBox.Text; if (_SimpleView) { url = control.DefaultUrl; } bool disabled = this.disabledCheckBox.Checked; bool appliesToSSL = this.appliesToSslCheckBox.Checked; int sequence = Convert.ToInt32(this.sequenceTextBox.Text, CultureInfo.CurrentCulture); WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None; String pricipal = this.principalTextBox.Text; if (!String.IsNullOrEmpty(this.principalTextBox.Text)) { principalType = (WebSiteControllerPrincipalType)Enum.Parse(typeof(WebSiteControllerPrincipalType), this.principalTypeList.SelectedValue); } Hashtable properties = null; if (control != null) { properties = control.Properties; } 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("#"); foreach (DictionaryEntry prop in properties) { builder.Append(String.Format("{0}:{1};", prop.Key, prop.Value)); } Guid itemGuid = _guid; int item = 0; if (itemGuid.Equals(Guid.Empty)) { itemGuid = _module.Id; item = -1; } else { item = 2; } if (_event == "Delete") { item = 1; } SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerRuleWorkItem.WorkItemTypeId, webId, siteId, item, true, itemGuid, Guid.Empty, site.SystemAccount.ID, null, builder.ToString(), Guid.Empty ); SPJobDefinitionCollection jobs = site.WebApplication.JobDefinitions; foreach (SPJobDefinition job in jobs) { if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName) { DateTime next = job.Schedule.NextOccurrence(job.LastRunTime); _seconds = next.Second.ToString(); break; } } //SPJobDefinition job = site.WebApplication.JobDefinitions[WebSiteControllerRuleWorkItem.WorkItemJobDisplayName]; //job.RunNow(); } }); }
private void CreateWorkItem(SPWeb web)//, HttpStatusCode code) { 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("/;"); builder.Append(disabled.ToString() + ";"); builder.Append(appliesToSSL.ToString() + ";"); builder.Append(sequence.ToString() + ";"); builder.Append(principalType.ToString() + ";"); builder.Append(pricipal + ";"); builder.Append("#"); string value = new JavaScriptSerializer().Serialize(this); builder.Append(String.Format("{0}:{1};", "GateKeeper", Encryption.Encrypt(value))); //builder.Append(value); string full = builder.ToString(); GateKeeperModule mod = new GateKeeperModule(); IWebSiteControllerModule imod = null; //WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType); while (imod == null) { try { imod = WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType); } catch (Exception ex) { ex.ToString(); } System.Threading.Thread.Sleep(1000); } Guid itemGuid = _guid; int item = 0; if (itemGuid.Equals(Guid.Empty)) { itemGuid = mod.Id; item = -1; } else { item = 2; } SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerRuleWorkItem.WorkItemTypeId, webId, siteId, item, true, itemGuid, Guid.Empty, site.SystemAccount.ID, null, builder.ToString(), Guid.Empty ); } }); }
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; * } * } * }); */ }