/// <summary> /// Gets BadValueError exception. /// </summary> /// <param name="e">The inner exception.</param> /// <param name="boxIdentity">The box identity.</param> /// <param name="userMessage">The user message.</param> /// <param name="socketsNames">The names of the sockets where are bad values.</param> /// <param name="restrictionType">Type of the restriction.</param> /// <returns> /// The <see cref="Ferda.Modules.BadValueError"/> exception. /// </returns> public static Ferda.Modules.BadValueError BadValueError(Exception e, string boxIdentity, string userMessage, string[] socketsNames, restrictionTypeEnum restrictionType) { Debug.WriteLine(userMessage); Ferda.Modules.BadValueError ex = new BadValueError(e); ex.boxIdentity = boxIdentity; ex.userMessage = userMessage; ex.socketsNames = socketsNames; ex.restrictionType = restrictionType; return ex; }
/// <summary> /// Tests if <c>propertyValue</c> of property named <c>propertyName</c> /// meets the requirements. Requirements are given by /// <see cref="T:Ferda.Modules.Serializer.BoxSerializer.Restriction">restrictions</see>. /// Iff <c>propertyValue</c> doesn`t meet the requirements than /// <see cref="T:Ferda.Modules.BadValueError"/> is thrown. /// </summary> /// <param name="boxInfo">The box info</param> /// <param name="propertyName">Name of property.</param> /// <param name="propertyValue">A double value of property.</param> /// <exception cref="T:Ferda.Modules.BadValueError"> /// This execption is thrown iff <c>propertyValue</c> doesn`t satisfy restrictions. /// </exception> public static void TryIsFloatingPropertyCorrect(IBoxInfo boxInfo, string propertyName, double propertyValue) { List<Restriction> restrictions = boxInfo.GetPropertyRestrictions(propertyName); BadValueError possibleException = new BadValueError(); foreach (Restriction restriction in restrictions) { if (restriction.floating.Length == 0) continue; if (restriction.min) { if (restriction.including) { if (!(restriction.floating[0] <= propertyValue)) { possibleException.restrictionType = restrictionTypeEnum.Minimum; throw possibleException; } } else { if (!(restriction.floating[0] < propertyValue)) { possibleException.restrictionType = restrictionTypeEnum.Minimum; throw possibleException; } } } else { if (restriction.including) { if (!(restriction.floating[0] >= propertyValue)) { possibleException.restrictionType = restrictionTypeEnum.Maximum; throw possibleException; } } else { if (!(restriction.floating[0] > propertyValue)) { possibleException.restrictionType = restrictionTypeEnum.Maximum; throw possibleException; } } } } }
/// <summary> /// Tests if <c>propertyValue</c> of property named <c>propertyName</c> /// meets the requirements. Requirements are given by /// <see cref="T:Ferda.Modules.Serializer.BoxSerializer.Restriction">restrictions</see>. /// Iff <c>propertyValue</c> doesn`t meet the requirements than /// <see cref="T:Ferda.Modules.BadValueError"/> is thrown. /// </summary> /// <param name="boxInfo">The box info</param> /// <param name="propertyName">Name of property.</param> /// <param name="propertyValue">A string value of property.</param> /// <exception cref="T:Ferda.Modules.BadValueError"> /// This execption is thrown iff <c>propertyValue</c> doesn`t satisfy restrictions. /// </exception> public static void TryIsStringPropertyCorrect(IBoxInfo boxInfo, string propertyName, string propertyValue) { string regexp = boxInfo.GetPropertyRegexp(propertyName); if (!String.IsNullOrEmpty(regexp)) { if (! System.Text.RegularExpressions.Regex.IsMatch(propertyValue, regexp)) { BadValueError possibleException = new BadValueError(); possibleException.restrictionType = restrictionTypeEnum.Regexp; throw possibleException; } } SelectString[] selectValues = boxInfo.GetPropertyFixedOptions(propertyName); if (selectValues.Length > 0) { bool inOptions = false; foreach (SelectString selectString in selectValues) { if (selectString.name == propertyValue) { inOptions = true; break; } } if (!inOptions) { BadValueError possibleException = new BadValueError(); possibleException.restrictionType = restrictionTypeEnum.NotInSelectOptions; throw possibleException; } } }