Пример #1
0
        private List <SemanticUrl> CheckSemantics(string _url)
        {
            SemanticModule     module  = new SemanticModule();
            List <SemanticUrl> entries = new List <SemanticUrl>();

            Uri baseUri = new Uri(SPContext.Current.Web.Url, UriKind.RelativeOrAbsolute);
            Uri url     = new Uri(baseUri, _url); ////WebSiteControllerModule.GetFullUrl(application.Context);

            try
            {
                bool   isControlled = false;
                SPSite site         = new SPSite(url.OriginalString);
                CheckUrlOnZones(site, url, out url, out isControlled, module.RuleType);

                if (isControlled)
                {
                    System.Collections.Generic.List <WebSiteControllerRule> Allrules = WebSiteControllerConfig.GetRulesForSiteCollection(new Uri(site.Url), module.RuleType);
                    List <WebSiteControllerRule> rules = new List <WebSiteControllerRule>();

                    foreach (WebSiteControllerRule arule in Allrules)
                    {
                        if (arule.RuleType == module.RuleType && arule.Properties.ContainsKey("OriginalUrl"))
                        {
                            string original = arule.Properties["OriginalUrl"].ToString().ToLower();
                            string _lurl    = _url.ToString().ToLower();
                            if ((original == _lurl) || (original.EndsWith(_lurl)))
                            {
                                string org = arule.Url;
                                if (org.EndsWith("/"))
                                {
                                    org = org.TrimEnd(new char[1] {
                                        '/'
                                    });
                                }
                                //if ((org != SPContext.Current.Site.Url) && (org != SPContext.Current.Web.Url))
                                //{
                                SemanticUrl sem = new SemanticUrl();
                                sem.OriginalUrl = arule.Properties["OriginalUrl"].ToString().ToLower();
                                sem.Semantic    = arule.Url;
                                sem.Id          = arule.Id;
                                sem.Disabled    = arule.IsDisabled;
                                entries.Add(sem);
                                //}
                            }
                        }
                    }

                    if (entries.Count > 0)
                    {
                        entries.Sort(SemanticUrl.UrlComparison);
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }

            return(entries);
        }
Пример #2
0
        protected void btn_Add_Click(object sender, EventArgs e)
        {
            pnl_wait.Attributes["style"] = "";
            SemanticModule mod = new SemanticModule();

            Uri baseUri = new Uri(SPContext.Current.Site.Url, UriKind.RelativeOrAbsolute);
            Uri url     = new Uri(baseUri, tbx_url.Text); ////WebSiteControllerModule.GetFullUrl(application.Context);

            if (!WebSiteControllerConfig.HasRule(SPContext.Current.Site.WebApplication, url, mod.RuleType))
            {
                CreateWorkItem(tbx_url.Text);
                System.Threading.Thread.Sleep((_seconds * 1000));
                SPUtility.Redirect(Request.RawUrl, (SPRedirectFlags.DoNotEncodeUrl | SPRedirectFlags.Trusted), HttpContext.Current);
            }
            else
            {
                WebSiteControllerRule rule = WebSiteControllerConfig.GetRule(SPContext.Current.Site.WebApplication, url, mod.RuleType);
                lbl_error.Visible = true;

                if (rule != null && rule.Properties.ContainsKey("OriginalUrl"))
                {
                    lbl_error.InnerHtml = "This url is alreay in use by <a target=\"_blank\" href=\"" + rule.Properties["OriginalUrl"].ToString() + "\" >" + rule.Properties["OriginalUrl"].ToString() + "</a>";
                }
            }
        }
Пример #3
0
        public CodeGenerator(SemanticModule module, SemanticContext semanticContext)
        {
            _module          = module;
            _semanticContext = semanticContext;

            _typeSizeManager = new ILTypeSizeManager(_structLayoutManager);
            _structLayoutManager.Setup(new StructLayoutGenerator(_typeSizeManager));
        }
Пример #4
0
 public AddressOfVisitor(
     FunctionStackLayout layout,
     SemanticModule module,
     StructLayoutManager structLayoutManager)
 {
     _layout = layout;
     _module = module;
     _structLayoutManager = structLayoutManager;
 }
Пример #5
0
 public UnaryOperationCodeGenVisitor(FunctionBuilder builder, IExpressionVisitor expressionVisitor, SemanticModule semanticModule, ILTypeSizeManager typeSizeManager, FunctionStackLayout functionStackLayout, StructLayoutManager structLayoutManager)
 {
     _builder             = builder;
     _expressionVisitor   = expressionVisitor;
     _semanticModule      = semanticModule;
     _typeSizeManager     = typeSizeManager;
     _functionStackLayout = functionStackLayout;
     _structLayoutManager = structLayoutManager;
 }
Пример #6
0
        public void RunAnalyserPass()
        {
            if (_parseModule == null)
            {
                throw new InvalidOperationException("RunHeaderPass has not been called");
            }

            if (_semanticModule != null)
            {
                throw new InvalidOperationException("RunAnalyserPass has already been called");
            }

            _semanticModule = _job._semanticAnalyzer.Process(_parseModule);
        }
Пример #7
0
 public FunctionCodeGenVisitor(
     FunctionBuilder functionBuilder,
     FunctionStackLayout layout,
     FunctionManager functionManager,
     SemanticModule module,
     SemanticContext semanticContext,
     StructLayoutManager structLayoutManager,
     ILTypeSizeManager typeSizeManager,
     List <string> strings
     )
 {
     _functionBuilder     = functionBuilder;
     _layout              = layout;
     _functionManager     = functionManager;
     _module              = module;
     _semanticContext     = semanticContext;
     _structLayoutManager = structLayoutManager;
     _typeSizeManager     = typeSizeManager;
     _strings             = strings;
 }
Пример #8
0
        public CodeGeneratorContext(Context context, SemanticModule semanticModule, SemanticContext semanticContext,
                                    string fileName, string dirName, string targetTriple, bool optimized, bool debugInfo, bool columnInfo)
        {
            Context         = context;
            SemanticModule  = semanticModule;
            SemanticContext = semanticContext;

            Module = context.CreateModule(fileName);
            Module.SetTarget(targetTriple);

            // Debug compile unit is always emitted even if debug info is not requested
            // This provides a standardized way to export enums in the module
            Module.AddModuleFlag(LLVMModuleFlagBehavior.LLVMModuleFlagBehaviorWarning, "Debug Info Version",
                                 Context.DebugMetadataVersion);
            if (targetTriple.Contains("-msvc"))
            {
                Module.AddModuleFlag(LLVMModuleFlagBehavior.LLVMModuleFlagBehaviorWarning, "CodeView",
                                     Metadata.FromValue(Value.ConstInt(Context.Int32Type, 1, false)));
            }

            DiFile = DiBuilder.CreateFile(fileName, dirName);
            // Just say that MonC is C89; hopefully debuggers won't care
            Metadata diCompileUnit = DiBuilder.CreateCompileUnit(LLVMDWARFSourceLanguage.LLVMDWARFSourceLanguageC89,
                                                                 DiFile, "MonC", optimized, "", 0, "", LLVMDWARFEmissionKind.LLVMDWARFEmissionFull, 0, false, false);

            DiModule = DiBuilder.CreateModule(diCompileUnit, fileName, "", "", "");

            DebugInfo  = debugInfo;
            ColumnInfo = columnInfo && debugInfo;

            // IR-independent manager to generate struct type layouts
            StructLayoutManager.Setup(new StructLayoutGenerator(new IndexTypeSizeManager()));

            // Struct sizes need to be resolved for debug info (which is target-dependent)
            Target        target  = Target.FromTriple(targetTriple);
            TargetMachine machine = target.CreateTargetMachine(targetTriple, "", "",
                                                               LLVMCodeGenOptLevel.LLVMCodeGenLevelDefault, LLVMRelocMode.LLVMRelocDefault,
                                                               LLVMCodeModel.LLVMCodeModelDefault);

            TargetDataLayout = machine.CreateTargetDataLayout();
        }
Пример #9
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();
                        }
                    }
                }
            });
        }
