コード例 #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            string name          = txtName.Text.Trim();
            string selector      = txtSelector.Text.Trim();
            string attributeName = txtAttributeName.Text;
            Type   type          = GetSelectedMode();

            FieldHelper.FieldFactory(type, name, selector, attributeName);
            DialogResult = DialogResult.OK;
            Close();
        }
コード例 #2
0
        public void Read(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            Reset();
            XmlDocument doc = new XmlDocument();

            doc.Load(path);

            XmlElement root = doc.DocumentElement;

            if (root.Name != DataFiles.AppName)
            {
                throw new Exception("Invalid data file format");
            }

            foreach (XmlElement element in root.ChildNodes.OfType <XmlElement>())
            {
                switch (element.Name)
                {
                case "Url":
                    Url = element.InnerText.Trim();
                    break;

                case "ContainerSelector":
                    Container = element.InnerText.Trim();
                    break;

                case "ItemSelector":
                    Item = element.InnerText.Trim();
                    break;

                case "NextPageSelector":
                    NextPage = element.InnerText.Trim();
                    break;

                case "DataSeparator":
                    DataSeparator = element.InnerText;
                    break;

                case "Placeholders":
                    foreach (XmlElement placeholderElement in element.ChildNodes.OfType <XmlElement>())
                    {
                        Placeholder placeholder = new Placeholder(placeholderElement.GetAttribute("Name"));
                        foreach (XmlElement valueElement in placeholderElement.ChildNodes.OfType <XmlElement>())
                        {
                            placeholder.Values.Add(valueElement.InnerText.Trim());
                        }
                        Placeholders.Add(placeholder);
                    }
                    break;

                case "Fields":
                    foreach (XmlElement fieldElement in element.ChildNodes.OfType <XmlElement>())
                    {
                        Fields.Add(FieldHelper.FieldFactory(FieldHelper.GetSymbolType(fieldElement.GetAttribute("Type")),
                                                            fieldElement.GetAttribute("Name"),
                                                            fieldElement.GetAttribute("Selector"),
                                                            fieldElement.GetAttribute("AttributeName")));
                    }
                    break;

                default:
                    break;
                }
            }
            FilePath = path;
        }