Пример #1
0
        public TemplateLoadResult LoadXMLTemplateFile()
        {
            if (this.TemplateFileName.Equals(string.Empty))
            {
                return(TemplateLoadResult.EmptyFileName);
            }

            if (!System.IO.File.Exists(this.TemplateFileName))
            {
                return(TemplateLoadResult.FileDoesNotExist);
            }

            XDocument xdoc = XDocument.Load(this.TemplateFileName);

            foreach (XElement xel in xdoc.Root.Elements("template"))
            {
                RuleTemplate rt = this.ParseTemplate(xel);
                if (rt != null)
                {
                    templates.Add(rt.TemplateName, rt);
                }
            }

            return(TemplateLoadResult.Success);
        }
Пример #2
0
        private RuleTemplate ParseTemplate(XElement templElt)
        {
            RuleTemplate rt = new RuleTemplate(
                templateName: (string)templElt.Attribute("name"),
                appName: (string)templElt.Element("ruleName"),
                appRule: (string)templElt.Element("rule")
                );

            return(rt);
        }
        public TemplateEditor(string templName, TemplateManager tm)
        {
            InitializeComponent();

            this.templateManager = tm;
            RuleTemplate rt = tm.GetRule(templName);

            this.TemplateName = templName;
            this.AppRuleName  = rt.AppName;
            this.AppRule      = rt.AppRule;
        }
Пример #4
0
        public TemplateModResult ModifyRule(RuleTemplate rt)
        {
            if (rt.TemplateName.Equals(string.Empty))
            {
                return(TemplateModResult.TemplateNameInvalid);
            }

            if (rt.AppName.Equals(string.Empty) ||
                rt.AppRule.Equals(string.Empty))
            {
                return(TemplateModResult.TemplateIncomplete);
            }

            templates[rt.TemplateName] = rt;

            return(TemplateModResult.TemplateModSuccess);
        }
Пример #5
0
        public TemplateModResult AddRule(RuleTemplate rule)
        {
            if (rule.TemplateName.Equals(string.Empty) ||
                rule.AppName.Equals(string.Empty) ||
                rule.AppRule.Equals(string.Empty))
            {
                return(TemplateModResult.TemplateIncomplete);
            }

            if (templates.ContainsKey(rule.TemplateName))
            {
                return(TemplateModResult.TemplateNameExists);
            }

            templates.Add(rule.TemplateName, rule);

            return(TemplateModResult.TemplateAddSuccess);
        }
        private void BtnOK_Click(object sender, EventArgs e)
        {
            RuleTemplate rt = new RuleTemplate(txtTemplateName.Text, txtAppName.Text, txtRule.Text);

            if (rt.IsValidRule())
            {
                if (this.templateManager.GetRule(rt.TemplateName) == null)
                {
                    this.templateManager.AddRule(rt);
                }
                else
                {
                    this.templateManager.ModifyRule(rt);
                }

                this.Close();
            }
            else
            {
                MessageBox.Show(rt.GetError());
            }
        }