Пример #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            lbl_url.InnerText = "Semantic Url : " + SPContext.Current.Site.Url + "/";

            if (!String.IsNullOrEmpty(Request.QueryString["List"]))
            {
                _List = Request.QueryString["List"];
            }

            if (!String.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                _ID = Request.QueryString["ID"];
            }

            if (!String.IsNullOrEmpty(_List) && !String.IsNullOrEmpty(_ID))
            {
                _Guid = new Guid(_List);
                _list = SPContext.Current.Web.Lists[_Guid];

                if (_list != null)
                {
                    _url = _list.GetItemById(int.Parse(_ID)).File.ServerRelativeUrl;
                }
            }

            gridSemantic.RowDataBound += new GridViewRowEventHandler(gridSemantic_RowDataBound);

            lbl_error.Visible            = false;
            pnl_wait.Attributes["style"] = "display:none;";

            if (!IsPostBack)
            {
                SemanticModule module = new SemanticModule();


                Uri baseUri = new Uri(SPContext.Current.Web.Url, UriKind.RelativeOrAbsolute);
                Uri url     = new Uri(baseUri, _url); ////WebSiteControllerModule.GetFullUrl(application.Context);

                try
                {
                    bool   isControlled = false;
                    SPSite site         = new SPSite(url.OriginalString);
                    CheckUrlOnZones(site, url, out url, out isControlled, module.RuleType);

                    //if (WebSiteControllerConfig.IsPageControlled(url, module.RuleType))
                    if (isControlled)
                    {
                        List <SemanticUrl> entries = new List <SemanticUrl>();

                        //SPSite site = new SPSite(url.OriginalString);

                        System.Collections.Generic.List <WebSiteControllerRule> Allrules = WebSiteControllerConfig.GetRulesForSiteCollection(new Uri(site.Url), module.RuleType);
                        List <WebSiteControllerRule> rules = new List <WebSiteControllerRule>();

                        foreach (WebSiteControllerRule arule in Allrules)
                        {
                            if (arule.RuleType == module.RuleType && arule.Properties.ContainsKey("OriginalUrl"))
                            {
                                string original = arule.Properties["OriginalUrl"].ToString().ToLower();
                                string _lurl    = _url.ToString().ToLower();
                                if ((original == _lurl))// || (original.EndsWith(_lurl)))
                                {
                                    string org = arule.Url;
                                    if (org.EndsWith("/"))
                                    {
                                        org = org.TrimEnd(new char[1] {
                                            '/'
                                        });
                                    }
                                    //if ((org != SPContext.Current.Site.Url) && (org != SPContext.Current.Web.Url))
                                    //{
                                    SemanticUrl sem = new SemanticUrl();
                                    sem.OriginalUrl = arule.Properties["OriginalUrl"].ToString().ToLower();
                                    sem.Semantic    = arule.Url;
                                    sem.Id          = arule.Id;
                                    sem.Disabled    = arule.IsDisabled;
                                    entries.Add(sem);
                                    //}
                                }
                            }
                        }

                        if (entries.Count > 0)
                        {
                            entries.Sort(SemanticUrl.UrlComparison);
                            gridSemantic.DataSource = entries;
                            gridSemantic.DataBind();
                            //Response.Write(rules.Count.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }
            else
            {
                pnl_wait.Attributes["style"] = "";
            }
        }
Пример #11
0
 internal Module CreateModule(FileInfo fileInfo, SemanticModule semanticModule,
                              SemanticContext semanticContext) =>
 CodeGenerator.Generate(_context, fileInfo.FullPath, semanticModule, semanticContext, _targetTriple,
                        _optBuilder, _debugInfo, _debugColumnInfo);
        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
                        );
                }
            });
        }
