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())));
            }
        }
Exemple #2
0
        public CrcParameterChoiceMapper.ParameterMapResult MapParameterChoices(CrcParameterChoiceCollection paramChoices)
        {
            // dry run on a clone first to check for errors
            var clone  = this.DeepClone();
            var mapper = new CrcParameterChoiceMapper();
            var verify = mapper.MapParameterChoices(clone, paramChoices);

            if (!verify.MappingValid)
            {
                return(verify);
            }

            // if still here then there are no errors - map to real object
            var results = mapper.MapParameterChoices(this, paramChoices);

            return(results);
        }
        public void CanMapDateParam()
        {
            var repDefn = this.MakeTestReportDefn();
            var choiceColl = new CrcParameterChoiceCollection();
            var dateChoice = new CrcParameterChoice();
            dateChoice.Name = "PretendDateParam";
            dateChoice.SingleValue = "2010-06-02";
            choiceColl.ParameterChoiceList.Add(dateChoice);

            var mapper = new CrcParameterChoiceMapper();
            var mapResult = mapper.MapParameterChoices(repDefn, choiceColl);

            Assert.IsTrue(mapResult.MappingValid);
            Assert.AreEqual(0, mapResult.Complaints.Count());

            var dateParamDefn = repDefn.ParameterDefinitions.FirstOrDefault(p=> p.Name == "PretendDateParam");
            Assert.IsNotNull(dateParamDefn);
            Assert.IsNotNull(dateParamDefn.ParameterChoice);
            Assert.AreEqual("2010-06-02", dateParamDefn.ParameterChoice.SingleValue);
        }
        public void CanParseEnUsDateEnGbDateAndGenericDate()
        {
            var mapper = new CrcParameterChoiceMapper();
            var pres1 = mapper.ParseDateStringVariousWays("8/4/2010 12:00:00 AM", "Flexi-Gb-Us");
            var pres2 = mapper.ParseDateStringVariousWays("04/08/2010 00:00:00", "Flexi-Gb-Us");
            // internal format used by CrissCross irrespective of culture
            var pres3 = mapper.ParseDateStringVariousWays("2012-03-09", "Flexi-Gb-Us");
            Assert.AreEqual(true, pres1.CouldParse);
            Assert.AreEqual(new DateTime(2010, 8, 4), pres1.DateTime, "EN-US failed");
            Assert.AreEqual(true, pres2.CouldParse);
            Assert.AreEqual(new DateTime(2010, 8, 4), pres2.DateTime, "EN-GB failed");

            Assert.AreEqual(true, pres3.CouldParse);
            Assert.AreEqual(new DateTime(2012, 3, 9), pres3.DateTime);
        }
        public void CanMapSingleSelectParam()
        {
            var repDefn = this.MakeTestReportDefn();
            var choiceColl = new CrcParameterChoiceCollection();
            var singleSelect = new CrcParameterChoice();
            singleSelect.Name = "PretendSingleSelect";
            singleSelect.SingleValue = "S2";
            choiceColl.ParameterChoiceList.Add(singleSelect);

            var mapper = new CrcParameterChoiceMapper();
            var mapResult = mapper.MapParameterChoices(repDefn, choiceColl);

            Assert.IsTrue(mapResult.MappingValid);
            Assert.AreEqual(0, mapResult.Complaints.Count());

            var singleParamDefn = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "PretendSingleSelect");
            Assert.IsNotNull(singleParamDefn);
            Assert.IsNotNull(singleParamDefn.ParameterChoice);
            Assert.AreEqual("S2", singleParamDefn.ParameterChoice.SingleValue);
        }
        public void CanMapMultiSelectParam()
        {
            var repDefn = this.MakeTestReportDefn();
            var choiceColl = new CrcParameterChoiceCollection();
            var multiSelect = new CrcParameterChoice();
            multiSelect.Name = "PretendMultiSelect";
            multiSelect.Values = new List<string>() { "M2", "M3" };

            choiceColl.ParameterChoiceList.Add(multiSelect);

            var mapper = new CrcParameterChoiceMapper();
            var mapResult = mapper.MapParameterChoices(repDefn, choiceColl);

            Assert.IsTrue(mapResult.MappingValid);
            Assert.AreEqual(0, mapResult.Complaints.Count());

            var multiParamDefn = repDefn.ParameterDefinitions.FirstOrDefault(p => p.Name == "PretendMultiSelect");
            Assert.IsNotNull(multiParamDefn);
            Assert.IsNotNull(multiParamDefn.ParameterChoice);
            Assert.AreEqual(2, multiParamDefn.ParameterChoice.Values.Count());
            Assert.IsNotNull(multiParamDefn.ParameterChoice.Values.FirstOrDefault(v => v == "M2"));
            Assert.IsNotNull(multiParamDefn.ParameterChoice.Values.FirstOrDefault(v => v == "M3"));
        }
        public void CanMapDetectWrongName()
        {
            var repDefn = this.MakeTestReportDefn();
            var choiceColl = new CrcParameterChoiceCollection();
            var multiSelect = new CrcParameterChoice();
            multiSelect.Name = "WrongName";
            multiSelect.Values = new List<string>() { "M2", "M3" };

            choiceColl.ParameterChoiceList.Add(multiSelect);

            var mapper = new CrcParameterChoiceMapper();
            var mapResult = mapper.MapParameterChoices(repDefn, choiceColl);

            Assert.IsFalse(mapResult.MappingValid);
            Assert.IsTrue(mapResult.Complaints.Contains("Param WrongName not found"));
        }
        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())));
        }