Пример #1
0
        private static string RequestedReport(ReportActionModel model)
        {
            if (!string.IsNullOrWhiteSpace(model.DataSource))
            {
                string[] reportIdParts = SplitReportId(model.ReportId);
                reportIdParts[DataSourcePartIndex] = model.DataSource;

                return string.Join(ReportIdPartSeperatorString, reportIdParts);
            }

            return model.ReportId;
        }
Пример #2
0
 public ActionResult Runner(IUser user, ReportActionModel model)
 {
     return CallAndTransformErrors(() => ProxyRunner(model, user), user);
 }
Пример #3
0
        private ActionResult ProxyRunner(ReportActionModel model, IUser user)
        {
            if (model != null && ModelState.IsValid)
            {
                using (var reportingClient = _reportingClientFactory.CreateClient(user))
                {
                    string errorMessage;
                    List<ParameterValue> parameterValues = null;
                    bool useParameterValues;

                    try
                    {
                        //This debug assert is needed prevent resharper from flagging model.ReportOutputType.Value as a possible exception
                        //this assert is guaranteed by the model as ReportOutputType is marked required
                        Debug.Assert(model.ReportOutputType != null, "ReportOutputType should never be null here.");
                        ReportOutputType reportOutputType = model.ReportOutputType.Value;

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

                        ValidateDates(parameterValues);

                        var byteArray = reportingClient.GenerateReport(RequestedReport(model),
                                                                       parameterValues,
                                                                       reportOutputType);
                        return new FileContentResult(byteArray, reportOutputType.ContentType())
                        {
                            FileDownloadName = string.Format(CultureInfo.CurrentCulture,
                                                             reportOutputType.FileNameFormat(),
                                                             model.ReportName)
                        };
                    }
                    catch (TimeoutException)
                    {
                        useParameterValues = false;
                        errorMessage = Resources.ReportTimeOutMessage;
                    }
                    catch (ReportingMessageQuotaExceededException)
                    {
                        useParameterValues = true;
                        errorMessage = Resources.ReportMessageQuotaExceededExceptionMessage;
                    }
                    catch (ReportingParameterValueException exception)
                    {
                        switch (exception.ErrorCode)
                        {
                            case ReportingParameterValueException.ErrorCodeEnum.MissingRequiredValue:
                                useParameterValues = true;
                                errorMessage = string.Format(CultureInfo.CurrentCulture, Resources.ReportParameterRequiredError, exception.ParameterPrompt);
                                break;
                            default:
                                useParameterValues = false;
                                errorMessage = Resources.ReportParameterInvalidError;
                                break;
                        }
                    }
                    catch (HttpRequestValidationException)
                    {
                        useParameterValues = false;
                        errorMessage = Resources.SchedulerReportUnacceptableValueMessage;
                    }
                    catch (ReportingDateException exception)
                    {
                        useParameterValues = true;
                        switch (exception.ErrorCode)
                        {
                            case ReportingDateException.ErrorCodeEnum.FromDateFormat: errorMessage = Resources.ReportDateInvalidFromFormatMessage; break;
                            case ReportingDateException.ErrorCodeEnum.ToDateFormat: errorMessage = Resources.ReportDateInvalidToFormatMessage; break;
                            case ReportingDateException.ErrorCodeEnum.FromDateRange: errorMessage = Resources.ReportDateInvalidFromRangeMessage; break;
                            case ReportingDateException.ErrorCodeEnum.ToDateRange: errorMessage = Resources.ReportDateInvalidToRangeMessage; break;
                            case ReportingDateException.ErrorCodeEnum.Sequence: errorMessage = Resources.ReportDateInvalidSequenceMessage; break;
                            default: errorMessage = Resources.ReportDateRangeInvalidMessage; break;
                        }
                    }
                    catch (ReportingExcelRenderingException)
                    {
                        useParameterValues = true;
                        errorMessage = Resources.ReportExceedingExcelWorksheeSizeMessage;
                    }

                    model.Parameters = new ReportParameters(reportingClient.GetParameters(model.ReportId, model.DataSource, ((useParameterValues) ? parameterValues : null)), false, parameterValues);

                    String reportUiCulture;
                    Report report = RetrieveReportForReportId(reportingClient, model.ReportId, model.DataSource, out reportUiCulture);
                    if (report == null)
                    {
                        return GetMissingReportView(model.ReportId);
                    }

                    model.DataSources = DataSourcesForReport(reportingClient, report);
                    model.ParametersView = DynamicParameters;
                    SetMessage(model, MessageType.Error, errorMessage);

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

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