Exemplo n.º 1
0
        /// <summary>
        /// Uses the style.
        /// </summary>
        /// <param name="styleName">Name of the style.</param>
        /// <returns></returns>
        internal void UseStyle(string styleName)
        {
            razorCompiler = new DefaultCompilerServiceFactory();
            razor = new TemplateService(razorCompiler.CreateCompilerService(Language.CSharp, false, null), null);
            razor.SetTemplateBase(typeof(TemplateHelperBase));
            razor.AddResolver(this);

            if (!StyleManager.StyleExist(styleName))
                Logger.Fatal("Cannot us style [{0}]. Style doesn't exist", styleName);

            CurrentStyleName = styleName;

            StyleDirectories.Clear();

            var includeBaseStyle = new List<string>();

            var styles = StyleManager.AvailableStyles;
            includeBaseStyle.Add(styleName);

            bool isNotComplete = true;

            // Compute directories to look, by following inheritance
            // In the same order they are declared
            while (isNotComplete)
            {
                isNotComplete = false;
                // Build directories to look for this specific style and all its base style);
                var toRemove = new List<StyleDefinition>();
                foreach (var style in styles)
                {
                    // Apply parameter inherited from style
                    if (style.Name == styleName)
                    {
                        foreach (var parameter in style.Parameters)
                        {
                            ((DynamicParam)Param).Properties.Remove(parameter.Name);
                            ((DynamicParam)Param).Properties.Add(parameter.Name, parameter.value);
                        }
                    }

                    if (includeBaseStyle.Contains(style.Name))
                    {
                        toRemove.Add(style);
                        StyleDirectories.Add(style.DirectoryPath);
                        isNotComplete = true;
                        if (style.HasBaseStyle)
                            includeBaseStyle.Add(style.BaseStyle);
                    }
                }

                // Remove the style that was processed by the previous loop
                foreach (var styleDefinition in toRemove)
                    styles.Remove(styleDefinition);
            }

            foreach (var styleDirectory in StyleDirectories)
            {
                Logger.Message("Using Style Directory [{0}]", styleDirectory);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Uses the style.
        /// </summary>
        /// <param name="styleName">Name of the style.</param>
        /// <returns></returns>
        internal void UseStyle(string styleName)
        {
            razorCompiler = new DefaultCompilerServiceFactory();
            razor         = new TemplateService(razorCompiler.CreateCompilerService(Language.CSharp, false, null), null);
            razor.SetTemplateBase(typeof(TemplateHelperBase));
            razor.AddResolver(this);

            if (!StyleManager.StyleExist(styleName))
            {
                Logger.Fatal("Cannot us style [{0}]. Style doesn't exist", styleName);
            }

            CurrentStyleName = styleName;

            StyleDirectories.Clear();

            var includeBaseStyle = new List <string>();

            var styles = StyleManager.AvailableStyles;

            includeBaseStyle.Add(styleName);

            bool isNotComplete = true;

            // Compute directories to look, by following inheritance
            // In the same order they are declared
            while (isNotComplete)
            {
                isNotComplete = false;
                // Build directories to look for this specific style and all its base style);
                var toRemove = new List <StyleDefinition>();
                foreach (var style in styles)
                {
                    // Apply parameter inherited from style
                    if (style.Name == styleName)
                    {
                        foreach (var parameter in style.Parameters)
                        {
                            ((DynamicParam)Param).Properties.Remove(parameter.Name);
                            ((DynamicParam)Param).Properties.Add(parameter.Name, parameter.value);
                        }
                    }

                    if (includeBaseStyle.Contains(style.Name))
                    {
                        toRemove.Add(style);
                        StyleDirectories.Add(style.DirectoryPath);
                        isNotComplete = true;
                        if (style.HasBaseStyle)
                        {
                            includeBaseStyle.Add(style.BaseStyle);
                        }
                    }
                }

                // Remove the style that was processed by the previous loop
                foreach (var styleDefinition in toRemove)
                {
                    styles.Remove(styleDefinition);
                }
            }

            foreach (var styleDirectory in StyleDirectories)
            {
                Logger.Message("Using Style Directory [{0}]", styleDirectory);
            }
        }