示例#1
0
        public static ReportRequestStatus FetchNewReport()
        {
            Console.WriteLine("Fetch new report");
            var status = new ReportRequestStatus();

            lock (_lock) {
                fetchingData = true;
                try{
                    var hasValidReport = MoodReport.HasValidReport;
                    status = MyMoodService.Current.RequestGlobalMoodReport();

                    if (status.Success && status.NewReportAvailable)
                    {
                        NSNotificationCenter.DefaultCenter.PostNotificationName("NewReportReceived", null);
                    }
                    else
                    {
                        if (!hasValidReport)
                        {
                            //first report so need to let loading screen know we are loaded
                            NSNotificationCenter.DefaultCenter.PostNotificationName("NoReportData", null);
                        }
                    }
                }catch (Exception ex) {
                    MyMoodLogger.Current.Error("Error fetching new report", ex, 1);
                } finally{
                    fetchingData = false;
                }
            }
            Console.WriteLine("Fetched new report");
            return(status);
        }
示例#2
0
        public void SyncData()
        {
            Console.WriteLine("SyncData");
            NotifySyncing();
            ReportRequestStatus status = ReportManager.FetchNewReport();

            NotifySyncComplete(status.Success ? SyncSuccessLevel.Success : SyncSuccessLevel.FailedSevere);
            Console.WriteLine("SyncData done.");
        }
示例#3
0
        public static ReportRequestStatus FetchReportDays(MoodReport report)
        {
            Console.WriteLine("Fetch report days");
            var status = new ReportRequestStatus();

            lock (_lock) {
                fetchingData = true;
                try{
                    //get rid of any pre fetched snapshots
                    DeleteReportSnapshots(report);
                    status = MyMoodService.Current.RequestGlobalMoodReportData(report);
                }catch (Exception ex) {
                    MyMoodLogger.Current.Error("Error fetching new report", ex, 1);
                }finally{
                    fetchingData = false;
                }
            }
            Console.WriteLine("Fetched report days");
            return(status);
        }
