Exemplo n.º 1
0
        public void Process(RenderLayoutArgs args)
        {
            if (Context.Site.Name == "shell")
            return;

              try
              {
            var head = WebUtil.FindControlOfType(Context.Page.Page, typeof(HtmlHead));
            if (head != null)
            {
              var filesJs = Directory.GetFiles(HttpContext.Current.Server.MapPath(Constants.FolderJs));
              foreach (var fileJs in filesJs)
              {
            var extension = Path.GetExtension(fileJs);
            if (extension != null && extension.Contains(".js"))
            {
              var fileName = Path.GetFileNameWithoutExtension(fileJs);
              if (fileName != null && fileName.IndexOf('-') > 1)
                fileName = fileName.Remove(fileName.IndexOf('-'));
              if (!IsFileExistOnPage(head, fileName))
              {
                IncludeJsToControl(head, Constants.FolderJs + Path.GetFileName(fileJs));
              }
            }
              }
            }
              }
              catch (Exception exception)
              {
            Log.Error("Feedback Module, InjectJs: ", exception,this);
              }
        }
        public override void Process(RenderLayoutArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            var item = Context.Item;

            if (item == null)
            {
                return;
            }

            var itemId     = item.ID.Guid;
            var templateId = item.Template.ID.Guid;

            var page            = Context.Page;
            var currentLanguage = Context.Language.Name;

            if (SitecoreFeatureToggles.ShouldReplaceLayout(itemId, templateId, currentLanguage))
            {
                page.ClearRenderings();

                var renderings = SitecoreFeatureToggles.GetLayoutReplacement(itemId, templateId, currentLanguage);
                foreach (var sublayout in renderings.Sublayouts)
                {
                    var rendering = GetRenderingByItemId(sublayout.SublayoutId, sublayout.Placeholder);
                    if (rendering != null)
                    {
                        page.AddRendering(rendering);
                    }
                }
            }
            else
            {
                var originalRenderings = page.Renderings.ToList();

                var sublayoutReplacements = SitecoreFeatureToggles.GetAllRenderingReplacements(currentLanguage);
                var foundReplacement      = false;
                foreach (var replacement in sublayoutReplacements)
                {
                    for (var i = 0; i < originalRenderings.Count; i++)
                    {
                        var reference = originalRenderings[i];
                        if (reference.RenderingID.Guid == replacement.Original)
                        {
                            foundReplacement = true;
                            var newRendering = GetRenderingByItemId(replacement.New, reference.Placeholder);
                            originalRenderings[i] = newRendering;
                        }
                    }
                }

                if (foundReplacement)
                {
                    page.ClearRenderings();
                    foreach (var reference in originalRenderings)
                    {
                        page.AddRendering(reference);
                    }
                }
            }
        }
        public new void Process(RenderLayoutArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            if (AnalyticsSettings.Enabled)
            {
                SiteContext site = Context.Site;
                if (((site != null) && site.EnableAnalytics))
                {
                    PageContext context2 = Context.Page;
                    if (context2 != null)
                    {
                        System.Web.UI.Page page = context2.Page;
                        if (page != null)
                        {
                            AnalyticsTracker.StartTracking();
                            if (AnalyticsTracker.IsActive)
                            {
                                PersonaHelper.Initialize(AnalyticsTracker.Current);

                                page.LoadComplete += Page_LoadComplete;
                                page.Unload += Page_Unload;
                            }
                        }
                    }
                }
            }
        }
        public override void Process(RenderLayoutArgs args)
        {
            var page = Sitecore.Context.Page;

            page?.Page.ClientScript.RegisterStartupScript(this.GetType(), "ApplicationInsightsKey", Scripts.KeyScript, false);
            page?.Page.ClientScript.RegisterStartupScript(this.GetType(), "ApplicationInsightsScript", Scripts.ClientScript, false);
        }
 public virtual void Process(RenderLayoutArgs args)
 {
     if (this.IsValidContextSite(args))
     {
         this.Render(args);
     }
 }
 /// <summary>
 /// Runs the processor.
 /// </summary>
 /// <param name="args">The arguments.</param>
 public override void Process(RenderLayoutArgs args)
 {
     if (!Context.PageMode.IsPreview || ID.IsNullOrEmpty(PersonaHelper.ActivePersona))
     {
         base.Process(args);
     }
     else
     {
         CustomProcess(args);
     }
 }
        public override void Render(RenderLayoutArgs args)
        {
            Control root = this.RootControlResolver != null?this.RootControlResolver.GetRootControl() : null;

            if (root != null)
            {
                foreach (var u in JavascriptUrls)
                {
                    root.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), u, string.Format(@"<script language=""javascript"" type=""text/javascript"" src=""{0}"" ></script>", u), false);
                }
            }
        }
        public virtual void Render(RenderLayoutArgs args)
        {
            Control controlToRender = this.GetControlToRender();

            if (controlToRender == null)
            {
                return;
            }

            Control root = this.RootControlResolver != null?this.RootControlResolver.GetRootControl() : null;

            if (root != null)
            {
                root.Controls.Add(controlToRender);
            }
        }
