Пример #1
0
 private static void LoadModelWithEmailValues(ReportSchedulerModel model, EmailDeliverySettings ds)
 {
     string addresses;
     string subject;
     string comment;
     ds.TryGetToValue(out addresses);
     ds.TryGetSubjectValue(out subject);
     ds.TryGetCommentValue(out comment);
     model.EmailAddresses = addresses;
     model.Subject = subject;
     model.Comment = comment;
 }
Пример #2
0
        private static ReportSchedulerModel CreateReportSchedulerModel(IReportingClient reportingClient, string reportUiCulture,
                                                                       Report report, SubscriptionDetails subscriptionDetails)
        {
            var subscriptionParameters = reportingClient.GetParameters(report.Id, DefaultReportDataSouce, subscriptionDetails.Parameters);
            bool endDateSpecified = subscriptionDetails.EndDateTime != DateTime.MinValue;
            var model = new ReportSchedulerModel
            {
                ReportId = report.Id,
                ScheduleId = subscriptionDetails.ScheduleId,
                ReportUiCulture = reportUiCulture,
                ReportName = report.Name,
                Description = subscriptionDetails.Description,
                Parameters = new ReportParameters(subscriptionParameters, true),
                ParametersView = DynamicParameters,
                ReportOutputType =
                    ReportOutputTypeFromDeliverySettings(
                        subscriptionDetails.DeliverySettings),
                ReportFrequency = ReportFrequencyFromScheduleDefinition(subscriptionDetails.ScheduleDefinition),
                ScheduledTime = subscriptionDetails.StartDateTime.ToShortTimeString(),
                StartDate = subscriptionDetails.StartDateTime.ToShortDateString(),
                EndDateSpecified = endDateSpecified,
                ReportDestination =
                    ReportDestinationFromDeliverySettings(
                        subscriptionDetails.DeliverySettings)
            };

            if (model.ReportFrequency == ReportFrequency.Weekly)
            {
                model.Weekday = WeeklyRecurrencePatternFromScheduleDefintion(subscriptionDetails.ScheduleDefinition);
            }

            if (endDateSpecified) model.EndDate = subscriptionDetails.EndDateTime.ToShortDateString();

            if (subscriptionDetails.DeliverySettings.ReportDestination == ReportDestination.FileShare)
            {
                LoadModelWithFileShareValues(model, subscriptionDetails.DeliverySettings.ToFileShareSettings());
            }
            else
            {
                LoadModelWithEmailValues(model, subscriptionDetails.DeliverySettings.ToEmailSettings());
            }

            return model;
        }
Пример #3
0
 private static void LoadModelWithFileShareValues(ReportSchedulerModel model, FileShareDeliverySettings ds)
 {
     string location;
     string userName;
     ds.TryGetPathValue(out location);
     ds.TryGetUserNameValue(out userName);
     model.Location = location;
     model.UserName = userName;
 }
Пример #4
0
        private static DeliverySettings DeliverySettingsFromReportSchedulerModel(ReportSchedulerModel model)
        {
            DeliverySettings deliverySettings;

            Debug.Assert(model.ReportOutputType != null, "model.ReportOutputType Should not be null");
            ReportOutputType reportOutputType = model.ReportOutputType.Value;

            if (model.ReportDestination == ReportDestination.Email)
            {
                deliverySettings = new EmailDeliverySettings(FormatEmailAddresses(model.EmailAddresses), null, null, null,
                                                             reportOutputType, IncludeReport.Yes,
                                                             EmailPriority.Normal, model.Subject,
                                                             model.Comment, IncludeLink.No);
            }
            else
            {
                deliverySettings = new FileShareDeliverySettings(model.ReportName, true,
                                                                 model.Location, reportOutputType,
                                                                 model.UserName, model.Password,
                                                                 WriteMode.AutoIncrement);
            }

            return deliverySettings;
        }
