private static List <Emdat.InVision.SSRS.ParameterValue> GetActualParameterValuesFromXml(string xml, string reportPath, DateTime?sourceDate) { if (!sourceDate.HasValue) { return(null); } using (Emdat.InVision.SSRS.ReportingService2005 ssrs = new Emdat.InVision.SSRS.ReportingService2005()) { //HACK: To get around issues between DEV-DB02 and the DC, use a local user if (0 == string.Compare(System.Configuration.ConfigurationManager.AppSettings["ReportServerUseDefaultCredentials"], "FALSE", StringComparison.OrdinalIgnoreCase)) { ssrs.UseDefaultCredentials = false; ssrs.Credentials = new NetworkCredential( System.Configuration.ConfigurationManager.AppSettings["ReportServerUserName"], System.Configuration.ConfigurationManager.AppSettings["ReportServerPassword"]); } else { ssrs.UseDefaultCredentials = true; } var prmVariables = ReportParametersHelper.GetParameterValuesFromXml(xml); var rptPrms = ssrs.GetReportParameters(reportPath, null, true, null, null); return ((from r in rptPrms where r.PromptUser //only care about non-internal params join p in prmVariables on r.Name equals p.Name into rpGroup from rp in rpGroup.DefaultIfEmpty(new Emdat.InVision.SSRS.ParameterValue { Name = r.Name, Value = r.DefaultValues != null && r.DefaultValues.Length > 0 ? r.DefaultValues[0] : null }) select new Emdat.InVision.SSRS.ParameterValue { Name = r.Name, Value = GetParameterValueFromExpression(r, rp, sourceDate.Value) }) .ToList()); } }
public static void CompleteExecution(ReportExecution execution) { #region logging execution.Log(TraceEventType.Verbose, "BEGIN CompleteExecution()"); #endregion try { int executionId = int.Parse(execution.Id); if (execution.State != ReportExecutionStateEnum.Failed && execution.State != ReportExecutionStateEnum.Succeeded) { throw new InvalidOperationException(string.Format("Execution {0} cannot be completed from its current state: {1}", executionId, execution.State)); } if (execution.State == ReportExecutionStateEnum.Succeeded && execution.Data == null) { throw new InvalidOperationException(string.Format("Execution {0} is in the 'Succeeded' state but it does not have any data", executionId)); } using (ReportingDataContext content = new ReportingDataContext("Emdat.InVision.ReportContent")) using (ReportingDataContext data = new ReportingDataContext()) { //only update content if the data has been set if (execution.State == ReportExecutionStateEnum.Succeeded && execution.Data != null) { #region logging execution.Log( TraceEventType.Verbose, "Setting execution data (fileType={0}, dataLength={1})", execution.FileType, execution.Data != null ? execution.Data.Length : 0); #endregion try { //save the report data var result = content.SetExecutionData(executionId, execution.FileType, execution.Data); if (result < 1) { throw new ApplicationException(string.Format("The execution data could not be set: {0}", executionId)); } } catch (Exception ex) { //TFS #13667: retry if there are problems saving the report content execution.Log(TraceEventType.Warning, "Exception saving report content: {0}", ex.Message); execution.Log(TraceEventType.Information, "{0}", ex); execution.Error = ex; execution.ErrorCount++; data.SetExecutionRetry( executionId, execution.Name, execution.StartTime, execution.EndTime, execution.ErrorDescription, execution.ErrorCode.HasValue ? (int?)execution.ErrorCode.Value : null, execution.ErrorCount, execution.ScheduledRunTime, "SYSTEM", DateTime.Now); return; } } //only fail if success or the error code is set, otherwise, retry if (execution.State == ReportExecutionStateEnum.Succeeded || execution.ErrorCode.HasValue) { string nextPrmsXml = ReportParametersHelper.GetParameterValuesXml(execution.NextScheduledRunParameters); #region logging execution.Log( TraceEventType.Verbose, "Setting execution status (name={0}, startTime={1:s}, endTime={2:s}, state={3}, errorCode={4}, errorCount={5}, usedHistory={6}, nextRun={7:s}, nextPrms={8}, report={9}, subscription={10}, format={11})", execution.Name, execution.StartTime, execution.EndTime, execution.State, execution.ErrorCode, execution.ErrorCount, !string.IsNullOrEmpty(execution.HistoryId), execution.NextScheduledRunTime, nextPrmsXml, execution.ReportId, execution.SubscriptionId, execution.FormatId); #endregion //update execution state data.SetExecutionStatus( reportExecutionID: executionId, name: execution.Name, startDate: execution.StartTime, endDate: execution.EndTime, reportExecutionStatusID: (int)execution.State, errorDescription: execution.ErrorDescription, errorCount: execution.ErrorCount, reportExecutionErrorID: execution.ErrorCode.HasValue ? (int?)execution.ErrorCode.Value : null, usedHistory: !string.IsNullOrEmpty(execution.HistoryId), nextExecutionDate: execution.NextScheduledRunTime, nextExecutionParameters: nextPrmsXml, nextExecutionReportID: execution.ReportId, nextExecutionSubscriptionID: execution.SubscriptionId, nextExecutionFormatID: execution.FormatId, modifiedUser: "******", modifiedDate: DateTime.Now); } else { #region logging execution.Log( TraceEventType.Verbose, "Setting execution retry (name={0}, startTime={1:s}, endTime={2:s}, state={3}, errorCode={4}, errorCount={5}, run={6})", execution.Name, execution.StartTime, execution.EndTime, execution.State, execution.ErrorCode, execution.ErrorCount, execution.ScheduledRunTime); #endregion //retry data.SetExecutionRetry( executionId, execution.Name, execution.StartTime, execution.EndTime, execution.ErrorDescription, execution.ErrorCode.HasValue ? (int?)execution.ErrorCode.Value : null, execution.ErrorCount, execution.ScheduledRunTime, "SYSTEM", DateTime.Now); } } } #region logging finally { execution.Log(TraceEventType.Verbose, "END CompleteExecution()"); } #endregion }