Exemplo n.º 9
0
        public void Process(RenderLayoutArgs args)
        {
            //put here validation you may require

            var head = WebUtil.FindControlOfType(Sitecore.Context.Page.Page, typeof(System.Web.UI.HtmlControls.HtmlHead));

            if (head != null)
            {
                //add any content in the head
                head.Controls.Add(new Literal(" CONTENT "));
            }
            else
            {
                //make sure to not break the app instead just log the error.
                Sitecore.Diagnostics.Log.Error("Error - The HEAD element must be runat=server", this);
            }
        }
Exemplo n.º 10
0
        public void Process(RenderLayoutArgs args)
        {
            if (Context.Site.Name == "shell")
            {
                return;
            }

            try
            {
                var head = WebUtil.FindControlOfType(Context.Page.Page, typeof(HtmlHead));
                if (head != null)
                {
                    if (!head.TemplateSourceDirectory.Contains("speak"))
                    {
                        var currentSimulatorId = DeviceSimulationUtil.GetCurrentSimulatorId();
                        if (currentSimulatorId.IsNull || currentSimulatorId == NoneSimulator.Id || currentSimulatorId == ID.Null)
                        {
                            var filesJs = Directory.GetFiles(HttpContext.Current.Server.MapPath(Constants.FolderJs));
                            foreach (var fileJs in filesJs)
                            {
                                var extension = Path.GetExtension(fileJs);
                                if (extension != null && extension.Contains(".js"))
                                {
                                    var fileName = Path.GetFileNameWithoutExtension(fileJs);
                                    if (fileName != null && fileName.IndexOf('-') > 1)
                                    {
                                        fileName = fileName.Remove(fileName.IndexOf('-'));
                                    }
                                    if (!IsFileExistOnPage(head, fileName))
                                    {
                                        IncludeJsToControl(head, Constants.FolderJs + Path.GetFileName(fileJs));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error("Feedback Module, InjectJs: ", exception, this);
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Adds sublayout onto the page
 /// </summary>
 /// <param name="args">
 public override void Process(RenderLayoutArgs args)
 {
     if (Context.Item != null)
     {
         if (Context.Item.Visualization.Layout == null)
         {
             Item layoutItem = ExtensionMethods.GetReferenceLayoutItem();
             if (layoutItem != null)
             {
                 IEnumerable renderingReferences =
                     layoutItem.Visualization.GetRenderings(Context.Device, true);
                 foreach (RenderingReference rendering in renderingReferences)
                 {
                     Context.Page.AddRendering(rendering);
                 }
             }
         }
     }
 }
        public override void Process(RenderLayoutArgs args)
        {
            if (HttpContext.Current.Request["sc_test"] == null)
            {
                return;
            }
            Sitecore.Context.Items["sc_test"] = HttpContext.Current.Request["sc_test"];

            ReadConfiguration();

            // For the purposes of testing, our database should *always* be master.
            Sitecore.Context.Database = Sitecore.Data.Database.GetDatabase("master");

            // Now re-fetch the context item from the master database.
            Sitecore.Context.Item = Sitecore.Context.Database.GetItem(Sitecore.Context.Item.ID.ToString(), Sitecore.Context.Language);

            InitCookies();
            InitContextItem();
            TestRunner runner = new TestRunner();
            runner.RunTest(_TestConfig);
            RevertContextItem();
            WriteOutput(runner);
        }
Exemplo n.º 13
0
        public override void Process(RenderLayoutArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            if (Context.Item == null || Context.Page == null || Context.Page.Renderings == null || Context.Page.Renderings.Count <= 0)
            {
                return;
            }

            if (!Helper.IsPrototypeMode())
            {
                return;
            }

            using (new ProfileSection("Insert prototype renderings into page."))
            {
                foreach (var rendering in Context.Page.Renderings.ToList())
                {
                    var itemResolverInfo = Helper.GetPrototypeItem(rendering.RenderingID);

                    if (itemResolverInfo != null)
                    {
                        if (itemResolverInfo.PrototypeItem != null &&
                            itemResolverInfo.PrototypeItem.ID != rendering.RenderingID)
                        {
                            rendering.SetRendering(itemResolverInfo.PrototypeItem.ID);
                        }
                        else if (!string.IsNullOrEmpty(itemResolverInfo.FilePath))
                        {
                            rendering.SetRendering(new ID(Constants.Renderings.FileReadId));
                            rendering.Settings.DataSource = itemResolverInfo.FilePath;
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
 public override void Process(RenderLayoutArgs args)
 {
     this.executor.ExecuteActions();
 }
        /// <summary>
        /// Is Valid Context Site
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        protected virtual bool IsValidContextSite(RenderLayoutArgs args)
        {
            var siteContext = Context.Site;

            return(siteContext != null && !this.FilterSites.Contains(siteContext.Name));
        }
Exemplo n.º 16
0
        public override void Process(RenderLayoutArgs args)
        {
            var httpContext = HttpContext.Current;
            if (httpContext == null)
            {
                return;
            }

            //Ensure that it's only the simulator console that can access this information
            //Other people shouldn't know what we're testing.
            var secret = Sitecore.Configuration.Settings.GetSetting("ColossusSecret");

            if (!string.IsNullOrEmpty(secret) && httpContext.Request.Headers["X-Colossus-Secret"] != secret)
            {
                return;
            }

            var visitTags = ParseHeaderValue(httpContext.Request.Headers["X-Colossus-Visit"]);
            var requestData = ParseHeaderValue(httpContext.Request.Headers["X-Colossus-Request"]);
            if (visitTags != null || requestData != null)
            {

                foreach (var proc in TagProcessors)
                {
                    proc.Process(visitTags ?? new JObject(), requestData ?? new JObject());
                }

                httpContext.Response.Headers.Add("X-Colossus-Processing", "OK");
            }

            if (httpContext.Request.Headers["X-Colossus-Map"] == "true")
            {
                httpContext.Response.AddHeader("X-Colossus-Map",  Map(Context.Item, new XDocument()).ToString());
            }

            var mapId = httpContext.Request.QueryString["colossus-map"];
            if (!string.IsNullOrEmpty(mapId))
            {
                var item = Context.Database.GetItem(ID.Parse(mapId));
                var map = Map(item, new XDocument());
                httpContext.Response.AddHeader("X-Colossus-Map", map.ToString());

                if (Tracker.Current != null)
                {
                    Switcher<ITracker, TrackerSwitcher>.Exit();
                }
                httpContext.Response.ContentType = "text/xml";
                httpContext.Response.Write(map.ToString());
                httpContext.Response.End();
            }

            var page = Context.Page;
            if (page != null && page.Renderings != null)
            {
                var renderings = new List<Dictionary<string, string>>();

                foreach (RenderingReference r in page.Renderings)
                {
                    var item = r.RenderingItem;
                    if (item != null && item.InnerItem != null)
                    {
                        renderings.Add(item.InnerItem.Fields.ToDictionary(f => f.Name, f => f.Value));
                    }
                }

                httpContext.Response.Headers.Add("X-Colossus-Renderings", renderings.ToJson());
            }

            if (Tracker.Current != null && Tracker.Current.CurrentPage != null)
            {
                var tc = Tracker.Current.CurrentPage.GetTestCombination();
                if (tc != null)
                {
                    httpContext.Response.Headers.Add("X-Colossus-TestSet", tc.Testset.ToJson());
                    httpContext.Response.Headers.Add("X-Colossus-Experience",
                        Enumerable.Range(0, tc.Testset.Variables.Count).Select(i => tc[i]).ToArray().ToJson());
                }
            }

            //if (Tracker.Current != null)
            //{
            //    foreach (var p in Tracker.Current.Interaction.Profiles.GetProfileNames())
            //    {
            //        if (Tracker.Current.Interaction.Profiles[p].PatternLabel == "Pat the Potential Traveller")
            //        {
            //            throw new Exception("Traveller");
            //        }
            //        HttpContext.Current.Response.Write(Tracker.Current.Interaction.Profiles[p].PatternLabel + "<br />");
            //    }
            //}

            //Tracker.Current.StartTracking();
            //var p = Tracker.Current.Interaction.GetOrCreateCurrentPage();
            //p.Duration = 1337;

            //HttpContext.Current.Response.Write(AnalyticsCount.CollectionRobotRequests.Value);
        }
        /// <summary>
        /// Process the renderings, enabling "Active Rules"
        /// </summary>
        /// <param name="args">The args.</param>
        private static void CustomProcess(RenderLayoutArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            using (new ProfileSection("Insert renderings into page."))
            {
                if (Context.Item != null)
                {
                    IEnumerable<RenderingReference> referenceArray = AddRenderings();

                    if (referenceArray != null)
                    {
                        foreach (RenderingReference reference in referenceArray)
                        {
                            Context.Page.AddRendering(reference);
                        }
                    }
                }
            }
        }