public void NumericState_NotEquals_NumericState() { var state1 = new ComponentState(5); var state2 = new ComponentState(6); state1.Equals(state2).ShouldBeEquivalentTo(false); }
public bool Connect() { if (State == ComponentState.Connected || State == ComponentState.Disposed) throw new InvalidOperationException("Invalid state"); if (!CheckIfPossibleToConnect()) { State = ComponentState.Failed; return false; } bool success = false; try { success = OnConnecting(); } catch (Exception e) { Debug.WriteLine(String.Format("Exception occured while attempting to connect to component {0}. The exception was: {1}", Name, e)); } if (!success) { State = ComponentState.Failed; return false; } State = ComponentState.Connected; return true; }
public static IAction GetSetStateAction(this IStateMachine stateStateMachine, ComponentState stateId) { if (stateStateMachine == null) throw new ArgumentNullException(nameof(stateStateMachine)); if (stateId == null) throw new ArgumentNullException(nameof(stateId)); return new Action(() => stateStateMachine.SetState(stateId)); }
public void State_NotEquals_State() { var state1 = new ComponentState("Off"); var state2 = new ComponentState("On"); state1.Equals(state2).ShouldBeEquivalentTo(false); }
public void UnknownState_NotEquals_DifferentState() { var state1 = new ComponentState(null); var state2 = new ComponentState(5); state1.Equals(state2).ShouldBeEquivalentTo(false); }
public void UnknownState_Equals_UnknownState() { var state1 = new ComponentState(null); var state2 = new ComponentState(null); state1.Equals(state2).ShouldBeEquivalentTo(true); }
protected void OnActiveStateChanged(ComponentState oldState, ComponentState newState) { _stateLastChanged = DateTime.Now; Log.Info($"Component '{Id}' updated state from '{oldState}' to '{newState}'"); StateChanged?.Invoke(this, new ComponentStateChangedEventArgs(oldState, newState)); }
public StateMachineState WithActuator(IActuator actuator, ComponentState state) { if (actuator == null) throw new ArgumentNullException(nameof(actuator)); _pendingActuatorStates.Add(new PendingActuatorState().WithActuator(actuator).WithState(state)); return this; }
public StateNotSupportedException(ComponentState state) : base($"State '{state}' is not supported.") { if (state == null) throw new ArgumentNullException(nameof(state)); State = state; }
public MachineComponent(Vector2 center, float width, float height, float rotation, float static_friction, float bounciness) : base(center, width, height, rotation, static_friction, bounciness) { this.currentState = ComponentState.notSelected; this.Texture = kTex; }
public ComponentIsInStateCondition(IComponent component, ComponentState state) { if (component == null) throw new ArgumentNullException(nameof(component)); if (state == null) throw new ArgumentNullException(nameof(state)); WithExpression(() => component.GetState().Equals(state)); }
public Component(Vector2 center, ComponentType type) { this.myType = type; this.currentState = ComponentState.notSelected; this.Radius = 50.0f; this.Center = center; }
public static bool SupportsState(this IComponent component, ComponentState componentState) { if (componentState == null) throw new ArgumentNullException(nameof(componentState)); if (component == null) throw new ArgumentNullException(nameof(component)); return component.GetSupportedStates().Any(s => s.Equals(componentState)); }
public void NumericValue_Serialize() { var state = new ComponentState(5F); var jsonValue = state.JToken; Assert.AreEqual(JTokenType.Float, jsonValue.Type); Assert.AreEqual(5, jsonValue.ToObject<int>()); }
public TestStateMachine CreateTestStateMachineWithActiveState(ComponentState id) { var stateMachine = new TestStateMachine(ComponentIdGenerator.EmptyId); stateMachine.AddState(new StateMachineState(id)); stateMachine.SetState(id); return stateMachine; }
public void StatefulState_Serialize() { var state = new ComponentState("Off"); var jsonValue = state.JToken; Assert.AreEqual(JTokenType.String, jsonValue.Type); Assert.AreEqual("Off", jsonValue.ToObject<string>()); }
public void UnknownState_Serialize() { var state = new ComponentState(null); var jsonValue = state.JToken; Assert.AreEqual(JTokenType.Null, jsonValue.Type); Assert.IsNull(jsonValue.ToObject<object>()); }
public static StateMachineState AddState(this StateMachine stateMachine, ComponentState id) { if (stateMachine == null) throw new ArgumentNullException(nameof(stateMachine)); if (id == null) throw new ArgumentNullException(nameof(id)); var state = new StateMachineState(id); stateMachine.AddState(state); return state; }
public TestStateMachine CreateTestStateMachineWithOnOffStates(ComponentState activeState) { var stateMachine = new TestStateMachine(ComponentIdGenerator.EmptyId); stateMachine.AddState(new StateMachineState(BinaryStateId.Off)); stateMachine.AddState(new StateMachineState(BinaryStateId.On)); stateMachine.SetState(activeState); return stateMachine; }
public bool selected(Vector2 touchLocation) { // did user touch this object? float distance = Vector2.Distance(this.Center, touchLocation); if ( distance <= this.Radius) { this.currentState = ComponentState.selected; return true; } else return false; }
protected void SetState(ComponentState newState) { if (newState.Equals(_state)) { return; } var oldValue = _state; _state = newState; OnActiveStateChanged(oldValue, newState); }
public ComponentState GetNextState(ComponentState baseStateId) { if (baseStateId.Equals(BinaryStateId.Off)) { return BinaryStateId.On; } if (baseStateId.Equals(BinaryStateId.On)) { return BinaryStateId.Off; } throw new StateNotSupportedException(baseStateId); }
public ComponentState GetNextState(ComponentState stateId) { if (stateId == null) throw new ArgumentNullException(nameof(stateId)); ThrowIfStateNotSupported(stateId); IStateMachineState startState = GetState(stateId); int indexOfStartState = _states.IndexOf(startState); if (indexOfStartState == _states.Count - 1) { return _states.First().Id; } return _states[indexOfStartState + 1].Id; }
private static void HandleBlindButtonPressedEvent(IRollerShutter rollerShutter, ComponentState direction) { if (direction.Equals(RollerShutterStateId.MovingUp) && rollerShutter.GetState().Equals(RollerShutterStateId.MovingUp)) { rollerShutter.SetState(RollerShutterStateId.Off); } else if (direction.Equals(RollerShutterStateId.MovingDown) && rollerShutter.GetState().Equals(RollerShutterStateId.MovingDown)) { rollerShutter.SetState(RollerShutterStateId.Off); } else if (direction.Equals(RollerShutterStateId.MovingDown)) { rollerShutter.SetState(RollerShutterStateId.MovingDown); } else if (direction.Equals(RollerShutterStateId.MovingUp)) { rollerShutter.SetState(RollerShutterStateId.MovingUp); } else { throw new InvalidOperationException(); } }
public virtual string Render(ComponentState state, ValidationMarkerMode showValidationMessageMode, IEnumerable<string> validationErrors) { if (state == ComponentState.Unvalidated && showValidationMessageMode != ValidationMarkerMode.Always) return ""; var builder = new TagBuilder("span"); if (state == ComponentState.Invalid) { var firstError = validationErrors.FirstOrDefault(); if (firstError != null) { builder.SetInnerText(firstError); builder.HtmlAttributes["class"] = "field-validation-message field-validation-error"; } } else if (state == ComponentState.Valid) builder.HtmlAttributes["class"] = "field-validation-message field-validation-ok"; else builder.HtmlAttributes["class"] = "field-validation-message"; return builder.ToString(); }
public ComponentContractInfo(ComponentBase component, BindableComponentStatus contractStatus, ComponentState contractState) { Assure.ArgumentNotNull(component, nameof(component)); Assure.ArgumentNotNull(contractStatus, nameof(contractStatus)); Component = component; ContractStatus = contractStatus; ContractState = contractState; }
/// <summary> /// States the specified value. /// </summary> /// <param name="value">The value.</param> /// <returns>TBuilder.</returns> public TBuilder State(ComponentState value) { Component.State = value; return(this as TBuilder); }
protected virtual void OnStateMachineStateChanged(IStateMachine stateMachine, ComponentState newState) { }
internal void SetError() => ComponentState = ComponentState.Error;
static ComponentState CreateComponentState( IComponent component, ComponentState parentComponentState = null) { return(new ComponentState(new TestRenderer(), 0, component, parentComponentState)); }
public void InitializeComplete() { state = ComponentState.Inititalize; OnInitializeComplete(); }
private RenderTreeFrame(int sequence, int componentSubtreeLength, Type componentType, ComponentState componentState, object componentKey) : this() { SequenceField = sequence; FrameTypeField = RenderTreeFrameType.Component; ComponentSubtreeLengthField = componentSubtreeLength; ComponentTypeField = componentType; ComponentKeyField = componentKey; if (componentState != null) { ComponentStateField = componentState; ComponentIdField = componentState.ComponentId; } }
/// <summary> /// Event which is raised whenever the state of a storage system changes. /// </summary> /// <param name="sender">Object instance which raised the event.</param> /// <param name="state">New state of the storage system.</param> static void StorageSystem_StateChanged(IStorageSystem sender, ComponentState state) { Console.WriteLine("Storage system changed state to '{0}'.", state.ToString()); }
public DirectionAnimation WithTargetState(ComponentState state) { _targetState = state; return this; }
public static void InitializingComponent(ILogger logger, ComponentState componentState, ComponentState parentComponentState) { if (logger.IsEnabled(LogLevel.Debug)) // This is almost always false, so skip the evaluations { if (parentComponentState == null) { InitializingRootComponent(logger, componentState.ComponentId, componentState.Component.GetType()); } else { InitializingChildComponent(logger, componentState.ComponentId, componentState.Component.GetType(), parentComponentState.ComponentId, parentComponentState.Component.GetType()); } } }
public override void HandleComponentState(ComponentState curState, ComponentState nextState) { if (!(curState is ContainerManagerComponentState cast)) { return; } // Delete now-gone containers. List <string> toDelete = null; foreach (var(id, container) in _containers) { if (!cast.Containers.ContainsKey(id)) { container.Shutdown(); toDelete ??= new List <string>(); toDelete.Add(id); } } if (toDelete != null) { foreach (var dead in toDelete) { _containers.Remove(dead); } } // Add new containers and update existing contents. foreach (var(id, contEnts) in cast.Containers) { var(show, entities) = contEnts; if (!_containers.TryGetValue(id, out var container)) { container = new ClientContainer(id, this); _containers.Add(id, container); } // sync show flag container.ShowContents = show; // Remove gone entities. List <IEntity> toRemove = null; foreach (var entity in container.Entities) { if (!entities.Contains(entity.Uid)) { toRemove ??= new List <IEntity>(); toRemove.Add(entity); } } if (toRemove != null) { foreach (var goner in toRemove) { container.DoRemove(goner); } } // Add new entities. foreach (var uid in entities) { var entity = Owner.EntityManager.GetEntity(uid); if (!container.Entities.Contains(entity)) { container.DoInsert(entity); } } } }
public void ShouldRenderComponent() { // given ComponentState expectedComponentState = ComponentState.Content; string expectedIdentityTextBoxPlaceholder = "Student Identity"; string expectedFirstNameTextBoxPlaceholder = "First Name"; string expectedMiddleNameTextBoxPlaceholder = "Middle Name"; string expectedLastnameTextBoxPlaceholder = "Last Name"; string expectedSubmitButtonLabel = "Submit Student"; // when this.renderedStudentRegistrationComponent = RenderComponent <StudentRegistrationComponent>(); // then this.renderedStudentRegistrationComponent.Instance.StudentView .Should().NotBeNull(); this.renderedStudentRegistrationComponent.Instance.State .Should().Be(expectedComponentState); this.renderedStudentRegistrationComponent.Instance.StudentIdentityTextBox .Should().NotBeNull(); this.renderedStudentRegistrationComponent.Instance.StudentIdentityTextBox.IsDisabled .Should().BeFalse(); this.renderedStudentRegistrationComponent.Instance.StudentIdentityTextBox.Placeholder .Should().Be(expectedIdentityTextBoxPlaceholder); this.renderedStudentRegistrationComponent.Instance.StudentFirstNameTextBox .Should().NotBeNull(); this.renderedStudentRegistrationComponent.Instance.StudentFirstNameTextBox.IsDisabled .Should().BeFalse(); this.renderedStudentRegistrationComponent.Instance.StudentFirstNameTextBox.Placeholder .Should().Be(expectedFirstNameTextBoxPlaceholder); this.renderedStudentRegistrationComponent.Instance.StudentMiddleNameTextBox .Should().NotBeNull(); this.renderedStudentRegistrationComponent.Instance.StudentMiddleNameTextBox.Placeholder .Should().Be(expectedMiddleNameTextBoxPlaceholder); this.renderedStudentRegistrationComponent.Instance.StudentMiddleNameTextBox.IsDisabled .Should().BeFalse(); this.renderedStudentRegistrationComponent.Instance.StudentLastNameTextBox .Should().NotBeNull(); this.renderedStudentRegistrationComponent.Instance.StudentLastNameTextBox.Placeholder .Should().Be(expectedLastnameTextBoxPlaceholder); this.renderedStudentRegistrationComponent.Instance.StudentLastNameTextBox.IsDisabled .Should().BeFalse(); this.renderedStudentRegistrationComponent.Instance.StudentGenderDropDown.Value .Should().BeOfType(typeof(StudentViewGender)); this.renderedStudentRegistrationComponent.Instance.StudentGenderDropDown .Should().NotBeNull(); this.renderedStudentRegistrationComponent.Instance.StudentGenderDropDown.IsDisabled .Should().BeFalse(); this.renderedStudentRegistrationComponent.Instance.DateOfBirthPicker .Should().NotBeNull(); this.renderedStudentRegistrationComponent.Instance.DateOfBirthPicker.IsDisabled .Should().BeFalse(); this.renderedStudentRegistrationComponent.Instance.SubmitButton.Label .Should().Be(expectedSubmitButtonLabel); this.renderedStudentRegistrationComponent.Instance.SubmitButton .Should().NotBeNull(); this.renderedStudentRegistrationComponent.Instance.SubmitButton.IsDisabled .Should().BeFalse(); this.renderedStudentRegistrationComponent.Instance.StatusLabel .Should().NotBeNull(); this.renderedStudentRegistrationComponent.Instance.StatusLabel.Value .Should().BeNull(); this.renderedStudentRegistrationComponent.Instance.Exception.Should().BeNull(); this.studentViewServiceMock.VerifyNoOtherCalls(); }
internal RenderTreeFrame WithComponent(ComponentState componentState) => new RenderTreeFrame(SequenceField, componentSubtreeLength: ComponentSubtreeLengthField, ComponentTypeField, componentState, ComponentKeyField);
public static IReadOnlyList <CascadingParameterState> FindCascadingParameters(ComponentState componentState) { var componentType = componentState.Component.GetType(); var infos = GetReflectedCascadingParameterInfos(componentType); // For components known not to have any cascading parameters, bail out early if (infos == null) { return(null); } // Now try to find matches for each of the cascading parameters // Defer instantiation of the result list until we know there's at least one List <CascadingParameterState> resultStates = null; var numInfos = infos.Length; for (var infoIndex = 0; infoIndex < numInfos; infoIndex++) { ref var info = ref infos[infoIndex]; var supplier = GetMatchingCascadingValueSupplier(info, componentState); if (supplier != null) { if (resultStates == null) { // Although not all parameters might be matched, we know the maximum number resultStates = new List <CascadingParameterState>(infos.Length - infoIndex); } resultStates.Add(new CascadingParameterState(info.ConsumerValueName, supplier)); } }
private void RegisterComponentContracts(ComponentBase component, Type[] componentContracts) { if (componentContracts == null || componentContracts.Length == 0) { // component doesn't implement any contracts return; } var componentType = component.GetType(); foreach (var componentContractType in componentContracts // ignore contract duplicates .Distinct()) { if (!componentContractType.IsInterface || !typeof(IComponentContract).IsAssignableFrom(componentContractType)) { Log.Error(LogContextEnum.Configuration, $"Component contract '{componentContractType.FullName}' is not an interface or doesn't inherit {nameof(IComponentContract)}."); continue; } if (!componentContractType.IsAssignableFrom(componentType)) { Log.Error(LogContextEnum.Configuration, $"Component '{componentType.FullName}' returned contract '{componentContractType.FullName}' that is not implemented by the component."); continue; } var contractStatusProperty = componentContractType.GetProperty(ContractStatusPropertyName); if (contractStatusProperty == null || !contractStatusProperty.CanRead || contractStatusProperty.CanWrite || contractStatusProperty.PropertyType != typeof(BindableComponentStatus)) { Log.Error(LogContextEnum.Configuration, $"Component contract '{componentContractType.FullName}' doesn't declare readable-only {ContractStatusPropertyName} property of type {nameof(BindableComponentStatus)} (required by convention)."); continue; } var contractStatus = (BindableComponentStatus)contractStatusProperty.GetValue(component); // check if separate contract status if (contractStatus != component.Status) { if (contractStatus == null) { Log.Error(LogContextEnum.Configuration, $"Component contract '{componentContractType.FullName}' status is null."); continue; } // todo: add support for a separate contract statuses (see architecture docs) // bind separate contract status to component status (status inheritance) // implement appropriate monitoring representation } ComponentState contractState = null; var contractStateProperty = componentContractType.GetProperty(ContractStatePropertyName); if (contractStateProperty != null && contractStateProperty.CanRead) { // no need to check on null - it's already checked contractState = (ComponentState)contractStateProperty.GetValue(component); } var componentContractInfo = new ComponentContractInfo(component, contractStatus, contractState); AddContractInfo(componentContractType, componentContractInfo); } }
internal void SetLoading() => ComponentState = ComponentState.Loading;
public ComponentStateService(ComponentState componentState = ComponentState.Loading) { ComponentState = componentState; }
private void OnStateChanged(ComponentState oldState, ComponentState newState) { StateChanged?.Invoke(this, new ComponentStateChangedEventArgs(oldState, newState)); }
public void ChangeStateTo(ComponentState <TManager> state) { ChangeStateTo(state.GetType()); }
private void SetStates(ComponentState state) { foreach (var rollerShutter in _rollerShutters) { _componentService.GetComponent<IRollerShutter>(rollerShutter).SetState(state); } }
public DirectionAnimation WithTargetState(ComponentState state) { _targetState = state; return(this); }
/// <inheritdoc /> public override void HandleComponentState(ComponentState state) { base.HandleComponentState(state); IsCurrentlyWorn = ((WearableAnimatedSpriteComponentState)state).IsCurrentlyWorn; }
internal void SetContent() => ComponentState = ComponentState.Content;
public DirectionAnimation WithTargetOffState() { _targetState = BinaryStateId.Off; return(this); }
internal void SetState(ComponentState componentState) => ComponentState = componentState;
public void Unsubscribe(ComponentState subscriber) => throw new NotImplementedException();
private void Update() { var oldState = _state; if (_fullOpenReedSwitch.Read() == BinaryState.Low) { _state = CasementStateId.Open; _openedTrigger.Execute(); return; } if (_tiltReedSwitch != null && _tiltReedSwitch.Read() == BinaryState.Low) { _state = CasementStateId.Tilt; _closedTrigger.Execute(); return; } else { _state = CasementStateId.Closed; _closedTrigger.Execute(); } OnStateChanged(oldState, _state); }
public ComponentNode(IssoPoint2D location) : base() { DisallowedDisplacements = new List <NodeDisplacement>(); this.location = location; state = ComponentState.csNormal; }
void ICascadingValueComponent.Unsubscribe(ComponentState subscriber) { _subscribers?.Remove(subscriber); }
protected override void OnInitialized() { this.State = ComponentState.Content; }
public DirectionAnimation WithTargetOffState() { _targetState = BinaryStateId.Off; return this; }
/// <inheritdoc /> public override void HandleComponentState(ComponentState state) { AABB = ((BoundingBoxComponentState)state).AABB; }