Exemplo n.º 1
0
        public void LoadXml(string path)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(path);
            //ReplaceTemplate item;
            foreach (XmlNode node in doc.SelectNodes("replaces/template"))
            {
                //Load Sub File.
                string file = Xmler.GetAttribute(node, "file");
                if (File.Exists(file))
                {
                    LoadXml(file);
                }

                // Load Current File
                string name = Xmler.GetAttribute(node, "name");
                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }

                string temp = name;
                int    i    = 0;
                while (templates.ContainsKey(temp))
                {
                    i++;
                    temp = temp + i.ToString();
                }
                name = temp;
            }
        }
Exemplo n.º 2
0
        public static void InitXmlSchema(string schemaPath)
        {
            string schema = Xmler.GetAppSettingValue("schema");

            if (string.IsNullOrEmpty(schema))
            {
                throw new XmlException("Missing schema config in App.config.");
            }

            TemplateDataSet.ReadXmlSchema(schemaPath);
        }
 public void WriteXml(XmlWriter writer)
 {
     writer.WriteStartElement(PromptedProperty.ClassName);
     writer.WriteElementString("PropertyName", this.PropertyName);
     writer.WriteElementString("PromptText", this.PromptText);
     writer.WriteElementString("DefaultValue", this.DefaultValue);
     writer.WriteElementString("AllowChange", this.AllowChange.ToString());
     if (HasAllowedValues == true)
     {
         Xmler.WriteXml(writer, this.AllowedValues, "AllowedValues", "AllowedValue");
     }
     writer.WriteEndElement();
 }
Exemplo n.º 4
0
        /// <summary>
        /// Show Pattern Config file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnOpen_Click(object sender, EventArgs e)
        {
            string txtopener       = Xmler.GetAppSettingValue("txtopener");
            string replacepatterns = Xmler.GetAppSettingValue("replacepatterns");

            if (!string.IsNullOrEmpty(txtopener))
            {
                Process.Start(txtopener, replacepatterns);
            }
            else
            {
                MessageBox.Show("Txt File Editor is Missing or not Config."
                                + "\nPlease Confirm the [txtopener] on *.exe.config ");
            }
        }
Exemplo n.º 5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

            string path            = Path.GetDirectoryName(Application.ExecutablePath);
            string schemaPath      = Path.Combine(path, Xmler.GetAppSettingValue("schema"));
            string xmlPath         = Path.Combine(path, Xmler.GetAppSettingValue("rules"));
            string xmlPathTemplate = Path.Combine(path, Xmler.GetAppSettingValue("template"));

            ReplaceLoader.InitXmlSchema(schemaPath);
            ReplaceLoader.LoadTemplate(xmlPath);
            ReplaceLoader.LoadTemplateXML(xmlPathTemplate);
            Application.Run(new FrmMDI());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get filters of do or undo.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private Dictionary <string, bool> GetFilters(XmlNode node)
        {
            Dictionary <string, bool> Filters = new Dictionary <string, bool>();

            foreach (XmlNode doNode in node.SelectNodes("inside"))
            {
                string filter = doNode.InnerText.Trim();
                if (string.IsNullOrEmpty(filter))
                {
                    continue;
                }
                string action   = Xmler.GetAttribute(doNode, "action");
                bool   isAction = false;
                bool.TryParse(action, out isAction);
                Filters[filter] = isAction;
            }
            return(Filters);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Load reference Dictionary form text file.
        /// </summary>
        /// <param name="node"></param>
        private void LoadDictionary(XmlNode node)
        {
            string file = Xmler.GetAttribute(node, "dictionary");

            if (File.Exists(file))
            {
                string[] contents = File.ReadAllLines(file, FileHelper.Encoding);
                string   key      = string.Empty;
                string   value    = string.Empty;
                foreach (string kv in contents)
                {
                    Match match = Regex.Match(kv, @"^\s*(\w+)=");
                    if (match.Success)
                    {
                        key   = match.Groups[1].Value;
                        value = kv.Substring(match.Index + match.Length);
                        this.Dictionary[key] = value;
                    }
                }
            }
        }
        public void ReadXml(XmlReader reader)
        {
            int ix;

            string[] nameStack = new string[99];

            // the current node must be the PromptedProperty.ClassName node.
            if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == PromptedProperty.ClassName))
            {
            }
            else
            {
                throw new ApplicationException(
                          "ReadXml method of PromptedProperty class expects current node to be " +
                          "named 'Field'");
            }

            bool fExit = false;

            while (true)
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:

                    if (reader.Name == "AllowedValues")
                    {
                        List <string> vlus = new List <string>();
                        Xmler.ReadXml(out vlus, reader, "AllowedValues", "AllowedValue");
                    }

                    else
                    {
                        // save the element name in stack of element names.
                        ix            = reader.Depth;
                        nameStack[ix] = reader.Name;
                    }
                    break;

                case XmlNodeType.Text:

                    ix = reader.Depth;
                    if ((ix > 1) && (nameStack[ix - 2] == PromptedProperty.ClassName))
                    {
                        string elemName = nameStack[ix - 1];
                        if (elemName == "PropertyName")
                        {
                            this.PropertyName = reader.Value;
                        }
                        else if (elemName == "PromptText")
                        {
                            this.PromptText = this.PromptText;
                        }
                        else if (elemName == "DefaultValue")
                        {
                            this.PromptText = this.DefaultValue;
                        }
                        else if (elemName == "AllowChange")
                        {
                            this.AllowChange = Boolean.Parse(reader.Value);
                        }
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (reader.Name == PromptedProperty.ClassName)
                    {
                        fExit = true;
                    }
                    break;
                }
                if (fExit == true)
                {
                    break;
                }

                // read the next node in the xml document.
                bool rc = reader.Read();

                // error if eof. should find the Field end element first.
                if (rc == false)
                {
                    throw new ApplicationException(
                              "ReadXml method of PromptedProperty class did not find 'Field' end element");
                }
            }
        }