Beispiel #1
0
        /// <summary>
        /// Adds a Snippet Control to this TemplateSlot.
        /// </summary>
        /// <param name="snippetInfo">The snippet info.</param>
        public void AddSnippet(SnippetControl snippetControl)
        {
            TemplateSlotItem item = new TemplateSlotItem();

            this.Controls.Add(item);
            item.Controls.Add(snippetControl);
        }
Beispiel #2
0
        /// <summary>
        /// Adds the snippet info from the PageAssembly instruction for each
        /// page template slot. Use the ID of the template slot control to match
        /// the snippet info slotname property.
        /// </summary>
        private void loadSnippetsIntoTemplateSlots()
        {
            if (TemplateSlots.Count > 0)
            {
                List <SnippetControl> supportingSnippets = new List <SnippetControl>();
                foreach (SnippetInfo snippet in PageAssemblyInstruction.Snippets)
                {
                    if (!String.IsNullOrEmpty(snippet.SlotName))
                    {
                        string slotName = snippet.SlotName.Trim();
                        if (TemplateSlots.ContainsSlotName(slotName))
                        {
                            try
                            {
                                SnippetControl snippetControl = (SnippetControl)Page.LoadControl(snippet.SnippetTemplatePath.Trim());

                                // Note this has to come before adding the template control to the control tree.
                                // This way, we can be sure any event in the control lifecycle like OnInit()
                                // already has the snippet info data.
                                snippetControl.SnippetInfo = snippet;

                                TemplateSlots[slotName].AddSnippet(snippetControl);

                                // Some snippetcontrol implement the ISupportingSnippet interface.
                                // The controls which implement ISupportingSnippet will provide additional
                                // snippet control that are required for the complete functionality.
                                // Add them to a collection that will be processed later.
                                if (snippetControl is ISupportingSnippet)
                                {
                                    SnippetControl[] supportingcontrols = ((ISupportingSnippet)snippetControl).GetSupportingSnippets();
                                    if (supportingcontrols != null)
                                    {
                                        supportingSnippets.AddRange(supportingcontrols);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                //Failed to load the slot template control. Log this error.
                                log.ErrorFormat("Failed to load snippet control: {0}", ex, snippet.SnippetTemplatePath);
                            }
                        }
                    }
                }

                foreach (SnippetControl supportSnippet in supportingSnippets)
                {
                    try
                    {
                        if (TemplateSlots.ContainsSlotName(supportSnippet.SnippetInfo.SlotName))
                        {
                            TemplateSlots[supportSnippet.SnippetInfo.SlotName].AddSnippet(supportSnippet);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error("Failed to add supporting snippet control", ex);
                    }
                }
            }
        }