Ejemplo n.º 1
0
        /// <summary>
        /// Gets a user-friendly list of report parameters
        /// </summary>
        /// <param name="reptDefn"></param>
        /// <param name="truncateListLimit">for multipicks, the max number of items to list (0 for all items)</param>
        /// <returns></returns>
        public List <string> GetReportParametersForUser(CrcReportDefinition reptDefn, int truncateListLimit)
        {
            var userParams = new List <string>();

            foreach (var paramDefn in reptDefn.ParameterDefinitions)
            {
                if (!paramDefn.IsEmptyEquivalent)
                {
                    string valueString = "";
                    if (paramDefn.ParameterType == CrcParameterType.Date)
                    {
                        valueString = DateTime.Parse(paramDefn.ParameterChoice.SingleValue).ToString("dd/MMM/yyyy");
                    }
                    else if (paramDefn.ParameterType == CrcParameterType.Boolean)
                    {
                        valueString = paramDefn.ParameterChoice.SingleValue;
                    }
                    else if (paramDefn.ParameterType == CrcParameterType.Text)
                    {
                        valueString = paramDefn.ParameterChoice.SingleValue;
                    }
                    else
                    {
                        valueString = SelectListAsString(paramDefn, truncateListLimit);
                    }
                    userParams.Add(String.Format("{0}: {1}", paramDefn.DisplayName, valueString));
                }
            }
            return(userParams);
        }
        public void ApplyParameterDefaults(rws.ReportParameter[] wsReportParameters, CrcReportDefinition repDef)
        {
            // first build up a choicecollection from the defaults
            var choiceCol = new CrcParameterChoiceCollection();

            foreach (var paramLoop in wsReportParameters)
            {
                if (paramLoop.DefaultValues != null)
                {
                    var crcChoice = new CrcParameterChoice(paramLoop.Name);
                    foreach (string valString in paramLoop.DefaultValues)
                    {
                        crcChoice.Values.Add(valString);
                    }

                    choiceCol.ParameterChoiceList.Add(crcChoice);
                }
            }
            // now apply it to the repdef
            var mapper    = new CrcParameterChoiceMapper();
            var mapResult = mapper.MapParameterChoices(repDef, choiceCol);

            if (!mapResult.MappingValid)
            {
                throw new ApplicationException(string.Format("Could not map report defaults for report {0}. Problems: {1}",
                                                             repDef.DisplayName, string.Join(", ", mapResult.Complaints.ToArray())));
            }
        }
