public static ReportFormat LoadReportFormat(string id)
        {
            int formatId = int.Parse(id);

#if MOCKUP
#else
            using (var sql = new Emdat.InVision.Sql.ReportingDataContext())
            {
                var formats =
                    from f in sql.GetFormat(formatId)
                    select new ReportFormat
                {
                    Id              = f.ReportFormatID.ToString(),
                    Name            = f.Name,
                    Description     = f.Description,
                    IsActive        = f.IsActive,
                    Value           = f.SSRSFormat,
                    FileExtension   = f.Extension,
                    HttpContentType = f.HTTPContentType,
                    DeviceInfo      = f.SSRSDeviceInfo
                };
                return(formats.FirstOrDefault());
            }
#endif
        }
Ejemplo n.º 2
0
        public static void DeleteSubscription(Subscription subscription)
        {
            //TODO: invalidate cached objects that are related to the specified subscription

            int subscriptionId = int.Parse(subscription.Id);

#if MOCKUP
            //build the subscriptions path
            string path = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["AppDataPathForMockup"], "Subscriptions");

            //find the file
            string file =
                (from f in Directory.GetFiles(path, string.Format("{0}.xml", subscription.Id), SearchOption.AllDirectories)
                 select f)
                .FirstOrDefault();

            if (file != null)
            {
                File.Delete(file);
            }
#else
            using (var sql = new Emdat.InVision.Sql.ReportingDataContext())
            {
                sql.DeleteSubscription(subscriptionId);
            }
