Ejemplo n.º 1
0
        public bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate(ATMLCommon.TestEquipmentNameSpace, GetType().Name, testSubject,
                                          errors));
        }
Ejemplo n.º 2
0
        public bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate(TestEquipmentNameSpace, "OperatingSystem", testSubject,
                                          errors));
        }
Ejemplo n.º 3
0
        public new bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate(ATMLCommon.TestEquipmentNameSpace, "TerminalBlock", testSubject,
                                          errors));
        }
Ejemplo n.º 4
0
        public new bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate(ATMLCommon.HardwareCommonNameSpace, GetType().Name, testSubject,
                                          errors));
        }
        public bool Validate(out string error)
        {
            error = null;
            bool isValid = true;
            var  sb      = new StringBuilder();

            if (_legalDocuments.Items != null)
            {
                foreach (var document in _legalDocuments.Items)
                {
                    var svr = new SchemaValidationResult();
                    isValid &= document.Validate(svr);
                    if (svr.HasErrors())
                    {
                        sb.Append(svr.ErrorMessage).Append(", ");
                    }
                }
                if (sb.ToString().EndsWith(", "))
                {
                    sb.Length = sb.Length - 2;
                }
                error = sb.ToString();
            }
            return(isValid);
        }
Ejemplo n.º 6
0
        public bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate("urn:IEEE-1671.4:2009.03:TestConfiguration", "TestConfiguration", testSubject,
                                          errors));
        }
Ejemplo n.º 7
0
        public SchemaValidationResult ValidateJsonAgainstSchema(string jsonSchema, string data)
        {
            var schema = JSchema.Parse(jsonSchema.Trim());

            var jsonData           = JToken.Parse(data.Trim());
            var parsedObjectsCount = jsonData.Children().Count();

            _logger.Information($"Number Of object parsed = {parsedObjectsCount} for schema \n {jsonSchema}");

            IList <ValidationError> validationErrors = new List <ValidationError>();

            jsonData.IsValid(schema, out validationErrors);

            int nullOccuranceCount = 0;
            var listOfErrors       = FilterNullValueError(validationErrors, ref nullOccuranceCount);

            var errorGroup = listOfErrors.GroupBy(x => x.ErrorType);

            foreach (var grouping in errorGroup)
            {
                _logger.Error($"ErrorType = {grouping.Key}. Count = {grouping.Count()}");
            }

            var schemaValidationResult = new SchemaValidationResult
            {
                SchemaValidationErrors = listOfErrors,
                ParsedObjectsCount     = parsedObjectsCount,
                NullOccurances         = nullOccuranceCount
            };

            return(schemaValidationResult);
        }
        public SchemaValidationResult Validate(object model)
        {
            var data     = model as QueryRequest;
            var result   = new SchemaValidationResult();
            var location = "QueryRequest";

            result.MissingCheck($"Issuer", data.Issuer, location);
            result.MissingCheck($"Issuer.Type", data.Issuer.Type, location);
            result.MaxRangeCheck($"Issuer.Type", data.Issuer.Type, location, SchemaValidationResult.DEFAULT_MAX_LENGTH);

            var identityValidator = _validatorFactory.GetIdentityValidator(data.Issuer);

            identityValidator.Validate("Issuer", data.Issuer, data, "QueryRequest", result);

            result.MaxRangeCheck($"Types", data.Types.Count, location, 127);
            var index = 0;

            foreach (var type in data.Types)
            {
                result.MaxRangeCheck($"Types[{index}]", type, location, 127);
                index++;
            }

            result.MaxRangeCheck($"Subjects", data.Subjects.Count, location, 1024);
            index = 0;
            foreach (var subject in data.Subjects)
            {
                result.MaxRangeCheck($"Subjects[{index}]", subject, location, 127);
                index++;
            }

            return(result);
        }
        public async void HandleMessage(IPublishedMessage publishedMessage)
        {
            try
            {
                using (var scope = _serviceProvider.CreateScope())
                {
                    // Create a scope so all dependency injections are available.
                    var text = Encoding.UTF8.GetString(publishedMessage.DataBytes);

                    var packageMessage = JsonConvert.DeserializeObject <PackageMessage>(text);
                    //if (_serverIdentityService.Id.Equals(packageMessage.ServerId)) // Do not process own package messages
                    //   return;

                    logger.LogInformation($"Received message from {packageMessage.ServerId}");

                    _packageMessageValidator.Validate(packageMessage);

                    var mediator = scope.ServiceProvider.GetRequiredService <IMediator>();
                    var package  = mediator.SendAndWait(new FetchPackageCommand(packageMessage.File));

                    if (package == null)
                    {
                        logger.LogError($"Error wrong notitifiation returned from FatchPackageCommand");
                        return;
                    }

                    if (package.Timestamps == null || package.Timestamps.Count == 0)
                    {
                        logger.LogError($"Error no timestamps was found on package id {package.Id} from server id {packageMessage.ServerId}");
                        return;
                    }

                    var packageValidator = scope.ServiceProvider.GetRequiredService <IPackageSchemaValidator>();
                    SchemaValidationResult validationResult = packageValidator.Validate(package); //
                    if (validationResult.ErrorsFound > 0)
                    {
                        logger.LogError(validationResult.ToString());
                        return;
                    }

                    var timestampValidator = scope.ServiceProvider.GetRequiredService <ITimestampProofValidator>();
                    if (!timestampValidator.Validate(package.Timestamps[0], out IList <string> errors))
                    {
                        var msg = string.Join(", ", errors);
                        logger.LogError(msg);
                        return;
                    }

                    //var peers = await Ipfs.PubSub.PublishAsync;

                    // Now add the package!
                    await mediator.Send(new AddPackageCommand(package));
                }
            }
            catch (Exception ex)
            {
                var msg = $"Message from server {publishedMessage.Sender.Id} failed with: {ex.Message}";
                logger.LogError(msg);
            }
        }
