Exemple #1
0
        /// <summary>
        /// Main entry point of the service.
        /// </summary>
        /// <returns></returns>
        protected override ServiceOutcome DoWork()
        {
            BasicReportServiceService panamaService = new BasicReportServiceService();
            BasicReportRequest        panamaReport  = new BasicReportRequest();

            // Initalize Panama sevice parameters.
            InitalizePanamaService(panamaService);

            if (_endPointLocation != null && _endPointLocation != "")
            {
                panamaService.Url = _endPointLocation + "/V4/BasicReportService";
            }

            _retrievelDate = DateTime.Now.AddDays(-1);
            // Initalize date parameters.
            panamaReport.startDate          = _retrievelDate;
            panamaReport.endDate            = _retrievelDate;
            panamaReport.dateRangeSpecified = false;
            panamaReport.endDateSpecified   = true;
            panamaReport.startDateSpecified = true;


            // http://searchmarketing.yahoo.com/developer/docs/V4/reference/reportDetails.php
            panamaReport.reportType = BasicReportType.AdvancedAdKeywordPerformanceByDay;

            panamaReport.reportTypeSpecified = true;
            panamaReport.reportName          = "Test";


            // Initalzie report FileOutputFormat to XML.
            FileOutputFormat reportFileFormat = new FileOutputFormat();

            reportFileFormat.fileOutputType          = FileOutputType.XML;
            reportFileFormat.fileOutputTypeSpecified = true;

            Retrieve(panamaService, panamaReport, reportFileFormat);

            return(ServiceOutcome.Success);
        }
Exemple #2
0
        /// <summary>
        /// Get the data from Panama to and save the data into xml file.
        /// </summary>
        /// <param name="panamaService"></param>
        /// <param name="panamaReport"></param>
        /// <param name="reportFileFormat"></param>
        private void Retrieve(BasicReportServiceService panamaService, BasicReportRequest panamaReport, FileOutputFormat reportFileFormat)
        {
            // Get report ID from Panama.
            long reportID = panamaService.addReportRequestForAccountID(PanamaAccountID, panamaReport);

            if (reportID == 0)
            {
                throw new Exception("Can't get data from Panama, report id = 0.");
            }

            // Get report url.
            string reportStatus = panamaService.getReportOutputUrl(reportID, reportFileFormat);

            try
            {
                while (reportStatus == ReportPending)
                {
                    reportStatus = panamaService.getReportOutputUrl(reportID, reportFileFormat);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            string reportUrl = reportStatus;

            //if (url == "failed")
            //{
            //    throw new Exception("Panama return invaild url, report creation failed.");
            //}

            string fileName = WriteResultToFile(reportUrl, _retrievelDate, true);

            // Insert the data to DB.
            SaveFilePathToDB(PanamaServiceType, fileName);
        }