#endif
        }
        public static IEnumerable <Category> ListCategories(int userId, ReportingApplication application)
        {
#if MOCKUP
            XDocument doc              = XDocument.Load(Path.Combine(System.Configuration.ConfigurationManager.AppSettings["AppDataPathForMockup"], "Reports.xml"));
            XElement  root             = doc.Element("Reports");
            var       reportCategories =
                from e in root.Elements("Report")
                orderby !string.IsNullOrEmpty(e.Attribute("Category_UISortOrder").Value) ? (int)e.Attribute("Category_UISortOrder") : int.MaxValue
                group e by(string) e.Attribute("Category") into categoryGroup
                select new Category
            {
                Name = !string.IsNullOrEmpty(categoryGroup.Key) ? categoryGroup.Key : "Miscellaneous Reports"
            };

            return(reportCategories);
#else
            using (var sql = new Emdat.InVision.Sql.ReportingDataContext(application))
            {
                var reportCategories =
                    from r in sql.ListReports(userId)
                    orderby r.CategorySortOrder
                    group r by r.CategoryName into categoryGroup
                    select new Category
                {
                    Name = !string.IsNullOrEmpty(categoryGroup.Key) ? categoryGroup.Key : "Miscellaneous Reports"
                };

                return(reportCategories.ToList());
            }
#endif
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads the execution data.
        /// </summary>
        /// <param name="execution">The execution.</param>
        /// <returns></returns>
        public static byte[] LoadExecutionData(Execution execution)
        {
            if (execution == null)
            {
                throw new ArgumentNullException("execution");
            }

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

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

            int executionId = int.Parse(execution.Id);

            using (var data = new Emdat.InVision.Sql.ReportingDataContext(execution.Application.Value, "Emdat.InVision.ReportContent"))
            {
                var result = data.GetExecutionData(executionId).FirstOrDefault();
                if (result == null || result.Data == null)
                {
                    throw new KeyNotFoundException(string.Format("Could not find data for report: {0}", executionId));
                }
                return(result.Data);
            }
        }
Ejemplo n.º 5
0
 public static void AddExecution(Subscription subscription, ReportingApplication application)
 {
     using (var sql = new Emdat.InVision.Sql.ReportingDataContext(application))
     {
         sql.AddSubscriptionExecution(int.Parse(subscription.Id), int.Parse(subscription.ReportId), int.Parse(subscription.FormatId), subscription.GetParameterValuesXml());
     }
 }
Ejemplo n.º 6
0
        public static IEnumerable <Category> ListReportsByCategory(int userId, ReportingApplication application)
        {
            using (var sql = new Emdat.InVision.Sql.ReportingDataContext(application))
            {
                var reportCategories =
                    from r in sql.ListReports(userId)
                    orderby r.CategorySortOrder
                    group r by r.CategoryName into categoryGroup
                    select new Category
                {
                    Name    = !string.IsNullOrEmpty(categoryGroup.Key) ? categoryGroup.Key : "Miscellaneous Reports",
                    Reports =
                        from r in categoryGroup
                        orderby
                        r.SortOrder.HasValue ? r.SortOrder.Value : int.MaxValue,
                    r.Name
                    select new Report
                    {
                        Id                       = r.ReportID.ToString(),
                        Name                     = r.Name,
                        Description              = r.Description,
                        ReportingServicesPath    = r.ReportPath,
                        Category                 = categoryGroup.Key,
                        ReportParametersUrl      = r.ReportParametersURL,
                        ReportingEnvironmentId   = (ReportingEnvironmentEnum)r.EnvironmentID,
                        ReportingEnvironmentName = r.EnvironmentName
                    }
                };

                return(reportCategories.ToList());
            }
        }
Ejemplo n.º 7
0
        public static IEnumerable <ExecutionStatus> ListExecutionStatuses()
        {
#if MOCKUP
            return(new ExecutionStatus[]
            {
                new ExecutionStatus
                {
                    Id = "1",
                    Name = "Pending",
                    Description = ""
                },
                new ExecutionStatus
                {
                    Id = "2",
                    Name = "Queued",
                    Description = ""
                },
                new ExecutionStatus
                {
                    Id = "3",
                    Name = "Running",
                    Description = ""
                },
                new ExecutionStatus
                {
                    Id = "4",
                    Name = "Succeeded",
                    Description = ""
                },
                new ExecutionStatus
                {
                    Id = "5",
                    Name = "Error",
                    Description = ""
                }
            });
#else
            if (_statuses == null ||
                _expireTime < DateTime.Now)
            {
                using (var sql = new Emdat.InVision.Sql.ReportingDataContext())
                {
                    var statuses =
                        from s in sql.ListExecutionStatuses()
                        select new ExecutionStatus
                    {
                        Id          = (ExecutionStatusEnum)s.ReportExecutionStatusID,
                        Name        = s.Name,
                        Description = s.Description
                    };
                    _statuses   = statuses.ToList();
                    _expireTime = DateTime.Now.AddMinutes(5);
                }
            }
            return(_statuses);
#endif
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        public static Report LoadReport(string reportId, int userId, int?clientId, ReportingApplication application, ReportingEnvironmentEnum environment)
        {
            #region input validation

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

            int reportIdValue = int.Parse(reportId);

            #endregion

            using (var sql = new Emdat.InVision.Sql.ReportingDataContext(application))
            {
                Report report =
                    (from r in sql.GetReport(reportIdValue, (int)environment)
                     select new Report
                {
                    Id = r.ReportID.ToString(),
                    Name = r.Name,
                    Description = r.Description,
                    ReportingServicesPath = r.ReportPath,
                    Category = r.CategoryName,
                    ReportParametersUrl = r.ReportParametersURL,
                    Options = r.Options
                })
                    .FirstOrDefault();
                if (report == null)
                {
                    throw new KeyNotFoundException(string.Format("The report could not be found: {0}", reportId));
                }
                else
                {
                    if (ReportingApplication.InQuiry == application && clientId.HasValue)
                    {
                        var clientLabels = ClientLabels.LoadClientLabels(clientId.Value, application);
                        clientLabels.ApplyToReport(report);
                    }
                }
                return(report);
            }
        }
Ejemplo n.º 10
0
        public static void DeleteExecution(Execution execution)
        {
            int executionId = int.Parse(execution.Id);

#if MOCKUP
            //build the subscriptions path
            string path = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["AppDataPathForMockup"], "Executions");

            //find the file
            string file =
                (from f in Directory.GetFiles(path, string.Format("{0}.xml", execution.Id), SearchOption.AllDirectories)
                 select f)
                .FirstOrDefault();

            if (file != null)
            {
                File.Delete(file);
            }

            //find the data file
            string dataPath = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["AppDataPathForMockup"], "ExecutionData");

            string dataFile =
                (from f in Directory.GetFiles(path, string.Format("{0}.*", execution.Id), SearchOption.AllDirectories)
                 select f)
                .FirstOrDefault();

            if (dataFile != null)
            {
                File.Delete(file);
            }
#else
            using (var data = new Emdat.InVision.Sql.ReportingDataContext("Emdat.InVision.ReportContent"))
                using (var info = new Emdat.InVision.Sql.ReportingDataContext())
                {
                    //transaction here would be distributed (not worth it)
                    //TODO: need a back-end process cleaning up "orphaned" executions
                    info.DeleteExecution(executionId);
                    data.DeleteExecutionData(executionId);
                }
#endif
        }
