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));
        }
Esempio n. 2
0
        public static Execution LoadExecution(string id, int userId, ReportingApplication application)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            int executionId = int.Parse(id);

            if (executionId < 1)
            {
                throw new ArgumentOutOfRangeException("id");
            }

            using (var sql = new Emdat.InVision.Sql.ReportingDataContext(application))
            {
                var result =
                    (from e in sql.GetExecution(userId, executionId)
                     select new Execution
                {
                    Application = application,
                    OwnerId = userId.ToString(),
                    Id = e.ReportExecutionID.ToString(),
                    Description = e.Name,
                    SubscriptionId = e.ReportSubscriptionID.ToString(),
                    ReportingEnvironmentId = (ReportingEnvironmentEnum)e.EnvironmentID,
                    ReportingEnvironmentName = e.EnvironmentName,
                    ReportId = e.ReportID.ToString(),
                    StatusId = (ExecutionStatusEnum)e.ReportExecutionStatusID,
                    FormatId = e.ReportFormatID.ToString(),
                    Parameters = ReportParametersHelper.GetParameterValuesFromXml(e.Parameters),
                    ActualCompletionTime = e.EndDate,
                    ActualStartTime = e.StartDate,
                    ExpirationDate = e.ExpirationDate,
                    ScheduledRunTime = e.ScheduledStartDate,
                    ModifiedDate = e.ModifiedDate,
                    ModifiedUser = e.ModifiedUser,
                    ErrorName = e.ErrorName,
                    ErrorDescription = e.ErrorDescription
                })
                    .FirstOrDefault();
                if (result == null)
                {
                    throw new KeyNotFoundException(string.Format("The report execution could not be found for user {0}: {1}", userId, executionId));
                }
                return(result);
            }
        }
Esempio n. 3
0
        public static IEnumerable <Execution> ListExecutions(int userId, int?companyId, ReportingApplication application, ICacheProvider cache, bool forceRefresh)
        {
            IEnumerable <Execution> executions = null;

            #region caching

            string cacheKey = string.Format("Emdat.InVision.Execution.ListExecutions({0},{1},{2})", userId, companyId, application);
            if (!forceRefresh && cache != null)
            {
                executions = cache[cacheKey] as IEnumerable <Execution>;
            }

            #endregion

            if (executions == null)
            {
                using (var sql = new Emdat.InVision.Sql.ReportingDataContext(application))
                {
                    var executionsQuery =
                        from e in sql.ListExecutions(userId, companyId)
                        let prms = ReportParametersHelper.GetParameterValuesFromXml(e.Parameters)
                                   //let startDatePrm = (from p in prms where p.Name == "Start_Date" select p.Value).FirstOrDefault()
                                   //let endDatePrm = (from p in prms where p.Name == "End_Date" select p.Value).FirstOrDefault()
                                   where e.ReportExecutionStatusID != (int)ExecutionStatusEnum.Running
                                   select new Execution
                    {
                        Application              = application,
                        OwnerId                  = e.OwnerID.ToString(),
                        OwnerName                = string.Format("{0}, {1}", e.OwnerNameLast, e.OwnerNameFirst),
                        OwnerUsername            = e.OwnerUsername,
                        Id                       = e.ReportExecutionID.ToString(),
                        ActualCompletionTime     = e.EndDate,
                        ActualStartTime          = e.StartDate,
                        Description              = e.Name, //string.Format("{0} ({1} - {2})", e.Name, startDatePrm, endDatePrm),
                        ExpirationDate           = e.ExpirationDate,
                        FormatId                 = e.ReportFormatID.ToString(),
                        Parameters               = prms,
                        ReportingEnvironmentId   = (ReportingEnvironmentEnum)e.EnvironmentID,
                        ReportingEnvironmentName = e.EnvironmentName,
                        ReportId                 = e.ReportID.ToString(),
                        ScheduledRunTime         = e.ScheduledStartDate,
                        SubscriptionId           = e.ReportSubscriptionID.ToString(),
                        StatusId                 = (ExecutionStatusEnum)e.ReportExecutionStatusID,
                        ErrorName                = e.ErrorName,
                        ErrorDescription         = e.ErrorDescription
                    };
                    executions = executionsQuery.ToList();

                    #region caching

                    //add to cache
                    if (cache != null)
                    {
                        cache.Add(cacheKey, executions, CacheDuration);
                    }

                    #endregion
                }
            }
            return(executions);
        }
Esempio n. 4
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));
 }