Ejemplo n.º 3
0
        public List <viewer.ReportParameter> GetReportParametersForSsrsReportViewer(CrcReportDefinition reptDefn)
        {
            var convertedParams = new List <viewer.ReportParameter>();

            foreach (var paramDefn in reptDefn.ParameterDefinitions)
            {
                if (paramDefn.ParameterChoice != null)
                {
                    var convParam = new viewer.ReportParameter();
                    convParam.Name = paramDefn.Name;
                    if (!string.IsNullOrEmpty(paramDefn.ParameterChoice.SingleValue))
                    {
                        foreach (var valLoop in paramDefn.ParameterChoice.Values)
                        {
                            convParam.Values.Add(valLoop);
                        }
                    }
                    else
                    {
                        // we want to record a null
                        convParam.Values.Add(null);
                    }
                    convertedParams.Add(convParam);
                }
            }
            return(convertedParams);
        }
        public CrcReportDefinition Create(string reportPath, rws.CatalogItem reportCatItem, rws.ReportParameter[] wsReportParameters, CrcExtraConfiguration extraConfig)
        {
            var repDef = new CrcReportDefinition();

            repDef.ReportPath = reportPath;
            if (reportCatItem != null)
            {
                repDef.DisplayName = reportCatItem.Name;
                repDef.Description = reportCatItem.Description;
            }
            if (string.IsNullOrEmpty(repDef.DisplayName))
            {
                repDef.DisplayName = CrcReportDefinition.ReportNameFromPath(repDef.ReportPath);
            }

            CrcReportConfig repConfig = null;

            if (extraConfig != null)
            {
                repConfig = extraConfig.GetReportConfig(repDef.ReportPath);
            }

            if (repConfig != null)
            {
                repDef.ReportHint = repConfig.ReportHint;
            }

            AddParameterDefinitions(wsReportParameters, repDef, extraConfig, repConfig);

            bool readSsrsDependantParams = false;

            if (extraConfig == null || !extraConfig.IgnoreSsrsParameterDependencies)
            {
                readSsrsDependantParams = true;
            }
            if (repConfig != null && repConfig.DependantParamsSpecified)
            {
                readSsrsDependantParams = false;
            }
            if (readSsrsDependantParams)
            {
                AddSsrsDependentParams(wsReportParameters, repDef);
            }

            CrossReferenceDependantParameters(repDef);
            ApplyParameterDefaults(wsReportParameters, repDef);
            CheckRequiredFromUser(repDef);

            return(repDef);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Applies the specified choices to the already-existing report definition
        /// and updates the dependant parameters
        /// </summary>
        public void RefreshDependantParameters(CrcReportDefinition repDefn, CrcParameterChoiceCollection newChoices)
        {
            var mapResult = repDefn.MapParameterChoices(newChoices);

            if (!mapResult.MappingValid)
            {
                // todo - friendlier message back to ui
                throw new ApplicationException(string.Format("invalid params - could not map supplied values to definitions for report {0}. complaints: {1}",
                                                             repDefn.DisplayName, string.Join(", ", mapResult.Complaints.ToArray())));
            }
            var conv = new CrcParameterConverter();
            List <ParameterValue> valueList = conv.GetParametersValuesForSsrsWebService(repDefn);
            // get new params from web service
            ReportingService2005Soap rService = m_ssrsSoapClientFactory.MakeSsrsSoapClient();

            logger.DebugFormat("RefreshDependantParameters: rep {0} calling WS to get new validvalid. Passing {1} values", repDefn.DisplayName, valueList.Count());

            var grpRequest  = new GetReportParametersRequest(repDefn.ReportPath, null, true, valueList.ToArray(), null);
            var grpResponse = rService.GetReportParameters(grpRequest);

            // work out which params to refresh
            List <string> paramsToRefresh = new List <string>();

            foreach (string updatedParam in newChoices.ParameterChoiceList.Select(p => p.Name))
            {
                var paramDefn = repDefn.ParameterDefinitions.First(p => p.Name == updatedParam);
                paramsToRefresh = paramsToRefresh.Union(paramDefn.DependantParameterNames).ToList();
            }
            logger.DebugFormat("RefreshDependantParameters: rep {0} based on choices, have {1} parameters that need refreshing", repDefn.DisplayName, paramsToRefresh.Count());

            var refresher = new CrcParameterRefresher();

            foreach (string paramLoop in paramsToRefresh)
            {
                var paramDefn          = repDefn.ParameterDefinitions.First(p => p.Name == paramLoop);
                var latestParamDetails = grpResponse.Parameters.FirstOrDefault(p => p.Name == paramLoop);
                if (latestParamDetails == null)
                {
                    throw new ApplicationException(String.Format("Was expecting web service to return new details for parameter {0} but none found",
                                                                 paramLoop));
                }
                refresher.RefreshParameter(paramDefn, latestParamDetails);
            }
        }
 public void CheckRequiredFromUser(CrcReportDefinition repDef)
 {
     foreach (var crcParam in repDef.ParameterDefinitions)
     {
         bool hasDefault     = (crcParam.ParameterChoice != null && crcParam.ParameterChoice.Values.Count() > 0);
         bool defaultIsNull  = false;
         bool defaultIsBlank = false;
         if (hasDefault)
         {
             defaultIsNull  = crcParam.ParameterChoice.Values.Exists(v => v == null);
             defaultIsBlank = crcParam.ParameterChoice.Values.Exists(v => v == string.Empty);
         }
         crcParam.RequiredFromUser = false;
         if (!crcParam.AllowNull && (!hasDefault || hasDefault && defaultIsNull))
         {
             crcParam.RequiredFromUser = true;
         }
     }
 }
 public void CrossReferenceDependantParameters(CrcReportDefinition repDef)
 {
     foreach (var crParamLoop in repDef.ParameterDefinitions)
     {
         foreach (var dependantName in crParamLoop.DependantParameterNames)
         {
             var match = repDef.ParameterDefinitions.FirstOrDefault(p => p.Name == dependantName);
             if (match == null)
             {
                 logger.DebugFormat("Report {0} Param {1} specified Dependant Param {2} but cannot find it",
                                    repDef.DisplayName, crParamLoop.Name, dependantName);
                 continue;
             }
             logger.DebugFormat("Report {0} Param {1} has Dependant ID {2} - found",
                                repDef.DisplayName, crParamLoop.Name, match.id);
             crParamLoop.DependantParameterIds.Add(match.id);
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Reads the dependent param info from the ssrs web service params and
        /// converts into dependAnt params (i.e. opposite way round)
        /// </summary>
        public void AddSsrsDependentParams(rws.ItemParameter[] wsReportParameters, CrcReportDefinition repDef)
        {
            foreach (var paramLoop in wsReportParameters)
            {
                if (paramLoop.Dependencies != null)
                {
                    logger.DebugFormat("AddSsrsDependantParams: Param {0} has dependencies {1} according to web service", paramLoop.Name, string.Join(", ", paramLoop.Dependencies));
                    foreach (string dependentParam in paramLoop.Dependencies)
                    {
                        var match = repDef.ParameterDefinitions.FirstOrDefault(p => p.Name == dependentParam);
                        if (match == null)
                        {
                            throw new ApplicationException(String.Format("Ssrs says {0} has Dependent {1} but could not find CrcParameterDefintiion {1} during make stage",
                                                                         paramLoop.Name, dependentParam));
                        }

                        match.DependantParameterNames.Add(paramLoop.Name);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public List <rws.ParameterValue> GetParametersValuesForSsrsWebService(CrcReportDefinition reptDefn)
        {
            var convertedParams = new List <rws.ParameterValue>();

            foreach (var paramDefn in reptDefn.ParameterDefinitions)
            {
                if (paramDefn.ParameterChoice != null)
                {
                    if (!string.IsNullOrEmpty(paramDefn.ParameterChoice.SingleValue))
                    {
                        foreach (string valLoop in paramDefn.ParameterChoice.Values)
                        {
                            var convParam = new rws.ParameterValue();
                            convParam.Name  = paramDefn.Name;
                            convParam.Value = valLoop;
                            convertedParams.Add(convParam);
                        }
                    }
                }
            }
            return(convertedParams);
        }
Ejemplo n.º 10
0
        public void AddParameterDefinitions(rws.ReportParameter[] wsReportParameters, CrcReportDefinition repDef, CrcExtraConfiguration extraConfig, CrcReportConfig reportConfig)
        {
            List <string> showByDefault = new List <string>();

            if (reportConfig != null)
            {
                showByDefault = reportConfig.GetParamsToShowByDefault();
            }
            List <string> defaultEmptyEquivalents = new List <string>();

            if (extraConfig != null && extraConfig.DefaultEmptyEquivalentValues != null)
            {
                defaultEmptyEquivalents = extraConfig.DefaultEmptyEquivalentValues;
            }

            foreach (var paramLoop in wsReportParameters)
            {
                CrcReportConfig.CrcParamConfig paramConfig = null;
                // get extra config for parameter, if there is any
                if (reportConfig != null)
                {
                    paramConfig = reportConfig.CrcParamConfigs.FirstOrDefault(p => p.ParamName == paramLoop.Name);
                }

                var crcParam = new CrcParameterDefinition();
                crcParam.Name       = paramLoop.Name;
                crcParam.id         = "param_" + paramLoop.Name.Replace(" ", "_");
                crcParam.AllowNull  = paramLoop.Nullable;
                crcParam.AllowBlank = paramLoop.AllowBlank;

                if (string.IsNullOrEmpty(paramLoop.Prompt))
                {
                    // if Prompt is null or empty, it means Parameter is 'Hidden' in SSRS
                    crcParam.Hidden      = true;
                    crcParam.DisplayName = paramLoop.Name;
                }
                else
                {
                    crcParam.DisplayName = paramLoop.Prompt;
                }
                if (string.IsNullOrEmpty(crcParam.DisplayName))
                {
                    crcParam.DisplayName = crcParam.Name;
                }
                // if PromptUser is false then Parameter is 'Internal' in SSRS
                if (!paramLoop.PromptUser)
                {
                    crcParam.Hidden = true;
                }
                if (paramLoop.Type == rws.ParameterTypeEnum.DateTime)
                {
                    crcParam.ParameterType = CrcParameterType.Date;
                }
                else if ((paramLoop.ValidValues != null && paramLoop.ValidValues.Count() > 0) ||
                         paramLoop.ValidValuesQueryBased)
                {
                    if (paramLoop.MultiValue)
                    {
                        crcParam.ParameterType = CrcParameterType.MultiSelect;
                    }
                    else
                    {
                        crcParam.ParameterType = CrcParameterType.Select;
                    }
                }
                else if (paramLoop.Type == rws.ParameterTypeEnum.Boolean)
                {
                    crcParam.ParameterType = CrcParameterType.Boolean;
                }
                else
                {
                    crcParam.ParameterType = CrcParameterType.Text;
                }


                if (paramLoop.ValidValues != null)
                {
                    foreach (var valLoop in paramLoop.ValidValues)
                    {
                        crcParam.ValidValues.Add(new CrcValidValue()
                        {
                            Value = valLoop.Value, Label = valLoop.Label
                        });
                    }
                    if (crcParam.ValidValues.Count() > 10)
                    {
                        crcParam.AllowListSearch = true;
                    }
                }


                // check config for dependencies
                if (paramConfig != null && paramConfig.DependantParams != null && paramConfig.DependantParams.Count() > 0)
                {
                    logger.DebugFormat("Param {0} has extraconfig dependancies: {1}",
                                       paramLoop.Name, string.Join(", ", paramConfig.DependantParams.ToArray()));
                    foreach (string dpname in paramConfig.DependantParams)
                    {
                        crcParam.DependantParameterNames.Add(dpname);
                    }
                }



                foreach (string sloop in defaultEmptyEquivalents)
                {
                    AddEmptyEquivalent(crcParam, sloop);
                }

                // check for specific empty equivalents for this parameter
                if (paramConfig != null && paramConfig.EmptyEquivalentValues != null)
                {
                    foreach (string sloop in paramConfig.EmptyEquivalentValues)
                    {
                        AddEmptyEquivalent(crcParam, sloop);
                    }
                }



                if (showByDefault.Contains(crcParam.Name))
                {
                    crcParam.AlwaysShow = true;
                }

                repDef.ParameterDefinitions.Add(crcParam);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// applies the specified CrcParameterChoiceCollection to the specified report definition
        /// will set the ParameterChoice property of matching ParameterDefinitions as required
        /// </summary>
        /// <param name="repDefn"></param>
        /// <param name="paramChoices"></param>
        /// <returns>ParameterMapResult - if MappingValid is false, see Complaints collection</returns>
        public ParameterMapResult MapParameterChoices(CrcReportDefinition repDefn, CrcParameterChoiceCollection paramChoices)
        {
            var res = new ParameterMapResult();

            res.Complaints = new List <string>();
            string cultureForDateParsing = GetCultureForDateParsing();

            foreach (CrcParameterChoice choiceLoop in paramChoices.ParameterChoiceList)
            {
                var defnMatch = repDefn.ParameterDefinitions.FirstOrDefault(pd => pd.Name == choiceLoop.Name);
                if (defnMatch == null)
                {
                    res.Complaints.Add(String.Format("Param {0} not found", choiceLoop.Name));
                    continue;
                }
                if (defnMatch.ParameterType == CrcParameterType.Date)
                {
                    if (choiceLoop.SingleValue == null)
                    {
                        defnMatch.ParameterChoice = choiceLoop.DeepClone();
                        continue;
                    }

                    var parseResult = ParseDateStringVariousWays(choiceLoop.SingleValue, cultureForDateParsing);
                    if (parseResult.CouldParse)
                    {
                        var parsedChoice = new CrcParameterChoice(choiceLoop.Name);
                        parsedChoice.SingleValue  = parseResult.DateTime.ToString("yyyy-MM-dd");
                        defnMatch.ParameterChoice = parsedChoice;
                        continue;
                    }
                    res.Complaints.Add(String.Format("Could not parse date {0} into Param {1}",
                                                     choiceLoop.SingleValue, choiceLoop.Name));
                }
                else if (defnMatch.ParameterType == CrcParameterType.Boolean)
                {
                    if (string.IsNullOrEmpty(choiceLoop.SingleValue) || choiceLoop.SingleValue == "True" ||
                        choiceLoop.SingleValue == "False")
                    {
                        defnMatch.ParameterChoice = choiceLoop.DeepClone();
                        continue;
                    }
                    res.Complaints.Add(String.Format("Could not parse boolean {0} into Param {1}",
                                                     choiceLoop.SingleValue, choiceLoop.Name));
                }
                else if (defnMatch.ParameterType == CrcParameterType.Text)
                {
                    defnMatch.ParameterChoice = choiceLoop.DeepClone();
                    continue;
                }
                else if (defnMatch.ValidValues.Count() > 0)
                {
                    bool valuesOK = true;
                    foreach (string chosenValue in choiceLoop.Values)
                    {
                        if (defnMatch.ValidValues.FirstOrDefault(vv => vv.Value == chosenValue) == null)
                        {
                            res.Complaints.Add(String.Format("Could not apply value {0} into Param {1} because it is not a valid option",
                                                             chosenValue, choiceLoop.Name));
                            valuesOK = false;
                        }
                    }
                    if (valuesOK)
                    {
                        defnMatch.ParameterChoice = choiceLoop.DeepClone();
                        continue;
                    }
                }
            }
            res.MappingValid = (res.Complaints.Count() == 0);
            return(res);
        }
Ejemplo n.º 12
0
 public List <string> GetReportParametersForUser(CrcReportDefinition reptDefn)
 {
     return(GetReportParametersForUser(reptDefn, 0));
 }