Exemplo n.º 1
0
        /// <summary>
        /// Delete an exist template.
        /// </summary>
        /// <param name="templateName">which template should delete.</param>
        /// <returns>updated LG file.</returns>
        public LGFile DeleteTemplate(string templateName)
        {
            var template = Templates.FirstOrDefault(u => u.Name == templateName);

            if (template != null)
            {
                var startLine = template.ParseTree.Start.Line - 1;
                var stopLine  = template.ParseTree.Stop.Line - 1;

                var newContent = ReplaceRangeContent(Content, startLine, stopLine, null);
                Initialize(LGParser.ParseText(newContent, Id, ImportResolver));
            }

            return(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a new template and return LG File.
        /// </summary>
        /// <param name="templateName">new template name.</param>
        /// <param name="parameters">new params.</param>
        /// <param name="templateBody">new  template body.</param>
        /// <returns>updated LG file.</returns>
        public LGFile AddTemplate(string templateName, List <string> parameters, string templateBody)
        {
            var template = Templates.FirstOrDefault(u => u.Name == templateName);

            if (template != null)
            {
                throw new Exception(LGErrors.TemplateExist(templateName));
            }

            var templateNameLine = BuildTemplateNameLine(templateName, parameters);
            var newTemplateBody  = ConvertTemplateBody(templateBody);
            var newContent       = $"{Content.TrimEnd()}\r\n\r\n{templateNameLine}\r\n{newTemplateBody}\r\n";

            Initialize(LGParser.ParseText(newContent, Id, ImportResolver));

            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// update an exist template.
        /// </summary>
        /// <param name="templateName">origin template name. the only id of a template.</param>
        /// <param name="newTemplateName">new template Name.</param>
        /// <param name="parameters">new params.</param>
        /// <param name="templateBody">new template body.</param>
        /// <returns>updated LG file.</returns>
        public LGFile UpdateTemplate(string templateName, string newTemplateName, List <string> parameters, string templateBody)
        {
            var template = Templates.FirstOrDefault(u => u.Name == templateName);

            if (template != null)
            {
                var templateNameLine = BuildTemplateNameLine(newTemplateName, parameters);
                var newTemplateBody  = ConvertTemplateBody(templateBody);
                var content          = $"{templateNameLine}\r\n{newTemplateBody}\r\n";
                var startLine        = template.ParseTree.Start.Line - 1;
                var stopLine         = template.ParseTree.Stop.Line - 1;

                var newContent = ReplaceRangeContent(Content, startLine, stopLine, content);
                Initialize(LGParser.ParseText(newContent, Id, ImportResolver));
            }

            return(this);
        }