Exemple #1
0
        public Company(DirectoryInfo companyDir, Dimensions dimensions, AdUrlDocument urls)
        {
            this.Directory = companyDir.FullName;
            this.Name      = companyDir.Name;

            this.Ads = companyDir.EnumerateFiles().Select(f => new Ad(f, dimensions, urls.GetDefaultUrl(this.Name), urls.GetCustomAdUrls(this.Name))).ToList().AsReadOnly();
        }
Exemple #2
0
        public static void Initialize(string rootPath)
        {
            Logger.Information($"Initializing the AdRotator at path \"{rootPath}\"...");
            try
            {
                var dirInfo = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, rootPath));
                var urlInfo = new AdUrlDocument(Path.Combine(dirInfo.FullName, "urls.xml"));

                dimensionRoots = dirInfo.EnumerateDirectories()
                                 .Select(d => new DimensionRoot(d, urlInfo))
                                 .Where(r => r.Companies.Count > 0)
                                 .ToList()
                                 .AsReadOnly();

                Logger.Information("AdRotator initialized successfully.");
            }
            catch (Exception ex)
            {
                Logger.Error("There was an error loading the AdRotator: " + ex);
                LoadException = ex;
            }

            adsById = dimensionRoots
                      .SelectMany(r => r.Companies)
                      .SelectMany(c => c.Ads)
                      .ToDictionary(a => a.UniqueId, StringComparer.OrdinalIgnoreCase);

            adRedirects = new AdUrlRedirects(adsById.Values.Select(a => a.OriginalUrl));
        }
Exemple #3
0
        public DimensionRoot(DirectoryInfo dir, AdUrlDocument urls)
        {
            var dim = Dimensions.TryParse(dir.Name);

            if (dim == null)
            {
                return;
            }

            this.Dimensions = (Dimensions)dim;

            this.Companies = dir.EnumerateDirectories()
                             .Select(d => new Company(d, this.Dimensions, urls))
                             .Where(c => c.Ads.Count > 0)
                             .ToList()
                             .AsReadOnly();
        }