public GateKeeperSettings Load() { GateKeeperSettings config = null; GateKeeperModule module = new GateKeeperModule(); HttpContext current = HttpContext.Current; HttpRequest request = current.Request; string currUrl = current.Request.Url.ToString(); string basePath = currUrl.Substring(0, currUrl.IndexOf(current.Request.Url.Host) + current.Request.Url.Host.Length); Uri url = new Uri(basePath); List <WebSiteControllerRule> rules = WebSiteControllerConfig.GetRulesForSiteCollection(url, module.RuleType); foreach (WebSiteControllerRule rule in rules) { //string props = rule.Properties.ToString(); if (rule.Properties.ContainsKey("GateKeeper")) { if (config == null) { try { string gateconfig = rule.Properties["GateKeeper"].ToString(); config = new JavaScriptSerializer().Deserialize <GateKeeperSettings>(Encryption.Decrypt(gateconfig)); config._guid = rule.Id; break; } catch (Exception ex) { ex.ToString(); //throw; } } } } if (config != null) { return(config); } else { return(new GateKeeperSettings()); } }
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 ); } }); }