示例#4
0
        public async override Task RunAsync(AuthorizationData authorizationData)
        {
            try
            {
                Service = new ServiceClient <IReportingService>(authorizationData);

                // Build a keyword performance report request, including Format, ReportName, Aggregation,
                // Scope, Time, Filter, and Columns.

                var report = new KeywordPerformanceReportRequest
                {
                    Format                 = ReportFormat.Tsv,
                    ReportName             = "My Keyword Performance Report",
                    ReturnOnlyCompleteData = false,
                    Aggregation            = ReportAggregation.Daily,

                    Scope = new AccountThroughAdGroupReportScope
                    {
                        AccountIds = new[] { authorizationData.AccountId },
                        AdGroups   = null,
                        Campaigns  = null
                    },

                    Time = new ReportTime
                    {
                        // You may either use a custom date range or predefined time.

                        //CustomDateRangeStart = new Date
                        //    {
                        //        Month = DateTime.Now.Month,
                        //        Day = DateTime.Now.Day,
                        //        Year = DateTime.Now.Year - 1
                        //    },
                        //CustomDateRangeEnd = new Date
                        //    {
                        //    Month = DateTime.Now.Month,
                        //    Day = DateTime.Now.Day,
                        //    Year = DateTime.Now.Year
                        //    },

                        PredefinedTime = ReportTimePeriod.Yesterday
                    },

                    // If you specify a filter, results may differ from data you see in the Bing Ads web application
                    Filter = new KeywordPerformanceReportFilter
                    {
                        DeviceType = DeviceTypeReportFilter.Computer |
                                     DeviceTypeReportFilter.SmartPhone
                    },

                    // Specify the attribute and data report columns.
                    Columns = new[]
                    {
                        KeywordPerformanceReportColumn.TimePeriod,
                        KeywordPerformanceReportColumn.AccountId,
                        KeywordPerformanceReportColumn.CampaignId,
                        KeywordPerformanceReportColumn.Keyword,
                        KeywordPerformanceReportColumn.KeywordId,
                        KeywordPerformanceReportColumn.DeviceType,
                        KeywordPerformanceReportColumn.BidMatchType,
                        KeywordPerformanceReportColumn.Clicks,
                        KeywordPerformanceReportColumn.Impressions,
                        KeywordPerformanceReportColumn.Ctr,
                        KeywordPerformanceReportColumn.AverageCpc,
                        KeywordPerformanceReportColumn.Spend,
                        KeywordPerformanceReportColumn.QualityScore
                    },

                    // You may optionally sort by any KeywordPerformanceReportColumn, and optionally
                    // specify the maximum number of rows to return in the sorted report.
                    Sort = new[]
                    {
                        new KeywordPerformanceReportSort
                        {
                            SortColumn = KeywordPerformanceReportColumn.Clicks,
                            SortOrder  = SortOrder.Ascending
                        }
                    },

                    MaxRows = 10,
                };

                // SubmitGenerateReport helper method calls the corresponding Bing Ads service operation
                // to request the report identifier. The identifier is used to check report generation status
                // before downloading the report.

                var reportRequestId = await SubmitGenerateReportAsync(report);

                OutputStatusMessage("Report Request ID: " + reportRequestId);

                var waitTime = new TimeSpan(0, 0, 30);
                ReportRequestStatus reportRequestStatus = null;

                // This example polls every 30 seconds up to 5 minutes.
                // In production you may poll the status every 1 to 2 minutes for up to one hour.
                // If the call succeeds, stop polling. If the call or
                // download fails, the call throws a fault.

                for (int i = 0; i < 10; i++)
                {
                    OutputStatusMessage(String.Format("Will check if the report is ready in {0} seconds: ", waitTime.Seconds));
                    Thread.Sleep(waitTime);

                    // PollGenerateReport helper method calls the corresponding Bing Ads service operation
                    // to get the report request status.
                    reportRequestStatus = await PollGenerateReportAsync(reportRequestId);

                    if (reportRequestStatus.Status == ReportRequestStatusType.Success ||
                        reportRequestStatus.Status == ReportRequestStatusType.Error)
                    {
                        break;
                    }

                    OutputStatusMessage("The report is not yet ready for download.");
                }

                if (reportRequestStatus != null)
                {
                    if (reportRequestStatus.Status == ReportRequestStatusType.Success)
                    {
                        var reportDownloadUrl = reportRequestStatus.ReportDownloadUrl;
                        OutputStatusMessage(String.Format("Downloading from {0}.", reportDownloadUrl));
                        OutputStatusMessage("\n");
                        DownloadFile(reportDownloadUrl, DownloadPath);
                        OutputStatusMessage(String.Format("The report was written to {0}.", DownloadPath));
                    }
                    else if (reportRequestStatus.Status == ReportRequestStatusType.Error)
                    {
                        OutputStatusMessage("The request failed. Try requesting the report " +
                                            "later.\nIf the request continues to fail, contact support.");
                    }
                    else  // Pending
                    {
                        OutputStatusMessage(String.Format("The request is taking longer than expected.\n " +
                                                          "Save the report ID ({0}) and try again later.", reportRequestId));
                    }
                }
            }
            // Catch authentication exceptions
            catch (OAuthTokenRequestException ex)
            {
                OutputStatusMessage(string.Format("Couldn't get OAuth tokens. Error: {0}. Description: {1}", ex.Details.Error, ex.Details.Description));
            }
            // Catch Reporting service exceptions
            catch (FaultException <Microsoft.BingAds.Reporting.AdApiFaultDetail> ex)
            {
                OutputStatusMessage(string.Join("; ", ex.Detail.Errors.Select(error => string.Format("{0}: {1}", error.Code, error.Message))));
            }
            catch (FaultException <Microsoft.BingAds.Reporting.ApiFaultDetail> ex)
            {
                OutputStatusMessage(string.Join("; ", ex.Detail.OperationErrors.Select(error => string.Format("{0}: {1}", error.Code, error.Message))));
                OutputStatusMessage(string.Join("; ", ex.Detail.BatchErrors.Select(error => string.Format("{0}: {1}", error.Code, error.Message))));
            }
            catch (WebException ex)
            {
                OutputStatusMessage(ex.Message);

                if (ex.Response != null)
                {
                    OutputStatusMessage("HTTP status code: " + ((HttpWebResponse)ex.Response).StatusCode);
                }
            }
            catch (IOException ex)
            {
                OutputStatusMessage(ex.Message);
            }
            catch (Exception ex)
            {
                OutputStatusMessage(ex.Message);
            }
        }