Beispiel #1
0
        internal CompiledCode GetSnippetRenderCode(string cacheKey, SnippetControl snippetControl)
        {
            CompiledCode compiledSnippet = (CompiledCode)_buildResult.CompiledSnippets[cacheKey];

            if (compiledSnippet == null)
            {
                lock (_buildResult.CompiledSnippets) {
                    compiledSnippet = (CompiledCode)_buildResult.CompiledSnippets[cacheKey];
                    if (compiledSnippet == null)
                    {
                        // It's not cached, so ask the control for the CodeDom tree and compile it
                        CodeMemberMethod codeDomMethod = snippetControl.GenerateRenderMemberMethod(_templateControlVirtualPath);
                        compiledSnippet = EngineHelper.CompileCodeDom(codeDomMethod, ScriptEngine);

                        // Cache it
                        _buildResult.CompiledSnippets[cacheKey] = compiledSnippet;
                    }
                }
            }

            return(compiledSnippet);
        }
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 this.SnippetInfo.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.Error("Failed to load snippet control-" + snippet.SnippetTemplatePath, ex);
                            }
                        }
                    }
                }

                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);
                    }
                }
            }
        }