Пример #5
0
        private static ScheduleDefinition ScheduleDefinitionFromReportSchedulerModel(ReportSchedulerModel model)
        {
            var startDate = DateTime.Parse(model.StartDate, CultureInfo.CurrentCulture);
            var runtTime = DateTime.Parse(model.ScheduledTime, CultureInfo.CurrentCulture);
            var startDateTime = new DateTime(startDate.Year, startDate.Month, startDate.Day,
                                             runtTime.Hour, runtTime.Minute, runtTime.Second, DateTimeKind.Local);

            var recurrencePattern = new WeeklyRecurrence
            {
                WeeksIntervalSpecified = true,
                WeeksInterval = 1,
                DaysOfWeek =
                    model.ReportFrequency == ReportFrequency.Daily
                        ? DailyDaysOfWeek
                        : WeeklyDayOfWeek(model.Weekday)
            };

            var scheduleDefinition = new ScheduleDefinition
            {
                StartDateTime = startDateTime,
                EndDateSpecified = model.EndDateSpecified,
                Item = recurrencePattern
            };

            if (model.EndDateSpecified)
            {
                scheduleDefinition.EndDate = DateTime.Parse(model.EndDate, CultureInfo.CurrentCulture);
            }

            return scheduleDefinition;
        }
Пример #6
0
        private ActionResult ProxyModifyScheduled(ReportSchedulerModel model, IUser user)
        {
            if (model != null)
            {
                using (var reportingClient = _reportingClientFactory.CreateClient(user))
                {
                    string errorMessage;
                    List<ParameterValue> parameterValues = null;

                    try
                    {
                        if (ModelState.IsValid)
                        {
                            Debug.Assert(model.ReportFrequency != null, "model.ReportFrequency != null");
                            string scheduleId;
                            //TODO:Fix this controller, controllers should not be accessing the http context like this
                            parameterValues = Request.Form.ToReportParameters().ToList();
                            if (!string.IsNullOrWhiteSpace(Request.Form["NewSchedule"]))
                            {
                                //This is very poorly designed. Updates and creations should not be handled by the same action
                                //as a result of this design we now have to check permissions inside of an action. Permissions
                                //should always be handled by filters not actions.
                                if(!user.HasPermission(PermissionNames.CanScheduleReports)) return new HttpStatusCodeResult(403);
                                scheduleId = reportingClient.ScheduleReport(
                                    model.ReportId, model.Description,
                                    parameterValues.Concat(
                                        DateTimeRangeParameterArrayForReportFrequency(model.ReportFrequency.Value)),
                                    ScheduleDefinitionFromReportSchedulerModel(model),
                                    DeliverySettingsFromReportSchedulerModel(model));
                            }
                            else
                            {
                                scheduleId = model.ScheduleId;

                                reportingClient.UpdateSubscription(
                                    model.ScheduleId, model.Description,
                                    parameterValues.Concat(
                                        DateTimeRangeParameterArrayForReportFrequency(model.ReportFrequency.Value)),
                                    ScheduleDefinitionFromReportSchedulerModel(model),
                                    DeliverySettingsFromReportSchedulerModel(model));
                            }

                            return RedirectToAction("ScheduledReport", new {scheduleId, reportId = model.ReportId});
                        }

                        errorMessage = GetModelStateErrorMessages();
                    }
                    catch (ReportingLocationException)
                    {
                        errorMessage = Resources.SchedulerReportLocationInvalidErrorMessage;
                    }
                    catch (ReportingUnexpectedException ex)
                    {
                        Log.Error("{0}\n{1}", ex.Message, ex.StackTrace);
                        errorMessage = Resources.SchedulerReportUnexpectedErrorMessage;
                    }
                    catch (HttpRequestValidationException)
                    {
                        errorMessage = Resources.SchedulerReportUnacceptableValueMessage;
                    }
                    
                    try
                    {
                        model.Parameters = new ReportParameters(reportingClient.GetParameters(model.ReportId, DefaultReportDataSouce, parameterValues), true);
                    }
                    catch (HttpRequestValidationException)
                    {
                        model.Parameters = new ReportParameters(reportingClient.GetParameters(model.ReportId, DefaultReportDataSouce, null), true, parameterValues);
                        errorMessage = Resources.SchedulerReportUnacceptableValueMessage;
                    }

                    model.ParametersView = DynamicParameters;
                    SetMessage(model, MessageType.Error, errorMessage);

                    return View("ModifyScheduled", model);
                }
            }

            return View("Scheduled");
        }
Пример #7
0
 public ActionResult ModifyScheduled(IUser user, ReportSchedulerModel model)
 {
     return CallAndTransformErrors(() => ProxyModifyScheduled(model, user), user);
 }
