コード例 #1
0
        /// <summary>
        /// Adds a new WebSiteControllerRule.
        /// </summary>
        /// <param name="siteCollection">The site collection.</param>
        /// <param name="page">The page to which the rule applied</param>
        /// <param name="ruleType">Type of the rule.</param>
        /// <param name="principal">The principal.</param>
        /// <param name="principalType">Type of the principal.</param>
        /// <param name="disabled">if set to <c>true</c> the rule is disabled.</param>
        /// <param name="appliesToSsl">if set to <c>true</c> the rule applies to SSL.</param>
        /// <param name="sequence">The sequence of the rule compared to other rules.</param>
        /// <param name="properties">The properties.</param>
        /// <returns>The resulting WebSiteControllerRule</returns>
        public static WebSiteControllerRule AddRule(
            SPWebApplication Webapp,
            string siteCollection,
            string page,
            string ruleType,
            string principal,
            WebSiteControllerPrincipalType principalType,
            bool disabled,
            bool appliesToSsl,
            int sequence,
            Hashtable properties)
        {
            WebApp = Webapp;
            WebSiteControllerConfig config = GetFromConfigDB();
            WebSiteControllerRule   rule   = new WebSiteControllerRule(
                siteCollection,
                page,
                ruleType,
                principal,
                principalType,
                disabled,
                appliesToSsl,
                sequence,
                config);

            rule.Name = rule.Id.ToString();

            if (properties != null)
            {
                foreach (DictionaryEntry property in properties)
                {
                    rule.Properties.Add(property.Key, property.Value);
                }
            }

            if (!IsDuplicateRule(rule))
            {
                config.rules.Add(rule);
                config.Update();
            }
            else
            {
                throw new SPDuplicateObjectException(rule + " is the same as another rule in the WebSiteControllerRules collection");
            }

            return(rule);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebSiteControllerRule"/> class.
        /// </summary>
        /// <param name="site">The site collection.</param>
        /// <param name="page">The page to which this rule applies.  It cannot be null</param>
        /// <param name="ruleType">Type of the rule.</param>
        /// <param name="principal">The principal.</param>
        /// <param name="principalType">Type of the principal.</param>
        /// <param name="disabled">if set to <c>true</c> the rule is disabled.</param>
        /// <param name="appliesToSsl">if set to <c>true</c> the rule applies to SSL.</param>
        /// <param name="sequence">The sequence of the rule compared to other rules.</param>
        /// <param name="parent">Parent object of the WebSiteControllerRule</param>
        public WebSiteControllerRule(
            string site,
            string page,
            string ruleType,
            string principal,
            WebSiteControllerPrincipalType principalType,
            bool disabled,
            bool appliesToSsl,
            int sequence,
            SPPersistedObject parent) :
            base(String.Empty, parent)
        {
            if (String.IsNullOrEmpty(site))
            {
                throw new ArgumentNullException("siteCollection");
            }

            if (String.IsNullOrEmpty(page))
            {
                throw new ArgumentNullException("page");
            }

            this.SiteCollection = site;

            // Trim the slash if the user put one in.  Slash is on the site collection
            if (page.StartsWith("/", StringComparison.Ordinal))
            {
                page = page.TrimStart('/');
            }

            this.page          = page;
            this.ruleType      = ruleType;
            this.principal     = principal;
            this.principalType = principalType;
            this.appliesToSsl  = appliesToSsl;
            this.disabled      = disabled;
            this.sequence      = sequence;
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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();
                        }
                    }
                }
            });
        }