Пример #14
0
        public static Module Generate(Context context, string path, SemanticModule module,
                                      SemanticContext semanticContext, string targetTriple, PassManagerBuilder?optBuilder, bool debugInfo,
                                      bool columnInfo)
        {
            // Path information for debug info nodes
            string fileName = Path.GetFileName(path);
            string dirName  = Path.GetDirectoryName(path);

            if (dirName == null)
            {
                dirName = "/";
            }
            else if (dirName.Length == 0)
            {
                dirName = ".";
            }

            // Create module and file-level debug info nodes
            using CodeGeneratorContext genContext = new CodeGeneratorContext(context, module, semanticContext, fileName,
                                                                             dirName, targetTriple, optBuilder != null, debugInfo, columnInfo);

            // Enum pass
            foreach (EnumNode enumNode in genContext.ParseModule.Enums)
            {
                Metadata[] enumerators = new Metadata[enumNode.Declarations.Count];
                for (int i = 0, ilen = enumNode.Declarations.Count; i < ilen; ++i)
                {
                    var enumeration = enumNode.Declarations[i];
                    enumerators[i] = genContext.DiBuilder.CreateEnumerator(enumeration.Name, i, false);
                }

                genContext.TryGetNodeSymbol(enumNode, out Symbol range);
                genContext.DiBuilder.CreateEnumerationType(genContext.DiFile,
                                                           (enumNode.IsExported ? "export." : "") + $"enum.{fileName}.{range.LLVMLine}", genContext.DiFile,
                                                           range.LLVMLine, genContext.DiBuilder.Int32Type.GetTypeSizeInBits(),
                                                           genContext.DiBuilder.Int32Type.GetTypeAlignInBits(), enumerators, genContext.DiBuilder.Int32Type);
            }

            // Struct pass
            foreach (StructNode structNode in genContext.ParseModule.Structs)
            {
                genContext.EnsureStruct(structNode);
            }

            // Declaration pass
            foreach (FunctionDefinitionNode function in genContext.ParseModule.Functions)
            {
                genContext.RegisterDefinedFunction(function);
            }

            // Definition pass
            foreach (FunctionDefinitionNode function in genContext.ParseModule.Functions)
            {
                CodeGeneratorContext.Function ctxFunction = genContext.GetFunctionDefinition(function);

                using Builder builder = genContext.Context.CreateBuilder();
                FunctionCodeGenVisitor functionCodeGenVisitor = new FunctionCodeGenVisitor(genContext, ctxFunction,
                                                                                           builder, ctxFunction.StartDefinition(genContext, builder));
                builder.PositionAtEnd(functionCodeGenVisitor._basicBlock);
                function.Body.VisitStatements(functionCodeGenVisitor);

                if (genContext.DebugInfo)
                {
                    // TODO: Use the body end rather than the function end
                    genContext.TryGetNodeSymbol(function, out Symbol range);
                    Metadata location = genContext.Context.CreateDebugLocation(range.End.Line + 1,
                                                                               genContext.ColumnInfo ? range.End.Column + 1 : 0, ctxFunction.DiFunctionDef,
                                                                               Metadata.Null);
                    builder.SetCurrentDebugLocation(location);
                }

                // If we still have a valid insert block, this function did not end with a return; Insert one now
                if (builder.InsertBlock.IsValid)
                {
                    if (ctxFunction.ReturnBlock != null)
                    {
                        builder.BuildBr(ctxFunction.ReturnBlock.Value);
                    }
                    else
                    {
                        builder.BuildRetVoid();
                    }
                }

                if (ctxFunction.ReturnBlock != null && ctxFunction.RetvalStorage != null)
                {
                    ctxFunction.FunctionValue.AppendExistingBasicBlock(ctxFunction.ReturnBlock.Value);
                    builder.PositionAtEnd(ctxFunction.ReturnBlock.Value);
                    Value retVal = builder.BuildLoad(ctxFunction.RetvalStorage.Value);
                    builder.BuildRet(retVal);
                }
            }

            // Remove unused metadata nodes for undefined functions
            genContext.FinalizeFunctions();

            // Finalize debug info
            genContext.DiBuilder.BuilderFinalize();

            // Run optimization passes on functions and module if a builder is supplied
            if (optBuilder != null)
            {
                using ModulePassManager modulePassManager     = new ModulePassManager(optBuilder);
                using FunctionPassManager functionPassManager = new FunctionPassManager(genContext.Module, optBuilder);

                functionPassManager.Initialize();
                foreach (var function in genContext.DefinedFunctions)
                {
                    functionPassManager.Run(function.Value.FunctionValue);
                }

                functionPassManager.FinalizeFunctionPassManager();

                modulePassManager.Run(genContext.Module);
            }

            // Done with everything in CodeGeneratorContext besides the Module
            return(genContext.Module);
        }
        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;
             *      }
             *  }
             * });
             */
        }