コード例 #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
ファイル: frmMain.cs プロジェクト: SoftCircuits/WebScraper
 private void lstFields_Format(object sender, ListControlConvertEventArgs e)
 {
     if (e.ListItem is Field field)
     {
         string mode = FieldHelper.GetDescription(field.GetType());
         if (field is AttributeField attributeField)
         {
             mode += $":{attributeField.AttributeName ?? "(null)"}";
         }
         e.Value = $"{field.Name ?? "(null)"}={field.Selector ?? "(null)"} ({mode})";
     }
 }
コード例 #3
0
        private void SetExtractMode(Type type)
        {
            string description = FieldHelper.GetDescription(type);

            foreach (string item in cboExtractMode.Items)
            {
                if (item == description)
                {
                    cboExtractMode.SelectedItem = item;
                    break;
                }
            }
        }
コード例 #4
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;
        }
コード例 #5
0
 private Type GetSelectedMode()
 {
     return(FieldHelper.GetDescriptionType(cboExtractMode.SelectedItem as string));
 }