Ejemplo n.º 11
0
 public static IEnumerable <Report> ListReports(int userId, ReportingApplication application)
 {
     using (var sql = new Emdat.InVision.Sql.ReportingDataContext(application))
     {
         var reports =
             from r in sql.ListReports(userId)
             orderby r.CategorySortOrder, r.SortOrder
             select new Report
         {
             Id                       = r.ReportID.ToString(),
             Name                     = r.Name,
             Description              = r.Description,
             ReportingServicesPath    = r.ReportPath,
             Category                 = r.CategoryName,
             ReportParametersUrl      = r.ReportParametersURL,
             ReportingEnvironmentId   = (ReportingEnvironmentEnum)r.EnvironmentID,
             ReportingEnvironmentName = r.EnvironmentName
         };
         return(reports.ToList());
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Loads the execution data into the specified stream.
        /// </summary>
        /// <param name="execution">The execution.</param>
        /// <param name="stream">The stream.</param>
        public static void LoadExecutionData(Execution execution, Stream stream)
        {
            if (execution == null)
            {
                throw new ArgumentNullException("execution");
            }

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

            if (!stream.CanWrite)
            {
                throw new InvalidOperationException("Stream is not writable");
            }

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

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

            int executionId = int.Parse(execution.Id);

            using (var data = new Emdat.InVision.Sql.ReportingDataContext(execution.Application.Value, "Emdat.InVision.ReportContent"))
            {
                var result = data.GetExecutionData(executionId, stream);
                if (result == null)
                {
                    throw new KeyNotFoundException(string.Format("Could not find data for report: {0}", executionId));
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Loads the execution data into the specified stream.
        /// </summary>
        /// <param name="execution">The execution.</param>
        public static System.Data.IDataReader LoadExecutionDataReader(Execution execution)
        {
            if (execution == null)
            {
                throw new ArgumentNullException("execution");
            }

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

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

            int executionId = int.Parse(execution.Id);

            using (var data = new Emdat.InVision.Sql.ReportingDataContext(execution.Application.Value, "Emdat.InVision.ReportContent"))
            {
                return(data.GetExecutionDataReader(executionId));
            }
        }
 public static ClientLabels LoadClientLabels(int clientId, ReportingApplication application)
 {
     using (var sql = new Emdat.InVision.Sql.ReportingDataContext(application))
     {
         return((from l in sql.GetClientLabels(clientId)
                 select new ClientLabels
         {
             LabelPatientID = l.LabelPatientID,
             LabelPatientName = l.LabelPatientName,
             LabelGender = l.LabelGender,
             LabelBirthdate = l.LabelBirthdate,
             LabelAppointmentDate = l.LabelAppointmentDate,
             LabelOrderNumber = l.LabelOrderNumber,
             LabelPatientLetter = l.LabelPatientLetter,
             LabelUserField1 = l.LabelUserField1,
             LabelUserField2 = l.LabelUserField2,
             LabelUserField3 = l.LabelUserField3,
             LabelUserField4 = l.LabelUserField4,
             LabelUserField5 = l.LabelUserField5,
             LabelBillingUnit = l.LabelBillingUnit,
             LabelDictator = l.LabelDictator
         }).FirstOrDefault());
     }
 }
Ejemplo n.º 15
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();
                    }
                }
        }
Ejemplo n.º 16
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);
            }
        }