Ejemplo n.º 10
0
        public bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate(ATMLCommon.HardwareCommonNameSpace, "Component", testSubject,
                                          errors));
        }
Ejemplo n.º 11
0
        public bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate(ATMLCommon.HardwareCommonNameSpace, "TriggerPropertyGroup",
                                          testSubject, errors));
        }
Ejemplo n.º 12
0
        public new bool Validate(SchemaValidationResult schemaValidationResult)
        {
            object testSubject = this;
            bool   isValid     = SchemaManager.Validate("urn:IEEE-1671:2010:Common", "Connector", testSubject,
                                                        schemaValidationResult);

            return(isValid);
        }
Ejemplo n.º 13
0
        public SchemaValidationResult ValidateSchema(XDocument docToValidate, XmlSchemaSet schemaToValidateAgainst)
        {
            var result = new SchemaValidationResult();

            docToValidate.Validate(schemaToValidateAgainst, (o, e) =>
            {
                result.AddError(e.Message);
            });

            return(result);
        }
Ejemplo n.º 14
0
            private void ValidateClaim(int claimIndex, Claim claim, SchemaValidationResult result)
            {
                var location = $"Claim Index: {claimIndex} - ";

                result.MaxRangeCheck("Id", claim.Id, location, ID_MAX_LENGTH);
                result.MaxRangeCheck("Type", claim.Type, location, TYPE_MAX_LENGTH);
                result.MaxRangeCheck("Value", claim.Value, location, CLAIM_MAX_LENGTH);
                result.MaxRangeCheck("Note", claim.Note, location, NOTE_MAX_LENGTH);

                ValidateIssuer(claim, location);
                ValidateSubject(claim, location);
                ValidateScope(claim, location);
                ValidateTimestamps(claim.Timestamps, location);
            }
Ejemplo n.º 15
0
 public SchemaValidationResult Validate(Claim claim)
 {
     try
     {
         result = new SchemaValidationResult();
         var testBuilder = new PackageBuilder(_merkleStrategyFactory, _hashAlgorithmFactory, _packageBinary);
         var claimIndex  = 0;
         testBuilder.AddClaim(claim);
         ValidateClaim(claimIndex++, claim, result);
     }
     catch (Exception ex)
     {
         result.Errors.Add(ex.Message);
     }
     return(result);
 }
        public bool Validate(out string error)
        {
            bool          isValid = true;
            StringBuilder sb      = new StringBuilder();

            foreach (NamedValue factoryDefault in _factoryDefaults)
            {
                SchemaValidationResult svr = new SchemaValidationResult();
                isValid &= factoryDefault.Validate(svr);
                if (svr.HasErrors())
                {
                    sb.Append(svr.ErrorMessage).Append(", ");
                }
            }
            if (sb.ToString().EndsWith(", "))
            {
                sb.Length = sb.Length - 2;
            }
            error = sb.ToString();
            return(isValid);
        }
