Ejemplo n.º 1
0
        /// <inheritdoc/>
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var  results      = new List <ValidationResult>();
            bool isProportion = (TakeStyle == TakeFromFilterStyle.TakeProportion || TakeStyle == TakeFromFilterStyle.SkipProportion);

            if (Value == 0)
            {
                string[] memberNames = new string[] { "Invalid value to take from filter" };
                results.Add(new ValidationResult($"Provide a {((isProportion)?"proportion":"number of individuals")} greater than 0 for [f={Name}] in [f={(Parent as CLEMModel).NameWithParent}]", memberNames));
            }

            if (isProportion)
            {
                if (Value > 1)
                {
                    bool isTake = (TakeStyle.ToString().Contains("Take"));

                    string[] memberNames = new string[] { $"Invalid proportion to {(isTake?"take":"skip")} from filter" };
                    results.Add(new ValidationResult($"The proportion to {(isTake ? "take" : "skip")} from [f={Name}] in [f={(Parent as CLEMModel).NameWithParent}] must be less than or equal to 1", memberNames));
                }
            }
            return(results);
        }
Ejemplo n.º 2
0
        private string takeString(bool htmltags)
        {
            using (StringWriter takeWriter = new StringWriter())
            {
                string cssSet   = "";
                string cssError = "";
                string cssClose = "";
                if (htmltags)
                {
                    cssSet   = "<span class = \"filterset\">";
                    cssError = "<span class = \"filtererror\">";
                    cssClose = "</span>";
                }
                bool isTake        = (TakeStyle.ToString().Contains("Take"));
                bool isIndividuals = (TakeStyle == TakeFromFilterStyle.TakeIndividuals || TakeStyle == TakeFromFilterStyle.SkipIndividuals);
                takeWriter.Write((isTake)?$"Take: ": "Skip: ");
                string errorString = "";
                if (Value < 0 || (isIndividuals & Value > 1))
                {
                    errorString = "Invalid";
                }

                if (errorString != "")
                {
                    takeWriter.Write($"{cssError}{errorString}{cssClose}");
                }
                else
                {
                    takeWriter.Write(cssSet);
                    takeWriter.Write((!isIndividuals ? Value.ToString("P0") : $"{Convert.ToInt32(Value)}"));
                    takeWriter.Write(cssClose);
                    takeWriter.WriteLine(((!isIndividuals) ? "" : " individuals"));
                }
                return(takeWriter.ToString());
            }
        }