Esempio n. 1
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            ReportService reportService = (ReportService)user.GetService(
                DfpService.v201411.ReportService);

            // Set the id of the completed report.
            long   reportJobId = long.Parse(_T("INSERT_REPORT_JOB_ID_HERE"));
            String fileName    = _T("INSERT_FILE_PATH_HERE");

            try {
                // Download report data.
                string url            = reportService.getReportDownloadURL(reportJobId, ExportFormat.CSV_EXCEL);
                byte[] gzipReport     = MediaUtilities.GetAssetDataFromUrl(url);
                string reportContents = Encoding.UTF8.GetString(MediaUtilities.DeflateGZipData(gzipReport));

                using (StreamWriter writer = new StreamWriter(fileName)) {
                    writer.Write(reportContents);
                }

                // Display results.
                Console.WriteLine("Report job with id '{0}' was downloaded to '{1}'.", reportJobId,
                                  fileName);
            } catch (Exception ex) {
                Console.WriteLine("Failed to download report. Exception says \"{0}\"", ex.Message);
            }
        }
 public void TestDeflateGZipData()
 {
     byte[] deflatedData = MediaUtilities.DeflateGZipData(compressedData);
     Assert.AreEqual(FILE_CONTENTS, Encoding.UTF8.GetString(deflatedData));
 }