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); } }
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); }
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); } }
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); }