Ejemplo n.º 17
0
        public static void AddSubscription(Subscription subscription)
        {
            #region validation

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

            //for InCommand, require a company ID
            if (subscription.Application.Value == ReportingApplication.InCommand &&
                !subscription.CompanyId.HasValue)
            {
                throw new InvalidOperationException("CompanyId is required for InCommand reports");
            }

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

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

            if (subscription.Parameters == null)
            {
                throw new InvalidOperationException("Parameters must be set");
            }

            //TODO: validate the parameters

            if (subscription.Schedule == null)
            {
                throw new InvalidOperationException("Schedule must be set");
            }

            //TODO: validate the schedule

            #endregion

            //set input values for the insert operation
            int reportingUserId = int.Parse(subscription.OwnerId);
            int reportId        = int.Parse(subscription.ReportId);
            int formatId        = int.Parse(subscription.FormatId);

            //get next run info
            NextRunInfo nextRunInfo = subscription.GetNextRunInfo(DateTime.Now);

            using (var sql = new Emdat.InVision.Sql.ReportingDataContext(subscription.Application.Value))
            {
                var result = sql.AddSubscription(
                    reportingUserId,
                    subscription.CompanyId,
                    reportId,
                    subscription.Description,
                    formatId,
                    subscription.IsActive,
                    subscription.GetParameterValuesXml(),
                    subscription.Schedule.GetFrequencyId(),
                    subscription.Schedule.GetFrequencyInterval(),
                    subscription.Schedule.GetFrequencyRecurrenceFactor(),
                    subscription.Schedule.GetFrequencyRelativeInterval(),
                    string.Format("{0:00}{1:00}{2:00}",
                                  subscription.Schedule.StartTime.Hours,
                                  subscription.Schedule.StartTime.Minutes,
                                  subscription.Schedule.StartTime.Seconds),
                    string.Format("{0:00}{1:00}{2:00}",
                                  subscription.Schedule.EndTime.Hours,
                                  subscription.Schedule.EndTime.Minutes,
                                  subscription.Schedule.EndTime.Seconds),
                    nextRunInfo.Date,
                    nextRunInfo.ParametersAsXml,
                    subscription.ModifiedUser,
                    DateTime.Now,
                    subscription.NotifyOnScreen,
                    subscription.NotifyEmail,
                    subscription.NotificationEmail,
                    subscription.Options,
                    (int)subscription.ReportingEnvironmentId).FirstOrDefault();
                if (result == null || !result.ReportSubscriptionID.HasValue)
                {
                    throw new ApplicationException("The subscription could not be added. The procedure did not return a result.");
                }
            }
        }
