protected override void OnStateChanged(ValidatorState state) { foreach (IHighlight i in GetComponents <IHighlight>()) { i.SetHighlightEnabled(state == ValidatorState.HIGHLIGHTED); } }
public void SetState(ValidatorState new_state, bool notify_parent = true) { if (state != new_state) { ForceStateChange(new_state, notify_parent); } }
public void ReturnsValidValidationResults(string deployRoot, long freeSpace, ValidatorState expectedResult, string resultMessage) { //Arrange Task task = Substitute.For <Task>("", 0, null, new List <InstallParam>(), new Dictionary <string, string>()); task.LocalParams.Returns(new List <InstallParam>()); InstallParam deployRootParam = new InstallParam("DeployRoot", deployRoot); task.LocalParams.Add(deployRootParam); List <Task> tasks = Substitute.For <List <Task> >(); tasks.Add(task); DiskSpaceValidator val = Substitute.ForPartsOf <DiskSpaceValidator>(); val.GetHardDriveFreeSpace(string.Empty).ReturnsForAnyArgs(freeSpace); val.Data["HardDriveWarningLimit"] = "5368709120"; val.Data["HardDriveErrorLimit"] = "3221225472"; val.Data["DeployRoot"] = "DeployRoot"; //Act IEnumerable <ValidationResult> results = val.Evaluate(tasks); //Assert Assert.Contains(results, r => r.State == expectedResult && r.Message == resultMessage); }
public void ReturnsValidValidationResults(bool fileExists, ValidatorState expectedResult) { //Arrange Task task = Substitute.For <Task>("", 0, null, new List <InstallParam>(), new Dictionary <string, string>()); task.LocalParams.Returns(new List <InstallParam>()); InstallParam licenseFileParam = new InstallParam("LicenseFile", @"C:\license.xml"); task.LocalParams.Add(licenseFileParam); List <Task> tasks = Substitute.For <List <Task> >(); tasks.Add(task); LicenseFileValidator val = Substitute.ForPartsOf <LicenseFileValidator>(); val.FileExists(string.Empty).ReturnsForAnyArgs(fileExists); val.Data["LicenseFileVariable"] = "LicenseFile"; //Act IEnumerable <ValidationResult> results = val.Evaluate(tasks); //Assert Assert.Contains(results, r => r.State == expectedResult); }
protected override void OnStateChanged(ValidatorState state) { Cleanup(); switch (state) { case ValidatorState.ENABLED: case ValidatorState.HIGHLIGHTED: case ValidatorState.VALIDATED: int nb_children = children.Count; current = nb_children; for (int i = 0; i < nb_children; i++) { if (children[i].State == ValidatorState.VALIDATED) { validatedIndexes.Add(i); validated[i] = true; } else { current = i; break; } } for (int i = current + 1; i < nb_children; i++) { children[i].SetState(type == Type.STRICT ? ValidatorState.DISABLED : state, false); } if (current < children.Count) { if (state != ValidatorState.VALIDATED) { children[current].SetState(state, false); } else { SetState(Previous); } } else if (state != ValidatorState.VALIDATED) { SetState(ValidatorState.VALIDATED); } break; default: foreach (Validator v in children) { v.SetState(state, false); } break; } }
protected override void OnStateChanged(ValidatorState state) { switch (state) { case ValidatorState.VALIDATED: foreach (Validator v in children) { if (v != validated) { v.SetState(ValidatorState.DISABLED, false); } } break; default: validated = null; foreach (Validator v in children) { v.SetState(state, false); } break; } }
public static void ValidateHostedWebCoreConsoleOutput(string log, ITestOutputHelper testLogger) { StringReader reader = new StringReader(log); ValidatorState currentState = ValidatorState.HWC_FIRING_UP; string line; testLogger?.WriteLine("LogValidator: start"); while ((line = reader.ReadLine()) != null) { testLogger?.WriteLine("LogValidator: in state '" + currentState + "' with line: '" + line + "'"); int splitAt = line.IndexOf("] "); if (splitAt == -1 || line.Length <= splitAt + "] ".Length) { Fail("badly formatted line: '" + line + "'"); } if (!line.Substring(splitAt + "] ".Length).StartsWith(expected[(int)currentState])) { Fail("unexpected line: " + line); } else { currentState++; } } if (currentState != ValidatorState.ALL_DONE) { Fail("file ended early"); } testLogger?.WriteLine("LogValidator: done."); }
public void Equals_DifferentKey() { ValidatorState newVs = new ValidatorState(); newVs.PublicKey = ECPoint.DecodePoint("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70b".HexToBytes(), ECCurve.Secp256r1); uut.PublicKey = ECPoint.DecodePoint("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c".HexToBytes(), ECCurve.Secp256r1); uut.Equals(newVs).Should().BeFalse(); }
private void Call(ValidatorState state) { if (this.stack.Count > 0x1c) { throw new FormatException(Strings.Validator_NestingOverflow(0x1c)); } this.stack.Push(state); }
public void TestValidatorState_ToByteArray() { ValidatorState input = new ValidatorState { Votes = new BigInteger(1000) }; input.ToByteArray().ToHexString().Should().Be("e803"); }
private void Check(string[] testStartDates, ValidatorState validatorState) { foreach (var maskedTextBoxDateTimeString in testStartDates) { var value = this._uiValidator.IsMaskedTextBoxDateStringValid(maskedTextBoxDateTimeString); Assert.AreEqual(value, validatorState); } }
public IEnumerable <(ECPoint PublicKey, BigInteger Votes)> GetRegisteredValidators(Snapshot snapshot) { return(snapshot.Storages.Find(new[] { Prefix_Validator }).Select(p => ( p.Key.Key.Skip(1).ToArray().AsSerializable <ECPoint>(), ValidatorState.FromByteArray(p.Value.Value).Votes ))); }
public IEnumerable <(ECPoint PublicKey, BigInteger Votes)> GetRegisteredValidators(StoreView snapshot) { byte[] prefix_key = StorageKey.CreateSearchPrefix(Id, new[] { Prefix_Validator }); return(snapshot.Storages.Find(prefix_key).Select(p => ( p.Key.Key.AsSerializable <ECPoint>(1), ValidatorState.FromByteArray(p.Value.Value).Votes ))); }
public void TestValidatorState_FromByteArray() { ValidatorState input = new ValidatorState { Votes = new BigInteger(1000) }; ValidatorState output = ValidatorState.FromByteArray(input.ToByteArray()); output.Should().BeEquivalentTo(input); }
private StackItem Vote(ApplicationEngine engine, VMArray args) { UInt160 account = new UInt160(args[0].GetByteArray()); ECPoint[] pubkeys = ((VMArray)args[1]).Select(p => p.GetByteArray().AsSerializable <ECPoint>()).ToArray(); if (!InteropService.CheckWitness(engine, account)) { return(false); } StorageKey key_account = CreateAccountKey(account); if (engine.Snapshot.Storages.TryGet(key_account) is null) { return(false); } StorageItem storage_account = engine.Snapshot.Storages.GetAndChange(key_account); AccountState state_account = new AccountState(storage_account.Value); foreach (ECPoint pubkey in state_account.Votes) { StorageItem storage_validator = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_Validator, pubkey.ToArray())); ValidatorState state_validator = ValidatorState.FromByteArray(storage_validator.Value); state_validator.Votes -= state_account.Balance; storage_validator.Value = state_validator.ToByteArray(); } pubkeys = pubkeys.Distinct().Where(p => engine.Snapshot.Storages.TryGet(CreateStorageKey(Prefix_Validator, p.ToArray())) != null).ToArray(); if (pubkeys.Length != state_account.Votes.Length) { StorageItem storage_count = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_ValidatorsCount), () => new StorageItem { Value = new ValidatorsCountState().ToByteArray() }); ValidatorsCountState state_count = ValidatorsCountState.FromByteArray(storage_count.Value); if (state_account.Votes.Length > 0) { state_count.Votes[state_account.Votes.Length - 1] -= state_account.Balance; } if (pubkeys.Length > 0) { state_count.Votes[pubkeys.Length - 1] += state_account.Balance; } storage_count.Value = state_count.ToByteArray(); } state_account.Votes = pubkeys; storage_account.Value = state_account.ToByteArray(); foreach (ECPoint pubkey in state_account.Votes) { StorageItem storage_validator = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_Validator, pubkey.ToArray())); ValidatorState state_validator = ValidatorState.FromByteArray(storage_validator.Value); state_validator.Votes += state_account.Balance; storage_validator.Value = state_validator.ToByteArray(); } return(true); }
public ExerciseValidator(Exercise exercise, IBodyDrawer exampleBodyDrawer) { // Set default state state = ValidatorState.NotStarted; frame = 0; current = 0; this.exercise = exercise; exerciseScores = new List <ExerciseScore>(); this.exampleBodyDrawer = exampleBodyDrawer; }
protected override System.Spatial.CoordinateSystem OnSetCoordinateSystem(System.Spatial.CoordinateSystem coordinateSystem) { ValidatorState state = this.stack.Peek(); this.Execute(PipelineCall.SetCoordinateSystem); if (state == CoordinateSystem) { this.validationCoordinateSystem = coordinateSystem; return(coordinateSystem); } if (this.validationCoordinateSystem != coordinateSystem) { throw new FormatException(Strings.Validator_SridMismatch); } return(coordinateSystem); }
protected override void RefreshState(ValidatorState state) { switch (state) { case ValidatorState.ENABLED: case ValidatorState.HIGHLIGHTED: case ValidatorState.VALIDATED: validated = null; foreach (Validator v in children) { if (v == null || v.State == ValidatorState.FAILED) { SetState(ValidatorState.FAILED); validated = null; break; } else if (v.State == ValidatorState.VALIDATED && validated == null) { validated = v; break; } } if (validated != null) { SetState(ValidatorState.VALIDATED); } else if (state == ValidatorState.VALIDATED) { SetState(Previous); } break; default: break; } }
protected void ForceStateChange(ValidatorState new_state, bool notify_parent = true) { Previous = state; state = new_state; OnStateChanged(state); RefreshState(state); ComputeScore(out score, out scoreWeight); Validator parent = transform.parent?.GetComponent <Validator>(); if (notify_parent && parent != null) { parent.RefreshState(parent.state); parent.ComputeScore(out parent.score, out parent.scoreWeight); } }
private bool Validator_Register(ExecutionEngine engine) { ECPoint pubkey = ECPoint.DecodePoint(engine.EvaluationStack.Pop().GetByteArray(), ECCurve.Secp256r1); if (pubkey.IsInfinity) { return(false); } if (!CheckWitness(engine, pubkey)) { return(false); } ValidatorState validator = validators.GetOrAdd(pubkey, () => new ValidatorState { PublicKey = pubkey }); engine.EvaluationStack.Push(StackItem.FromInterface(validator)); return(true); }
protected override void OnBalanceChanging(ApplicationEngine engine, UInt160 account, AccountState state, BigInteger amount) { DistributeGas(engine, account, state); if (amount.IsZero) { return; } if (state.Votes.Length == 0) { return; } foreach (ECPoint pubkey in state.Votes) { StorageItem storage_validator = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_Validator, pubkey.ToArray())); ValidatorState state_validator = ValidatorState.FromByteArray(storage_validator.Value); state_validator.Votes += amount; storage_validator.Value = state_validator.ToByteArray(); } StorageItem storage_count = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_ValidatorsCount)); ValidatorsCountState state_count = ValidatorsCountState.FromByteArray(storage_count.Value); state_count.Votes[state.Votes.Length - 1] += amount; storage_count.Value = state_count.ToByteArray(); }
public void Initialize(XmlSchemaObject partialValidationType) { if (_currentState != ValidatorState.None && _currentState != ValidatorState.Finish) { throw new InvalidOperationException(SR.Format(SR.Sch_InvalidStateTransition, new string[] { s_methodNames[(int)_currentState], s_methodNames[(int)ValidatorState.Start] })); } if (partialValidationType == null) { throw new ArgumentNullException(nameof(partialValidationType)); } if (!(partialValidationType is XmlSchemaElement || partialValidationType is XmlSchemaAttribute || partialValidationType is XmlSchemaType)) { throw new ArgumentException(SR.Sch_InvalidPartialValidationType); } _currentState = ValidatorState.Start; Reset(); _partialValidationType = partialValidationType; }
private void Persist(Block block) { WriteBatch batch = new WriteBatch(); DbCache <UInt160, AccountState> accounts = new DbCache <UInt160, AccountState>(db, DataEntryPrefix.ST_Account, batch); DbCache <UInt256, UnspentCoinState> unspentcoins = new DbCache <UInt256, UnspentCoinState>(db, DataEntryPrefix.ST_Coin, batch); DbCache <UInt256, SpentCoinState> spentcoins = new DbCache <UInt256, SpentCoinState>(db, DataEntryPrefix.ST_SpentCoin, batch); DbCache <ECPoint, ValidatorState> validators = new DbCache <ECPoint, ValidatorState>(db, DataEntryPrefix.ST_Validator, batch); DbCache <UInt256, AssetState> assets = new DbCache <UInt256, AssetState>(db, DataEntryPrefix.ST_Asset, batch); DbCache <UInt160, ContractState> contracts = new DbCache <UInt160, ContractState>(db, DataEntryPrefix.ST_Contract, batch); DbCache <StorageKey, StorageItem> storages = new DbCache <StorageKey, StorageItem>(db, DataEntryPrefix.ST_Storage, batch); DbMetaDataCache <ValidatorsCountState> validators_count = new DbMetaDataCache <ValidatorsCountState>(db, DataEntryPrefix.IX_ValidatorsCount); long amount_sysfee = GetSysFeeAmount(block.PrevHash) + (long)block.Transactions.Sum(p => p.SystemFee); batch.Put(SliceBuilder.Begin(DataEntryPrefix.DATA_Block).Add(block.Hash), SliceBuilder.Begin().Add(amount_sysfee).Add(block.Trim())); foreach (Transaction tx in block.Transactions) { batch.Put(SliceBuilder.Begin(DataEntryPrefix.DATA_Transaction).Add(tx.Hash), SliceBuilder.Begin().Add(block.Index).Add(tx.ToArray())); unspentcoins.Add(tx.Hash, new UnspentCoinState { Items = Enumerable.Repeat(CoinState.Confirmed, tx.Outputs.Length).ToArray() }); foreach (TransactionOutput output in tx.Outputs) { AccountState account = accounts.GetAndChange(output.ScriptHash, () => new AccountState(output.ScriptHash)); if (account.Balances.ContainsKey(output.AssetId)) { account.Balances[output.AssetId] += output.Value; } else { account.Balances[output.AssetId] = output.Value; } if (output.AssetId.Equals(GoverningToken.Hash) && account.Votes.Length > 0) { foreach (ECPoint pubkey in account.Votes) { validators.GetAndChange(pubkey, () => new ValidatorState(pubkey)).Votes += output.Value; } validators_count.GetAndChange().Votes[account.Votes.Length - 1] += output.Value; } } foreach (var group in tx.Inputs.GroupBy(p => p.PrevHash)) { Transaction tx_prev = GetTransaction(ReadOptions.Default, group.Key, out int height); foreach (CoinReference input in group) { unspentcoins.GetAndChange(input.PrevHash).Items[input.PrevIndex] |= CoinState.Spent; TransactionOutput out_prev = tx_prev.Outputs[input.PrevIndex]; AccountState account = accounts.GetAndChange(out_prev.ScriptHash); if (out_prev.AssetId.Equals(GoverningToken.Hash)) { spentcoins.GetAndChange(input.PrevHash, () => new SpentCoinState { TransactionHash = input.PrevHash, TransactionHeight = (uint)height, Items = new Dictionary <ushort, uint>() }).Items.Add(input.PrevIndex, block.Index); if (account.Votes.Length > 0) { foreach (ECPoint pubkey in account.Votes) { ValidatorState validator = validators.GetAndChange(pubkey); validator.Votes -= out_prev.Value; if (!validator.Registered && validator.Votes.Equals(Fixed8.Zero)) { validators.Delete(pubkey); } } validators_count.GetAndChange().Votes[account.Votes.Length - 1] -= out_prev.Value; } } account.Balances[out_prev.AssetId] -= out_prev.Value; } } switch (tx) { #pragma warning disable CS0612 case RegisterTransaction tx_register: assets.Add(tx.Hash, new AssetState { AssetId = tx_register.Hash, AssetType = tx_register.AssetType, Name = tx_register.Name, Amount = tx_register.Amount, Available = Fixed8.Zero, Precision = tx_register.Precision, Fee = Fixed8.Zero, FeeAddress = new UInt160(), Owner = tx_register.Owner, Admin = tx_register.Admin, Issuer = tx_register.Admin, Expiration = block.Index + 2 * 2000000, IsFrozen = false }); break; #pragma warning restore CS0612 case IssueTransaction _: foreach (TransactionResult result in tx.GetTransactionResults().Where(p => p.Amount < Fixed8.Zero)) { assets.GetAndChange(result.AssetId).Available -= result.Amount; } break; case ClaimTransaction _: foreach (CoinReference input in ((ClaimTransaction)tx).Claims) { if (spentcoins.TryGet(input.PrevHash)?.Items.Remove(input.PrevIndex) == true) { spentcoins.GetAndChange(input.PrevHash); } } break; #pragma warning disable CS0612 case EnrollmentTransaction tx_enrollment: validators.GetAndChange(tx_enrollment.PublicKey, () => new ValidatorState(tx_enrollment.PublicKey)).Registered = true; break; #pragma warning restore CS0612 case StateTransaction tx_state: foreach (StateDescriptor descriptor in tx_state.Descriptors) { switch (descriptor.Type) { case StateType.Account: ProcessAccountStateDescriptor(descriptor, accounts, validators, validators_count); break; case StateType.Validator: ProcessValidatorStateDescriptor(descriptor, validators); break; } } break; #pragma warning disable CS0612 case PublishTransaction tx_publish: contracts.GetOrAdd(tx_publish.ScriptHash, () => new ContractState { Script = tx_publish.Script, ParameterList = tx_publish.ParameterList, ReturnType = tx_publish.ReturnType, ContractProperties = (ContractPropertyState)Convert.ToByte(tx_publish.NeedStorage), Name = tx_publish.Name, CodeVersion = tx_publish.CodeVersion, Author = tx_publish.Author, Email = tx_publish.Email, Description = tx_publish.Description }); break; #pragma warning restore CS0612 case InvocationTransaction tx_invocation: CachedScriptTable script_table = new CachedScriptTable(contracts); using (StateMachine service = new StateMachine(block, accounts, assets, contracts, storages)) { ApplicationEngine engine = new ApplicationEngine(TriggerType.Application, tx_invocation, script_table, service, tx_invocation.Gas); ///add log bool bLog = false; var split = block.Header.Index % this.fulllog_splitcount; if (this.FullLogPath != null && split == this.fulllog_splitindex) // && this.FullLogSkip.Contains(itx.Hash.ToString()) == false) { bLog = true; } if (bLog) { engine.BeginDebug(); } engine.LoadScript(tx_invocation.Script, false); if (engine.Execute()) { service.Commit(); } ApplicationExecuted?.Invoke(this, new ApplicationExecutedEventArgs(tx_invocation, service.Notifications.ToArray(), engine)); //write fulllog if (bLog) { string filename = System.IO.Path.Combine(this.FullLogPath, tx.Hash.ToString() + ".llvmhex.txt"); if (engine.FullLog != null) { engine.FullLog.Save(filename); } } } break; } } accounts.DeleteWhere((k, v) => !v.IsFrozen && v.Votes.Length == 0 && v.Balances.All(p => p.Value <= Fixed8.Zero)); accounts.Commit(); unspentcoins.DeleteWhere((k, v) => v.Items.All(p => p.HasFlag(CoinState.Spent))); unspentcoins.Commit(); spentcoins.DeleteWhere((k, v) => v.Items.Count == 0); spentcoins.Commit(); validators.Commit(); assets.Commit(); contracts.Commit(); storages.Commit(); validators_count.Commit(batch); batch.Put(SliceBuilder.Begin(DataEntryPrefix.SYS_CurrentBlock), SliceBuilder.Begin().Add(block.Hash).Add(block.Index)); db.Write(WriteOptions.Default, batch); current_block_height = block.Index; }
/// <summary> /// Push a new state onto the stack /// </summary> /// <param name="state">The new state</param> private void Call(ValidatorState state) { if (this.stack.Count > MaxGeometryCollectionDepth) { throw new FormatException(Strings.Validator_NestingOverflow(MaxGeometryCollectionDepth)); } this.stack.Push(state); }
private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo) { if (lName == null) { throw new ArgumentNullException("localName"); } if (ns == null) { throw new ArgumentNullException("namespaceUri"); } ValidatorState toState = (this.validationStack.Length > 1) ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute; this.CheckStateTransition(toState, MethodNames[(int) toState]); object typedValue = null; this.attrValid = true; XmlSchemaValidity notKnown = XmlSchemaValidity.NotKnown; XmlSchemaAttribute schemaAttribute = null; XmlSchemaSimpleType xmlType = null; ns = this.nameTable.Add(ns); if (Ref.Equal(ns, this.NsXmlNs)) { return null; } SchemaAttDef def = null; SchemaElementDecl elementDecl = this.context.ElementDecl; XmlQualifiedName key = new XmlQualifiedName(lName, ns); if (this.attPresence[key] != null) { this.SendValidationEvent("Sch_DuplicateAttribute", key.ToString()); if (schemaInfo != null) { schemaInfo.Clear(); } return null; } if (Ref.Equal(ns, this.NsXsi)) { lName = this.nameTable.Add(lName); if ((Ref.Equal(lName, this.xsiTypeString) || Ref.Equal(lName, this.xsiNilString)) || (Ref.Equal(lName, this.xsiSchemaLocationString) || Ref.Equal(lName, this.xsiNoNamespaceSchemaLocationString))) { this.attPresence.Add(key, SchemaAttDef.Empty); } else { this.attrValid = false; this.SendValidationEvent("Sch_NotXsiAttribute", key.ToString()); } } else { AttributeMatchState state2; object obj4; XmlSchemaObject partialValidationType = (this.currentState == ValidatorState.TopLevelAttribute) ? this.partialValidationType : null; def = this.compiledSchemaInfo.GetAttributeXsd(elementDecl, key, partialValidationType, out state2); switch (state2) { case AttributeMatchState.AttributeFound: break; case AttributeMatchState.AnyIdAttributeFound: if (this.wildID != null) { this.SendValidationEvent("Sch_MoreThanOneWildId", string.Empty); } else { this.wildID = def; XmlSchemaComplexType schemaType = elementDecl.SchemaType as XmlSchemaComplexType; if (!schemaType.ContainsIdAttribute(false)) { break; } this.SendValidationEvent("Sch_AttrUseAndWildId", string.Empty); } goto Label_0409; case AttributeMatchState.UndeclaredElementAndAttribute: def = this.CheckIsXmlAttribute(key); if (def != null) { break; } if (((elementDecl != null) || (this.processContents != XmlSchemaContentProcessing.Strict)) || ((key.Namespace.Length == 0) || !this.compiledSchemaInfo.Contains(key.Namespace))) { if (this.processContents != XmlSchemaContentProcessing.Skip) { this.SendValidationEvent("Sch_NoAttributeSchemaFound", key.ToString(), XmlSeverityType.Warning); } } else { this.attrValid = false; this.SendValidationEvent("Sch_UndeclaredAttribute", key.ToString()); } goto Label_0409; case AttributeMatchState.UndeclaredAttribute: def = this.CheckIsXmlAttribute(key); if (def != null) { break; } this.attrValid = false; this.SendValidationEvent("Sch_UndeclaredAttribute", key.ToString()); goto Label_0409; case AttributeMatchState.AnyAttributeLax: this.SendValidationEvent("Sch_NoAttributeSchemaFound", key.ToString(), XmlSeverityType.Warning); goto Label_0409; case AttributeMatchState.ProhibitedAnyAttribute: def = this.CheckIsXmlAttribute(key); if (def != null) { break; } this.attrValid = false; this.SendValidationEvent("Sch_ProhibitedAttribute", key.ToString()); goto Label_0409; case AttributeMatchState.ProhibitedAttribute: this.attrValid = false; this.SendValidationEvent("Sch_ProhibitedAttribute", key.ToString()); goto Label_0409; case AttributeMatchState.AttributeNameMismatch: this.attrValid = false; this.SendValidationEvent("Sch_SchemaAttributeNameMismatch", new string[] { key.ToString(), ((XmlSchemaAttribute) partialValidationType).QualifiedName.ToString() }); goto Label_0409; case AttributeMatchState.ValidateAttributeInvalidCall: this.currentState = ValidatorState.Start; this.attrValid = false; this.SendValidationEvent("Sch_ValidateAttributeInvalidCall", string.Empty); goto Label_0409; default: goto Label_0409; } schemaAttribute = def.SchemaAttribute; if (elementDecl != null) { this.attPresence.Add(key, def); } if (attributeValueGetter != null) { obj4 = attributeValueGetter(); } else { obj4 = attributeStringValue; } typedValue = this.CheckAttributeValue(obj4, def); XmlSchemaDatatype dtype = def.Datatype; if ((dtype.Variety == XmlSchemaDatatypeVariety.Union) && (typedValue != null)) { XsdSimpleValue value2 = typedValue as XsdSimpleValue; xmlType = value2.XmlType; dtype = value2.XmlType.Datatype; typedValue = value2.TypedValue; } this.CheckTokenizedTypes(dtype, typedValue, true); if (this.HasIdentityConstraints) { this.AttributeIdentityConstraints(key.Name, key.Namespace, typedValue, obj4.ToString(), dtype); } } Label_0409: if (!this.attrValid) { notKnown = XmlSchemaValidity.Invalid; } else if (def != null) { notKnown = XmlSchemaValidity.Valid; } if (schemaInfo != null) { schemaInfo.SchemaAttribute = schemaAttribute; schemaInfo.SchemaType = (schemaAttribute == null) ? null : schemaAttribute.AttributeSchemaType; schemaInfo.MemberType = xmlType; schemaInfo.IsDefault = false; schemaInfo.Validity = notKnown; } if (this.ProcessSchemaHints && (this.validatedNamespaces[ns] == null)) { this.validatedNamespaces.Add(ns, ns); } return typedValue; }
public void Initialize(XmlSchemaObject partialValidationType) { if ((this.currentState != ValidatorState.None) && (this.currentState != ValidatorState.Finish)) { throw new InvalidOperationException(Res.GetString("Sch_InvalidStateTransition", new string[] { MethodNames[(int) this.currentState], MethodNames[1] })); } if (partialValidationType == null) { throw new ArgumentNullException("partialValidationType"); } if ((!(partialValidationType is XmlSchemaElement) && !(partialValidationType is XmlSchemaAttribute)) && !(partialValidationType is XmlSchemaType)) { throw new ArgumentException(Res.GetString("Sch_InvalidPartialValidationType")); } this.currentState = ValidatorState.Start; this.Reset(); this.partialValidationType = partialValidationType; }
private void Init() { this.validationStack = new HWStack(10); this.attPresence = new Hashtable(); this.Push(XmlQualifiedName.Empty); this.dummyPositionInfo = new PositionInfo(); this.positionInfo = this.dummyPositionInfo; this.validationEventSender = this; this.currentState = ValidatorState.None; this.textValue = new StringBuilder(100); this.xmlResolver = new XmlUrlResolver(); this.contextQName = new XmlQualifiedName(); this.Reset(); this.RecompileSchemaSet(); this.NsXs = this.nameTable.Add("http://www.w3.org/2001/XMLSchema"); this.NsXsi = this.nameTable.Add("http://www.w3.org/2001/XMLSchema-instance"); this.NsXmlNs = this.nameTable.Add("http://www.w3.org/2000/xmlns/"); this.NsXml = this.nameTable.Add("http://www.w3.org/XML/1998/namespace"); this.xsiTypeString = this.nameTable.Add("type"); this.xsiNilString = this.nameTable.Add("nil"); this.xsiSchemaLocationString = this.nameTable.Add("schemaLocation"); this.xsiNoNamespaceSchemaLocationString = this.nameTable.Add("noNamespaceSchemaLocation"); }
protected override void RefreshState(ValidatorState state) { switch (state) { case ValidatorState.ENABLED: case ValidatorState.HIGHLIGHTED: case ValidatorState.VALIDATED: int nb_children = children.Count; switch (type) { case Type.STRICT: for (int i = 0; i < current && i < nb_children; i++) { if (children[i].State != ValidatorState.VALIDATED) { Reset(state); return; } } while (current < nb_children && children[current].State == ValidatorState.VALIDATED) { validatedIndexes.Add(current); current++; if (current < nb_children) { children[current].SetState(state, false); } } if (current >= nb_children) { SetState(ValidatorState.VALIDATED); } break; default: for (int i = 0; i < nb_children; i++) { if ((children[i].State == ValidatorState.VALIDATED) != validated[i]) { if (validated[i]) { Reset(state); return; } else { validated[i] = true; validatedIndexes.Add(i); } } } if (validatedIndexes.Count == nb_children) { SetState(ValidatorState.VALIDATED); } break; } break; default: break; } }
private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo) { if (lName == null) { throw new ArgumentNullException("localName"); } if (ns == null) { throw new ArgumentNullException("namespaceUri"); } ValidatorState toState = validationStack.Length > 1 ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute; CheckStateTransition(toState, MethodNames[(int)toState]); object typedVal = null; attrValid = true; XmlSchemaValidity localValidity = XmlSchemaValidity.NotKnown; XmlSchemaAttribute localAttribute = null; XmlSchemaSimpleType localMemberType = null; ns = nameTable.Add(ns); if(Ref.Equal(ns,NsXmlNs)) { return null; } SchemaAttDef attributeDef = null; SchemaElementDecl currentElementDecl = context.ElementDecl; XmlQualifiedName attQName = new XmlQualifiedName(lName, ns); if (attPresence[attQName] != null) { //this attribute already checked as it is duplicate; SendValidationEvent(Res.Sch_DuplicateAttribute, attQName.ToString()); if (schemaInfo != null) { schemaInfo.Clear(); } return null; } if (!Ref.Equal(ns,NsXsi)) { // XmlSchemaObject pvtAttribute = currentState == ValidatorState.TopLevelAttribute ? partialValidationType : null; AttributeMatchState attributeMatchState; attributeDef = compiledSchemaInfo.GetAttributeXsd(currentElementDecl, attQName, pvtAttribute, out attributeMatchState); switch (attributeMatchState) { case AttributeMatchState.UndeclaredElementAndAttribute: if((attributeDef = CheckIsXmlAttribute(attQName)) != null) { //Try for xml attribute goto case AttributeMatchState.AttributeFound; } if (currentElementDecl == null && processContents == XmlSchemaContentProcessing.Strict && attQName.Namespace.Length != 0 && compiledSchemaInfo.Contains(attQName.Namespace) ) { attrValid = false; SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString()); } else if (processContents != XmlSchemaContentProcessing.Skip) { SendValidationEvent(Res.Sch_NoAttributeSchemaFound, attQName.ToString(), XmlSeverityType.Warning); } break; case AttributeMatchState.UndeclaredAttribute: if((attributeDef = CheckIsXmlAttribute(attQName)) != null) { goto case AttributeMatchState.AttributeFound; } else { attrValid = false; SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString()); } break; case AttributeMatchState.ProhibitedAnyAttribute: if((attributeDef = CheckIsXmlAttribute(attQName)) != null) { goto case AttributeMatchState.AttributeFound; } else { attrValid = false; SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString()); } break; case AttributeMatchState.ProhibitedAttribute: attrValid = false; SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString()); break; case AttributeMatchState.AttributeNameMismatch: attrValid = false; SendValidationEvent(Res.Sch_SchemaAttributeNameMismatch, new string[] { attQName.ToString(), ((XmlSchemaAttribute)pvtAttribute).QualifiedName.ToString()}); break; case AttributeMatchState.ValidateAttributeInvalidCall: Debug.Assert(currentState == ValidatorState.TopLevelAttribute); //Re-set state back to start on error with partial validation type currentState = ValidatorState.Start; attrValid = false; SendValidationEvent(Res.Sch_ValidateAttributeInvalidCall, string.Empty); break; case AttributeMatchState.AnyIdAttributeFound: if (wildID == null) { wildID = attributeDef; Debug.Assert(currentElementDecl != null); XmlSchemaComplexType ct = currentElementDecl.SchemaType as XmlSchemaComplexType; Debug.Assert(ct != null); if (ct.ContainsIdAttribute(false)) { SendValidationEvent(Res.Sch_AttrUseAndWildId, string.Empty); } else { goto case AttributeMatchState.AttributeFound; } } else { //More than one attribute per element cannot match wildcard if both their types are derived from ID SendValidationEvent(Res.Sch_MoreThanOneWildId, string.Empty); } break; case AttributeMatchState.AttributeFound: Debug.Assert(attributeDef != null); localAttribute = attributeDef.SchemaAttribute; if (currentElementDecl != null) { //Have to add to hashtable to check whether to add default attributes attPresence.Add(attQName, attributeDef); } object attValue; if (attributeValueGetter != null) { attValue = attributeValueGetter(); } else { attValue = attributeStringValue; } typedVal = CheckAttributeValue(attValue, attributeDef); XmlSchemaDatatype datatype = attributeDef.Datatype; if (datatype.Variety == XmlSchemaDatatypeVariety.Union && typedVal != null) { //Unpack the union XsdSimpleValue simpleValue = typedVal as XsdSimpleValue; Debug.Assert(simpleValue != null); localMemberType = simpleValue.XmlType; datatype = simpleValue.XmlType.Datatype; typedVal = simpleValue.TypedValue; } CheckTokenizedTypes(datatype, typedVal, true); if (HasIdentityConstraints) { AttributeIdentityConstraints(attQName.Name, attQName.Namespace, typedVal, attValue.ToString(), datatype); } break; case AttributeMatchState.AnyAttributeLax: SendValidationEvent(Res.Sch_NoAttributeSchemaFound, attQName.ToString(), XmlSeverityType.Warning); break; case AttributeMatchState.AnyAttributeSkip: break; default: break; } } else { //Attribute from xsi namespace lName = nameTable.Add(lName); if (Ref.Equal(lName, xsiTypeString) || Ref.Equal(lName, xsiNilString) || Ref.Equal(lName, xsiSchemaLocationString) || Ref.Equal(lName, xsiNoNamespaceSchemaLocationString)) { attPresence.Add(attQName, SchemaAttDef.Empty); } else { attrValid = false; SendValidationEvent(Res.Sch_NotXsiAttribute, attQName.ToString()); } } if (!attrValid) { localValidity = XmlSchemaValidity.Invalid; } else if (attributeDef != null) { localValidity = XmlSchemaValidity.Valid; } if (schemaInfo != null) { schemaInfo.SchemaAttribute = localAttribute; schemaInfo.SchemaType = localAttribute == null ? null : localAttribute.AttributeSchemaType; schemaInfo.MemberType = localMemberType; schemaInfo.IsDefault = false; schemaInfo.Validity = localValidity; } if (ProcessSchemaHints) { if (validatedNamespaces[ns] == null) { validatedNamespaces.Add(ns, ns); } } return typedVal; }
private void Jump(ValidatorState state) { this.stack.Pop(); this.stack.Push(state); }
protected override void RefreshState(ValidatorState state) { //Debug.Log(name + "//" + state); }
private void Init() { validationStack = new HWStack(STACK_INCREMENT); attPresence = new Hashtable(); Push(XmlQualifiedName.Empty); dummyPositionInfo = new PositionInfo(); //Dummy position info, will return (0,0) if user does not set the LineInfoProvider property positionInfo = dummyPositionInfo; validationEventSender = this; currentState = ValidatorState.None; textValue = new StringBuilder(100); xmlResolver = System.Xml.XmlConfiguration.XmlReaderSection.CreateDefaultResolver(); contextQName = new XmlQualifiedName(); //Re-use qname Reset(); RecompileSchemaSet(); //Gets compiled info from set as well //Get already Atomized strings NsXs = nameTable.Add(XmlReservedNs.NsXs); NsXsi = nameTable.Add(XmlReservedNs.NsXsi); NsXmlNs = nameTable.Add(XmlReservedNs.NsXmlNs); NsXml = nameTable.Add(XmlReservedNs.NsXml); xsiTypeString = nameTable.Add("type"); xsiNilString = nameTable.Add("nil"); xsiSchemaLocationString = nameTable.Add("schemaLocation"); xsiNoNamespaceSchemaLocationString = nameTable.Add("noNamespaceSchemaLocation"); }
static void Main(string[] args) { if (args.Length != 4) { Console.Error.WriteLine("Usage: SHS.RegressionTest3 <servers.txt> <numPages> <numIterations> <numValThreads>"); } else { int numPages = int.Parse(args[1]); int numIters = int.Parse(args[2]); int numValidators = int.Parse(args[3]); var sw = Stopwatch.StartNew(); var svc = new Service(args[0]); Console.WriteLine("Service currently provides {0} servers", svc.NumServers()); var store = svc.CreateStore(); Console.WriteLine("Created new store with GUID {0:N}", store.ID); // Create a validation graph with "numPages" vertices and (for now) no edges var rand = new Random(123456); var pages = new string[numPages]; var fwds = new List<int>[numPages]; var bwds = new List<int>[numPages]; for (int i = 0; i < pages.Length; i++) { var r = rand.Next(); pages[i] = string.Format("http://www.{0:D2}.com/{1}", rand.Next(1, 100), RandomString(rand)); fwds[i] = new List<int>(); bwds[i] = new List<int>(); } Array.Sort(pages); Console.WriteLine("Synthesized {0} URLs ({1} duplicates)", pages.Length, pages.Length - pages.Distinct().Count()); for (int iter = 0; iter < numIters; iter++) { var batchSize = rand.Next(10, 50); var plBatch = new List<PL>(); long addCtr = 0; long delCtr = 0; while (plBatch.Count < batchSize) { // Pick a page var src = rand.Next(0, pages.Length); if (plBatch.Exists(x => x.src == src)) continue; var list = fwds[src]; foreach (var dst in list) { bwds[dst].Remove(src); } if (list.Count == 0) { // If this page has no links, create between 20 and 50 links, with bias towards the "neighborhood" var numAdds = rand.Next(20, 51); while (numAdds > 0) { var dst = (int)RandomNormal(rand, src, 100); if (dst >= 0 && dst < pages.Length && !list.Contains(dst) && dst != src) { list.Add(dst); addCtr++; numAdds--; } } } else { // Otherwise, choose about half of the links to delete, and add about the same number of new links var dels = list.Where(x => rand.Next(0, 2) == 0).ToList(); delCtr += dels.Count; var numAdds = rand.Next(dels.Count - 3, dels.Count + 4); while (numAdds > 0) { var dst = (int)RandomNormal(rand, src, 100); if (dst >= 0 && dst < pages.Length && !list.Contains(dst) && dst != src) { list.Add(dst); addCtr++; numAdds--; } } list = list.Except(dels).ToList(); } foreach (var dst in list) { bwds[dst].Add(src); } fwds[src] = list; plBatch.Add(new PL { src = src, dsts = CloneList(list) }); } var pageLinksBatch = plBatch.Select(x => new PageLinks { pageUrl = pages[x.src], linkUrls = x.dsts.Select(y => pages[y]).ToArray() }).ToList(); int epoch = store.AddPageLinks(pageLinksBatch.GetEnumerator()); //store.MarkAtomic(); var snapFwds = CloneLists(fwds); var snapBwds = CloneLists(bwds); for (int i = 0; i < numValidators; i++) { var vs = new ValidatorState(args[0], store.ID, epoch, plBatch, pages, snapFwds, snapBwds); new Thread(vs.DoWork).Start(); } var srcUrls = plBatch.Select(x => pages[x.src]).ToArray(); var srcUids = store.BatchedUrlToUid(srcUrls, ref epoch); var fwdLinkUids = store.BatchedGetLinks(srcUids, Dir.Fwd, ref epoch); for (int i = 0; i < fwdLinkUids.Length; i++) { var fwdLinkUrlsR = store.BatchedUidToUrl(fwdLinkUids[i], ref epoch); var fwdLinkUrlsL = fwds[plBatch[i].src].Select(x => pages[x]).ToArray(); if (!SameSets(fwdLinkUrlsR, fwdLinkUrlsL)) { lock (Console.Out) { Console.WriteLine("Detected inconsistenty! srcURL[{0}]={1}", i, srcUrls[i]); Console.WriteLine("{0} fwd link URLs according to SHS", fwdLinkUrlsR.Length); for (int k = 0; k < fwdLinkUrlsR.Length; k++) { Console.WriteLine(" fwdLinkUrlsR[{0}]={1}", k, fwdLinkUrlsR[k]); } Console.WriteLine("{0} fwd link URLs according to local state", fwdLinkUrlsL.Length); for (int k = 0; k < fwdLinkUrlsL.Length; k++) { Console.WriteLine(" fwdLinkUrlsL[{0}]={1}", k, fwdLinkUrlsL[k]); } } throw new Exception(); } var bwdLinkUids = store.BatchedGetLinks(fwdLinkUids[i], Dir.Bwd, ref epoch); for (int j = 0; j < bwdLinkUids.Length; j++) { var bwdLinkUrlsR = store.BatchedUidToUrl(bwdLinkUids[j], ref epoch); var bwdLinkUrlsL = bwds[Idx(fwdLinkUrlsR[j], pages, plBatch[i].dsts)].Select(x => pages[x]).ToArray(); if (!SameSets(bwdLinkUrlsR, bwdLinkUrlsL)) { lock (Console.Out) { Console.WriteLine("Detected inconsistenty!"); Console.WriteLine(" srcURL[{0}]={1}", i, srcUrls[i]); Console.WriteLine(" dstURL[{0}]={1}", j, fwdLinkUrlsR[j]); Console.WriteLine("{0} bwd link URLs according to SHS", bwdLinkUrlsR.Length); for (int k = 0; k < bwdLinkUrlsR.Length; k++) { Console.WriteLine(" bwdLinkUrlsR[{0}]={1}", k, bwdLinkUrlsR[k]); } Console.WriteLine("{0} bwd link URLs according to local state", bwdLinkUrlsL.Length); for (int k = 0; k < bwdLinkUrlsL.Length; k++) { Console.WriteLine(" bwdLinkUrlsL[{0}]={1}", k, bwdLinkUrlsL[k]); } } throw new Exception(); } } } Console.WriteLine("Iteration {0}: Put {1} PageLinks into store, Adding {2} and deleting {3} links. Validation passed!", iter, batchSize, addCtr, delCtr); } Console.WriteLine("{0} of {1} non-mutating validation threads were exempted, validated {2} of graph on average", counters.numEpochPassed, counters.numChecks, counters.sumFractionChecked / counters.numChecks); Console.WriteLine("Done. RegressionTest3 took {0} seconds", 0.001 * sw.ElapsedMilliseconds); } }
private void CheckStateTransition(ValidatorState toState, string methodName) { if (!ValidStates[(int)_currentState, (int)toState]) { if (_currentState == ValidatorState.None) { throw new InvalidOperationException(SR.Format(SR.Sch_InvalidStartTransition, new string[] { methodName, s_methodNames[(int)ValidatorState.Start] })); } throw new InvalidOperationException(SR.Format(SR.Sch_InvalidStateTransition, new string[] { s_methodNames[(int)_currentState], methodName })); } _currentState = toState; }
public void Initialize() { if (_currentState != ValidatorState.None && _currentState != ValidatorState.Finish) { throw new InvalidOperationException(SR.Format(SR.Sch_InvalidStateTransition, new string[] { s_methodNames[(int)_currentState], s_methodNames[(int)ValidatorState.Start] })); } _currentState = ValidatorState.Start; Reset(); }
protected void Reset(ValidatorState state) { ForceStateChange(state == ValidatorState.VALIDATED ? Previous : state); }
/// <summary> /// Replace the current state on the stack with the new state /// </summary> /// <param name="state">The new state</param> private void Jump(ValidatorState state) { this.stack.Pop(); Debug.Assert(this.stack.Count > 0, "the stack should always have the SetCoordinateSystemState"); this.stack.Push(state); }
public void SkipToEndElement(XmlSchemaInfo schemaInfo) { if (validationStack.Length <= 1) { throw new InvalidOperationException(Res.GetString(Res.Sch_InvalidEndElementMultiple, MethodNames[(int)ValidatorState.SkipToEndElement])); } CheckStateTransition(ValidatorState.SkipToEndElement, MethodNames[(int)ValidatorState.SkipToEndElement]); if (schemaInfo != null) { SchemaElementDecl currentElementDecl = context.ElementDecl; if (currentElementDecl != null) { schemaInfo.SchemaType = currentElementDecl.SchemaType; schemaInfo.SchemaElement = GetSchemaElement(); } else { schemaInfo.SchemaType = null; schemaInfo.SchemaElement = null; } schemaInfo.MemberType = null; schemaInfo.IsNil = context.IsNill; schemaInfo.IsDefault = context.IsDefault; Debug.Assert(context.Validity != XmlSchemaValidity.Valid); schemaInfo.Validity = context.Validity; } context.ValidationSkipped = true; currentState = ValidatorState.SkipToEndElement; Pop(); }
internal void GetUnspecifiedDefaultAttributes(ArrayList defaultAttributes, bool createNodeData) { this.currentState = ValidatorState.Attribute; SchemaElementDecl elementDecl = this.context.ElementDecl; if ((elementDecl != null) && elementDecl.HasDefaultAttribute) { for (int i = 0; i < elementDecl.DefaultAttDefs.Count; i++) { SchemaAttDef def = (SchemaAttDef) elementDecl.DefaultAttDefs[i]; if (!this.attPresence.Contains(def.Name) && (def.DefaultValueTyped != null)) { string attributeNS = this.nameTable.Add(def.Name.Namespace); string array = string.Empty; if (attributeNS.Length > 0) { array = this.GetDefaultAttributePrefix(attributeNS); if ((array == null) || (array.Length == 0)) { this.SendValidationEvent("Sch_DefaultAttributeNotApplied", new string[] { def.Name.ToString(), QNameString(this.context.LocalName, this.context.Namespace) }); continue; } } XmlSchemaDatatype dtype = def.Datatype; if (createNodeData) { ValidatingReaderNodeData data = new ValidatingReaderNodeData { LocalName = this.nameTable.Add(def.Name.Name), Namespace = attributeNS, Prefix = this.nameTable.Add(array), NodeType = XmlNodeType.Attribute }; AttributePSVIInfo info = new AttributePSVIInfo(); XmlSchemaInfo attributeSchemaInfo = info.attributeSchemaInfo; if (def.Datatype.Variety == XmlSchemaDatatypeVariety.Union) { XsdSimpleValue defaultValueTyped = def.DefaultValueTyped as XsdSimpleValue; attributeSchemaInfo.MemberType = defaultValueTyped.XmlType; dtype = defaultValueTyped.XmlType.Datatype; info.typedAttributeValue = defaultValueTyped.TypedValue; } else { info.typedAttributeValue = def.DefaultValueTyped; } attributeSchemaInfo.IsDefault = true; attributeSchemaInfo.Validity = XmlSchemaValidity.Valid; attributeSchemaInfo.SchemaType = def.SchemaType; attributeSchemaInfo.SchemaAttribute = def.SchemaAttribute; data.RawValue = attributeSchemaInfo.XmlType.ValueConverter.ToString(info.typedAttributeValue); data.AttInfo = info; defaultAttributes.Add(data); } else { defaultAttributes.Add(def.SchemaAttribute); } this.CheckTokenizedTypes(dtype, def.DefaultValueTyped, true); if (this.HasIdentityConstraints) { this.AttributeIdentityConstraints(def.Name.Name, def.Name.Namespace, def.DefaultValueTyped, def.DefaultValueRaw, dtype); } } } } }
internal void GetUnspecifiedDefaultAttributes(ArrayList defaultAttributes, bool createNodeData) { currentState = ValidatorState.Attribute; SchemaElementDecl currentElementDecl = context.ElementDecl; if (currentElementDecl != null && currentElementDecl.HasDefaultAttribute) { for (int i = 0; i < currentElementDecl.DefaultAttDefs.Count; ++i) { SchemaAttDef attdef = (SchemaAttDef)currentElementDecl.DefaultAttDefs[i]; if (!attPresence.Contains(attdef.Name)) { if (attdef.DefaultValueTyped == null) { //Invalid attribute default in the schema continue; } //Check to see default attributes WILL be qualified if attributeFormDefault = qualified in schema string attributeNS = nameTable.Add(attdef.Name.Namespace); string defaultPrefix = string.Empty; if (attributeNS.Length > 0) { defaultPrefix = GetDefaultAttributePrefix(attributeNS); if (defaultPrefix == null || defaultPrefix.Length == 0) { SendValidationEvent(Res.Sch_DefaultAttributeNotApplied, new string[2] { attdef.Name.ToString(), QNameString(context.LocalName, context.Namespace)}); continue; } } XmlSchemaDatatype datatype = attdef.Datatype; if (createNodeData) { ValidatingReaderNodeData attrData = new ValidatingReaderNodeData(); attrData.LocalName = nameTable.Add(attdef.Name.Name); attrData.Namespace = attributeNS; attrData.Prefix = nameTable.Add(defaultPrefix); attrData.NodeType = XmlNodeType.Attribute; //set PSVI properties AttributePSVIInfo attrValidInfo = new AttributePSVIInfo(); XmlSchemaInfo attSchemaInfo = attrValidInfo.attributeSchemaInfo; Debug.Assert(attSchemaInfo != null); if (attdef.Datatype.Variety == XmlSchemaDatatypeVariety.Union) { XsdSimpleValue simpleValue = attdef.DefaultValueTyped as XsdSimpleValue; attSchemaInfo.MemberType = simpleValue.XmlType; datatype = simpleValue.XmlType.Datatype; attrValidInfo.typedAttributeValue = simpleValue.TypedValue; } else { attrValidInfo.typedAttributeValue = attdef.DefaultValueTyped; } attSchemaInfo.IsDefault = true; attSchemaInfo.Validity = XmlSchemaValidity.Valid; attSchemaInfo.SchemaType = attdef.SchemaType; attSchemaInfo.SchemaAttribute = attdef.SchemaAttribute; attrData.RawValue = attSchemaInfo.XmlType.ValueConverter.ToString(attrValidInfo.typedAttributeValue); attrData.AttInfo = attrValidInfo; defaultAttributes.Add(attrData); } else { defaultAttributes.Add(attdef.SchemaAttribute); } CheckTokenizedTypes(datatype, attdef.DefaultValueTyped, true); if (HasIdentityConstraints) { AttributeIdentityConstraints(attdef.Name.Name, attdef.Name.Namespace, attdef.DefaultValueTyped, attdef.DefaultValueRaw, datatype); } } } } return; }
public void Initialize() { if ((this.currentState != ValidatorState.None) && (this.currentState != ValidatorState.Finish)) { throw new InvalidOperationException(Res.GetString("Sch_InvalidStateTransition", new string[] { MethodNames[(int) this.currentState], MethodNames[1] })); } this.currentState = ValidatorState.Start; this.Reset(); }
private void Init() { _validationStack = new HWStack(STACK_INCREMENT); _attPresence = new Hashtable(); Push(XmlQualifiedName.Empty); _dummyPositionInfo = new PositionInfo(); //Dummy position info, will return (0,0) if user does not set the LineInfoProvider property _positionInfo = _dummyPositionInfo; _validationEventSender = this; _currentState = ValidatorState.None; _textValue = new StringBuilder(100); _xmlResolver = null; _contextQName = new XmlQualifiedName(); //Re-use qname Reset(); RecompileSchemaSet(); //Gets compiled info from set as well //Get already Atomized strings _nsXs = _nameTable.Add(XmlReservedNs.NsXs); _nsXsi = _nameTable.Add(XmlReservedNs.NsXsi); _nsXmlNs = _nameTable.Add(XmlReservedNs.NsXmlNs); _nsXml = _nameTable.Add(XmlReservedNs.NsXml); _xsiTypeString = _nameTable.Add("type"); _xsiNilString = _nameTable.Add("nil"); _xsiSchemaLocationString = _nameTable.Add("schemaLocation"); _xsiNoNamespaceSchemaLocationString = _nameTable.Add("noNamespaceSchemaLocation"); }
public void SkipToEndElement(XmlSchemaInfo schemaInfo) { if (this.validationStack.Length <= 1) { throw new InvalidOperationException(Res.GetString("Sch_InvalidEndElementMultiple", new object[] { MethodNames[10] })); } this.CheckStateTransition(ValidatorState.SkipToEndElement, MethodNames[10]); if (schemaInfo != null) { SchemaElementDecl elementDecl = this.context.ElementDecl; if (elementDecl != null) { schemaInfo.SchemaType = elementDecl.SchemaType; schemaInfo.SchemaElement = this.GetSchemaElement(); } else { schemaInfo.SchemaType = null; schemaInfo.SchemaElement = null; } schemaInfo.MemberType = null; schemaInfo.IsNil = this.context.IsNill; schemaInfo.IsDefault = this.context.IsDefault; schemaInfo.Validity = this.context.Validity; } this.context.ValidationSkipped = true; this.currentState = ValidatorState.SkipToEndElement; this.Pop(); }
public void TestSetup() { uut = new ValidatorState(); }
private void CheckStateTransition(ValidatorState toState, string methodName) { if (!ValidStates[(int) this.currentState, (int) toState]) { if (this.currentState == ValidatorState.None) { throw new InvalidOperationException(Res.GetString("Sch_InvalidStartTransition", new string[] { methodName, MethodNames[1] })); } throw new InvalidOperationException(Res.GetString("Sch_InvalidStateTransition", new string[] { MethodNames[(int) this.currentState], methodName })); } this.currentState = toState; }
static void Main(string[] args) { if (args.Length != 4) { Console.Error.WriteLine("Usage: SHS.RegressionTest3 <servers.txt> <numPages> <numIterations> <numValThreads>"); } else { int numPages = int.Parse(args[1]); int numIters = int.Parse(args[2]); int numValidators = int.Parse(args[3]); var sw = Stopwatch.StartNew(); var svc = new Service(args[0]); Console.WriteLine("Service currently provides {0} servers", svc.NumServers()); var store = svc.CreateStore(); Console.WriteLine("Created new store with GUID {0:N}", store.ID); // Create a validation graph with "numPages" vertices and (for now) no edges var rand = new Random(123456); var pages = new string[numPages]; var fwds = new List <int> [numPages]; var bwds = new List <int> [numPages]; for (int i = 0; i < pages.Length; i++) { var r = rand.Next(); pages[i] = string.Format("http://www.{0:D2}.com/{1}", rand.Next(1, 100), RandomString(rand)); fwds[i] = new List <int>(); bwds[i] = new List <int>(); } Array.Sort(pages); Console.WriteLine("Synthesized {0} URLs ({1} duplicates)", pages.Length, pages.Length - pages.Distinct().Count()); for (int iter = 0; iter < numIters; iter++) { var batchSize = rand.Next(10, 50); var plBatch = new List <PL>(); long addCtr = 0; long delCtr = 0; while (plBatch.Count < batchSize) { // Pick a page var src = rand.Next(0, pages.Length); if (plBatch.Exists(x => x.src == src)) { continue; } var list = fwds[src]; foreach (var dst in list) { bwds[dst].Remove(src); } if (list.Count == 0) { // If this page has no links, create between 20 and 50 links, with bias towards the "neighborhood" var numAdds = rand.Next(20, 51); while (numAdds > 0) { var dst = (int)RandomNormal(rand, src, 100); if (dst >= 0 && dst < pages.Length && !list.Contains(dst) && dst != src) { list.Add(dst); addCtr++; numAdds--; } } } else { // Otherwise, choose about half of the links to delete, and add about the same number of new links var dels = list.Where(x => rand.Next(0, 2) == 0).ToList(); delCtr += dels.Count; var numAdds = rand.Next(dels.Count - 3, dels.Count + 4); while (numAdds > 0) { var dst = (int)RandomNormal(rand, src, 100); if (dst >= 0 && dst < pages.Length && !list.Contains(dst) && dst != src) { list.Add(dst); addCtr++; numAdds--; } } list = list.Except(dels).ToList(); } foreach (var dst in list) { bwds[dst].Add(src); } fwds[src] = list; plBatch.Add(new PL { src = src, dsts = CloneList(list) }); } var pageLinksBatch = plBatch.Select(x => new PageLinks { pageUrl = pages[x.src], linkUrls = x.dsts.Select(y => pages[y]).ToArray() }).ToList(); int epoch = store.AddPageLinks(pageLinksBatch.GetEnumerator()); //store.MarkAtomic(); var snapFwds = CloneLists(fwds); var snapBwds = CloneLists(bwds); for (int i = 0; i < numValidators; i++) { var vs = new ValidatorState(args[0], store.ID, epoch, plBatch, pages, snapFwds, snapBwds); new Thread(vs.DoWork).Start(); } var srcUrls = plBatch.Select(x => pages[x.src]).ToArray(); var srcUids = store.BatchedUrlToUid(srcUrls, ref epoch); var fwdLinkUids = store.BatchedGetLinks(srcUids, Dir.Fwd, ref epoch); for (int i = 0; i < fwdLinkUids.Length; i++) { var fwdLinkUrlsR = store.BatchedUidToUrl(fwdLinkUids[i], ref epoch); var fwdLinkUrlsL = fwds[plBatch[i].src].Select(x => pages[x]).ToArray(); if (!SameSets(fwdLinkUrlsR, fwdLinkUrlsL)) { lock (Console.Out) { Console.WriteLine("Detected inconsistenty! srcURL[{0}]={1}", i, srcUrls[i]); Console.WriteLine("{0} fwd link URLs according to SHS", fwdLinkUrlsR.Length); for (int k = 0; k < fwdLinkUrlsR.Length; k++) { Console.WriteLine(" fwdLinkUrlsR[{0}]={1}", k, fwdLinkUrlsR[k]); } Console.WriteLine("{0} fwd link URLs according to local state", fwdLinkUrlsL.Length); for (int k = 0; k < fwdLinkUrlsL.Length; k++) { Console.WriteLine(" fwdLinkUrlsL[{0}]={1}", k, fwdLinkUrlsL[k]); } } throw new Exception(); } var bwdLinkUids = store.BatchedGetLinks(fwdLinkUids[i], Dir.Bwd, ref epoch); for (int j = 0; j < bwdLinkUids.Length; j++) { var bwdLinkUrlsR = store.BatchedUidToUrl(bwdLinkUids[j], ref epoch); var bwdLinkUrlsL = bwds[Idx(fwdLinkUrlsR[j], pages, plBatch[i].dsts)].Select(x => pages[x]).ToArray(); if (!SameSets(bwdLinkUrlsR, bwdLinkUrlsL)) { lock (Console.Out) { Console.WriteLine("Detected inconsistenty!"); Console.WriteLine(" srcURL[{0}]={1}", i, srcUrls[i]); Console.WriteLine(" dstURL[{0}]={1}", j, fwdLinkUrlsR[j]); Console.WriteLine("{0} bwd link URLs according to SHS", bwdLinkUrlsR.Length); for (int k = 0; k < bwdLinkUrlsR.Length; k++) { Console.WriteLine(" bwdLinkUrlsR[{0}]={1}", k, bwdLinkUrlsR[k]); } Console.WriteLine("{0} bwd link URLs according to local state", bwdLinkUrlsL.Length); for (int k = 0; k < bwdLinkUrlsL.Length; k++) { Console.WriteLine(" bwdLinkUrlsL[{0}]={1}", k, bwdLinkUrlsL[k]); } } throw new Exception(); } } } Console.WriteLine("Iteration {0}: Put {1} PageLinks into store, Adding {2} and deleting {3} links. Validation passed!", iter, batchSize, addCtr, delCtr); } Console.WriteLine("{0} of {1} non-mutating validation threads were exempted, validated {2} of graph on average", counters.numEpochPassed, counters.numChecks, counters.sumFractionChecked / counters.numChecks); Console.WriteLine("Done. RegressionTest3 took {0} seconds", 0.001 * sw.ElapsedMilliseconds); } }
public ExerciseScore Check(ConvertedBody bodyLive) { // Get body from current frame ConvertedBody bodyJSON = exercise.ExerciseRecording.ConvertedBodies[frame]; // Check move ExerciseScore exerciseScore; exerciseScore = Validate(bodyLive, bodyJSON); // Draw red body with current frame exampleBodyDrawer.DrawSkeleton(bodyJSON.CheckJoints); switch (state) { case ValidatorState.NotStarted: // Wait for user to start if (frame == 0 && !exerciseScore.Check) { return(exerciseScore); } state = ValidatorState.Checking; return(exerciseScore); case ValidatorState.WaitingForNext: // Wait for user to start if (frame == 0 && !exerciseScore.Check) { return(exerciseScore); } state = ValidatorState.Checking; return(exerciseScore); case ValidatorState.Checking: if (exerciseScore.Check) { // Check completed frame++; latestValidatedCheck = DateTime.Now; } // Find end of exercise if (frame == exercise.ExerciseRecording.ConvertedBodies.Count - 1) { frame = 0; current++; UnityEngine.Debug.Log(current + " - " + exercise.Amount); if (current == exercise.Amount) { state = ValidatorState.Done; } else { state = ValidatorState.WaitingForNext; } return(exerciseScore); } // Check if user missed checks for more then 1 second and cancel current exercise UnityEngine.Debug.Log(latestValidatedCheck < DateTime.Now.AddSeconds(-5)); if (latestValidatedCheck < DateTime.Now.AddSeconds(-5)) { state = ValidatorState.WaitingForNext; frame = 0; return(exerciseScore); } UnityEngine.Debug.Log(frame); state = ValidatorState.Checking; return(exerciseScore); case ValidatorState.Done: return(null); default: return(null); } }
public IEnumerable <ECPoint> GetValidators(IEnumerable <Transaction> others) { Snapshot snapshot = Clone(); foreach (Transaction tx in others) { foreach (TransactionOutput output in tx.Outputs) { AccountState account = snapshot.Accounts.GetAndChange(output.ScriptHash, () => new AccountState(output.ScriptHash)); if (account.Balances.ContainsKey(output.AssetId)) { account.Balances[output.AssetId] += output.Value; } else { account.Balances[output.AssetId] = output.Value; } if (output.AssetId.Equals(Blockchain.GoverningToken.Hash) && account.Votes.Length > 0) { foreach (ECPoint pubkey in account.Votes) { snapshot.Validators.GetAndChange(pubkey, () => new ValidatorState(pubkey)).Votes += output.Value; } snapshot.ValidatorsCount.GetAndChange().Votes[account.Votes.Length - 1] += output.Value; } } foreach (var group in tx.Inputs.GroupBy(p => p.PrevHash)) { Transaction tx_prev = snapshot.GetTransaction(group.Key); foreach (CoinReference input in group) { TransactionOutput out_prev = tx_prev.Outputs[input.PrevIndex]; AccountState account = snapshot.Accounts.GetAndChange(out_prev.ScriptHash); if (out_prev.AssetId.Equals(Blockchain.GoverningToken.Hash)) { if (account.Votes.Length > 0) { foreach (ECPoint pubkey in account.Votes) { ValidatorState validator = snapshot.Validators.GetAndChange(pubkey); validator.Votes -= out_prev.Value; if (!validator.Registered && validator.Votes.Equals(Fixed8.Zero)) { snapshot.Validators.Delete(pubkey); } } snapshot.ValidatorsCount.GetAndChange().Votes[account.Votes.Length - 1] -= out_prev.Value; } } account.Balances[out_prev.AssetId] -= out_prev.Value; } } switch (tx) { #pragma warning disable CS0612 case EnrollmentTransaction tx_enrollment: snapshot.Validators.GetAndChange(tx_enrollment.PublicKey, () => new ValidatorState(tx_enrollment.PublicKey)).Registered = true; break; #pragma warning restore CS0612 case StateTransaction tx_state: foreach (StateDescriptor descriptor in tx_state.Descriptors) { switch (descriptor.Type) { case StateType.Account: Blockchain.ProcessAccountStateDescriptor(descriptor, snapshot); break; case StateType.Validator: Blockchain.ProcessValidatorStateDescriptor(descriptor, snapshot); break; } } break; } } int count = (int)snapshot.ValidatorsCount.Get().Votes.Select((p, i) => new { Count = i, Votes = p }).Where(p => p.Votes > Fixed8.Zero).ToArray().WeightedFilter(0.25, 0.75, p => p.Votes.GetData(), (p, w) => new { p.Count, Weight = w }).WeightedAverage(p => p.Count, p => p.Weight); count = Math.Max(count, Blockchain.StandbyValidators.Length); HashSet <ECPoint> sv = new HashSet <ECPoint>(Blockchain.StandbyValidators); ECPoint[] pubkeys = snapshot.Validators.Find().Select(p => p.Value).Where(p => (p.Registered && p.Votes > Fixed8.Zero) || sv.Contains(p.PublicKey)).OrderByDescending(p => p.Votes).ThenBy(p => p.PublicKey).Select(p => p.PublicKey).Take(count).ToArray(); IEnumerable <ECPoint> result; if (pubkeys.Length == count) { result = pubkeys; } else { HashSet <ECPoint> hashSet = new HashSet <ECPoint>(pubkeys); for (int i = 0; i < Blockchain.StandbyValidators.Length && hashSet.Count < count; i++) { hashSet.Add(Blockchain.StandbyValidators[i]); } result = hashSet; } return(result.OrderBy(p => p)); }
public void Initialize(XmlSchemaObject partialValidationType) { if (currentState != ValidatorState.None && currentState != ValidatorState.Finish) { throw new InvalidOperationException(Res.GetString(Res.Sch_InvalidStateTransition, new string[] { MethodNames[(int)currentState], MethodNames[(int)ValidatorState.Start] })); } if (partialValidationType == null) { throw new ArgumentNullException("partialValidationType"); } if (!(partialValidationType is XmlSchemaElement || partialValidationType is XmlSchemaAttribute || partialValidationType is XmlSchemaType)) { throw new ArgumentException(Res.GetString(Res.Sch_InvalidPartialValidationType)); } currentState = ValidatorState.Start; Reset(); this.partialValidationType = partialValidationType; }
public void Initialize() { if (currentState != ValidatorState.None && currentState != ValidatorState.Finish) { throw new InvalidOperationException(Res.GetString(Res.Sch_InvalidStateTransition, new string[] { MethodNames[(int)currentState], MethodNames[(int)ValidatorState.Start] })); } currentState = ValidatorState.Start; Reset(); }