void BeforeSwitchingMonth() //checks before switching the month { var results = from a in CalendarDays join b in SavedReports on a.Date equals b.Date where a.Entry == "" || !string.IsNullOrEmpty(a.Entry) select new { itemA = a, itemB = b }; foreach (var result in results) { if (result.itemA.Entry == "") //if the user deletes a value in the entry after inserting it { result.itemB.Entry = null; } else { //if there is a saved report with same date => replace it result.itemB.Entry = result.itemA.Entry; result.itemA.Entry = null; } } bool valuechanged = false; //if no saved report in the same date already exist, create new one if (SavedReports.Count == 0) { NewObject = new Day(); SavedReports.Add(NewObject); valuechanged = true; } var results3 = from a in CalendarDays from b in SavedReports select new { itemA = a, itemB = b }; foreach (var result in results3.ToList()) { if (result.itemA.Date != result.itemB.Date && !string.IsNullOrEmpty(result.itemA.Entry)) { NewObject = new Day { Date = result.itemA.Date, Entry = result.itemA.Entry }; SavedReports.Add(NewObject); result.itemA.Entry = null; } } if (valuechanged == true) { SavedReports.RemoveAt(0); } }
/// <summary>Runs multiple Publisher requests against the AdSense Management API.</summary> internal void RunCalls() { Accounts accounts = GetAllAccounts(); // Get an example account, so we can run the following samples. adSenseAccount = accounts.Items.NullToEmpty().FirstOrDefault(); if (adSenseAccount != null) { DisplayAccountTree(adSenseAccount.Id); DisplayAllAdClientsForAccount(adSenseAccount.Id); } var adClients = GetAllAdClients(); // Get an ad client, so we can run the rest of the samples. var exampleAdClient = adClients.Items.NullToEmpty().FirstOrDefault(); if (exampleAdClient != null) { var adUnits = GetAllAdUnits(exampleAdClient.Id); // Get an example ad unit, so we can run the following sample. var exampleAdUnit = adUnits.Items.NullToEmpty().FirstOrDefault(); if (exampleAdUnit != null) { DisplayAllCustomChannelsForAdUnit(exampleAdClient.Id, exampleAdUnit.Id); } var customChannels = GetAllCustomChannels(exampleAdClient.Id); // Get an example custom channel, so we can run the following sample. var exampleCustomChannel = customChannels.Items.NullToEmpty().FirstOrDefault(); if (exampleCustomChannel != null) { DisplayAllAdUnits(exampleAdClient.Id, exampleCustomChannel.Id); } DisplayAllUrlChannels(exampleAdClient.Id); DisplayAllSavedAdStyles(); SavedReports savedReports = GetAllSavedReports(); // Get an example saved report, so we can run the following sample. var exampleSavedReport = savedReports.Items.NullToEmpty().FirstOrDefault(); if (exampleSavedReport != null) { GenerateSavedReport(exampleSavedReport.Id); } GenerateReport(exampleAdClient.Id); GenerateReportWithPaging(exampleAdClient.Id); CollateReportData(); } DisplayAllMetricsAndDimensions(); DisplayAllAlerts(); }
/// <summary> /// Gets and prints all the saved reports for the logged in user's default account. /// </summary> /// <returns>The last page of the retrieved saved reports.</returns> private SavedReports GetAllSavedReports() { Console.WriteLine("================================================================="); Console.WriteLine("Listing all saved reports"); Console.WriteLine("================================================================="); // Retrieve ad client list in pages and display data as we receive it. string pageToken = null; SavedReports savedReportResponse = null; do { var savedReportRequest = service.Accounts.Reports.Saved.List(adSenseAccount.Id); savedReportRequest.MaxResults = maxListPageSize; savedReportRequest.PageToken = pageToken; savedReportResponse = savedReportRequest.Execute(); if (!savedReportResponse.Items.IsNullOrEmpty()) { foreach (var savedReport in savedReportResponse.Items) { Console.WriteLine( "Saved report with ID \"{0}\" and name \"{1}\" was found.", savedReport.Id, savedReport.Name); } } else { Console.WriteLine("No saved saved reports found."); } pageToken = savedReportResponse.NextPageToken; }while (pageToken != null); Console.WriteLine(); return(savedReportResponse); }