Ejemplo n.º 18
0
        public static void UpdateSubscription(Subscription subscription)
        {
            #region validation

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

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

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

            if (subscription.Parameters == null)
            {
                throw new InvalidOperationException("Parameters must be set");
            }

            if (subscription.Schedule == null)
            {
                throw new InvalidOperationException("Schedule must be set");
            }

            #endregion

            //set input values for the insert operation
            int reportingUserId = int.Parse(subscription.OwnerId);
            int subscriptionId  = int.Parse(subscription.Id);
            int reportId        = int.Parse(subscription.ReportId);
            int formatId        = int.Parse(subscription.FormatId);

            //get next run info
            NextRunInfo nextRunInfo = subscription.GetNextRunInfo(DateTime.Now);

            //load old values
            Subscription oldSubscription = LoadSubscription(
                subscription.Id,
                reportingUserId,
                subscription.Application.Value);

            //only change the properties that are not "read-only"
            oldSubscription.Application  = subscription.Application;
            oldSubscription.FormatId     = subscription.FormatId;
            oldSubscription.IsActive     = subscription.IsActive;
            oldSubscription.ModifiedDate = DateTime.Now;
            oldSubscription.ModifiedUser = subscription.ModifiedUser;
            oldSubscription.Description  = subscription.Description;
            oldSubscription.Parameters   = subscription.Parameters;
            oldSubscription.Schedule     = subscription.Schedule;

            using (var sql = new Emdat.InVision.Sql.ReportingDataContext(subscription.Application.Value))
            {
                int result = sql.EditSubscription(
                    reportingUserId,
                    subscriptionId,
                    reportId,
                    subscription.Description,
                    formatId,
                    subscription.IsActive,
                    subscription.GetParameterValuesXml(),
                    subscription.Schedule.GetFrequencyId(),
                    subscription.Schedule.GetFrequencyInterval(),
                    subscription.Schedule.GetFrequencyRecurrenceFactor(),
                    subscription.Schedule.GetFrequencyRelativeInterval(),
                    string.Format("{0:00}{1:00}{2:00}",
                                  subscription.Schedule.StartTime.Hours,
                                  subscription.Schedule.StartTime.Minutes,
                                  subscription.Schedule.StartTime.Seconds),
                    string.Format("{0:00}{1:00}{2:00}",
                                  subscription.Schedule.EndTime.Hours,
                                  subscription.Schedule.EndTime.Minutes,
                                  subscription.Schedule.EndTime.Seconds),
                    nextRunInfo.Date,
                    nextRunInfo.ParametersAsXml,
                    subscription.ModifiedUser,
                    DateTime.Now,
                    subscription.NotifyOnScreen,
                    subscription.NotifyEmail,
                    subscription.NotificationEmail,
                    subscription.Options,
                    (int)subscription.ReportingEnvironmentId);
                if (result < 1)
                {
                    throw new ApplicationException("The subscription was not updated. No rows were modified.");
                }
            }
        }
        public static IEnumerable <ReportFormat> ListReportFormats()
        {
#if MOCKUP
            return(new ReportFormat[]
            {
                new ReportFormat
                {
                    Id = "1",
                    Name = "Comma Separated Values",
                    FileExtension = "csv",
                    Description = "",
                    IsActive = true,
                    Value = "CSV"
                },
                new ReportFormat
                {
                    Id = "2",
                    Name = "HTML",
                    FileExtension = "html",
                    Description = "",
                    IsActive = true,
                    Value = "HTML"
                },
                new ReportFormat
                {
                    Id = "3",
                    Name = "Adobe PDF",
                    FileExtension = "pdf",
                    Description = "",
                    IsActive = true,
                    Value = "PDF"
                },
                new ReportFormat
                {
                    Id = "1",
                    Name = "XML",
                    FileExtension = "xml",
                    Description = "",
                    IsActive = true,
                    Value = "XML"
                }
            });
#else
            if (_formats == null ||
                _expireTime < DateTime.Now)
            {
                using (var sql = new Emdat.InVision.Sql.ReportingDataContext())
                {
                    var formats =
                        from f in sql.ListFormats()
                        where f.IsActive
                        orderby f.Name
                        select new ReportFormat
                    {
                        Id              = f.ReportFormatID.ToString(),
                        Name            = f.Name,
                        Description     = f.Description,
                        IsActive        = f.IsActive,
                        Value           = f.SSRSFormat,
                        FileExtension   = f.Extension,
                        HttpContentType = f.HTTPContentType,
                        DeviceInfo      = f.SSRSDeviceInfo
                    };
                    _formats    = formats.ToList();
                    _expireTime = DateTime.Now.AddMinutes(5);
                }
            }
            return(_formats);
#endif
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
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);
        }