コード例 #5
0
        protected override bool ProcessWorkItems(SPContentDatabase contentDatabase, SPWorkItemCollection workItems, SPJobState jobState)
        {
            foreach (SPWorkItem workItem in workItems)
            {
                if (workItem != null)
                {
                    try
                    {
                        SPSite site = new SPSite(workItem.SiteId);
                        IWebSiteControllerModule module = null;
                        WebSiteControllerRule    rule   = null;
                        bool _deleted = false;
                        //int ItemID = workItem.ItemId;

                        if (workItem.ItemId > 0)
                        {
                            rule = WebSiteControllerConfig.GetRule(contentDatabase.WebApplication, workItem.ItemGuid);
                        }
                        else
                        {
                            module = WebSiteControllerConfig.GetModule(contentDatabase.WebApplication, workItem.ItemGuid);
                        }

                        if (rule != null)
                        {
                            WebSiteControllerConfig.RemoveRule(rule.Id);
                            _deleted = true;
                        }

                        if (workItem.ItemId < 0 || _deleted)
                        {
                            string[] data                = workItem.TextPayload.Split(new char[] { '#' });
                            string   parameterRule       = data[0];
                            string   parameterProperties = data[1];
                            string[] rules               = parameterRule.Split(new char[] { ';' });

                            string url      = rules[0];
                            bool   disabled = bool.Parse(rules[1]);
                            bool   ssl      = bool.Parse(rules[2]);
                            int    sequence = int.Parse(rules[3]);

                            WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None;

                            if (!String.IsNullOrEmpty(rules[4]))
                            {
                                principalType = (WebSiteControllerPrincipalType)Enum.Parse(typeof(WebSiteControllerPrincipalType), rules[4]);
                            }
                            string principal = rules[5];

                            string ruletype = string.Empty;

                            if (module != null || String.IsNullOrEmpty(rule.RuleType))
                            {
                                ruletype = module.RuleType;
                            }
                            else if (rule != null && ruletype == string.Empty)
                            {
                                ruletype = rule.RuleType;
                            }

                            string[]  properties = parameterProperties.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                            Hashtable props      = new Hashtable();

                            foreach (string prop in properties)
                            {
                                try
                                {
                                    if (!string.IsNullOrEmpty(prop))
                                    {
                                        string[] keyval = prop.Split(new char[] { ':' });
                                        props.Add(keyval[0], keyval[1]);
                                    }
                                }
                                catch { };
                            }

                            if (_deleted && workItem.ItemId != 1)
                            {
                                WebSiteControllerConfig.AddRule(contentDatabase.WebApplication,
                                                                site.Url + "/",
                                                                url,
                                                                rule.RuleType,
                                                                rule.Principal,
                                                                rule.PrincipalType,
                                                                disabled,
                                                                ssl,
                                                                sequence,
                                                                props
                                                                );
                            }

                            if (workItem.ItemId == -1)
                            {
                                WebSiteControllerConfig.AddRule(contentDatabase.WebApplication,
                                                                site.Url + "/",
                                                                url,
                                                                ruletype,
                                                                principal,
                                                                principalType,
                                                                disabled,
                                                                ssl,
                                                                sequence,
                                                                props
                                                                );
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                        //throw (ex);
                    }
                    finally
                    {
                        DeleteWorkItem(workItems, workItem);
                        //using (SPSite site = new SPSite(workItem.SiteId))
                        //{

                        //    using (SPWeb web = site.OpenWeb(workItem.WebId))
                        //    {
                        //        SPWorkItemCollection deletableCollection = workItems.SubCollection(site, web, (uint)workItem.i, (uint)itemIndex + 1);
                        //        deletableCollection.DeleteWorkItem(currentItem.Id);

                        //        //workItems.CompleteInProgressWorkItems(workItem.ParentId, workItem.Type, workItem.BatchId);
                        //        //workItems.SubCollection(site, web, 0, (uint)workItems.Count).DeleteWorkItem(workItem.Id);

                        //    }

                        //}

                        ////workItems.DeleteWorkItem(workItem.Id);
                    }
                }
            }
            return(true);
        }
コード例 #6
0
        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 { };
                }
            });
        }
コード例 #7
0
        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
                        );
                }
            });
        }
コード例 #8
0
        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
                        );
                }
            });
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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();
                }
            });
        }
コード例 #11
0
        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
                        );
                }
            });
        }
コード例 #12
0
        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;
             *      }
             *  }
             * });
             */
        }