예제 #1
0
        private static string[] PeVerify(byte[] peImage, int domainId, string assemblyPath)
        {
            lock (s_guard)
            {
                GCHandle pinned = GCHandle.Alloc(peImage, GCHandleType.Pinned);
                try
                {
                    IntPtr buffer = pinned.AddrOfPinnedObject();

                    ICLRValidator validator = (ICLRValidator)RuntimeEnvironment.GetRuntimeInterfaceAsObject(s_clsIdClrRuntimeHost, typeof(ICLRRuntimeHost).GUID);
                    ValidationErrorHandler errorHandler = new ValidationErrorHandler(validator);

                    IMetaDataDispenser dispenser = (IMetaDataDispenser)RuntimeEnvironment.GetRuntimeInterfaceAsObject(s_clsIdCorMetaDataDispenser, typeof(IMetaDataDispenser).GUID);

                    // the buffer needs to be pinned during validation
                    Guid riid = typeof(IMetaDataImport).GUID;
                    object metaDataImport = null;
                    if (assemblyPath != null)
                    {
                        dispenser.OpenScope(assemblyPath, CorOpenFlags.ofRead, ref riid, out metaDataImport);
                    }
                    else
                    {
                        dispenser.OpenScopeOnMemory(buffer, (uint)peImage.Length, CorOpenFlags.ofRead, ref riid, out metaDataImport);
                    }

                    IMetaDataValidate metaDataValidate = (IMetaDataValidate)metaDataImport;
                    metaDataValidate.ValidatorInit(CorValidatorModuleType.ValidatorModuleTypePE, errorHandler);
                    metaDataValidate.ValidateMetaData();

                    validator.Validate(errorHandler, (uint)domainId, ValidatorFlags.VALIDATOR_EXTRA_VERBOSE,
                        ulMaxError: 10, token: 0, fileName: assemblyPath, pe: buffer, ulSize: (uint)peImage.Length);

                    return errorHandler.GetOutput();
                }
                finally
                {
                    pinned.Free();
                }
            }
        }
        private static bool Rule02(string name, NodeIndex nodeIndex, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement context in list) {
                XmlElement	    startDate	= XPath.Path (context, "novation", "firstPeriodStartDate");
                XmlAttribute	href;

                if ((startDate == null) || (href = startDate.GetAttributeNode ("href"))== null) continue;

                XmlElement		target	= nodeIndex.GetElementById (href.Value);

                if ((target == null) || !target.LocalName.Equals("party")) {
                    errorHandler ("305", context,
                        "The @href attribute on the firstPeriodStartDate must reference a party",
                        name, href.Value);

                    result = false;
                }
            }
            return (result);
        }
예제 #3
0
        private static bool Rule40(string name, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool		result = true;

            foreach (XmlElement context in list) {
                XmlElement	tranche	= XPath.Path (context, "generalTerms", "indexReferenceInformation", "tranche");
                XmlElement	attach	= XPath.Path (tranche, "attachmentPoint");
                XmlElement	exhaust	= XPath.Path (tranche, "exhaustionPoint");

                if ((attach == null) || (exhaust == null) || LessOrEqual (ToDecimal (attach), ToDecimal (exhaust))) continue;

                errorHandler ("305", tranche,
                        "attachmentPoint must be less than or equal to exhaustionPoint.",
                        name, null);

                result = false;
            }
            return (result);
        }
예제 #4
0
 internal bool PerformValidation(NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return (Validate (nodeIndex, errorHandler));
 }
예제 #5
0
        private static bool Rule38(string name, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool		result = true;

            foreach (XmlElement context in list) {
                XmlElement 	pool	= XPath.Path (context, "generalTerms", "basketReferenceInformation", "referencePool");
                XmlNodeList	items	= XPath.Paths (pool, "referencePoolItem", "constituentWeight", "basketPercentage");

                if (items.Count == 0) continue;

                Decimal total = 0;
                foreach (XmlElement item in items)
                    total += ToDecimal (item);

                if (Equal (total, decimal.One)) continue;

                errorHandler ("305", pool,
                        "The sum of referencePoolItem/constituentWeight/basketPercentage should be equal to 1",
                        name, total.ToString ());

                result = false;
            }
            return (result);
        }
