public string GetNextRunParameterValuesXml(DateTime sourceDateTime)
        {
            //calculate parameter values to be used for the first run
            var rptPrms      = Report.GetReportParameters(this.ReportId, this.Parameters, int.Parse(this.OwnerId), this.ClientId, this.Application.Value, this.ReportingEnvironmentId);
            var firstRunPrms =
                from r in rptPrms
                select new ParameterValue
            {
                Name  = r.Name,
                Value = GetParameterValueFromExpression(r, sourceDateTime)
            };

            return(ReportParametersHelper.GetParameterValuesXml(firstRunPrms));
        }
Beispiel #2
0
        public static void AddExecution(Execution execution, byte[] reportData)
        {
            #region validation

            if (execution == null)
            {
                throw new ArgumentNullException("execution");
            }

            if (reportData == null)
            {
                throw new ArgumentNullException("reportData");
            }

            if (!execution.Application.HasValue)
            {
                throw new InvalidOperationException("Application must be set");
            }

            if (execution.Application.Value == ReportingApplication.InCommand &&
                !execution.CompanyId.HasValue)
            {
                throw new InvalidOperationException("CompanyId must be set for InCommand reports");
            }

            if (string.IsNullOrEmpty(execution.OwnerId))
            {
                throw new InvalidOperationException("OwnerId must be set");
            }

            if (string.IsNullOrEmpty(execution.ReportId))
            {
                throw new InvalidOperationException("ReportId must be set");
            }

            if (string.IsNullOrEmpty(execution.FormatId))
            {
                throw new InvalidOperationException("FormatId must be set");
            }

            if (execution.Parameters == null)
            {
            }

            #endregion

            int reportingUserId = int.Parse(execution.OwnerId);
            int reportId        = int.Parse(execution.ReportId);
            int reportFormatId  = int.Parse(execution.FormatId);

            using (var data = new Emdat.InVision.Sql.ReportingDataContext(execution.Application.Value, "Emdat.InVision.ReportContent"))
                using (var info = new Emdat.InVision.Sql.ReportingDataContext(execution.Application.Value))
                {
                    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
                    {
                        //add the new execution record
                        var result = (info.AddExecution(
                                          reportingUserId,
                                          execution.CompanyId,
                                          execution.Description,
                                          execution.ActualCompletionTime,
                                          reportId,
                                          reportFormatId,
                                          ReportParametersHelper.GetParameterValuesXml(execution.Parameters),
                                          false,
                                          execution.ModifiedUser,
                                          execution.ModifiedDate,
                                          (int)execution.ReportingEnvironmentId)).FirstOrDefault();
                        if (result == null || !result.ReportExecutionID.HasValue)
                        {
                            throw new ApplicationException(string.Format("Unable to add execution '{0}'. The procedure did not return a new ID.", execution.Description));
                        }

                        //avoid using a distributed transaction
                        //if the following write fails, the outer transaction will get rolled back
                        using (TransactionScope noTs = new TransactionScope(TransactionScopeOption.Suppress))
                        {
                            //add the report content
                            var rowsAffected = data.SetExecutionData(result.ReportExecutionID.Value, execution.FormatFileType, reportData);
                            if (rowsAffected < 1)
                            {
                                throw new ApplicationException("SetExecutionData failed. No rows were affected");
                            }
                            noTs.Complete();
                        }

                        //complete the outer transaction
                        ts.Complete();
                    }
                }
        }
 public string GetParameterValuesXml()
 {
     return(ReportParametersHelper.GetParameterValuesXml(this.Parameters));
 }