コード例 #1
0
    /// <summary>
    /// Schedules and downloads a report.
    /// </summary>
    /// <param name="service">The report service instance.</param>
    /// <param name="queryId">The query id to be used for generating reports.
    /// </param>
    /// <param name="reportFilePath">The file path to which the downloaded report
    /// should be saved.</param>
    private bool ScheduleAndDownloadReport(ReportRemoteService service, long queryId,
        string reportFilePath) {
      // Create report request and submit it to the server.
      ReportRequest reportRequest = new ReportRequest();
      reportRequest.queryId = queryId;

      ReportInfo reportInfo = service.runDeferredReport(reportRequest);
      long reportId = reportInfo.reportId;
      reportRequest.reportId = reportId;

      while (reportInfo.status.name != "COMPLETE") {
        Thread.Sleep(TIME_BETWEEN_CHECKS);
        reportInfo = service.getReport(reportRequest);
        if (reportInfo.status.name == "ERROR") {
          throw new Exception("Deferred report failed with errors. Run in the UI to " +
              "troubleshoot.");
        }
      }

      FileStream fs = null;
      try {
        fs = File.OpenWrite(reportFilePath);
        byte[] data = MediaUtilities.GetAssetDataFromUrl(reportInfo.url);
        fs.Write(data, 0, data.Length);
        return true;
      } catch {
        return false;
      } finally {
        if (fs != null) {
          fs.Close();
        }
      }
    }
コード例 #2
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The Dfa user object running the code example.
    /// </param>
    public override void Run(DfaUser user) {
      // Create ReportRemoteService instance.
      ReportRemoteService service = (ReportRemoteService) user.GetService(
          DfaService.v1_19.ReportRemoteService);

      long queryId = long.Parse(_T("INSERT_QUERY_ID_HERE"));

      // Create report request object.
      ReportRequest reportRequest = new ReportRequest();
      reportRequest.queryId = queryId;

      try {
        // Request generation of a report for your query.
        ReportInfo reportInfo = service.runDeferredReport(reportRequest);

        // Display success message.
        Console.WriteLine("Report with ID '{0}' has been scheduled.", reportInfo.reportId);
      } catch (Exception ex) {
        Console.WriteLine("Failed to schedule report. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #3
0
    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="user">The Dfa user object running the code example.
    /// </param>
    public override void Run(DfaUser user) {
      // Create ReportRemoteService instance.
      ReportRemoteService service = (ReportRemoteService) user.GetService(
          DfaService.v1_19.ReportRemoteService);

      long reportId = long.Parse(_T("INSERT_REPORT_ID_HERE"));

      // Create report request object.
      ReportRequest reportRequest = new ReportRequest();
      reportRequest.reportId = reportId;

      try {
        // Get report information.
        ReportInfo reportInfo = service.getReport(reportRequest);
        // Display information on the report.
        Console.WriteLine("Report with ID '{0}', status of '{1}', and URL of '{2}' was found.",
            reportInfo.reportId, reportInfo.status.name, reportInfo.url);
       } catch (Exception ex) {
        Console.WriteLine("Failed to retrieve report. Exception says \"{0}\"", ex.Message);
      }
    }
コード例 #4
0
 public ReportInfo runDeferredReport(ReportRequest ReportRequest) {
   object[] results = this.Invoke("runDeferredReport", new object[] {ReportRequest});
   return ((ReportInfo) (results[0]));
 }
コード例 #5
0
    /// <summary>
    /// Schedules and downloads a report.
    /// </summary>
    /// <param name="loginService">The login service instance.</param>
    /// <param name="reportService">The report service instance.</param>
    /// <param name="userName">The user name to be used for authentication
    /// purposes.</param>
    /// <param name="password">The password to be used for authentication
    /// purposes.</param>
    /// <param name="queryId">The query id to be used for generating reports.
    /// </param>
    /// <param name="filePath">The file path to which the downloaded report
    /// should be saved.</param>
    public void ScheduleAndDownloadReport(LoginRemoteService loginService,
        ReportRemoteService reportService, string userName, string password, long queryId,
        string filePath) {

      // Override the credentials in App.config with the ones the user
      // provided.
      string authToken = loginService.authenticate(userName, password).token;

      reportService.Token.Username = userName;
      reportService.Token.Password = authToken;

      // Create report request and submit it to the server.
      ReportRequest reportRequest = new ReportRequest();
      reportRequest.queryId = queryId;

      try {
        ReportInfo reportInfo = reportService.runDeferredReport(reportRequest);
        long reportId = reportInfo.reportId;
        Console.WriteLine("Report with ID '{0}' has been scheduled.", reportId);

        reportRequest.reportId = reportId;

        while (reportInfo.status.name != "COMPLETE") {
          Console.WriteLine("Still waiting for report with ID '{0}', current status is '{1}'.",
              reportId, reportInfo.status.name);
          Console.WriteLine("Waiting 10 minutes before checking on report status.");
          // Wait 10 minutes.
          Thread.Sleep(TIME_BETWEEN_CHECKS);
          reportInfo = reportService.getReport(reportRequest);
          if (reportInfo.status.name == "ERROR") {
            throw new Exception("Deferred report failed with errors. Run in the UI to " +
                "troubleshoot.");
          }
        }

        using (FileStream fs = File.OpenWrite(filePath)) {
          byte[] bytes = MediaUtilities.GetAssetDataFromUrl(reportInfo.url);
          fs.Write(bytes, 0, bytes.Length);
        }

        Console.WriteLine("Report successfully downloaded to '{0}'.", filePath);
      } catch (Exception ex) {
        Console.WriteLine("Failed to schedule and download report. Exception says \"{0}\"",
            ex.Message);
      }
    }