Ejemplo n.º 1
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 search criteria object.
            ReportSearchCriteria reportSearchCriteria = new ReportSearchCriteria();

            reportSearchCriteria.queryId = queryId;

            try {
                // Get report information.
                ReportInfoRecordSet reportInfoRecordSet =
                    service.getReportsByCriteria(reportSearchCriteria);

                // Display information on reports.
                if (reportInfoRecordSet.records != null && reportInfoRecordSet.records.Length > 0)
                {
                    foreach (ReportInfo report in reportInfoRecordSet.records)
                    {
                        Console.WriteLine("Report with ID '{0}', status of '{1}' and URL of '{2}' was found.",
                                          report.reportId, report.status, report.url);
                    }
                }
                else
                {
                    Console.WriteLine("No reports found for your query ID.");
                }
            } catch (Exception ex) {
                Console.WriteLine("Failed to retrieve all reports. Exception says \"{0}\"", ex.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Schedules and downloads a report given a query id.
        /// </summary>
        /// <param name="queryId">The query id.</param>
        /// <param name="reportFilePath">The path to which the report should be
        /// downloaded.</param>
        /// <returns>True, if the report was downloaded successfully, false
        /// otherwise.</returns>
        internal bool GetReport(long queryId, string reportFilePath)
        {
            // Create ReportRemoteService instance.
            ReportRemoteService service = (ReportRemoteService)user.GetService(
                DfaService.v1_19.ReportRemoteService);

            return(ScheduleAndDownloadReport(service, queryId, reportFilePath));
        }
Ejemplo n.º 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)
        {
            string userName = _T("INSERT_USERNAME_HERE");
            string password = _T("INSERT_PASSWORD_HERE");
            long   queryId  = long.Parse(_T("INSERT_QUERY_ID_HERE"));
            string filePath = _T("INSERT_PATH_TO_SAVE_REPORT_HERE");

            ReportRemoteService reportService = (ReportRemoteService)user.GetService(
                DfaService.v1_19.ReportRemoteService);
            LoginRemoteService loginService = (LoginRemoteService)user.GetService(
                DfaService.v1_19.LoginRemoteService);

            ScheduleAndDownloadReport(loginService, reportService, userName, password, queryId, filePath);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Main method, to run this code example as a standalone application.
        /// </summary>
        /// <param name="args">The command line arguments.</param>
        public static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("This program requires 4 command line arguments:");
                Console.WriteLine("\t1. DFA username\n\t2. DFA password\n" +
                                  "\t3. Query ID number\n\t4. Output filename.");
                Console.WriteLine("Example usage: RCReport.exe username@dfa password456 " +
                                  "12345 report.zip");
            }

            RCReport codeExample = new RCReport();

            Console.WriteLine(codeExample.Description);
            DfaUser             user          = new DfaUser();
            ReportRemoteService reportService = (ReportRemoteService)user.GetService(
                DfaService.v1_19.ReportRemoteService);
            LoginRemoteService loginService = (LoginRemoteService)user.GetService(
                DfaService.v1_19.LoginRemoteService);

            codeExample.ScheduleAndDownloadReport(loginService, reportService, args[0], args[1],
                                                  long.Parse(args[2]), args[3]);
        }
        /// <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);
            }
        }
Ejemplo n.º 8
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);
            }
        }