/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event to initialize the page. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param> protected override void OnInit(EventArgs e) { SPContext.Current.Web.AllowUnsafeUpdates = true; if (!String.IsNullOrEmpty(Request.QueryString["guid"])) { _guid = new Guid(Request.QueryString["guid"]); } if (!String.IsNullOrEmpty(Request.QueryString["ruletype"])) { _ruletype = Request.QueryString["ruletype"]; } if (!String.IsNullOrEmpty(Request.QueryString["Source"])) { _source = Request.QueryString["Source"]; } if (this.Page.Request["__EVENTTARGET"] == RibbonPostbackId) { _event = this.Page.Request["__EVENTARGUMENT"]; } if (_event == "GoModules") { GoBack(); } if (!string.IsNullOrEmpty(_ruletype)) { _module = WebSiteControllerConfig.GetModule(SPContext.Current.Site.WebApplication, _ruletype); } try { if (_module != null) { if (!String.IsNullOrEmpty(_module.Control)) { WebSiteControllerRuleControl control = (WebSiteControllerRuleControl)Page.LoadControl(_module.Control); control.ID = "moduleControl"; if (control.SimpleView) { _SimpleView = control.SimpleView; ControlCollection controls = this.defaultPlaceHolder.Controls; foreach (Control ctrl in controls) { ctrl.Visible = false; } } this.propertiesPlaceholder.Controls.Add(control); } } } catch (Exception ex) { ex.ToString(); } SPContext.Current.Web.AllowUnsafeUpdates = false; }
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(); } }); }