예제 #1
0
        private void LoadXmloldScripts()
        {
            // InitMappingTable();
              xmlConf = new XmlConf(textConfig.Text);

              grabberscript = new GrabberScript();
              bool needsConversion = false;
              string strTemp;
              string[] split;
              List<string> fields;

              // load old script into XMLnode
              var doc = new XmlDocument();
              doc.Load(textConfig.Text);
              XmlNode script = doc.ChildNodes[1].FirstChild;

              #region init the new data structure
              if (grabberscript == null) grabberscript = new Grabber.Data.GrabberScript();

              if (grabberscript.Settings.Count == 0)
              {
            #region Create Settings
            GrabberScript.SettingsRow settings = grabberscript.Settings.NewSettingsRow();
            settings.DBName = xmlConf.find(xmlConf.listGen, TagName.DBName)._Value;
            try { settings.Version = xmlConf.find(xmlConf.listGen, TagName.Version)._Value; } catch (Exception) { settings.Version = ""; }
            settings.URLPrefix = xmlConf.find(xmlConf.listGen, TagName.URLPrefix)._Value;
            try { settings.Language = xmlConf.find(xmlConf.listGen, TagName.Language)._Value; } catch (Exception) { settings.Language = ""; }
            try { settings.Type = xmlConf.find(xmlConf.listGen, TagName.Type)._Value; }
            catch (Exception) { settings.Type = ""; }
            try { settings.SearchCleanup = xmlConf.find(xmlConf.listGen, TagName.SearchCleanup)._Value; }
            catch (Exception) { settings.SearchCleanup = ""; }
            try { settings.Encoding = xmlConf.find(xmlConf.listGen, TagName.Encoding)._Value; }
            catch (Exception) { settings.Encoding = ""; }
            try { settings.Accept = xmlConf.find(xmlConf.listGen, TagName.Accept)._Value; }
            catch (Exception) { settings.Accept = ""; }
            try { settings.Useragent = xmlConf.find(xmlConf.listGen, TagName.UserAgent)._Value; }
            catch (Exception) { settings.Useragent = ""; }
            try { settings.Headers = xmlConf.find(xmlConf.listGen, TagName.Headers)._Value; }
            catch (Exception) { settings.Headers = ""; }
            try { settings.FileBasedReader = (xmlConf.find(xmlConf.listGen, TagName.FileBasedReader)._Value == "true"); }
            catch (Exception) { settings.FileBasedReader = false; }
            grabberscript.Settings.AddSettingsRow(settings);
            #endregion
              }
              if (grabberscript.UserOptions.Count == 0)
              {
            #region Create UserOptions
            GrabberScript.UserOptionsRow useroptions = grabberscript.UserOptions.NewUserOptionsRow();
            // ToDo: Might load values here
            try { useroptions.MaxActors = xmlConf.find(xmlConf.listDetail, TagName.KeyCreditsMaxItems)._Value; }
            catch { useroptions.MaxActors = string.Empty; }

            string strGrabActorRoles = "";
            try
            {
              strGrabActorRoles = xmlConf.find(xmlConf.listDetail, TagName.KeyCreditsGrabActorRoles)._Value;
              useroptions.GrabActorRoles = strGrabActorRoles == "true";
            }
            catch
            {
              useroptions.GrabActorRoles = false;
            }

            try { useroptions.MaxProducers = xmlConf.find(xmlConf.listDetail, TagName.KeyProductMaxItems)._Value; }
            catch { useroptions.MaxProducers = string.Empty; }

            try { useroptions.MaxDirectors = xmlConf.find(xmlConf.listDetail, TagName.KeyRealiseMaxItems)._Value; }
            catch { useroptions.MaxDirectors = string.Empty; }

            try { useroptions.MaxWriters = xmlConf.find(xmlConf.listDetail, TagName.KeyWriterMaxItems)._Value; }
            catch { useroptions.MaxWriters = string.Empty; }

            try { useroptions.TitleCountry = xmlConf.find(xmlConf.listDetail, TagName.KeyTTitleLanguage)._Value; }
            catch { useroptions.TitleCountry = string.Empty; }

            try { useroptions.MaxTitles = xmlConf.find(xmlConf.listDetail, TagName.KeyTTitleMaxItems)._Value; }
            catch { useroptions.MaxTitles = string.Empty; }

            try { useroptions.CertificationCountry = xmlConf.find(xmlConf.listDetail, TagName.KeyCertificationLanguage)._Value; }
            catch { useroptions.CertificationCountry = string.Empty; }
            grabberscript.UserOptions.AddUserOptionsRow(useroptions);
            #endregion
              }
              if (grabberscript.URLSearch.Count == 0)
              {
            #region Create URLSearch
            GrabberScript.URLSearchRow urlsearch = grabberscript.URLSearch.NewURLSearchRow();
            urlsearch.URL = xmlConf.find(xmlConf.listSearch, TagName.URL)._Value;
            urlsearch.Redirection = xmlConf.find(xmlConf.listSearch, TagName.URL)._Param1;
            urlsearch.StartPage = xmlConf.find(xmlConf.listSearch, TagName.KeyStartPage)._Value;
            urlsearch.NextPage = xmlConf.find(xmlConf.listSearch, TagName.KeyNextPage)._Value;
            urlsearch.StepPage = xmlConf.find(xmlConf.listSearch, TagName.KeyStepPage)._Value;
            grabberscript.URLSearch.AddURLSearchRow(urlsearch);
            // GrabberScript.SearchRow[] fields = urlsearch.GetSearchRows().Length;
            if (grabberscript.URLSearch[0].GetSearchDetailsRows().Length == 0)
            {
              #region load URLSearchDetails
              //AntMovieCatalog.CustomFieldRow cfr = data.CustomField.NewCustomFieldRow();
              //cfr.SetParentRow(data.CustomFieldsProperties[0]);
              //cfr.Tag = customFieldDefinition[0];
              //cfr.Name = (!string.IsNullOrEmpty(TranslateColumn(customFieldDefinition[0]))) ? TranslateColumn(customFieldDefinition[0]) : customFieldDefinition[1];
              //cfr.Type = customFieldDefinition[2];
              //data.CustomField.AddCustomFieldRow(cfr);
              foreach (string property in searchUrlItemsList)
              {
            GrabberScript.SearchDetailsRow search = grabberscript.SearchDetails.NewSearchDetailsRow();
            search.SetParentRow(grabberscript.URLSearch[0]);
            search.Name = property.Replace("Link", "DetailsURL");
            try { search.Start = XmlConvert.DecodeName(script.SelectSingleNodeFast("URLSearch/KeyStart" + property).InnerText); } catch (Exception) { search.Start = ""; }
            try { search.End = XmlConvert.DecodeName(script.SelectSingleNodeFast("URLSearch/KeyEnd" + property).InnerText); } catch (Exception) { search.End = ""; }
            try { search.RegExp = XmlConvert.DecodeName(script.SelectSingleNodeFast("URLSearch/Key" + property + "RegExp").InnerText); } catch (Exception) { search.RegExp = ""; }
            grabberscript.SearchDetails.AddSearchDetailsRow(search);
              }
              #endregion
            }
            #endregion
              }

              #region create the detail items collection
              GrabberScript.DetailsRow Details = grabberscript.Details.NewDetailsRow();
              grabberscript.Details.AddDetailsRow(Details);

              foreach (var grabDetailItem in GrabberUrlClass.GrabDetailItems)
              {
            string name = grabDetailItem.GrabName;

            GrabberScript.DetailRow detail = grabberscript.Detail.NewDetailRow();
            // detail.InternalName = name;
            detail.Name = grabDetailItem.DisplayName;
            detail.Type = (name.ToLower().StartsWith("url")) ? "URL" : "Value";
            detail.SetParentRow(Details);

            try
            {
              detail.Start = XmlConvert.DecodeName(script.SelectSingleNodeFast("Details/KeyStart" + name).InnerText) ?? "";
              detail.End = XmlConvert.DecodeName(script.SelectSingleNodeFast("Details/KeyEnd" + name).InnerText) ?? "";
              detail.Param1 = XmlConvert.DecodeName(script.SelectSingleNodeFast("Details/KeyStart" + name).Attributes["Param1"].InnerText) ?? "";
              detail.Param2 = XmlConvert.DecodeName(script.SelectSingleNodeFast("Details/KeyStart" + name).Attributes["Param2"].InnerText) ?? "";
              try { detail.Param3 = XmlConvert.DecodeName(script.SelectSingleNodeFast("Details/Key" + name + "RegExp").InnerText) ?? ""; }
              catch (Exception) { detail.Param3 = ""; }
              detail.Index = XmlConvert.DecodeName(script.SelectSingleNodeFast("Details/Key" + name + "Index").InnerText) ?? "";
              detail.SourcePage = XmlConvert.DecodeName(script.SelectSingleNodeFast("Details/Key" + name + "Page").InnerText) ?? "";
              try { detail.MaxItems = XmlConvert.DecodeName(script.SelectSingleNodeFast("Details/Key" + name + "MaxItems").InnerText) ?? ""; }
              catch (Exception) { detail.MaxItems = ""; }
              try { detail.Filter = XmlConvert.DecodeName(script.SelectSingleNodeFast("Details/Key" + name + "Language").InnerText); }
              catch (Exception) { detail.Filter = ""; }
              detail.GetRoles = true;
              detail.ApplyReplacements = false;
              detail.RunTime = 0;
              detail.FinalRegExp = "";
              // detail.Result = "";

              // strActivePage = this.LoadPage(strPage);
            }
            catch (Exception)
            {
              // if Start fails, we have to assume, there is no definition, so we create an empty one
              detail.Start = "";
              detail.End = "";
              detail.Param1 = "";
              detail.Param2 = "";
              detail.Param3 = "";
              detail.Index = "";
              detail.SourcePage = "";
              detail.MaxItems = "";
              detail.Filter = "";
              detail.GetRoles = true;
              detail.ApplyReplacements = false;
              detail.RunTime = 0;
              detail.FinalRegExp = "";
              // detail.Result = "";
            }

            grabberscript.Detail.AddDetailRow(detail);

              }

              #endregion

              #region create the mapper collection
              // Read Mapping Infos
              fields = GrabberUrlClass.FieldList();

              if (grabberscript.MappingRules.Count == 0)
              {
            GrabberScript.MappingRulesRow row = grabberscript.MappingRules.NewMappingRulesRow();
            grabberscript.MappingRules.AddMappingRulesRow(row);
              }

              for (int i = 0; i < 40; i++)
              {
            GrabberScript.MappingRuleRow mappingRule = grabberscript.MappingRule.NewMappingRuleRow();
            mappingRule.SetParentRow(grabberscript.MappingRules[0]);
            try
            {
              var val1 = xmlConf.find(xmlConf.listMapping, "Field_" + i)._Param1;
              if (string.IsNullOrEmpty(val1))
            val1 = fields[i]; // if missing field in script, replace DB-field name with "right one"
              var val2 = xmlConf.find(xmlConf.listMapping, "Field_" + i)._Param2;
              var val3 = xmlConf.find(xmlConf.listMapping, "Field_" + i)._Param3;
              var val4 = xmlConf.find(xmlConf.listMapping, "Field_" + i)._Param4;
              var val5 = xmlConf.find(xmlConf.listMapping, "Field_" + i)._Param5;
              var val6 = xmlConf.find(xmlConf.listMapping, "Field_" + i)._Param6;
              var val7 = xmlConf.find(xmlConf.listMapping, "Field_" + i)._Param7;

              mappingRule.Number = i;
              mappingRule.InputField = val1;
              mappingRule.OutputField = val2;
              mappingRule.Replace = Convert.ToBoolean(val3);
              mappingRule.AddStart = Convert.ToBoolean(val4);
              mappingRule.AddEnd = Convert.ToBoolean(val5);
              mappingRule.MergePreferInput = Convert.ToBoolean(val6);
              mappingRule.MergePreferOutput = Convert.ToBoolean(val7);
              mappingRule.ApplyReplacements = false; //new param, initialized false
            }
            catch (Exception)
            {
              mappingRule.Number = i;
              mappingRule.InputField = fields[i];
              mappingRule.OutputField = "";
              mappingRule.Replace = false;
              mappingRule.AddStart = false;
              mappingRule.AddEnd = false;
              mappingRule.MergePreferInput = false;
              mappingRule.MergePreferOutput = false;
              mappingRule.ApplyReplacements = false; //new param, initialized false
            }
            grabberscript.MappingRule.AddMappingRuleRow(mappingRule);

              }

              #endregion

              #endregion

              // save new format - will overwrite the old script !!!
        }
