private static void PopulateAds() { string jsonContent; if (File.Exists(AdsFileDownloadCache)) { // Read from the downloaded file jsonContent = File.ReadAllText(AdsFileDownloadCache); } else { // Read from the embedded resource using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(AdsEmbeddedResource)) using (StreamReader reader = new StreamReader(stream)) jsonContent = reader.ReadToEnd(); } // Extract the requested ads AdJSON json = JsonConvert.DeserializeObject <AdJSON>(jsonContent); foreach (AdApp app in json.apps) { if (app.app.Equals(DemoUtilities.AppAdName, StringComparison.InvariantCultureIgnoreCase)) { lock (AdsLock) { // Clear previous if (app.ads != null && app.ads.Count > 0) { Ads.Clear(); } // Add new Ads.AddRange(app.ads.Select(ad => ad.content)); // Shuffle for (int i = 0, n = Ads.Count; i < n - 1; i++) { int j = Random.Next(i, n); string temp = Ads[i]; Ads[i] = Ads[j]; Ads[j] = temp; } break; } } } }