Ejemplo n.º 17
0
        private bool ValidatePackage(PackageInfo packageInfo, Package package)
        {
            if (package == null)
            {
                _logger.LogError($"Error wrong notitifiation returned from FatchPackageCommand");
                return(false);
            }

            if (package.Timestamps == null || package.Timestamps.Count == 0)
            {
                _logger.LogError($"Error no timestamps was found on package id {package.Id}");
                return(false);
            }

            // Verify package
            SchemaValidationResult validationResult = _packageSchemaValidator.Validate(package); //

            if (validationResult.ErrorsFound > 0)
            {
                _logger.LogError(validationResult.ToString());
                return(false);
            }

            if (!_timestampProofValidator.Validate(package.Timestamps[0], out IList <string> errors))
            {
                var msg = string.Join(", ", errors);
                _logger.LogError(msg);
                return(false);
            }

            if (!ByteComparer.EqualityComparer.Equals(packageInfo.Id, package.Id))
            {
                _logger.LogError($"Error PackageInfo id {packageInfo.Id} is not the same as package id {package.Id} from file {packageInfo.File}");
                return(false);
            }


            return(true);
        }
        public SchemaValidationResult Validate(XmlDocument document)
        {
            if (document.Schemas.Count == 0)
                throw new InvalidOperationException("The document must have a schema assigned.");

            var result = new SchemaValidationResult();

            document.Validate((sender, e) =>
                {
                    // This stinks, there has got to be a better way.
                    string source = null;
                    var ex = e.Exception as XmlSchemaValidationException;
                    if(ex != null)
                    {
                        var element = ex.SourceObject as XmlElement;
                        if (element != null)
                            source = string.Format("Element '{0}'", element.Name);
                    }

                    result.Messages.Add(string.Format("{0}: {1}", source ?? "no source", e.Message));
                });

            return result;
        }
Ejemplo n.º 19
0
        public void Validate(string name, Identity identity, object source, string location, SchemaValidationResult result)
        {
            var claim = source as Claim;

            result.MaxRangeCheck($"{name} Id", identity.Id, location, 40);
            if (claim != null)
            {
                result.MissingCheck($"{name} Proof", identity.Id, location);
                result.MaxRangeCheck($"{name} Proof", identity.Proof, location, SchemaValidationResult.DEFAULT_TITLE_LENGTH);
            }

            // TODO: Properly validate Id
            var regex = new Regex(@"^[13nmD][a-km-zA-HJ-NP-Z0-9]{26,33}$");

            if (!regex.IsMatch(identity.Id))
            {
                result.Errors.Add(string.Format(InvalidAddressErrorTemplate, location, $"{name} Id"));
                return;
            }
            if (claim != null)
            {
                var message = _claimBinary.GetIdSource(claim).ConvertToBase64();
                if (!_derivationSecp256K1PKH.VerifySignatureMessage(message, identity.Proof, identity.Id))
                {
                    result.Errors.Add(string.Format(InvalidProofErrorTemplate, location, $"{name} Proof"));
                }
            }
        }
