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(); }
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)); }
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(); }