Пример #8
0
        private ActionResult ProxyScheduler(ReportSchedulerModel model, IUser user)
        {
            if (model != null)
            {
                using (var reportingClient = _reportingClientFactory.CreateClient(user))
                {
                    string errorMessage;
                    List<ParameterValue> parameterValues = null;

                    try
                    {
                        parameterValues = Request.Form.ToReportParameters().ToList();

                        if (ModelState.IsValid)
                        {
                            Debug.Assert(model.ReportFrequency != null, "model.ReportFrequency != null");
                            string scheduleId = reportingClient.ScheduleReport(
                                model.ReportId, model.Description,
                                parameterValues.Concat(DateTimeRangeParameterArrayForReportFrequency(model.ReportFrequency.Value)),
                                ScheduleDefinitionFromReportSchedulerModel(model),
                                DeliverySettingsFromReportSchedulerModel(model));

                            return RedirectToAction("ScheduledReport", new { scheduleId, reportId = model.ReportId });
                        }

                        errorMessage = GetModelStateErrorMessages();
                    }
                    catch (ReportingLocationException)
                    {
                        errorMessage = Resources.SchedulerReportLocationInvalidErrorMessage;
                    }
                    catch (ReportingUnexpectedException ex)
                    {
                        Log.Error("{0}\n{1}", ex.Message, ex.StackTrace);
                        errorMessage = Resources.SchedulerReportUnexpectedErrorMessage;
                    }
                    catch (ReportingParameterValueException exception)
                    {
                        switch (exception.ErrorCode)
                        {
                            case ReportingParameterValueException.ErrorCodeEnum.MissingRequiredValue:
                                errorMessage = string.Format(CultureInfo.CurrentCulture, Resources.ReportParameterRequiredError, exception.ParameterPrompt);
                                break;
                            default:
                                errorMessage = Resources.ReportParameterInvalidError;
                                break;
                        }
                    }
                    catch (HttpRequestValidationException)
                    {
                        errorMessage = Resources.SchedulerReportUnacceptableValueMessage;
                    }
                   
                    try
                    {
                        model.Parameters = new ReportParameters(reportingClient.GetParameters(model.ReportId, DefaultReportDataSouce, parameterValues), true);
                    }
                    catch (HttpRequestValidationException)
                    {
                        model.Parameters = new ReportParameters(reportingClient.GetParameters(model.ReportId, DefaultReportDataSouce, null), true, parameterValues);
                        errorMessage = Resources.SchedulerReportUnacceptableValueMessage;
                    }

                    model.ParametersView = DynamicParameters;
                    SetMessage(model, MessageType.Error, errorMessage);

                    return View("Scheduler", model);
                }
            }

            return View("Index");
        }
Пример #9
0
        private ActionResult ProxyScheduler(string reportId, IUser user, string messageType, string messageText)
        {
            using (var reportingClient = _reportingClientFactory.CreateClient(user))
            {
                string reportUiCulture;
                Report report = RetrieveReportForReportId(reportingClient, reportId, DefaultReportDataSouce, out reportUiCulture);
                if (report == null)
                {
                    // Show the user that we encountered an error
                    return View("MissingReport", new MissingReportModel
                    {
                        ReportId = reportId,
                        Error = Resources.ReportsViewInvalidReportErrorMessage,
                        Title = Resources.ReportSchedulerViewPageTitle
                    });
                }

                // Show the user the view to schedule the report
                DateTime now = DateTime.Now;
                var reportSchedulerModel = new ReportSchedulerModel
                {
                    ReportId = report.Id,
                    ReportUiCulture = reportUiCulture,
                    ReportName = report.Name,
                    Parameters = new ReportParameters(report.Parameters, true),
                    ParametersView = DynamicParameters,
                    ScheduledTime = new DateTime(now.Year, now.Month, now.Day, 8, 0, 0).ToShortTimeString(),
                    StartDate = now.ToShortDateString(),
                    ReportOutputType = ReportOutputType.Excel,
                    ReportFrequency = ReportFrequency.Daily
                };

                SetMessage(reportSchedulerModel, messageType, messageText);
                return View("Scheduler", reportSchedulerModel);
            }
        }
Пример #10
0
 private static void SetMessage(ReportSchedulerModel model, string messageType, string messageText)
 {
     model.MessageType = messageType;
     model.MessageText = messageText;
 }