예제 #2
0
        public bool LoadXml()
        {
            grabberscript = new GrabberScript();
              string strTemp;
              string[] split;
              List<string> fields;

              try
              {
            using (var fs = new FileStream(textConfig.Text, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
              grabberscript = new GrabberScript();
              //// synchronize dataset with hierarchical XMLdoc
              //xmlDoc = new XmlDataDocument(data);
              //xmlDoc.Load(fs);
              grabberscript.ReadXml(fs);
              fs.Close();
            }
              }
              catch (Exception ex)
              {
            MessageBox.Show("Config not loaded !\n\nError: " + ex.Message, "Info");
            return false;
              }

              try
              {
            string test = grabberscript.UserOptions[0].PreferredLanguage; // this one does not exist in old scripts !
              }
              catch (Exception ex)
              {
            MessageBox.Show("Script is not compatible!\n\nYou might try to convert it to current format.\n\nError: " + ex.Message, "Info");
            return false;
              }

              #region init GUI with settings and URLsearch options

              //textName.Text = grabberscript.Settings[0].DBName;
              //textVersion.Text = !grabberscript.Settings[0].IsVersionNull() ? grabberscript.Settings[0].Version : "";
              //textURLPrefix.Text = grabberscript.Settings[0].URLPrefix;
              //textLanguage.Text = !grabberscript.Settings[0].IsLanguageNull() ? grabberscript.Settings[0].Language : "";
              //textType.Text = !grabberscript.Settings[0].IsTypeNull() ? grabberscript.Settings[0].Type : "";
              //textSearchCleanup.Text = !grabberscript.Settings[0].IsSearchCleanupNull() ? grabberscript.Settings[0].SearchCleanup : "";
              //textEncoding.Text = !grabberscript.Settings[0].IsEncodingNull() ? grabberscript.Settings[0].Encoding : "";
              //textAccept.Text = !grabberscript.Settings[0].IsAcceptNull() ? grabberscript.Settings[0].Accept : "";
              //textUserAgent.Text = !grabberscript.Settings[0].IsUseragentNull() ? grabberscript.Settings[0].Useragent : "";
              //textHeaders.Text = !grabberscript.Settings[0].IsHeadersNull() ? grabberscript.Settings[0].Headers : "";
              //cbFileBasedReader.Checked = !grabberscript.Settings[0].IsFileBasedReaderNull() && grabberscript.Settings[0].FileBasedReader;

              textName.Text = grabberscript.Settings[0].DBName;
              textVersion.Text = grabberscript.Settings[0].Version;
              textURLPrefix.Text = grabberscript.Settings[0].URLPrefix;
              textLanguage.Text = grabberscript.Settings[0].Language;
              textType.Text = grabberscript.Settings[0].Type;
              textSearchCleanup.Text = grabberscript.Settings[0].SearchCleanup;
              textEncoding.Text = grabberscript.Settings[0].Encoding;
              textAccept.Text = grabberscript.Settings[0].Accept;
              textUserAgent.Text = grabberscript.Settings[0].Useragent;
              textHeaders.Text = grabberscript.Settings[0].Headers;
              cbFileBasedReader.Checked = grabberscript.Settings[0].FileBasedReader;

              TextURL.Text = grabberscript.URLSearch[0].URL;
              textRedir.Text = grabberscript.URLSearch[0].Redirection;
              textStartPage.Text = grabberscript.URLSearch[0].StartPage;
              textNextPage.Text = grabberscript.URLSearch[0].NextPage;
              textStepPage.Text = grabberscript.URLSearch[0].StepPage;

              textPage.Text = textStartPage.Text;

              foreach (GrabberScript.SearchDetailsRow searchRow in grabberscript.URLSearch[0].GetSearchDetailsRows())
              {
            // nothing to do here, only will be used when user selects the field in GUI
            switch (searchRow.Name)
            {
              case "List":
            //textStartPage.Text = searchRow.Start;
            //ToDo: Init values, if necessary

            break;
            }
              }
              #endregion

              #region Load User Settings
              cbMaxActors.Text = grabberscript.UserOptions[0].MaxActors;
              cbMaxActors.Enabled = !string.IsNullOrEmpty(cbMaxActors.Text);
              chkGrabActorRoles.Checked = grabberscript.UserOptions[0].GrabActorRoles;

              // ToDo: once we load the data, the check can be reenabled
              //string strGrabActorRoles = "";
              //string strGrabActorRegex = "";
              //try
              //{
              //  strGrabActorRoles = xmlConf.find(xmlConf.listDetail, TagName.KeyCreditsGrabActorRoles)._Value;
              //  strGrabActorRegex = xmlConf.find(xmlConf.listDetail, TagName.KeyCreditsRegExp)._Value;
              //}
              //catch
              //{
              //  chkGrabActorRoles.Checked = false;
              //  chkGrabActorRoles.Enabled = false;
              //}
              //if (string.IsNullOrEmpty(strGrabActorRoles) || string.IsNullOrEmpty(strGrabActorRegex))
              //  chkGrabActorRoles.Enabled = false;
              //else chkGrabActorRoles.Enabled = true;

              cbMaxProducers.Text = grabberscript.UserOptions[0].MaxProducers;
              cbMaxProducers.Enabled = !string.IsNullOrEmpty(this.cbMaxProducers.Text);

              cbMaxDirectors.Text = grabberscript.UserOptions[0].MaxDirectors;
              cbMaxDirectors.Enabled = !string.IsNullOrEmpty(this.cbMaxDirectors.Text);

              cbMaxWriters.Text = grabberscript.UserOptions[0].MaxWriters;
              cbMaxWriters.Enabled = !string.IsNullOrEmpty(this.cbMaxWriters.Text);

              cbTtitlePreferredLanguage.Text = grabberscript.UserOptions[0].TitleCountry;
              //if (string.IsNullOrEmpty(cbTtitlePreferredLanguage.Text)) cbTtitlePreferredLanguage.Enabled = false;
              //else cbTtitlePreferredLanguage.Enabled = true;
              cbTtitleMaxTitles.Text = grabberscript.UserOptions[0].MaxTitles;
              cbTtitleMaxTitles.Enabled = !string.IsNullOrEmpty(cbTtitleMaxTitles.Text);
              cbCertificationPreferredLanguage.Text = grabberscript.UserOptions[0].CertificationCountry;
              //if (string.IsNullOrEmpty(cbCertificationPreferredLanguage.Text)) cbCertificationPreferredLanguage.Enabled = false;
              //else cbCertificationPreferredLanguage.Enabled = true;

              // Add Dropdownentries to User Options
              cbTtitlePreferredLanguage.Items.Clear();
              split = grabberscript.UserOptions[0].TitleCountryAll.ToString().Split(new Char[] { ',', ';', '/' }, StringSplitOptions.RemoveEmptyEntries);
              Array.Sort(split);
              foreach (var strDroptext in split)
              {
            if (!cbTtitlePreferredLanguage.Items.Contains(strDroptext.Trim()))
              cbTtitlePreferredLanguage.Items.Add(strDroptext.Trim());
              }
              cbTtitlePreferredLanguage.Enabled = cbTtitlePreferredLanguage.Items.Count > 0;

              cbCertificationPreferredLanguage.Items.Clear();
              try
              {
            strTemp = grabberscript.UserOptions[0].CertificationCountry;
              }
              catch
              {
            strTemp = string.Empty;
              }
              split = strTemp.Split(new Char[] { ',', ';', '/' }, StringSplitOptions.RemoveEmptyEntries);
              Array.Sort(split);
              foreach (var strDroptext in split)
              {
            if (!cbCertificationPreferredLanguage.Items.Contains(strDroptext.Trim()))
              cbCertificationPreferredLanguage.Items.Add(strDroptext.Trim());
              }
              cbCertificationPreferredLanguage.Enabled = cbCertificationPreferredLanguage.Items.Count > 0;

              cbAllowMideaInfo.Checked = grabberscript.UserOptions[0].GetMediaInfo;

              cbGoogleTranslateLanguage.Text = grabberscript.UserOptions[0].TranslationLanguage;

              #endregion

              #region Load Mapping to mapping matrix
              fields = Grabber.GrabberUrlClass.FieldList();
              for (int i = 0; i < grabberscript.MappingRules[0].GetMappingRuleRows().Length; i++)
              {
            var mapRuleRow = grabberscript.MappingRules[0].GetMappingRuleRows()[i];
            dataGridViewMapping.Rows[i].Cells[1].Value = mapRuleRow.InputField;
            dataGridViewMapping.Rows[i].Cells[2].Value = mapRuleRow.OutputField;
            dataGridViewMapping.Rows[i].Cells[3].Value = mapRuleRow.Replace;
            dataGridViewMapping.Rows[i].Cells[4].Value = mapRuleRow.AddStart;
            dataGridViewMapping.Rows[i].Cells[5].Value = mapRuleRow.AddEnd;
            dataGridViewMapping.Rows[i].Cells[6].Value = mapRuleRow.MergePreferInput;
            dataGridViewMapping.Rows[i].Cells[7].Value = mapRuleRow.MergePreferOutput;
            // dataGridViewMapping.Rows[i].Cells[8].Value = mapRuleRow.ApplyReplacements;
              }
              #endregion

              return true;
        }