Ejemplo n.º 1
0
 private void CheckTemplate(TemplateConfig template)
 {
     if (string.IsNullOrWhiteSpace(template.Template))
     {
         template.Template = File.ReadAllText(template.TemplatePath);
     }
     if (string.IsNullOrWhiteSpace(template.Code))
     {
         LuaTemplateParse parser = new LuaTemplateParse
         {
             Config = template
         };
         parser.Compile();
     }
 }
Ejemplo n.º 2
0
        private void SaveTemplate()
        {
            if (string.IsNullOrWhiteSpace(CurrentTemplate))
            {
                MessageBox.Show("模板内容不能为空");
                return;
            }
            CurrentTemplateConfig.Template = CurrentTemplate;
            try
            {
                LuaTemplateParse parser = new LuaTemplateParse
                {
                    Config = CurrentTemplateConfig
                };
                parser.Compile();
            }
            catch (Exception e)
            {
                ExtendCode = e.ToString();
                TabIndex   = 2;
                MessageBox.Show("模板解析发生错误");
                return;
            }
            CurrentLua      = CurrentTemplateConfig.Code;
            CurrentTemplate = CurrentTemplateConfig.Template;

            var cl = CurrentTemplateConfig.Classify;

            if (CurrentTemplateConfig.TemplatePath != null)
            {
                File.WriteAllText(CurrentTemplateConfig.TemplatePath, CurrentTemplateConfig.Template);
            }

            if (string.IsNullOrWhiteSpace(CurrentTemplateConfig.Name))
            {
                MessageBox.Show("必须有一个名称(Name)");
                return;
            }
            if (string.IsNullOrWhiteSpace(CurrentTemplateConfig.Caption))
            {
                MessageBox.Show("必须有一个标题(Caption)");
                return;
            }
            if (string.IsNullOrWhiteSpace(CurrentTemplateConfig.Classify))
            {
                MessageBox.Show("必须有一个分类(Classify)");
                return;
            }
            if (cl != null && cl != CurrentTemplateConfig.Classify)
            {
                var cla = Templates.FirstOrDefault(p => p.Name == cl);
                cla?.Templates.Remove(CurrentTemplateConfig);
            }
            var ncla = Templates.FirstOrDefault(p => p.Name == CurrentTemplateConfig.Classify);

            if (ncla == null)
            {
                Templates.Add(ncla = new TemplateClassify {
                    Name = CurrentTemplateConfig.Classify
                });
            }
            if (!ncla.Templates.Contains(CurrentTemplateConfig))
            {
                ncla.Templates.Add(CurrentTemplateConfig);
            }
            string path = IOHelper.CheckPath(GlobalConfig.ProgramRoot, "Templates", CurrentTemplateConfig.Classify);

            path = Path.Combine(path, CurrentTemplateConfig.Caption + ".lt");
            if (!string.IsNullOrWhiteSpace(CurrentTemplateConfig.TemplatePath) &&
                !string.Equals(CurrentTemplateConfig.TemplatePath, path, StringComparison.OrdinalIgnoreCase) &&
                File.Exists(CurrentTemplateConfig.TemplatePath))
            {
                File.Delete(CurrentTemplateConfig.TemplatePath);
            }
            CurrentTemplateConfig.TemplatePath = path;
            File.WriteAllText(path, CurrentTemplateConfig.Template);
        }