예제 #6
0
        // --------------------------------------------------------------------
        private static bool Rule13(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("creditDefaultSwap")) {
                foreach (XmlElement buyer in XPath.Paths (context, "protectionTerms", "creditEvents", "creditEventNotice", "notifyingParty", "buyerPartyReference")) {
                    string		buyerName;
                    string		referenceName;

                    if (Equal (
                            buyerName = buyer.GetAttribute ("href"),
                            referenceName = XPath.Path (context, "generalTerms", "buyerPartyReference").GetAttribute ("href")))
                        continue;

                    errorHandler ("305", context,
                        "Credit event notice references buyer party reference " + buyerName +
                        " but general terms references " + referenceName,
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
        private static bool Rule02(string name, NodeIndex nodeIndex, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement context in list) {
                XmlAttribute	href;
                XmlElement		target;

                if (((href = context.GetAttributeNode ("href")) == null) ||
                    ((target = nodeIndex.GetElementById (href.Value)) == null)) continue;

                string targetName = target.LocalName;

                if (targetName.Equals ("creditCurve") ||
                    targetName.Equals ("fxCurve") ||
                    targetName.Equals ("volatilityRepresentation") ||
                    targetName.Equals ("yieldCurve")) continue;

                errorHandler ("305", context,
                    "@href must match the @id attribute of an element of type PricingStructure",
                    name, targetName);

                result = false;
            }
            return (result);
        }
예제 #8
0
        private static bool Rule04b(string name, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool		result = true;

            foreach (XmlElement context in list) {
                if (!Exists (XPath.Path (context, "creditDefaultSwap"))) continue;
                if (!IsIsda2003 (context)) continue;

                foreach (XmlNode type in XPath.Paths (context, "documentation", "contractualTermsSupplement", "type")) {
                    if (type.InnerText.Trim ().StartsWith ("ISDA1999Credit")) {
                        errorHandler ("305", context,
                            "The contractualTermSupplement/type name may not begin with ISDA1999Credit",
                            name, type.InnerText);

                        result = false;
                    }
                }
            }
            return (result);
        }
예제 #9
0
        private static bool Rule08(string name, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool			result = true;

            foreach (XmlElement trade in list) {
                if (IsLongForm (trade)) {
                    XmlElement		context = XPath.Path (trade, "creditDefaultSwap", "generalTerms");

                    if (!Exists (XPath.Path (context, "scheduledTerminationDate"))) continue;

                    if (Or (
                            Exists (XPath.Path (context, "scheduledTerminationDate", "adjustableDate", "dateAdjustments")),
                            Exists (XPath.Path (context, "scheduledTerminationDate", "adjustableDate", "dateAdjustmentsReference"))))
                        continue;

                    errorHandler ("305", context,
                        "Neither date adjustments nor a date adjustments reference " +
                        "have been supplied for the scheduled termination date",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
예제 #10
0
 /// <summary>
 /// Validates the HTML.
 /// </summary>
 public void Validate(PostBackValueDictionary postBackValues, Validator validator, ValidationErrorHandler errorHandler)
 {
     mod.Html = validator.GetString(errorHandler, wysiwygEditor.GetPostBackValue(postBackValues), true);
 }
        /// <summary>
        /// Creates a simple HTML editor.
        /// </summary>
        /// <param name="value">Do not pass null.</param>
        /// <param name="allowEmpty"></param>
        /// <param name="validationMethod">The validation method. Do not pass null.</param>
        /// <param name="setup">The setup object for the HTML editor.</param>
        /// <param name="maxLength"></param>
        public WysiwygHtmlEditor(
            string value, bool allowEmpty, Action <string, Validator> validationMethod, WysiwygHtmlEditorSetup setup = null, int?maxLength = null)
        {
            setup = setup ?? new WysiwygHtmlEditorSetup();

            var id = new ElementId();
            FormValue <string> formValue = null;

            formValue = new FormValue <string>(
                () => value,
                () => setup.IsReadOnly ? "" : id.Id,
                v => v,
                rawValue => {
                if (rawValue == null)
                {
                    return(PostBackValueValidationResult <string> .CreateInvalid());
                }

                // This hack prevents the NewLine that CKEditor seems to always add to the end of the textarea from causing
                // ValueChangedOnPostBack to always return true.
                if (rawValue.EndsWith(Environment.NewLine) && rawValue.Remove(rawValue.Length - Environment.NewLine.Length) == formValue.GetDurableValue())
                {
                    rawValue = formValue.GetDurableValue();
                }

                return(PostBackValueValidationResult <string> .CreateValid(rawValue));
            });

            var modificationValue = new PageModificationValue <string>();

            PageComponent = new ElementComponent(
                context => {
                id.AddId(context.Id);

                var displaySetup = setup.DisplaySetup ?? new DisplaySetup(true);
                displaySetup.AddJsShowStatements(getJsShowStatements(context.Id, false, setup.CkEditorConfiguration));
                displaySetup.AddJsHideStatements("CKEDITOR.instances.{0}.destroy(); $( '#{0}' ).css( 'display', 'none' );".FormatWith(context.Id));

                return(new ElementData(
                           () => {
                    var attributes = new List <Tuple <string, string> >();
                    if (setup.IsReadOnly)
                    {
                        attributes.Add(Tuple.Create("disabled", "disabled"));
                    }
                    else
                    {
                        attributes.Add(Tuple.Create("name", context.Id));
                    }
                    if (!displaySetup.ComponentsDisplayed)
                    {
                        attributes.Add(Tuple.Create("style", "display: none"));
                    }

                    return new ElementLocalData(
                        "textarea",
                        new FocusabilityCondition(!setup.IsReadOnly),
                        isFocused => new ElementFocusDependentData(
                            attributes: attributes,
                            includeIdAttribute: true,
                            jsInitStatements: displaySetup.ComponentsDisplayed ? getJsShowStatements(context.Id, isFocused, setup.CkEditorConfiguration) : ""));
                },
                           children: new TextNode(() => TextControlSetup.GetTextareaValue(modificationValue.Value)).ToCollection()));
            },
                formValue: formValue);

            formValue.AddPageModificationValue(modificationValue, v => v);

            Validation = formValue.CreateValidation(
                (postBackValue, validator) => {
                if (setup.ValidationPredicate != null && !setup.ValidationPredicate(postBackValue.ChangedOnPostBack))
                {
                    return;
                }

                var errorHandler   = new ValidationErrorHandler("HTML");
                var validatedValue = maxLength.HasValue
                                                                     ? validator.GetString(errorHandler, postBackValue.Value, allowEmpty, maxLength.Value)
                                                                     : validator.GetString(errorHandler, postBackValue.Value, allowEmpty);
                if (errorHandler.LastResult != ErrorCondition.NoError)
                {
                    setup.ValidationErrorNotifier?.Invoke();
                    return;
                }

                validationMethod(validatedValue, validator);
            });
        }
예제 #12
0
 /// <summary>
 /// Determines if the <see cref="XmlDocument"/> instance indexed by the
 /// provided <see cref="NodeIndex"/> has business data content that passes a
 /// validation test. If errors are detected they will be reported through
 /// the <see cref="ValidationErrorHandler"/> instance passed as an argument.
 /// </summary>
 /// <remarks>Note that test returns <c>true</c> if it does not fail,
 /// including circumstances when the test is inapplicable to the
 /// <see cref="XmlDocument"/> under examination.
 /// </remarks>
 /// <param name="nodeIndex">The <see cref="NodeIndex"/> instance to examine.</param>
 /// <param name="errorHandler">An <see cref="ValidationErrorHandler"/> instance used to report
 /// validation failures.</param>
 /// <returns><c>false</c> if the validation test failed, <c>true</c> otherwise.
 /// </returns>
 protected abstract bool Validate(NodeIndex nodeIndex, ValidationErrorHandler errorHandler);
예제 #13
0
 internal bool PerformValidation(NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return(Validate(nodeIndex, errorHandler));
 }
예제 #14
0
 /// <summary>
 /// Determines if the given <see cref="XmlDocument"/> instance's business
 /// data content passes a validation test. If errors are detected these will
 /// be reported through the <see cref="ValidationErrorHandler"/> instance passed as an
 /// argument.
 /// </summary>
 /// <remarks>Note that test returns <c>true</c> if it does not fail,
 /// including circumstances when the test is inapplicable to the
 /// <see cref="XmlDocument"/> under examination.
 /// </remarks>
 /// <param name="document">The <see cref="XmlDocument"/> instance to examine.</param>
 /// <param name="errorHandler">An <see cref="ValidationErrorHandler"/> delegate used to report
 /// validation failures.</param>
 /// <returns><c>false</c> if the validation test failed, <c>true</c> otherwise.
 /// </returns>
 public bool Validate(XmlDocument document, ValidationErrorHandler errorHandler)
 {
     return(Validate(new NodeIndex(document), errorHandler));
 }
예제 #15
0
        /// <summary>
        /// Validates the time and returns the time. The value is expressed in time since 12AM on an arbitrary day.
        /// </summary>
        public TimeSpan ValidateAndGetTimeSpan(PostBackValueDictionary postBackValues, Validator validator, ValidationErrorHandler errorHandler)
        {
            if (textBox != null)
            {
                return(validator.GetTimeOfDayTimeSpan(
                           errorHandler,
                           textBox.GetPostBackValue(postBackValues).ToUpper(),
                           DateTimeTools.HourAndMinuteFormat.ToSingleElementArray()));
            }

            var selectedItemIdInPostBack = selectList.ValidateAndGetSelectedItemIdInPostBack(postBackValues, validator);

            if (selectedItemIdInPostBack.HasValue)
            {
                return(selectedItemIdInPostBack.Value);
            }
            errorHandler.SetValidationResult(ValidationResult.Empty());
            errorHandler.HandleResult(validator, true);
            return(default(TimeSpan));
        }
 /// <summary>
 /// Validates and returns the duration, a secondary validation in case javascript is disabled on the client system.
 /// </summary>
 public TimeSpan ValidateAndGetPostBackDuration(PostBackValueDictionary postBackValues, Validator validator, ValidationErrorHandler validationErrorHandler)
 {
     if (tooLongOrInvalidCharacters(durationPicker.GetPostBackValue(postBackValues)))
     {
         validator.NoteErrorAndAddMessage("Please enter a valid duration.");
         return(TimeSpan.Zero);
     }
     return(validator.GetTimeSpan(validationErrorHandler, parseTimeSpan(durationPicker.GetPostBackValue(postBackValues))));
 }
예제 #17
0
        // --------------------------------------------------------------------
        private static bool Rule42(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("generalTerms")) {
                XmlElement	basket			= XPath.Path (context, "basketReferenceInformation");
                XmlElement	substitution	= XPath.Path (context, "substitution");

                if ((basket == null) && (substitution != null)) {
                    errorHandler ("305", context,
                        "If basketReferenceInformation is not present then substitution must not be present.",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
예제 #18
0
 /// <summary>
 /// Determines if the <see cref="XmlDocument"/> instance indexed by the
 /// provided <see cref="NodeIndex"/> has business data content that passes a
 /// validation test. If errors are detected they will be reported through
 /// the <see cref="ValidationErrorHandler"/> instance passed as an argument.
 /// </summary>
 /// <remarks>Note that test returns <c>true</c> if it does not fail,
 /// including circumstances when the test is inapplicable to the
 /// <see cref="XmlDocument"/> under examination.
 /// </remarks>
 /// <param name="nodeIndex">The <see cref="NodeIndex"/> instance to examine.</param>
 /// <param name="errorHandler">An <see cref="ValidationErrorHandler"/> instance used to report
 /// validation failures.</param>
 /// <returns><c>false</c> if the validation test failed, <c>true</c> otherwise.
 /// </returns>
 protected override bool Validate(NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return(function(DisplayName, nodeIndex, errorHandler));
 }
예제 #19
0
        /// <summary>
        /// Validates the date and returns the date.
        /// </summary>
        public DateTime ValidateAndGetPostBackDate(PostBackValueDictionary postBackValues, Validator validator, ValidationErrorHandler errorHandler)
        {
            var date = validator.GetDateTime(errorHandler, textBox.GetPostBackValue(postBackValues), null, min, max);

            if (errorHandler.LastResult == ErrorCondition.NoError && date.HasTime())
            {
                validator.NoteErrorAndAddMessage("Time information is not allowed.");
            }
            return(date);
        }
예제 #20
0
 /// <summary>
 /// Uses the default FpML <see cref="RuleSet"/> to perform a semantic validation of
 /// the <see cref="XmlDocument"/> and reports errors (if any).
 /// </summary>
 /// <param name="document">The <see cref="XmlDocument"/> to be validated.</param>
 /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param>
 /// <returns><b>true</b> if the <see cref="XmlDocument"/> successfully passed all
 /// applicable rules, <b>false</b> if one or more rules failed.</returns>
 public static bool Validate(XmlDocument document, ValidationErrorHandler errorHandler)
 {
     return(Validate(document, AllRules.Rules, errorHandler));
 }
예제 #21
0
        // --------------------------------------------------------------------
        private static bool Rule06(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("generalTerms")) {
                XmlElement  buyer   = context ["buyerPartyReference"];
                XmlElement  seller  = context ["sellerPartyReference"];

                if ((buyer == null) || (seller == null) ||
                    NotEqual (buyer.GetAttribute ("href"), seller.GetAttribute ("href")))
                    continue;

                errorHandler ("305", context,
                    "Buyer party reference is equal to seller party reference",
                    name, seller.GetAttribute ("href"));

                result = false;
            }
            return (result);
        }
예제 #22
0
        /// <summary>
        /// Attempts to parse an XML document from a string and then pass it through
        /// the specified validation rule set.
        /// </summary>
        /// <param name="xml">The XML string to be parsed.</param>
        /// <param name="rules">The <see cref="RuleSet"/> used for validation.</param>
        /// <param name="eventHandler">A <see cref="ValidationEventHandler"/> used to report parser errors.</param>
        /// <param name="errorHandler">An <see cref="ValidationErrorHandler"/> used to report validation errors.</param>
        /// <returns></returns>
        public static bool ParseAndValidate(string xml, RuleSet rules, ValidationEventHandler eventHandler, ValidationErrorHandler errorHandler)
        {
            XmlDocument document = Parse(xml, eventHandler);

            return((document != null) ? Validate(document, rules, errorHandler) : false);
        }
예제 #23
0
        // --------------------------------------------------------------------
        private static bool Rule11(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement trade in nodeIndex.GetElementsByName ("trade")) {
                if (IsIsda2003 (trade) && IsLongForm (trade)) {
                    XmlElement	context = XPath.Path (trade, "creditDefaultSwap", "generalTerms", "referenceInformation") as XmlElement;

                    if (Exists (XPath.Path (context, "allGuarantees"))) continue;

                    errorHandler ("305", context,
                        "allGuarantees element missing in protection terms",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
예제 #24
0
 /// <summary>
 /// Attempts to parse an XML document from a string and then pass it through
 /// the default FpML validation rule set.
 /// </summary>
 /// <param name="xml">The XML string to be parsed.</param>
 /// <param name="eventHandler">A <see cref="ValidationEventHandler"/> used to report parser errors.</param>
 /// <param name="errorHandler">An <see cref="ValidationErrorHandler"/> used to report validation errors.</param>
 /// <returns></returns>
 public static bool ParseAndValidate(string xml, ValidationEventHandler eventHandler, ValidationErrorHandler errorHandler)
 {
     return(ParseAndValidate(xml, AllRules.Rules, eventHandler, errorHandler));
 }
예제 #25
0
        // --------------------------------------------------------------------
        private static bool Rule16(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result = true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("creditDefaultSwap")) {
                if (Implies (
                        And (
                            Equal (
                                Count (XPath.Paths (context, "generalTerms", "referenceInformation", "referenceObligation")), 1),
                            Exists (XPath.Path (context, "cashSettlementTerms", "valuationDate", "multipleValuationDates"))),
                        Or (
                            Equal (
                                XPath.Path (context, "cashSettlementTerms", "valuationMethod"),
                                "AverageMarket"),
                            Or (
                                Equal (
                                    XPath.Path (context, "cashSettlementTerms", "valuationMethod"),
                                    "Highest"),
                                Equal (
                                    XPath.Path (context, "cashSettlementTerms", "valuationMethod"),
                                    "AverageHighest")))))
                    continue;

                errorHandler ("305", context,
                    "If there is exactly one generalTerms/referenceInformation/referenceObligation " +
                    "and cashSettlementTerms/valuationDate/multipleValuationDates occurs " +
                    "then the value of cashSettlementTerms/valuationMethod must be " +
                    "AverageMarket, Highest or AverageHighest",
                    name, XPath.Path (context, "cashSettlementTerms", "valuationMethod").InnerText);

                result = false;
            }
            return (result);
        }
예제 #26
0
        /// <summary>
        /// Attempts to parse an XML document from a <see cref="Stream"/> and then
        /// pass it though the specified validation rule set.
        /// </summary>
        /// <param name="schemaOnly">Indicates only schema based documents to be processed.</param>
        /// <param name="stream">The <see cref="Stream"/> to process XML from.</param>
        /// <param name="rules">The <see cref="RuleSet"/> used for validation.</param>
        /// <param name="eventHandler">A <see cref="ValidationEventHandler"/> used to report parser errors.</param>
        /// <param name="errorHandler">An <see cref="ValidationErrorHandler"/> used to report validation errors.</param>
        /// <returns></returns>
        public static bool ParseAndValidate(bool schemaOnly, Stream stream, RuleSet rules, ValidationEventHandler eventHandler, ValidationErrorHandler errorHandler)
        {
            XmlDocument document = Parse(schemaOnly, stream, eventHandler);

            return((document != null) ? Validate(document, errorHandler) : false);
        }
        private static bool Rule01(string name, NodeIndex nodeIndex, XmlNodeList list,
            ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement	 context in list) {
                XmlElement		generic	= XPath.Path (context, "generic");
                XmlAttribute	href;
                XmlElement		target;

                if ((generic == null) ||
                    ((href = generic.GetAttributeNode ("href")) == null) ||
                    ((target = nodeIndex.GetElementById (href.Value)) == null)) continue;

                string targetName = target.LocalName;

                if (targetName.Equals ("basket") ||
                    targetName.Equals ("cash") ||
                    targetName.Equals ("commodity") ||
                    targetName.Equals ("deposit") ||
                    targetName.Equals ("bond") ||
                    targetName.Equals ("convertibleBond") ||
                    targetName.Equals ("equity") ||
                    targetName.Equals ("exchangeTradedFund") ||
                    targetName.Equals ("index") ||
                    targetName.Equals ("future") ||
                    targetName.Equals ("fxRate") ||
                    targetName.Equals ("loan") ||
                    targetName.Equals ("mortgage") ||
                    targetName.Equals ("mutualFund") ||
                    targetName.Equals ("rateIndex") ||
                    targetName.Equals ("simpleCreditDefautSwap") ||
                    targetName.Equals ("simpleFra") ||
                    targetName.Equals ("simpleIrSwap") ||
                    targetName.Equals ("dealSummary") ||
                    targetName.Equals ("facilitySummary")) continue;

                errorHandler ("305", context,
                    "generic/@href must match the @id attribute of an element of type Asset",
                    name, targetName);

                result = false;
            }
            return (result);
        }
예제 #28
0
 /// <summary>
 /// Attempts to parse an XML document from a <see cref="Stream"/> and then
 /// pass it though the default FpML validation rule set.
 /// </summary>
 /// <param name="schemaOnly">Indicates only schema based documents to be processed.</param>
 /// <param name="stream">The <see cref="Stream"/> to process XML from.</param>
 /// <param name="eventHandler">A <see cref="ValidationEventHandler"/> used to report parser errors.</param>
 /// <param name="errorHandler">An <see cref="ValidationErrorHandler"/> used to report validation errors.</param>
 /// <returns></returns>
 public static bool ParseAndValidate(bool schemaOnly, Stream stream, ValidationEventHandler eventHandler, ValidationErrorHandler errorHandler)
 {
     return(ParseAndValidate(schemaOnly, stream, AllRules.Rules, eventHandler, errorHandler));
 }
예제 #29
0
        /// <summary>
        /// Validates the data content of a set of elements by locating the scheme
        /// identified by the scheme attribute or a default on the root element
        /// for pre FpML-4-0 instances.
        /// </summary>
        /// <param name="list">An <see cref="XmlNodeList"/> of elements to check.</param>
        /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param>
        /// <returns><c>true</c> if the code values pass the checks, <c>false</c>
        /// otherwise.</returns>
        protected bool Validate(XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool result = true;

            if (list.Count > 0)
            {
                XmlElement fpml    = DOM.GetParent(list [0] as XmlElement);
                string     version = null;

                // Find the FpML root node
                while (fpml != null)
                {
                    if (fpml.LocalName.Equals("FpML"))
                    {
                        version = fpml.GetAttribute("version");
                        break;
                    }
                    if (fpml.HasAttribute("fpmlVersion"))
                    {
                        version = fpml.GetAttribute("fpmlVersion");
                        break;
                    }
                    fpml = DOM.GetParent(fpml);
                }

                SchemeCollection schemes =
                    (Releases.FPML.GetReleaseForVersion(version) as ISchemeAccess).SchemeCollection;

                foreach (XmlElement context in list)
                {
                    // If there is no local override then look for a default on the FpML
                    // element in pre 3-0 versions.
                    string uri = context.GetAttribute(attributeName);
                    if (((uri == null) || (uri.Length == 0)) && (version != null))
                    {
                        string [] components = version.Split('-');
                        if ((components.Length > 1) && (components [0].CompareTo("4") < 0))
                        {
                            ISchemeAccess provider
                                = Specification.ReleaseForDocument(context.OwnerDocument) as ISchemeAccess;

                            string name = provider.SchemeDefaults.GetDefaultAttributeForScheme(attributeName);
                            if (name != null)
                            {
                                uri = fpml.GetAttribute(name);
                            }
                        }
                    }

                    if ((uri == null) || (uri.Length == 0))
                    {
                        errorHandler("305", context,
                                     "A qualifying scheme URI has not been defined for this element",
                                     Name, context.LocalName);

                        result = false;
                        continue;
                    }

                    Scheme scheme = schemes.FindSchemeForUri(uri);
                    if (scheme == null)
                    {
                        errorHandler("305", context,
                                     "An unrecognized scheme URI has been used as a qualifier",
                                     Name, uri);

                        result = false;
                        continue;
                    }

                    string value = context.InnerText.Trim();
                    if (scheme.IsValid(value))
                    {
                        continue;
                    }

                    errorHandler("305", context,
                                 "The code value '" + value + "' is not valid in scheme '" + scheme.Uri + "'",
                                 Name, value);

                    result = false;
                }
            }
            return(result);
        }
예제 #30
0
 /// <summary>
 /// Uses the indicated <see cref="RuleSet"/> to perform a semantic validation of
 /// the <see cref="XmlDocument"/> and reports errors (if any).
 /// </summary>
 /// <param name="document">The <see cref="XmlDocument"/> to be validated.</param>
 /// <param name="rules">The <see cref="RuleSet"/> to use.</param>
 /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param>
 /// <returns><b>true</b> if the <see cref="XmlDocument"/> successfully passed all
 /// applicable rules, <b>false</b> if one or more rules failed.</returns>
 public static bool Validate(XmlDocument document, RuleSet rules, ValidationErrorHandler errorHandler)
 {
     return(rules.Validate(document, errorHandler));
 }
예제 #31
0
        private static bool Rule39(string name, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool		result = true;

            foreach (XmlElement context in list) {
                XmlElement	info	= XPath.Path (context, "generalTerms", "basketReferenceInformation");
                XmlElement	nth		= XPath.Path (context, "nthToDefault");
                XmlElement	mth		= XPath.Path (context, "mthToDefault");

                if ((nth == null) || (mth == null) || (ToInteger (nth) < ToInteger (mth))) continue;

                errorHandler ("305", info,
                        "If nthToDefault is present and mthToDefault is present then nthToDefault must be less than mthToDefault.",
                        name, null);

                result = false;
            }
            return (result);
        }
예제 #32
0
 // --------------------------------------------------------------------
 private static bool Rule44(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return (Rule44 (name, nodeIndex.GetElementsByName ("creditDefaultSwap"), errorHandler));
 }
예제 #33
0
        // --------------------------------------------------------------------
        private static bool Rule41(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("generalTerms")) {
                XmlElement		tranche		= XPath.Path (context, "indexReferenceInformation", "tranche");
                XmlElement		delivery	= XPath.Path (context, "modifiedEquityDelivery");

                if ((tranche == null) && (delivery != null)) {
                    errorHandler ("305", context,
                        "If indexReferenceInformation/tranche is not present then modifiedEquityDelivery must not be present.",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
예제 #34
0
        private static bool Rule01b(string name, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in list) {
                XmlElement		cds;

                if (Exists (cds = XPath.Path (context, "creditDefaultSwap"))) {
                    if (!IsCreditIndex (cds)) continue;

                    XmlNode			tradeDate		= XPath.Path (context, "tradeHeader", "tradeDate");
                    XmlNode			effectiveDate	= XPath.Path (context, "creditDefaultSwap", "generalTerms", "effectiveDate", "unadjustedDate");

                    if ((tradeDate == null) || (effectiveDate == null) || !Less (tradeDate, effectiveDate ))
                        continue;

                    errorHandler ("305", context,
                        "Trade date " + tradeDate.InnerText.Trim () + " is not before " +
                        "effective date " + effectiveDate.InnerText.Trim (),
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
예제 #35
0
        // --------------------------------------------------------------------
        private static bool Rule43(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool		result 	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("creditDefaultSwap")) {
                if (!IsSingleName (context)) continue;

                if (!Exists (XPath.Path(context, "feeLeg", "initialPayment"))) continue;

                XmlElement	payer		= XPath.Path (context, "feeLeg", "initialPayment", "payerPartyReference");
                XmlElement	receiver 	= XPath.Path (context, "feeLeg", "initialPayment", "receiverPartyReference");
                XmlElement	seller		= XPath.Path (context, "generalTerms", "sellerPartyReference");
                XmlElement	buyer		= XPath.Path (context, "generalTerms", "buyerPartyReference");

                if ((payer != null) && (seller != null) && (receiver != null) && (buyer != null)) {
                    if (payer.GetAttribute ("href").Equals (buyer.GetAttribute ("href")) &&
                        receiver.GetAttribute ("href").Equals (seller.GetAttribute ("href")))
                        continue;
                }

                errorHandler ("305", context,
                    "The initial payment should be paid by the protection buyer to the protection seller",
                    name, null);

                result = false;
            }
            return (result);
        }
예제 #36
0
        /// <summary>
        /// Validates the data content of a set of elements by locating the scheme
        /// identified by the scheme attribute.
        /// </summary>
        /// <param name="list">An <see cref="XmlNodeList"/> of elements to check.</param>
        /// <param name="errorHandler">The <see cref="ValidationErrorHandler"/> used to report issues.</param>
        /// <returns><c>true</c> if the code values pass the checks, <c>false</c>
        /// otherwise.</returns>
        protected bool Validate(XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool result = true;

            if (list.Count > 0)
            {
                XmlElement fpml    = DOM.GetParent(list [0] as XmlElement);
                string     version = null;

                // Find the FpML root node
                while ((fpml != null) && !fpml.LocalName.Equals("FpML"))
                {
                    fpml = DOM.GetParent(fpml);
                }

                if (fpml != null)
                {
                    version = fpml.GetAttribute("version");
                }

                SchemeCollection schemes =
                    (Releases.FPML.GetReleaseForVersion(version) as ISchemeAccess).SchemeCollection;

                foreach (XmlElement context in list)
                {
                    string uri = context.GetAttribute(attributeName);

                    if ((uri == null) || (uri.Length == 0))
                    {
                        errorHandler("305", context,
                                     "A qualifying scheme URI has not been defined for this element",
                                     Name, context.LocalName);

                        result = false;
                        continue;
                    }

                    Scheme scheme = schemes.FindSchemeForUri(uri);
                    if (scheme == null)
                    {
                        errorHandler("305", context,
                                     "An unrecognized scheme URI has been used as a qualifier",
                                     Name, uri);

                        result = false;
                        continue;
                    }

                    string value = context.InnerText.Trim();
                    if (scheme.IsValid(value))
                    {
                        continue;
                    }

                    errorHandler("305", context,
                                 "The code value '" + value + "' is not valid in scheme '" + scheme.Uri + "'",
                                 Name, value);

                    result = false;
                }
            }
            return(result);
        }
예제 #37
0
        private static bool Rule44(string name, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool		result = true;

            foreach (XmlElement context in list) {
                XmlElement	pool	= XPath.Path (context, "generalTerms", "basketReferenceInformation", "referencePool");
                XmlNodeList	items  	= XPath.Paths (pool, "referencePoolItem");
                XmlNodeList	weights	= XPath.Paths (pool, "referencePoolItem", "constituentWeight", "basketPercentage");

                if ((weights.Count == 0) || (weights.Count == items.Count)) continue;

                errorHandler ("305", pool,
                        "Either every referencePoolItem should have a basketPercentage or none should have one",
                        name, null);

                result = false;
            }
            return (result);
        }
예제 #38
0
        //---------------------------------------------------------------------

        private static bool Rule06(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            return(Rule06(name, nodeIndex.GetElementsByName("americanExercise"), errorHandler));
        }
예제 #39
0
        private static bool Rule02(string name, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in list) {
                if (context ["calculationAgent"] != null) {
                    bool			failed	= false;

                    foreach (XmlNode node in context ["calculationAgent"].ChildNodes) {
                        if (node.NodeType == XmlNodeType.Element) {
                            if (node.LocalName.Equals ("calculationAgentPartyReference"))
                                continue;

                            if (node.LocalName.Equals ("calculationAgentParty") &&
                                node.InnerText.Trim ().Equals ("AsSpecifiedInMasterAgreement"))
                                continue;

                            failed = true;
                        }
                    }

                    if (failed) {
                        errorHandler ("305", context,
                            "The calculationAgent element may only contain calculationAgentPartyReferences " +
                            "or a calculationAgentParty with the value 'AsSpecifiedInMasterAgreement",
                            name, null);

                        result = false;
                    }
                }
            }
            return (result);
        }
예제 #40
0
        //---------------------------------------------------------------------

        private static bool Rule10(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            return(Rule10(name, nodeIndex.GetElementsByName("calculationAgent"), errorHandler));
        }
예제 #41
0
        // --------------------------------------------------------------------
        private static bool Rule05(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("generalTerms")) {
                if (Exists (XPath.Path (context, "scheduledTerminationDate", "adjustableDate"))) {
                    XmlNode			effectiveDate	= XPath.Path (context, "effectiveDate", "unadjustedDate");
                    XmlNode			terminationDate	= XPath.Path (context, "scheduledTerminationDate", "adjustableDate", "unadjustedDate");

                    if ((effectiveDate == null) || (terminationDate == null) || Less (effectiveDate, terminationDate ))
                        continue;

                    errorHandler ("305", context,
                        "Effective date " + effectiveDate.InnerText.Trim () + " is not " +
                        "before scheduled termination date " + terminationDate.InnerText.Trim (),
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
예제 #42
0
        //---------------------------------------------------------------------

        private static bool Rule11(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            return(Rule11(name, nodeIndex.GetElementsByName("businessDateRange"), errorHandler));
        }
예제 #43
0
 // --------------------------------------------------------------------
 private static bool Rule08(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
 {
     return (
           Rule08 (name, nodeIndex.GetElementsByName ("trade"), errorHandler)
         & Rule08 (name, nodeIndex.GetElementsByName ("contract"), errorHandler));
 }
예제 #44
0
        //---------------------------------------------------------------------

        private static bool Rule13A(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            return(Rule13A(name, nodeIndex.GetElementsByName("sellerPartyReference"), errorHandler, nodeIndex));
        }
예제 #45
0
        // --------------------------------------------------------------------
        private static bool Rule10(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("referenceInformation")) {
                string			primaryReference;
                string			primaryId;

                foreach (XmlElement primary in XPath.Paths (context, "referenceObligation", "guarantorReference")) {
                    if (Equal (
                            primaryReference = primary.GetAttribute ("href"),
                            primaryId		 = context ["referenceEntity"].GetAttribute ("id")))
                        continue;

                    errorHandler ("305", context,
                        "Primary obligor reference '" + primaryReference +
                        "' should point to the reference entity ' " + primaryId + "'",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
예제 #46
0
        //---------------------------------------------------------------------

        private static bool Rule14B(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            return(Rule14B(name, nodeIndex.GetElementsByName("calculationAgentPartyReference"), errorHandler, nodeIndex));
        }
예제 #47
0
        // --------------------------------------------------------------------
        private static bool Rule12(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("referenceInformation")) {
                if (Exists (context ["referencePrice"])) {
                    if (GreaterOrEqual (context ["referencePrice"], 0.0))
                        continue;

                    errorHandler ("305", context,
                        "If referencePrice is present it must not have a negative " +
                        "value",
                        name, context ["referencePrice"].InnerText);

                    result = false;
                }
            }
            return (result);
        }
 /// <summary>
 /// Validates the date and returns the date.
 /// </summary>
 public DateTime ValidateAndGetPostBackDate(PostBackValueDictionary postBackValues, Validator validator, ValidationErrorHandler errorHandler)
 {
     return(validator.GetDateTime(
                errorHandler,
                textBox.GetPostBackValue(postBackValues).ToUpper(),
                DateTimeTools.MonthDayYearFormats.Select(i => i + " " + DateTimeTools.HourAndMinuteFormat).ToArray(),
                min,
                max));
 }
예제 #49
0
        // --------------------------------------------------------------------
        private static bool Rule14(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            bool			result	= true;

            foreach (XmlElement context in nodeIndex.GetElementsByName ("creditDefaultSwap")) {
                foreach (XmlElement seller in XPath.Paths (context, "protectionTerms", "creditEvents", "creditEventNotice", "notifyingParty", "sellerPartyReference")) {
                    if (Equal (seller.GetAttribute ("href"),
                            XPath.Path (context, "generalTerms", "sellerPartyReference").GetAttribute ("href")))
                        continue;

                    errorHandler ("305", context,
                        "If protectionTerms/creditEvents/creditEventNotice/notifyingParty/sellerPartyReference " +
                        "is present, its @href attribute must match that of generalTerms/sellerPartyReference",
                        name, null);

                    result = false;
                }
            }
            return (result);
        }
예제 #50
0
        private static bool Rule02(string name, NodeIndex nodeIndex, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool result = true;

            foreach (XmlElement context in list)
            {
                XmlAttribute href;
                XmlElement   target;

                if (((href = context.GetAttributeNode("href")) == null) ||
                    ((target = nodeIndex.GetElementById(href.Value)) == null))
                {
                    continue;
                }

                string targetName = target.LocalName;

                if (targetName.Equals("creditCurve") ||
                    targetName.Equals("fxCurve") ||
                    targetName.Equals("volatilityRepresentation") ||
                    targetName.Equals("yieldCurve"))
                {
                    continue;
                }

                errorHandler("305", context,
                             "@href must match the @id attribute of an element of type PricingStructure",
                             name, targetName);

                result = false;
            }
            return(result);
        }
        // --------------------------------------------------------------------
        private static bool Rule02(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            if (nodeIndex.HasTypeInformation)
                return (Rule02 (name, nodeIndex, nodeIndex.GetElementsByType (DetermineNamespace (nodeIndex), "PaymentCalculationPeriod"), errorHandler));

            return (Rule02 (name, nodeIndex, nodeIndex.GetElementsByName ("paymentCalculationPeriod"), errorHandler));
        }
        // --------------------------------------------------------------------

        private static bool Rule05(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            return(Rule05(name, nodeIndex, XPath.Paths(nodeIndex.GetElementsByName("novation"), ".."), errorHandler));
        }
        // --------------------------------------------------------------------
        private static bool Rule01(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            if (nodeIndex.HasTypeInformation)
                return (Rule01 (name, nodeIndex, nodeIndex.GetElementsByType (DetermineNamespace (nodeIndex), "PricingDataPointCoordinate"), errorHandler));

            return (Rule01 (name, nodeIndex, nodeIndex.GetElementsByName ("coordinate"), errorHandler));
        }
        private static bool Rule05(string name, NodeIndex nodeIndex, XmlNodeList list, ValidationErrorHandler errorHandler)
        {
            bool result = true;

            foreach (XmlElement context in list)
            {
                XmlElement   startDate = XPath.Path(context, "novation", "firstPeriodStartDate");
                XmlAttribute href;

                if ((startDate == null) || (href = startDate.GetAttributeNode("href")) == null)
                {
                    continue;
                }

                XmlElement target = nodeIndex.GetElementById(href.Value);

                if ((target == null) || !target.LocalName.Equals("party"))
                {
                    errorHandler("305", context,
                                 "The @href attribute on the firstPeriodStartDate must reference a party",
                                 name, href.Value);

                    result = false;
                }
            }
            return(result);
        }
예제 #55
0
 /// <summary>
 /// Determines if the given <see cref="XmlDocument"/> instance's business
 /// data content passes a validation test. If errors are detected these will
 /// be reported through the <see cref="ValidationErrorHandler"/> instance passed as an
 /// argument.
 /// </summary>
 /// <remarks>Note that test returns <c>true</c> if it does not fail,
 /// including circumstances when the test is inapplicable to the
 /// <see cref="XmlDocument"/> under examination.
 /// </remarks>
 /// <param name="document">The <see cref="XmlDocument"/> instance to examine.</param>
 /// <param name="errorHandler">An <see cref="ValidationErrorHandler"/> delegate used to report
 /// validation failures.</param>
 /// <returns><c>false</c> if the validation test failed, <c>true</c> otherwise.
 /// </returns>
 public bool Validate(XmlDocument document, ValidationErrorHandler errorHandler)
 {
     return (Validate (new NodeIndex (document), errorHandler));
 }
예제 #56
0
        // --------------------------------------------------------------------

        private static bool Rule04(string name, NodeIndex nodeIndex, ValidationErrorHandler errorHandler)
        {
            return(Rule04(name, nodeIndex.GetElementsByName("equityBermudaExercise"), errorHandler));
        }
예제 #57
0
 /// <summary>
 /// Determines if the <see cref="XmlDocument"/> instance indexed by the
 /// provided <see cref="NodeIndex"/> has business data content that passes a
 /// validation test. If errors are detected they will be reported through
 /// the <see cref="ValidationErrorHandler"/> instance passed as an argument.
 /// </summary>
 /// <remarks>Note that test returns <c>true</c> if it does not fail,
 /// including circumstances when the test is inapplicable to the
 /// <see cref="XmlDocument"/> under examination.
 /// </remarks>
 /// <param name="nodeIndex">The <see cref="NodeIndex"/> instance to examine.</param>
 /// <param name="errorHandler">An <see cref="ValidationErrorHandler"/> instance used to report
 /// validation failures.</param>
 /// <returns><c>false</c> if the validation test failed, <c>true</c> otherwise.
 /// </returns>
 protected abstract bool Validate(NodeIndex nodeIndex, ValidationErrorHandler errorHandler);
        /// <summary>
        /// Creates a time control.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="allowEmpty"></param>
        /// <param name="setup">The setup object for the time control.</param>
        /// <param name="minValue">The earliest allowed time.</param>
        /// <param name="maxValue">The latest allowed time. This can be earlier than <paramref name="minValue"/> to create a range spanning midnight.</param>
        /// <param name="minuteInterval">Allows the user to select values only in the given increments. Be aware that other values can still be sent from the
        /// browser via a crafted request.</param>
        /// <param name="validationMethod">The validation method. Pass null if you’re only using this control for page modification.</param>
        public TimeControl(
            LocalTime?value, bool allowEmpty, TimeControlSetup setup = null, LocalTime?minValue = null, LocalTime?maxValue = null, int minuteInterval = 15,
            Action <LocalTime?, Validator> validationMethod          = null)
        {
            setup    = setup ?? TimeControlSetup.Create();
            minValue = minValue ?? LocalTime.Midnight;

            if (minuteInterval < 30)
            {
                var textControl = new TextControl(
                    value.HasValue ? new TimeSpan(value.Value.TickOfDay).ToTimeOfDayHourAndMinuteString() : "",
                    allowEmpty,
                    setup: setup.IsReadOnly
                                                       ? TextControlSetup.CreateReadOnly(validationPredicate: setup.ValidationPredicate, validationErrorNotifier: setup.ValidationErrorNotifier)
                                                       : TextControlSetup.Create(
                        autoFillTokens: setup.AutoFillTokens,
                        action: new SpecifiedValue <FormAction>(setup.Action),
                        valueChangedAction: setup.ValueChangedAction,
                        pageModificationValue: setup.PageModificationValue,
                        validationPredicate: setup.ValidationPredicate,
                        validationErrorNotifier: setup.ValidationErrorNotifier),
                    validationMethod: validationMethod == null
                                                                  ? (Action <string, Validator>)null
                                                                  : (postBackValue, validator) => {
                    var errorHandler   = new ValidationErrorHandler("time");
                    var validatedValue = validator.GetNullableTimeOfDayTimeSpan(
                        errorHandler,
                        postBackValue.ToUpper(),
                        TewlContrib.DateTimeTools.HourAndMinuteFormat.ToCollection().ToArray(),
                        allowEmpty)
                                         .ToNewUnderlyingValue(v => LocalTime.FromTicksSinceMidnight(v.Ticks));
                    if (errorHandler.LastResult != ErrorCondition.NoError)
                    {
                        setup.ValidationErrorNotifier?.Invoke();
                        return;
                    }

                    var wrap = maxValue < minValue.Value;
                    if (!wrap
                                                                                      ? validatedValue < minValue.Value || validatedValue > maxValue
                                                                                      : validatedValue < minValue.Value && validatedValue > maxValue)
                    {
                        validator.NoteErrorAndAddMessage("The time is too early or too late.");
                        setup.ValidationErrorNotifier?.Invoke();
                        return;
                    }

                    validationMethod(validatedValue, validator);
                });

                Labeler = textControl.Labeler;

                PageComponent = new DisplayableElement(
                    context => new DisplayableElementData(
                        setup.DisplaySetup,
                        () => new DisplayableElementLocalData(
                            "div",
                            focusDependentData: new DisplayableElementFocusDependentData(
                                includeIdAttribute: true,
                                jsInitStatements: "{0}.timepicker( {{ {1} }} );".FormatWith(
                                    getTextControlExpression(context.Id),
                                    StringTools.ConcatenateWithDelimiter(
                                        ", ",
                                        "timeFormat: 'h:mmt'",
                                        "stepMinute: {0}".FormatWith(minuteInterval),
                                        "showButtonPanel: false")))),
                        classes: elementClass.Add(setup.Classes ?? ElementClassSet.Empty),
                        children: textControl.PageComponent.ToCollection()
                        .Concat(
                            setup.IsReadOnly
                                                                        ? Enumerable.Empty <PhrasingComponent>()
                                                                        : new EwfButton(
                                new CustomButtonStyle(children: new FontAwesomeIcon("fa-clock-o").ToCollection()),
                                behavior: new CustomButtonBehavior(() => "{0}.timepicker( 'show' );".FormatWith(getTextControlExpression(context.Id))),
                                classes: new ElementClass("icon")).ToCollection())
                        .Materialize()));

                Validation = textControl.Validation;
            }
            else
            {
                var items = from time in getTimes(minValue.Value, maxValue, minuteInterval)
                            let timeSpan = new TimeSpan(time.TickOfDay)
                                           select SelectListItem.Create <LocalTime?>(time, timeSpan.ToTimeOfDayHourAndMinuteString());

                var selectList = SelectList.CreateDropDown(
                    setup.IsReadOnly
                                                ? DropDownSetup.CreateReadOnly(
                        items,
                        placeholderText: "",
                        validationPredicate: setup.ValidationPredicate,
                        validationErrorNotifier: setup.ValidationErrorNotifier)
                                                : DropDownSetup.Create(
                        items,
                        placeholderText: "",
                        autoFillTokens: setup.AutoFillTokens,
                        action: new SpecifiedValue <FormAction>(setup.Action),
                        selectionChangedAction: setup.ValueChangedAction,
                        validationPredicate: setup.ValidationPredicate,
                        validationErrorNotifier: setup.ValidationErrorNotifier),
                    value,
                    placeholderIsValid: allowEmpty,
                    validationMethod: validationMethod);

                Labeler = selectList.Labeler;

                PageComponent = new GenericFlowContainer(
                    selectList.PageComponent.ToCollection(),
                    displaySetup: setup.DisplaySetup,
                    classes: elementClass.Add(setup.Classes ?? ElementClassSet.Empty));

                Validation = selectList.Validation;
            }
        }