public async Task Should_create_events_from_snapshots_with_schema_ids() { var trigger = new ContentChangedTriggerV2 { Schemas = ReadonlyList.Create( new ContentChangedTriggerSchemaV2 { SchemaId = schemaMatch.Id }) }; var ctx = Context(trigger); A.CallTo(() => contentRepository.StreamAll(ctx.AppId.Id, A <HashSet <DomainId> > .That.Is(schemaMatch.Id), default)) .Returns(new List <ContentEntity> { new ContentEntity { SchemaId = schemaMatch }, new ContentEntity { SchemaId = schemaMatch } }.ToAsyncEnumerable()); var result = await sut.CreateSnapshotEventsAsync(ctx, default).ToListAsync(); var typed = result.OfType <EnrichedContentEvent>().ToList(); Assert.Equal(2, typed.Count); Assert.Equal(2, typed.Count(x => x.Type == EnrichedContentEventType.Created)); }
private void TestForTrigger(bool handleAll, NamedId <DomainId>?schemaId, string?condition, Action <RuleContext> action) { var trigger = new ContentChangedTriggerV2 { HandleAll = handleAll }; if (schemaId != null) { trigger = trigger with { Schemas = ReadonlyList.Create( new ContentChangedTriggerSchemaV2 { SchemaId = schemaId.Id, Condition = condition }) }; } action(Context(trigger)); if (string.IsNullOrWhiteSpace(condition)) { A.CallTo(() => scriptEngine.Evaluate(A <ScriptVars> ._, A <string> ._, default)) .MustNotHaveHappened(); } else { A.CallTo(() => scriptEngine.Evaluate(A <ScriptVars> ._, condition, default)) .MustHaveHappened(); } }
public JsonSchemaProperty?Visit(IField <ReferencesFieldProperties> field, Args args) { var property = JsonTypeBuilder.ArrayProperty(JsonTypeBuilder.String()); property.Default = field.Properties.DefaultValue; if (field.Properties.MinItems != null) { property.MinItems = field.Properties.MinItems.Value; } if (field.Properties.MaxItems != null) { property.MaxItems = field.Properties.MaxItems.Value; } property.ExtensionData = new Dictionary <string, object> { ["schemaIds"] = field.Properties.SchemaIds ?? ReadonlyList.Empty <DomainId>() }; property.UniqueItems = !field.Properties.AllowDuplicates; return(property); }
public HouseToBuild(int ind, List <Resource> cost) { StaticCost = new ReadonlyList <Resource>(cost); MinResourcesCount = -1; MaxResourcesCount = -1; DifferentResourcesCount = -1; this.Ind = ind; }
public HouseToBuild(int ind, int minCount, int maxCount, int differentCount) { StaticCost = null; MinResourcesCount = minCount; MaxResourcesCount = maxCount; DifferentResourcesCount = differentCount; this.Ind = ind; }
/** Moves the object kinematically. */ public override void MoveTo(ReadonlyList<Hand> hands, PhysicsMoveInfo info, Vector3 solvedPosition, Quaternion solvedRotation) { if (info.shouldTeleport) { _obj.warper.Teleport(solvedPosition, solvedRotation); } else { _obj.rigidbody.MovePosition(solvedPosition); _obj.rigidbody.MoveRotation(solvedRotation); } }
private Task <IReadOnlyList <IAssetFolderEntity> > GetAssetPathAsync(DomainId parentId, AssetFolderScope scope) { if (scope == AssetFolderScope.Items) { return(Task.FromResult <IReadOnlyList <IAssetFolderEntity> >(ReadonlyList.Empty <IAssetFolderEntity>())); } return(assetQuery.FindAssetFolderAsync(Context.App.Id, parentId, HttpContext.RequestAborted)); }
public BuiltHouse(List <Resource> spentResources) { SpentResources = new ReadonlyList <Resource> (spentResources); Score = 0; foreach (var resource in spentResources) { Score += Config.GetPointsPerResource(resource); } }
static TestSchemas() { Ref1 = Mocks.Schema(TestApp.DefaultId, Ref1Id, new Schema(Ref1Id.Name) .Publish() .AddString(1, "schemaRef1Field", Partitioning.Invariant)); Ref2 = Mocks.Schema(TestApp.DefaultId, Ref2Id, new Schema(Ref2Id.Name) .Publish() .AddString(1, "schemaRef2Field", Partitioning.Invariant)); Default = Mocks.Schema(TestApp.DefaultId, DefaultId, new Schema(DefaultId.Name) .Publish() .AddJson(1, "my-json", Partitioning.Invariant, new JsonFieldProperties()) .AddString(2, "my-string", Partitioning.Invariant, new StringFieldProperties()) .AddString(3, "my-localized-string", Partitioning.Language, new StringFieldProperties()) .AddNumber(4, "my-number", Partitioning.Invariant, new NumberFieldProperties()) .AddAssets(5, "my-assets", Partitioning.Invariant, new AssetsFieldProperties()) .AddBoolean(6, "my-boolean", Partitioning.Invariant, new BooleanFieldProperties()) .AddDateTime(7, "my-datetime", Partitioning.Invariant, new DateTimeFieldProperties()) .AddReferences(8, "my-references", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = Ref1Id.Id }) .AddReferences(9, "my-union", Partitioning.Invariant, new ReferencesFieldProperties()) .AddGeolocation(10, "my-geolocation", Partitioning.Invariant, new GeolocationFieldProperties()) .AddComponent(11, "my-component", Partitioning.Invariant, new ComponentFieldProperties { SchemaId = Ref1Id.Id }) .AddComponents(12, "my-components", Partitioning.Invariant, new ComponentsFieldProperties { SchemaIds = ReadonlyList.Create(Ref1.Id, Ref2.Id) }) .AddTags(13, "my-tags", Partitioning.Invariant, new TagsFieldProperties()) .AddArray(100, "my-array", Partitioning.Invariant, f => f .AddBoolean(121, "nested-boolean", new BooleanFieldProperties()) .AddNumber(122, "nested-number", new NumberFieldProperties())) .SetScripts(new SchemaScripts { Query = "<query-script>" })); }
public static Query <T> Query <T>(this ReadonlyList <T> rList) { var pooledArr = ArrayPool <T> .Spawn(rList.Count); for (int i = 0; i < rList.Count; i++) { pooledArr[i] = rList[i]; } return(new Query <T>(pooledArr, rList.Count)); }
public async Task Should_not_add_error_if_value_has_not_duplicates() { var sut = Field(new ArrayFieldProperties { UniqueFields = ReadonlyList.Create("myString") }); await sut.ValidateAsync(CreateValue(Object("myString", "1"), Object("myString", "2")), errors); Assert.Empty(errors); }
public void Should_not_add_error_if_inline_editing_is_allowed_for_editor(NumberFieldEditor editor) { var sut = new NumberFieldProperties { InlineEditable = true, Editor = editor, AllowedValues = ReadonlyList.Create(1.0) }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); Assert.Empty(errors); }
public async Task Should_add_error_if_value_has_duplicates() { var sut = Field(new ArrayFieldProperties { UniqueFields = ReadonlyList.Create("myString") }); await sut.ValidateAsync(CreateValue(Object("myString", "1"), Object("myString", "1")), errors); errors.Should().BeEquivalentTo( new[] { "Must not contain items with duplicate 'myString' fields." }); }
public async Task Should_not_add_error_if_schemas_is_empty() { var trigger = new ContentChangedTriggerV2 { Schemas = ReadonlyList.Empty <ContentChangedTriggerSchemaV2>() }; var errors = await RuleTriggerValidator.ValidateAsync(appId.Id, trigger, appProvider); Assert.Empty(errors); }
public async Task Should_add_error_if_value_has_duplicates() { var(id, sut, components) = Field(new ComponentsFieldProperties { UniqueFields = ReadonlyList.Create("componentField") }); await sut.ValidateAsync(CreateValue(2, id.ToString(), "componentField", 1), errors, components : components); errors.Should().BeEquivalentTo( new[] { "Must not contain items with duplicate 'componentField' fields." }); }
public async Task Should_add_error_if_number_is_not_allowed() { var sut = Field(new NumberFieldProperties { AllowedValues = ReadonlyList.Create(10d) }); await sut.ValidateAsync(CreateValue(20), errors); errors.Should().BeEquivalentTo( new[] { "Not an allowed value." }); }
public async Task Should_add_error_if_string_not_allowed() { var sut = Field(new StringFieldProperties { AllowedValues = ReadonlyList.Create("Foo") }); await sut.ValidateAsync(CreateValue("Bar"), errors); errors.Should().BeEquivalentTo( new[] { "Not an allowed value." }); }
public LanguageConfig ToSource() { if (!IsOptional && (Fallback == null || Fallback.Length == 0)) { return(LanguageConfig.Default); } else { return(new LanguageConfig(IsOptional, ReadonlyList.Create(Fallback))); } }
private static void BuildComponent(JsonSchema jsonSchema, ReadonlyList <DomainId>?schemaIds, Args args) { if (args.WithComponents) { var discriminator = new OpenApiDiscriminator { PropertyName = Component.Discriminator }; foreach (var schema in args.Components.Resolve(schemaIds).Values) { // Create a reference to give it a nice name in code generation. var(reference, actual) = args.Factory($"{schema.TypeName()}ComponentDto"); if (actual != null) { foreach (var field in schema.Fields.ForApi(args.WithHidden)) { var property = BuildProperty( field, args.Components, schema, args.Factory, args.WithHidden, args.WithComponents); if (property != null) { property.SetRequired(field.RawProperties.IsRequired); property.SetDescription(field); actual.Properties.Add(field.Name, property); } } } jsonSchema.OneOf.Add(reference); discriminator.Mapping[schema.Name] = reference; } jsonSchema.DiscriminatorObject = discriminator; if (discriminator.Mapping.Count > 0) { jsonSchema.Properties.Add(Component.Discriminator, JsonTypeBuilder.StringProperty(isRequired: true)); } } else { jsonSchema.AllowAdditionalProperties = true; } }
public async Task Should_add_error_if_value_has_no_discriminator() { var(_, sut, components) = Field(new ComponentFieldProperties { SchemaIds = ReadonlyList.Create(schemaId1, schemaId2) }); await sut.ValidateAsync(CreateValue(null, "field", 1), errors, components : components); errors.Should().BeEquivalentTo( new[] { "Invalid component. No 'schemaId' field found." }); }
public async Task Should_add_error_if_value_contains_an_not_allowed_values() { var sut = Field(new TagsFieldProperties { AllowedValues = ReadonlyList.Create("tag-2", "tag-3") }); await sut.ValidateAsync(CreateValue("tag-1", "tag-2", null), errors); errors.Should().BeEquivalentTo( new[] { "[1]: Not an allowed value." }); }
//计算任务显示内容 public static string MissionContent(MissionBaseRecord missionData, ReadonlyList <int> data) { var str = "("; if (data[0] == (int)eMissionState.Finished) { str += GameUtils.GetDictionaryText(1031); } else if (data[0] == (int)eMissionState.Acceptable) { str += GameUtils.GetDictionaryText(1034); } else if (data[0] == (int)eMissionState.Failed) { str += GameUtils.GetDictionaryText(1033); } else { var missionType = (eMissionType)missionData.FinishCondition; switch (missionType) { case eMissionType.Finish: { str += GameUtils.GetDictionaryText(1031); } break; case eMissionType.AcceptProgressBar: case eMissionType.AreaProgressBar: case eMissionType.AcceptStroy: { str += string.Format("{0}/{1}", 0, 1); } break; default: { str += string.Format("{0}/{1}", data[2], data[4]); } break; } } str += ")"; if (data[0] == (int)eMissionState.Finished) { str = "[5DFF00]" + str + "[-]"; } return(str); }
public JsonSchemaProperty?Visit(IField <ReferencesFieldProperties> field, Args args) { var property = JsonTypeBuilder.ArrayProperty(JsonTypeBuilder.String()); property.Format = GeoJson.Format; property.ExtensionData = new Dictionary <string, object> { ["schemaIds"] = field.Properties.SchemaIds ?? ReadonlyList.Empty <DomainId>() }; return(property); }
public void Should_update_language() { var config_1 = config_0.Set(Language.IT); var config_2 = config_1.Set(Language.IT, true, Language.EN); config_2.Languages.Should().BeEquivalentTo( new Dictionary <string, LanguageConfig> { [Language.EN] = new LanguageConfig(), [Language.IT] = new LanguageConfig(true, ReadonlyList.Create(Language.EN)) }); Assert.Equal(Language.EN, config_2.Master); }
/** Samples the current velocity and adds it to the rolling average. */ public override void OnHold(ReadonlyList<Hand> hands) { _velocityQueue.Enqueue(new VelocitySample(_obj.warper.RigidbodyPosition, _obj.warper.RigidbodyRotation, Time.fixedTime)); while (true) { VelocitySample oldest = _velocityQueue.Peek(); //Dequeue conservatively if the oldest is more than 4 frames later than the start of the window if (oldest.time + Time.fixedDeltaTime * 4 < Time.fixedTime - _windowLength - _windowDelay) { _velocityQueue.Dequeue(); } else { break; } } }
public void Should_add_error_if_inline_editing_is_not_allowed_for_editor(StringFieldEditor editor) { var sut = new StringFieldProperties { InlineEditable = true, Editor = editor, AllowedValues = ReadonlyList.Create("Value") }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); errors.Should().BeEquivalentTo( new List <ValidationError> { new ValidationError("Inline editing is only allowed for dropdowns, slugs and input fields.", "InlineEditable", "Editor") }); }
public void Should_add_error_if_inline_editing_is_not_allowed_for_editor(NumberFieldEditor editor) { var sut = new NumberFieldProperties { InlineEditable = true, Editor = editor, AllowedValues = ReadonlyList.Create(1.0) }; var errors = FieldPropertiesValidator.Validate(sut).ToList(); errors.Should().BeEquivalentTo( new List <ValidationError> { new ValidationError("Inline editing is not allowed for Radio editor.", "InlineEditable", "Editor") }); }
public void CanUpdateSettings_should_not_throw_exception_if_setting_is_valid() { var command = new UpdateAppSettings { Settings = new AppSettings { Patterns = ReadonlyList.Create( new Pattern("name", "[a-z]")), Editors = ReadonlyList.Create( new Editor("name", "url/to/editor")) } }; GuardApp.CanUpdateSettings(command); }
public void Should_eliminate_invalid_fallbacks_and_self() { var config_1 = config_0.Set(Language.IT); var config_2 = config_1.Set(Language.IT); var config_3 = config_2.Set(Language.IT, true, Language.EN, Language.IT, Language.DE); config_3.Languages.Should().BeEquivalentTo( new Dictionary <string, LanguageConfig> { [Language.EN] = new LanguageConfig(), [Language.IT] = new LanguageConfig(true, ReadonlyList.Create(Language.EN)) }); Assert.Equal(Language.EN, config_2.Master); }
public async Task Should_add_error_if_image_has_invalid_extension() { var sut = Validator(new AssetsFieldProperties { AllowedExtensions = ReadonlyList.Create("mp4") }); await sut.ValidateAsync(CreateValue(Document.AssetId, Image1.AssetId), errors); errors.Should().BeEquivalentTo( new[] { "[1]: Must be an allowed extension.", "[2]: Must be an allowed extension." }); }
public async Task Should_not_add_error_if_schemas_ids_are_valid() { A.CallTo(() => appProvider.GetSchemaAsync(appId.Id, A <DomainId> ._, false, default)) .Returns(Mocks.Schema(appId, schemaId)); var trigger = new ContentChangedTriggerV2 { Schemas = ReadonlyList.Create(new ContentChangedTriggerSchemaV2 { SchemaId = schemaId.Id }) }; var errors = await RuleTriggerValidator.ValidateAsync(appId.Id, trigger, appProvider); Assert.Empty(errors); }
public void DrawLines(ReadonlyList <Vector3> linePositions) { if (!this.enabled) { return; } if (linePositions.Count <= 1) { return; } addLine(linePositions[0], linePositions[1]); for (int i = 2; i < linePositions.Count; i++) { appendLinePosition(linePositions[i]); } }
public override void GetHoldingPose(ReadonlyList<Hand> hands, out Vector3 newPosition, out Quaternion newRotation) { KabschC.Reset(ref _kabsch); Vector3 bodyPosition = _obj.warper.RigidbodyPosition; Quaternion bodyRotation = _obj.warper.RigidbodyRotation; Matrix4x4 it = Matrix4x4.TRS(bodyPosition, bodyRotation, Vector3.one); for (int h = 0; h < hands.Count; h++) { Hand hand = hands[h]; var collection = _handIdToPoints[hand.Id]; for (int f = 0; f < NUM_FINGERS; f++) { Finger finger = hand.Fingers[f]; Finger.FingerType fingerType = finger.Type; for (int j = 0; j < NUM_BONES; j++) { Bone.BoneType boneType = (Bone.BoneType)j; Bone bone = finger.Bone(boneType); Vector3 localPos = collection.GetLocalPosition(fingerType, boneType); Vector3 bonePos = bone.NextJoint.ToVector3(); //Do the solve such that the objects positions are matched to the new bone positions LEAP_VECTOR point1 = (it.MultiplyPoint3x4(localPos) - bodyPosition).ToCVector(); LEAP_VECTOR point2 = (bonePos - bodyPosition).ToCVector(); KabschC.AddPoint(ref _kabsch, ref point1, ref point2, 1.0f); } } } performSolve(); LEAP_VECTOR leapTranslation; LEAP_QUATERNION leapRotation; KabschC.GetTranslation(ref _kabsch, out leapTranslation); KabschC.GetRotation(ref _kabsch, out leapRotation); newPosition = bodyPosition + leapTranslation.ToVector3(); newRotation = leapRotation.ToQuaternion() * bodyRotation; }
/** Moves the object by applying forces and torque. */ public override void MoveTo(ReadonlyList<Hand> hands, PhysicsMoveInfo info, Vector3 solvedPosition, Quaternion solvedRotation) { if (info.shouldTeleport) { _obj.warper.Teleport(solvedPosition, solvedRotation); } else { Vector3 targetVelocity = PhysicsUtility.ToLinearVelocity(_obj.warper.RigidbodyPosition, solvedPosition, Time.fixedDeltaTime); Vector3 targetAngularVelocity = PhysicsUtility.ToAngularVelocity(_obj.warper.RigidbodyRotation, solvedRotation, Time.fixedDeltaTime); float targetSpeedSqrd = targetVelocity.sqrMagnitude; if (targetSpeedSqrd > _maxVelocitySqrd) { float targetPercent = (_maxVelocity * _obj.Manager.SimulationScale) / Mathf.Sqrt(targetSpeedSqrd); targetVelocity *= targetPercent; targetAngularVelocity *= targetPercent; } float followStrength = _strengthByDistance.Evaluate(info.remainingDistanceLastFrame / _obj.Manager.SimulationScale); Vector3 lerpedVelocity = Vector3.Lerp(_obj.rigidbody.velocity, targetVelocity, followStrength); Vector3 lerpedAngularVelocity = Vector3.Lerp(_obj.rigidbody.angularVelocity, targetAngularVelocity, followStrength); Vector3 centerOfMassOffset = _obj.warper.RigidbodyRotation * _obj.rigidbody.centerOfMass; _obj.rigidbody.velocity = lerpedVelocity + Vector3.Cross(lerpedAngularVelocity, centerOfMassOffset); _obj.rigidbody.angularVelocity = lerpedAngularVelocity; } }
/** * Calculate the best holding pose given the current state of the hands and * interactable object. * @param hands the list of hands with the current tracking data. * @param position A Vector3 object to be filled with the disred object position. * @param rotation A Quaternion object to be filled with the desired rotation. * @since 4.1.4 */ public abstract void GetHoldingPose(ReadonlyList<Hand> hands, out Vector3 position, out Quaternion rotation);
/** * Move the interactable object to or towards the Interaction Engine's desired position. * * @param hands the list of Leap.Hand objects involved in the interaction. * @param info hints about the move. * @param solvedPosition the target position calculated by the Interaction Engine. * @param solvedRotation the target rotation calculated by the Interaction Engine. * @since 4.1.4 */ public abstract void MoveTo(ReadonlyList<Hand> hands, PhysicsMoveInfo info, Vector3 solvedPosition, Quaternion solvedRotation);
/** Does nothing in this implementation. */ public override void OnHold(ReadonlyList<Hand> hands) { }
/// <summary> /// Called by InteractionManager every frame that a Hand continues to grasp this object. This callback /// is invoked both in LateUpdate. /// </summary> public abstract void NotifyHandsHoldGraphics(ReadonlyList<Hand> hands);
protected override void OnHandsHoldPhysics(ReadonlyList<Hand> hands) { base.OnHandsHoldPhysics(hands); PhysicsMoveInfo info = new PhysicsMoveInfo(); info.remainingDistanceLastFrame = Vector3.Distance(_warper.RigidbodyPosition, _solvedPosition); info.shouldTeleport = _notifiedOfTeleport; _controllers.HoldingPoseController.GetHoldingPose(hands, out _solvedPosition, out _solvedRotation); _controllers.MoveToController.MoveTo(hands, info, _solvedPosition, _solvedRotation); if (_controllers.ThrowingController != null) { _controllers.ThrowingController.OnHold(hands); } }
/** * Called every physics frame while an interactable object is being held. * @param hands a list of the hands holding the object. * @since 4.1.4 */ public abstract void OnHold(ReadonlyList<Hand> hands);
protected override void OnHandsHoldGraphics(ReadonlyList<Hand> hands) { base.OnHandsHoldGraphics(hands); if (_material.WarpingEnabled) { Vector3 deltaPosition = Quaternion.Inverse(_solvedRotation) * (_warper.RigidbodyPosition - _solvedPosition); Quaternion deltaRotation = Quaternion.Inverse(_solvedRotation) * _warper.RigidbodyRotation; Vector3 newPosition; Quaternion newRotation; _controllers.HoldingPoseController.GetHoldingPose(hands, out newPosition, out newRotation); Vector3 graphicalPosition = newPosition + newRotation * deltaPosition; Quaternion graphicalRotation = newRotation * deltaRotation; _warper.WarpPercent = _material.WarpCurve.Evaluate(deltaPosition.magnitude / _manager.SimulationScale); _warper.SetGraphicalPosition(graphicalPosition, graphicalRotation); } }