Esempio n. 6
0
        public static Subscription LoadSubscription(string id, int userId, ReportingApplication application)
        {
            #region validation

            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            int subscriptionId = int.Parse(id);

            if (subscriptionId < 1)
            {
                throw new ArgumentOutOfRangeException("id");
            }

            #endregion

            using (var sql = new Emdat.InVision.Sql.ReportingDataContext(application))
            {
                var subscription =
                    (from s in sql.GetSubscription(subscriptionId)
                     let next = sql.GetSubscriptionNextExecution(s.ReportSubscriptionID).FirstOrDefault()
                                let prev = sql.GetSubscriptionPreviousExecution(s.ReportSubscriptionID).FirstOrDefault()
                                           let notifications = sql.GetSubscriptionNotifications(s.ReportSubscriptionID)
                                                               let notificationEmail =
                         (notifications.Any(n => n.ReportNotificationTypeID == 2) && !String.IsNullOrEmpty(notifications.FirstOrDefault(n => n.ReportNotificationTypeID == 2).ReportNotificationOptions)) ?
                         XDocument.Parse(notifications.FirstOrDefault(n => n.ReportNotificationTypeID == 2).ReportNotificationOptions).Element("NotificationOptions").Element("EmailAddress").Value : string.Empty
                         let schedule = new Schedule(
                             s.ScheduleFrequencyID,
                             s.FrequencyInterval,
                             s.FrequencyRecurrenceFactor,
                             s.FrequencyRelativeInterval,
                             next != null ? next.ScheduledStartDate : prev != null ? prev.ScheduledStartDate : null,
                             s.StartTime,
                             s.EndTime)
                                        select new Subscription
                {
                    Application = application,
                    OwnerId = userId.ToString(),
                    Description = s.Name,
                    FormatId = s.ReportFormatID.ToString(),
                    Id = s.ReportSubscriptionID.ToString(),
                    IsActive = s.IsActive,
                    ErrorDescription = prev != null ? prev.ReportExecutionErrorDescription : null,
                    LastRunEndTime = prev != null ? prev.EndDate : null,
                    LastRunScheduledTime = prev != null ? prev.ScheduledStartDate : null,
                    LastRunStartTime = prev != null ? prev.StartDate : null,
                    ModifiedDate = s.ModifiedDate,
                    ModifiedUser = s.ModifiedUser,
                    NextRunTime = next != null ? next.ScheduledStartDate : null,
                    Parameters = ReportParametersHelper.GetParameterValuesFromXml(s.Parameters),
                    ReportingEnvironmentId = (ReportingEnvironmentEnum)s.EnvironmentID,
                    ReportingEnvironmentName = s.EnvironmentName,
                    ReportId = s.ReportID.ToString(),
                    NotifyOnScreen = notifications.Any(n => n.ReportNotificationTypeID == 1),
                    NotifyEmail = notifications.Any(n => n.ReportNotificationTypeID == 2),
                    NotificationEmail = notificationEmail,
                    ScheduleOptionId = next != null && next.ScheduledStartDate.HasValue ? ScheduleOptionEnum.Schedule :
                                       schedule.RecurrenceOption == ScheduleRecurrence.Once ? ScheduleOptionEnum.QueueNow :
                                       false == s.IsActive ? ScheduleOptionEnum.Schedule :
                                       ScheduleOptionEnum.QueueNow,
                    Schedule = schedule,
                    StatusId = s.IsActive ? GetSubscriptionStatus(prev, next) : ExecutionStatusEnum.Inactive,
                    Options = s.Options
                }).FirstOrDefault();
                if (subscription == null)
                {
                    throw new KeyNotFoundException(string.Format("The report subscription could not be found: {0}", id));
                }
                return(subscription);
            }
        }
Esempio n. 7
0
        public static IEnumerable <Subscription> ListSubscriptions(int userId, int?companyId, ReportingApplication application, ICacheProvider cache, bool forceRefresh)
        {
            IEnumerable <Subscription> subscriptions = null;

            #region caching

            string cacheKey = string.Format("Emdat.InVision.Subscription.ListSubscriptions({0},{1},{2})", userId, companyId, application);
            if (!forceRefresh && cache != null)
            {
                subscriptions = cache[cacheKey] as IEnumerable <Subscription>;
            }

            #endregion

            if (subscriptions == null)
            {
                using (var sql = new Emdat.InVision.Sql.ReportingDataContext(application))
                {
                    var subscriptionsQuery =
                        from s in sql.ListSubscriptions(userId, companyId)
                        let next                       = sql.GetSubscriptionNextExecution(s.ReportSubscriptionID).FirstOrDefault()
                                              let prev = sql.GetSubscriptionPreviousExecution(s.ReportSubscriptionID).FirstOrDefault()
                                                         select new Subscription
                    {
                        Application              = application,
                        OwnerId                  = s.OwnerID.ToString(),
                        OwnerName                = string.Format("{0}, {1}", s.OwnerNameLast, s.OwnerNameFirst),
                        OwnerUsername            = s.OwnerUsername,
                        Description              = s.Name,
                        FormatId                 = s.ReportFormatID.ToString(),
                        Id                       = s.ReportSubscriptionID.ToString(),
                        IsActive                 = s.IsActive,
                        ErrorDescription         = prev != null ? prev.ReportExecutionErrorDescription : null,
                        LastRunEndTime           = prev != null ? prev.EndDate : null,
                        LastRunScheduledTime     = prev != null ? prev.ScheduledStartDate : null,
                        LastRunStartTime         = prev != null ? prev.StartDate : null,
                        ModifiedDate             = s.ModifiedDate,
                        ModifiedUser             = s.ModifiedUser,
                        NextRunTime              = next != null ? next.ScheduledStartDate : null,
                        Parameters               = ReportParametersHelper.GetParameterValuesFromXml(s.Parameters),
                        ReportingEnvironmentId   = (ReportingEnvironmentEnum)s.EnvironmentID.GetValueOrDefault(1),
                        ReportingEnvironmentName = s.EnvironmentName,
                        ReportId                 = s.ReportID.ToString(),
                        //								ScheduleOption = ???,
                        Schedule = new Schedule(
                            s.ScheduleFrequencyID,
                            s.FrequencyInterval,
                            s.FrequencyRecurrenceFactor,
                            s.FrequencyRelativeInterval,
                            next != null ? next.ScheduledStartDate : null,
                            s.StartTime,
                            s.EndTime),
                        StatusId = s.IsActive ? GetSubscriptionStatus(prev, next) : ExecutionStatusEnum.Inactive,
                        Options  = s.Options
                    };
                    subscriptions = subscriptionsQuery.ToList();

                    #region caching

                    //add to cache
                    if (cache != null)
                    {
                        cache.Add(cacheKey, subscriptions, CacheDuration);
                    }

                    #endregion
                }
            }
            return(subscriptions);
        }