Ejemplo n.º 20
0
        public void Validate(string name, Identity identity, object source, string location, SchemaValidationResult result)
        {
            result.MaxRangeCheck($"{name} Id", identity.Id, location, SchemaValidationResult.DEFAULT_TITLE_LENGTH);
            result.MaxRangeCheck($"{name} Proof", identity.Proof, location, 0);

            var regex = new Regex(@"^[13nmD][a-km-zA-HJ-NP-Z0-9]{26,33}$");

            if (!regex.IsMatch(identity.Id))
            {
                result.Errors.Add(string.Format(InvalidAddressErrorTemplate, location, $"{name} Id"));
                return;
            }
        }
        void TestEquipmentControl_Validating(object sender, CancelEventArgs e)
        {
            TestEquipment testEquipment = TestEquipment;

            if (testEquipment != null)
            {
                if (testEquipment.FacilitiesRequirements != null)
                {
                    var svr = new SchemaValidationResult();
                    if (!testEquipment.FacilitiesRequirements.Validate(svr))
                    {
                        tabFacilities.ToolTipText = svr.ErrorMessage;
                    }
                }
                if (testEquipment.Controllers != null)
                {
                    foreach (Controller controller in testEquipment.Controllers)
                    {
                        var svr = new SchemaValidationResult();
                        if (!controller.Validate(svr))
                        {
                            tabControllers.ToolTipText = svr.ErrorMessage;
                        }
                    }
                }
                if (testEquipment.Software != null)
                {
                    foreach (ItemDescription itemDescription in testEquipment.Software)
                    {
                        var svr = new SchemaValidationResult();
                        if (!itemDescription.Validate(svr))
                        {
                            tabSoftware.ToolTipText = svr.ErrorMessage;
                        }
                    }
                }
                if (testEquipment.Paths != null)
                {
                    foreach (Path item in testEquipment.Paths)
                    {
                        var svr = new SchemaValidationResult();
                        if (!item.Validate(svr))
                        {
                            tabPaths.ToolTipText = svr.ErrorMessage;
                        }
                    }
                }
                if (testEquipment.Specifications != null)
                {
                    var svr = new SchemaValidationResult();
                    if (!testEquipment.Specifications.Validate(svr))
                    {
                        tabSpecifications.ToolTipText = svr.ErrorMessage;
                    }
                }
                if (testEquipment.Switching != null)
                {
                    var svr = new SchemaValidationResult();
                    if (!testEquipment.Switching.Validate(svr))
                    {
                        tabSwitching.ToolTipText = svr.ErrorMessage;
                    }
                }
                if (testEquipment.Resources != null)
                {
                    foreach (Resource item in testEquipment.Resources)
                    {
                        var svr = new SchemaValidationResult();
                        if (!item.Validate(svr))
                        {
                            tabResources.ToolTipText = svr.ErrorMessage;
                        }
                    }
                }
                if (testEquipment.Capabilities != null)
                {
                    var svr = new SchemaValidationResult();
                    if (!testEquipment.Capabilities.Validate(svr))
                    {
                        tabCapabilities.ToolTipText = svr.ErrorMessage;
                    }
                }
                if (testEquipment.TerminalBlocks != null)
                {
                    var svr = new SchemaValidationResult();
                    if (!testEquipment.TerminalBlocks.Validate(svr))
                    {
                        tabTerminalBlocks.ToolTipText = svr.ErrorMessage;
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public new bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate(TestStationNameSpace, "TestStationDescription", testSubject, errors));
        }
Ejemplo n.º 23
0
        public void Validate(string name, Identity identity, object source, string location, SchemaValidationResult result)
        {
            result.MaxRangeCheck($"{name} Id", identity.Id, location, SchemaValidationResult.DEFAULT_MAX_LENGTH);
            result.MaxRangeCheck($"{name} Proof", identity.Proof, location, 0);

            var regex = new Regex(@"^\w+$"); // ^[0-9]+$

            if (!regex.IsMatch(identity.Id))
            {
                result.Errors.Add(string.Format(NotAlphaNumericErrorTemplate, location, $"{name}.Id"));
            }
        }
        public void Validate(string name, Identity identity, object source, string location, SchemaValidationResult result)
        {
            result.MaxRangeCheck($"{name} Id", identity.Id, location, SchemaValidationResult.DEFAULT_TITLE_LENGTH);
            result.MaxRangeCheck($"{name} Proof", identity.Proof, location, 0);

            if (!Uri.IsWellFormedUriString(identity.Id, UriKind.Absolute))
            {
                result.Errors.Add(string.Format(NotUriErrorTemplate, location, $"{name}.Id"));
            }
        }
Ejemplo n.º 25
0
        private void HardwareItemDescriptionControl_Validating(object sender, CancelEventArgs e)
        {
            tabInterface.BackColor = Color.White;
            operationalRequirementsControl.HasErrors = false;
            interfaceListControl.HasErrors           = false;
            legalDocumentListControl.HasErrors       = false;
            errorProvider.SetError(interfaceListControl, "");
            errorProvider.SetError(operationalRequirementsControl, "");
            errorProvider.SetError(legalDocumentListControl, "");

            foreach (TabPage tabPage in tabPanelControl.TabPages)
            {
                tabPage.ToolTipText = "";
            }

            //-------------------------------------------------------------------------------------------------------//
            //--- TODO: Would like to generically walk all the tab controls to validate and set the tooltip text. ---//
            //-------------------------------------------------------------------------------------------------------//
            string defError;

            if (factoryDefaultsListControl.FactoryDefaults != null &&
                !factoryDefaultsListControl.Validate(out defError))
            {
                errorProvider.SetError(factoryDefaultsListControl, defError);
                tabDefaults.ToolTipText = defError;
                OnError(sender, errorProvider.GetError(this));
            }

            if (identificationControl.Identification == null ||
                string.IsNullOrEmpty(identificationControl.Identification.ModelName))
            {
                errorProvider.SetError(identificationControl, Resources.errmsg_An_Identification_Model_Name_is_required_);
                tabIdentification.ToolTipText = Resources.errmsg_An_Identification_Model_Name_is_required_;
                e.Cancel = true;
                OnError(sender, errorProvider.GetError(this));
            }

            if (operationalRequirementsControl.OperationalRequirements != null)
            {
                var errors = new SchemaValidationResult();
                if (!operationalRequirementsControl.OperationalRequirements.Validate(errors))
                {
                    errorProvider.SetError(operationalRequirementsControl, errors.ErrorMessage);
                    tabRequirements.ToolTipText = errors.ErrorMessage;
                    tabOperational.ToolTipText  = errors.ErrorMessage;
                    operationalRequirementsControl.HasErrors = true;
                    OnError(sender, errors.ErrorMessage);
                }
            }

            if (interfaceListControl.PhysicalInterface != null &&
                (interfaceListControl.PhysicalInterface.Items == null || (interfaceListControl.PhysicalInterface.Items != null &&
                                                                          interfaceListControl.PhysicalInterface.Items.Count == 0)))
            {
                errorProvider.SetError(interfaceListControl, Resources.errmsg_at_least_one_interface_item);
                tabInterface.ToolTipText       = Resources.errmsg_at_least_one_interface_item;
                interfaceListControl.HasErrors = true;
                OnError(sender, errorProvider.GetError(this));
            }

            if (legalDocumentListControl.LegalDocuments != null)
            {
                string error;
                if (!legalDocumentListControl.Validate(out error))
                {
                    tabLegal.ToolTipText = error;
                    legalDocumentListControl.HasErrors = true;
                    errorProvider.SetError(legalDocumentListControl, error);
                    OnError(sender, errorProvider.GetError(this));
                }
            }
        }
Ejemplo n.º 26
0
        public bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate("urn:IEEE-1671:2010:Common", "IdentificationNumber", testSubject, errors));
        }
Ejemplo n.º 27
0
        public bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate("urn:IEEE-1671:2010:Common", "unsignedLong", testSubject, errors));
        }
Ejemplo n.º 28
0
        public bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate("urn:IEEE-1671:2010:HardwareCommon", "OperationalRequirements", testSubject, errors));
        }
Ejemplo n.º 29
0
 public void Validate(string name, Identity identity, object source, string location, SchemaValidationResult result)
 {
     result.MaxRangeCheck($"{name} Id", identity.Id, location, SchemaValidationResult.DEFAULT_MAX_LENGTH);
     result.MaxRangeCheck($"{name} Proof", identity.Proof, location, 0);
 }
Ejemplo n.º 30
0
        public bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate("urn:IEEE-1671.2:2012:InstrumentDescription", "InstrumentDescription", testSubject, errors));
        }
Ejemplo n.º 31
0
        public bool Validate(SchemaValidationResult errors)
        {
            object testSubject = this;

            return(SchemaManager.Validate("urn:IEEE-1671:2010:HardwareCommon", "Switching", testSubject, errors));
        }