Пример #1
0
 public void Execute(GrabConfiguration grabConfiguration)
 {
     try
     {
         ReportStatus("Updating siteini.user", "");
         Log.Debug(string.Format("Updating siteini.user for {0}", grabConfiguration.Name));
         var siteIniUserDir    = new DirectoryInfo(Path.Combine(grabConfiguration.Path.FullName, Settings.Default.SiteIniUser));
         var listUserCountries = new ListCountries(siteIniUserDir);
         var userCountries     = listUserCountries.Execute();
         var sitePackDir       = new DirectoryInfo(Path.Combine(Locations.WorkingDirectory.FullName, Settings.Default.SiteIniPack));
         var listAllCountries  = new ListCountries(sitePackDir);
         var allCountries      = listAllCountries.Execute();
         var selectedSites     = userCountries.SelectMany(x => x.Sites).ToList();
         var allSites          = allCountries.SelectMany(x => x.Sites).ToList();
         for (int i = 0; i < selectedSites.Count; i++)
         {
             ReportStatus("Updating siteini.user", string.Format("{0} / {1}", i + 1, selectedSites.Count));
             site item        = selectedSites[i];
             var  siteXmlPack = allSites.SingleOrDefault(x => x.Path.Name == item.Path.Name);
             if (siteXmlPack != null)
             {
                 File.Copy(siteXmlPack.Path.FullName, item.Path.FullName, true);
                 if (siteXmlPack.IniPath.Exists)
                 {
                     File.Copy(siteXmlPack.IniPath.FullName, item.IniPath.FullName, true);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error(string.Format("Search for configurations failed.{0}{1}", Environment.NewLine, ex.Message), ex);
         throw;
     }
 }
Пример #2
0
        public GrabConfiguration Execute(DirectoryInfo configurationDirectory)
        {
            try
            {
                ReportStatus("Loading configuration", "");
                Log.Debug(string.Format("Loading user configuration from {0}", configurationDirectory.FullName));

                var webGrabConfFile = Path.Combine(configurationDirectory.FullName, Settings.Default.WebGrabConfigFileName);
                if (File.Exists(webGrabConfFile))
                {
                    var userConfig = new GrabConfiguration(configurationDirectory);
                    userConfig.Config      = settings.LoadFromFile(webGrabConfFile);
                    userConfig.Config.Path = new FileInfo(webGrabConfFile);
                    var siteIniUserDir = new DirectoryInfo(Path.Combine(configurationDirectory.FullName, Settings.Default.SiteIniUser));
                    if (siteIniUserDir.Exists)
                    {
                        var listCountries = new ListCountries(siteIniUserDir);
                        var countries     = listCountries.Execute();
                        userConfig.Countries = countries;
                    }
                    Log.Debug(string.Format("Loaded user config {0}", userConfig.Name));
                    return(userConfig);
                }
                Log.WarnFormat("{0} not found in {1}", Settings.Default.WebGrabConfigFileName, configurationDirectory.FullName);
                return(null);
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Failed to load user configuration.{0}{1}", Environment.NewLine, ex.Message), ex);
                throw;
            }
        }