예제 #1
0
        /// <summary>
        /// Genererates a snapshot report
        /// </summary>
        /// <param name="reportPath">The report path</param>
        /// <param name="reportParameters">The report default params</param>
        /// <returns>The snapshot history id</returns>
        private string RunSnapshotReport(string reportPath, RS.ReportParameter[] parameters)
        {
            string historyID = null;

            RS.Warning[] warnings = null;
            RS.ScheduleDefinitionOrReference schedule = null;

            RS.ReportingService2005 managementProxy = new RS.ReportingService2005();
            managementProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;

            // Check the execution options of the report (live or snapshot)
            RS.ExecutionSettingEnum execitionOption = managementProxy.GetExecutionOptions(reportPath, out schedule);

            if (execitionOption == RS.ExecutionSettingEnum.Live)
            {
                throw new ApplicationException(String.Format("Report {0} is not configured for snapshot execution", reportPath));
            }

            // All parameters have to be assigned default values before snapshot is generated
            if (parameters != null)
            {
                managementProxy.SetReportParameters(reportPath, parameters);
            }

            // Create the report snapshot
            managementProxy.UpdateReportExecutionSnapshot(reportPath);

            // Check if the report is configured to keep snapshots in history
            bool keepExecutionShapshots = false;
            bool result = managementProxy.GetReportHistoryOptions(reportPath, out keepExecutionShapshots, out schedule);

            if (keepExecutionShapshots)
            {
                // history is automatically created, get the list of history runs
                RS.ReportHistorySnapshot[] history = managementProxy.ListReportHistory(reportPath);
                // Need to sort by date since history runs may not be chronologically sorted
                Array.Sort(history, CompareReportHistoryByDate);
                historyID = history[history.Length - 1].HistoryID; //grab the last history run
            }
            else
            {
                // explicitly create history snapshot
                historyID = managementProxy.CreateReportHistorySnapshot(reportPath, out warnings);
            }

            return(historyID);
        }
예제 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            bool   forRendering = false;
            string historyID    = null;

            RS.ParameterValue[]        values      = null;
            RS.DataSourceCredentials[] credentials = null;
            string reportPath = "/AdventureWorks Sample Reports/Employee Sales Summary";

            // parameters for Employee Sales Summary report
            RS.ReportingService2005 managementProxy = new RS.ReportingService2005();
            managementProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
            RS.ReportParameter[] parameters = managementProxy.GetReportParameters(reportPath, historyID, forRendering, values, credentials);

            parameters[0].Name             = "ReportMonth";
            parameters[0].DefaultValues[0] = "12";
            parameters[1].Name             = "ReportYear";
            parameters[1].DefaultValues[0] = "2003";
            parameters[2].Name             = "EmpID";
            parameters[2].DefaultValues    = new string[] { "288" };
            historyID = RunSnapshotReport(reportPath, parameters);
        }