void Update() { if (!Application.isPlaying) { return; } if (Action == null) { return; } if (Action.HasEnded) { CurrentEvent = null; if (HasReachedMaxTriggerCount()) { m_currState = HandlerState.TERMINATED; } else { m_currState = HandlerState.SLEEPING; } return; } if (Action.IsRunning) { Action.Update(); } }
protected override bool HandleByte(byte messageByte) { switch (currentState) { case HandlerState.StartEnd: currentState = HandlerState.SysexCommand; return(true); case HandlerState.SysexCommand: currentState = HandlerState.PinMapping; return(true); case HandlerState.PinMapping: if (messageByte == MessageConstants.SYSEX_END) { messageBroker.CreateEvent(message); Reset(); return(false); } if (messageByte > 127) { throw new MessageHandlerException(BaseExceptionMessage + "This is not a valid mapping"); } message.PinMappings.Add(messageByte); return(true); default: throw new ArgumentOutOfRangeException(); } }
private void TriggerAction() { m_currState = HandlerState.RUNNING; m_triggerCount++; Action.Trigger(); }
public bool Start() { lock (_lockObject) { // Do not start if handler is in failed state if (_handlerState == HandlerState.Failed) { return(false); } if (_handlerProxy == null) { _appDomain = CreateDomain(); RunningHandlerProxy proxy; var initResult = InitializeAndStartRunningHandler(out proxy); if (initResult.HasError) { _logger.Error("Handler: Init failed: {0}: {1}", initResult.ErrorReason, initResult.ErrorMessage); SetFailed(); return(false); } _handlerProxy = proxy; _lastStartTime = DateTime.Now; _handlerMessage = String.Empty; } _handlerState = HandlerState.Running; } return(true); }
private void AbortExecution(HandlerState state) { bool canAbort; lock (state) { if (state.IsExited) { // The handler has already exited. return; } // Check if we can call Thread.Abort() or if the handler thread is // currently in a critical section and needs to abort himself when // leaving the critical section. canAbort = !state.IsCriticalSection; state.AbortState = canAbort ? AbortState.IsAborting : AbortState.ShouldAbort; } if (canAbort) { /* The handler thread is not in a critical section so we can * directly abort it. * This needs to be done outside of the lock because Abort() could * block if the thread is currently in a finally handler (and * trying to lock on the state object), which could lead to a * deadlock. */ state.HandlerThread.Abort(state); } }
public override bool Handle(byte messageByte) { if (!CanHandle(messageByte)) { Reset(); throw new MessageHandlerException("Error with the incoming byte. This is not a valid DigitalMessage"); } switch (currentHandlerState) { case HandlerState.StartEnd: message.Port = messageByte & MessageConstants.MESSAGEPINMASK; currentHandlerState = HandlerState.LSB; return(true); case HandlerState.LSB: LSBCache = messageByte; currentHandlerState = HandlerState.MSB; return(true); case HandlerState.MSB: message.PinStates = BitHelper.PortVal2PinVals((byte)BitHelper.BytesToInt(LSBCache, messageByte)); messageBroker.CreateEvent(message); Reset(); return(false); default: throw new ArgumentOutOfRangeException(); } }
public void AssociationInitializeMethod() { ISemanticData _testISemanticData = new TestISemanticData(); Assert.IsNotNull(_testISemanticData); TestAssociation _nt = new TestAssociation(_testISemanticData, "AssociationInitializeMethod"); Assert.IsNotNull(_nt); int _eventsCount = 0; HandlerState _lastState = default(HandlerState); _nt.StateChangedEventHandler += (x, y) => { _eventsCount++; _lastState = y.State; }; Assert.AreEqual <HandlerState>(HandlerState.NoConfiguration, _nt.State.State); Assert.AreEqual <int>(0, _eventsCount); _nt.Initialize(); Assert.AreEqual <int>(1, _eventsCount); Assert.IsNotNull(_lastState); Assert.AreEqual <HandlerState>(HandlerState.Disabled, _lastState); Assert.AreEqual <HandlerState>(HandlerState.Disabled, _nt.State.State); _nt.State.Enable(); Assert.AreEqual <int>(2, _eventsCount); Assert.IsNotNull(_lastState); Assert.AreEqual <HandlerState>(HandlerState.Operational, _lastState); Assert.AreEqual <HandlerState>(HandlerState.Operational, _nt.State.State); _nt.State.Disable(); Assert.AreEqual <int>(3, _eventsCount); Assert.IsNotNull(_lastState); Assert.AreEqual <HandlerState>(HandlerState.Disabled, _lastState); Assert.AreEqual <HandlerState>(HandlerState.Disabled, _nt.State.State); }
/// <summary> /// Constructor /// </summary> public HandlerInstance(Logger logger, PackageManager packageManager) { _logger = logger; _packageManager = packageManager; Id = Guid.NewGuid(); _handlerState = HandlerState.Stopped; }
protected override bool HandleByte(byte messageByte) { switch (currentHandlerState) { case HandlerState.StartEnd: currentHandlerState = HandlerState.StringDataCommand; return(true); case HandlerState.StringDataCommand: // MAX_DATA bytes AFTER the command byte currentByteCount = 0; currentHandlerState = HandlerState.String; return(true); case HandlerState.String: if (messageByte == 0xF7) { // Get the string we have been building all along message.Message = stringBuilder.ToString(); messageBroker.CreateEvent(message); Reset(); return(false); } HandleChar(messageByte); return(true); default: throw new MessageHandlerException("Unknown SysexMessage handler state"); } }
/// <summary> /// This method is used to disable an already enabled <see cref="Association" /> object. /// This method call shall be rejected if the current State is <see cref="HandlerState.Disabled" /> or <see cref="HandlerState.NoConfiguration" />. /// </summary> /// <exception cref="System.ArgumentException">Wrong state</exception> public void Disable() { if (State != HandlerState.Operational) { throw new ArgumentException("Wrong state"); } State = HandlerState.Disabled; }
private void RecordPropertyHandler(HandlerState propertyHandlerState, string guid, string title) { PropertyHandlerState = propertyHandlerState; PropertyHandlerGuid = guid; PropertyHandlerTitle = title; OnPropertyChanged("PropertyHandlerDisplay"); OnPropertyChanged("Weight"); }
/// <summary> /// Stops the handler and does not start it again /// </summary> public bool Disable() { lock (_lockObject) { Stop(); _handlerState = HandlerState.Disabled; } return(true); }
private void RaiseHandlerState(HandlerState state) { EventHandler <AssociationStateChangedEventArgs> _hc = StateChangedEventHandler; if (_hc != null) { _hc(this, new AssociationStateChangedEventArgs(state)); } }
/// <summary> /// This method is used to enable a configured <see cref="Association" /> object. If a normal operation is possible, the state changes into <see cref="HandlerState.Operational" /> state. /// In the case of an error situation, the state changes into <see cref="HandlerState.Error" />. The operation is rejected if the current <see cref="State" /> is not <see cref="HandlerState.Disabled" />. /// </summary> /// <exception cref="System.ArgumentException">Wrong state</exception> public void Enable() { if (State != HandlerState.Disabled) { throw new ArgumentException("Wrong state"); } State = HandlerState.Operational; m_Parent.OnEnable(); }
/// <summary> /// Constructs and initializes the handler /// </summary> /// <param name = "model"></param> public AbstractHandler(ComponentModel model) { this.model = model; state = HandlerState.Valid; InitializeCustomDependencies(); if (model.ExtendedProperties.Contains("component_resolving_handler") == false) return; resolvingHandler = model.ExtendedProperties["component_resolving_handler"] as ComponentResolvingDelegate; }
public bool SetFinished() { lock (_lockObject) { _handlerState = HandlerState.Finished; CleanupProxy(false); CleanupAppDomain(); } return(true); }
public bool Stop() { lock (_lockObject) { _handlerState = HandlerState.Stopped; CleanupProxy(true); CleanupAppDomain(); } return(true); }
protected override bool HandleByte(byte messageByte) { switch (currentHandlerState) { case HandlerState.StartEnd: currentHandlerState = HandlerState.StartSysex; return(true); case HandlerState.StartSysex: // MAX_DATA bytes AFTER the command byte currentByteCount = 0; currentHandlerState = HandlerState.QueryFirmware; return(true); case HandlerState.QueryFirmware: if (messageByte > 127) { currentHandlerState = HandlerState.StartEnd; throw new MessageHandlerException(BaseExceptionMessage + "Major Version should be < 128"); } currentHandlerState = HandlerState.MajorVersion; message.MajorVersion = messageByte; return(true); case HandlerState.MajorVersion: if (messageByte > 127) { currentHandlerState = HandlerState.StartEnd; throw new MessageHandlerException(BaseExceptionMessage + "Minor Version should be < 128"); } currentHandlerState = HandlerState.MinorVersion; message.MinorVersion = messageByte; return(true); case HandlerState.MinorVersion: currentHandlerState = HandlerState.FirmwareName; HandleChar(messageByte); return(true); case HandlerState.FirmwareName: if (messageByte == MessageConstants.SYSEX_END) { // Get the string we have been building all along message.FirmwareName = stringBuilder.ToString(); messageBroker.CreateEvent(message); Reset(); return(false); } HandleChar(messageByte); return(true); default: throw new MessageHandlerException("Unknown SysexMessage handler state"); } }
public Controller() { SetEnabled = true; IsStoped = true; OnceTime = false; Log = new Stopwatch(); Timing = new Stopwatch(); State = new HandlerState(); Timeout = new TimeSpan(0, 0, 0); Intervel = new TimeSpan(1, 0, 0); }
/// <summary> /// Tells the handler to keep running but without generating additional jobs /// </summary> public bool Pause() { lock (_lockObject) { if (_handlerState == HandlerState.Running || _handlerState == HandlerState.Idle) { _handlerState = HandlerState.Paused; return(true); } } return(false); }
/// <summary> /// Re-enables the handler so it could start again /// </summary> public bool Enable() { lock (_lockObject) { if (_handlerState == HandlerState.Disabled) { _handlerState = HandlerState.Stopped; return(true); } } return(false); }
public async Task Sync_handler_correctly_calls_handler_method_and_wraps_with_completed_task() { var method = typeof(IHandler).GetMethod("B") !; var handler = Substitute.For <IHandler>(); var state = new HandlerState(method, handler); var args = new object[] { 1 }; await HandlerSubscriber.SyncHandler(args, state); handler.Received() .B(1); }
public async Task Async_handler_correctly_calls_handler_method() { var method = typeof(IHandler).GetMethod("A") !; var handler = Substitute.For <IHandler>(); var state = new HandlerState(method, handler); var args = new object[] { 1, "s" }; await HandlerSubscriber.AsyncHandler(args, state); await handler.Received() .A(1, "s"); }
protected override bool HandleByte(byte messageByte) { switch (currentState) { case HandlerState.StartEnd: currentState = HandlerState.SysexCommand; return(true); case HandlerState.SysexCommand: currentState = HandlerState.PinMode; return(true); case HandlerState.PinMode: // If the message has finished Reset and return that we won't handle other bytes if (messageByte == MessageConstants.SYSEX_END) { Reset(); messageBroker.CreateEvent(new CapabilitiesFinishedMessage()); return(false); } // We finished with a pin so create a capability message for this pin // we don't change the currentState because the next byte could be // a mode byte, or a finish message byte if (messageByte == MessageConstants.FINISHED_PIN_CAPABILITIES) { message.PinNo = currentPin++; messageBroker.CreateEvent(message); message = new CapabilityMessage(); return(true); } // Some assurance that we get an actual mode if (messageByte > Enum.GetValues(typeof(PinModes)).Length) { Reset(); throw new MessageHandlerException(BaseExceptionMessage + "There is no such pin mode"); } currentMode = (PinModes)messageByte; currentState = HandlerState.PinResolution; return(true); case HandlerState.PinResolution: message.Modes[currentMode] = messageByte; currentState = HandlerState.PinMode; return(true); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Start handler /// </summary> public void Start() { if (BluetoothRadio.IsSupported) { State = HandlerState.Working; Thread thread = new Thread(EstabilishBtConnection); thread.Start(); } else MessageBox.Show(@"Error to start SingleHandler. Reasons: 1. Bluetooth-module is not supported. 2. Bluetooth is turn off. "); }
protected override bool HandleByte(byte messageByte) { switch (currentHandlerState) { case HandlerState.StartEnd: currentHandlerState = HandlerState.Command; return(true); case HandlerState.Command: currentHandlerState = HandlerState.PinNo; return(true); case HandlerState.PinNo: if (messageByte > MessageConstants.MAX_PINS) { throw new MessageHandlerException(BaseExceptionMessage + "The pin number is wrong"); } message.PinNo = messageByte; currentHandlerState = HandlerState.PinMode; return(true); case HandlerState.PinMode: if (messageByte >= Enum.GetValues(typeof(PinModes)).Length) { throw new MessageHandlerException(BaseExceptionMessage + "This is no valid PinMode"); } message.Mode = (PinModes)messageByte; currentHandlerState = HandlerState.PinState; return(true); case HandlerState.PinState: if (messageByte == MessageConstants.SYSEX_END) { if (stateBytesReceived == 0) { throw new MessageHandlerException(BaseExceptionMessage + "There was no state in the message for pin " + message.PinNo); } messageBroker.CreateEvent(message); Reset(); return(false); } message.State |= messageByte << (stateBytesReceived * 7); stateBytesReceived++; return(true); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Start handler /// </summary> public void Start() { if (BluetoothRadio.IsSupported) { State = HandlerState.Working; Thread thread = new Thread(EstabilishBtConnection); thread.Start(); } else { MessageBox.Show(@"Error to start SingleHandler. Reasons: 1. Bluetooth-module is not supported. 2. Bluetooth is turn off. "); } }
private async Task RunMonitoringTask(HandlerState state, int timeout) { // Wait until the handler thread entered the try-block. // Use a synchronous wait because we expect this to be a very short // period of time. state.WaitSemaphore.Wait(); // Now asynchronously wait until the specified time has passed or the // semaphore has been released. In the latter case there is no need to // call AbortExecution(). bool completed = await state.WaitSemaphore.WaitAsync(timeout); // Abort the handler thread. if (!completed) { AbortExecution(state); } }
/// <summary> /// Connect to device and handle received packets from connected device. /// </summary> private void EstabilishBtConnection() { bool isConnected = false; while (State != HandlerState.Finished) { // Try listen. if (isConnected) { NetworkStream stream = _client.GetStream(); byte[] data = new byte[PacketSize]; // If device is disconnected... infinity loop, i guess. Because value of ReadTimeout is -1. stream.Read(data, 0, PacketSize); stream.Flush(); Action(data); } else // Try connect, if is not connected { isConnected = IsGlove ? ConnectArduino(ref _client, MacAddress) : ConnectAndroid(ref _listener, ref _client); if (isConnected) { isConnected = _client != null && _client.Connected; } } } if (_client != null) { _client.GetStream().Close(); _client.Dispose(); } if (_listener != null) { _listener.Server.Dispose(); _listener.Stop(); } State = HandlerState.Finished; }
/// <summary> /// Checks for idle time and sets the status appropriately /// </summary> public void CheckIdle() { bool isInIdleTime = false; if (_idleInfo != null) { // Set to idle if needed var now = DateTime.Now.TimeOfDay; if (_idleInfo.Start < _idleInfo.End) { if (now >= _idleInfo.Start && now <= _idleInfo.End) { isInIdleTime = true; } } else { if (now >= _idleInfo.Start || now <= _idleInfo.End) { isInIdleTime = true; } } } lock (_lockObject) { // Check if we're outside the idletime but the handler is still idle if (!isInIdleTime && _handlerState == HandlerState.Idle) { // Set it to running _handlerState = HandlerState.Running; } // We're inside the idle time but the handler is still running if (isInIdleTime && _handlerState == HandlerState.Running) { // Set it to idle _handlerState = HandlerState.Idle; } } }
static bool Compare(ref HandlerState handler, ref HandlerState composite) { var hhashes = handler.BlockSigInfos[handler.BlockIndex].Hashes; int hi = handler.HashIndex; var chashes = composite.BlockSigInfos[composite.BlockIndex].Hashes; int ci = composite.HashIndex; while (true) { if (hi >= hhashes.Count && ci >= chashes.Count) { break; } if (hi >= hhashes.Count) { if (handler.BlockSigInfos[handler.BlockIndex].EndsInRet) { break; } } if (hi >= hhashes.Count || ci >= chashes.Count) { return(false); } var hhash = hhashes[hi++]; var chash = chashes[ci++]; if (chash != hhash) { return(false); } } handler.HashIndex = hi; composite.HashIndex = ci; return(true); }
public override bool Handle(byte messageByte) { if (!CanHandle(messageByte)) { Reset(); throw new MessageHandlerException(BaseExceptionMessage); } switch (currentHandlerState) { case HandlerState.StartEnd: currentHandlerState = HandlerState.MajorVersion; return(true); case HandlerState.MajorVersion: if (messageByte > 127) { currentHandlerState = HandlerState.StartEnd; throw new MessageHandlerException(BaseExceptionMessage + "Major Version should be < 128."); } message.MajorVersion = messageByte; currentHandlerState = HandlerState.MinorVersion; return(true); case HandlerState.MinorVersion: if (messageByte > 127) { currentHandlerState = HandlerState.StartEnd; throw new MessageHandlerException(BaseExceptionMessage + "Minor Version should be < 128."); } message.MinorVersion = messageByte; messageBroker.CreateEvent(message); Reset(); return(false); default: throw new ArgumentOutOfRangeException(); } }
static bool Compare(ref HandlerState handler, ref HandlerState composite) { var hinstrs = handler.Blocks[handler.BlockIndex].Instructions; int hi = handler.InstructionIndex; var cinstrs = composite.Blocks[composite.BlockIndex].Instructions; int ci = composite.InstructionIndex; while (true) { if (hi >= hinstrs.Count && ci >= cinstrs.Count) break; if (hi >= hinstrs.Count || ci >= cinstrs.Count) return false; var hinstr = hinstrs[hi++]; var cinstr = cinstrs[ci++]; if (hinstr.OpCode.Code == Code.Nop || cinstr.OpCode.Code == Code.Nop) { if (hinstr.OpCode.Code != Code.Nop) hi--; if (cinstr.OpCode.Code != Code.Nop) ci--; continue; } if (hi == hinstrs.Count && hinstr.OpCode.Code == Code.Ret) { if (cinstr.OpCode.Code != Code.Br && cinstr.OpCode.Code != Code.Ret) ci--; break; } if (hinstr.OpCode.Code != cinstr.OpCode.Code) return false; if (hinstr.OpCode.Code == Code.Ldfld && hi + 1 < hinstrs.Count && ci + 1 < cinstrs.Count) { var hfield = hinstr.Operand as FieldDef; var cfield = cinstr.Operand as FieldDef; if (hfield != null && cfield != null && !hfield.IsStatic && !cfield.IsStatic && hfield.DeclaringType == handler.HandlerMethod.Method.DeclaringType && cfield.DeclaringType == composite.HandlerMethod.Method.DeclaringType && SignatureEqualityComparer.Instance.Equals(hfield.Signature, cfield.Signature)) { cinstr = cinstrs[ci++]; hinstr = hinstrs[hi++]; if (cinstr.OpCode.Code != Code.Ldc_I4 || hinstr.OpCode.Code != Code.Ldc_I4) return false; continue; } } if (!CompareOperand(hinstr.OpCode.OperandType, cinstr.Operand, hinstr.Operand)) return false; } handler.InstructionIndex = hi; composite.InstructionIndex = ci; return true; }
public FindHandlerState(HandlerState compositeState, Dictionary<int, bool> visitedCompositeBlocks, bool done) { this.CompositeState = compositeState; this.VisitedCompositeBlocks = new Dictionary<int, bool>(visitedCompositeBlocks); this.Done = done; }
protected void SetNewState(HandlerState newState) { if (state != newState) { state = newState; RaiseHandlerStateChanged(); } }
/// <summary> /// Constructs and initializes the handler /// </summary> /// <param name = "model"></param> protected AbstractHandler(ComponentModel model) { this.model = model; state = HandlerState.Valid; InitializeCustomDependencies(); }
/// <summary> /// Initializes a new instance of the <see cref="AssociationStateChangedEventArgs"/> class. /// </summary> /// <param name="state">The state of the configurable object state <see cref="HandlerState"/>.</param> public AssociationStateChangedEventArgs(HandlerState state) { State = state; }
private void RaiseHandlerState(HandlerState state) { EventHandler<AssociationStateChangedEventArgs> _hc = StateChangedEventHandler; if (_hc != null) _hc(this, new AssociationStateChangedEventArgs(state)); }
protected void SetNewState(HandlerState newState) { state = newState; }
public void InitState() { _state = new HandlerState { socket = new MessageWebSocket(), subbedChannels = new List<string>() }; _state.socket.Closed += (sender, args) => _state.closed = true; _state.socket.MessageReceived += (sender, args) => { try { JArray messages; using (var reader = args.GetDataReader()) { messages = JArray.Parse(reader.ReadString(reader.UnconsumedBufferLength)); } foreach (var message in messages) { ProcessMessage(message); } } catch { _state.socket.Dispose(); _state.closed = true; OnDisconnect(); } }; }
static bool Compare(ref HandlerState handler, ref HandlerState composite) { var hhashes = handler.BlockSigInfos[handler.BlockIndex].Hashes; int hi = handler.HashIndex; var chashes = composite.BlockSigInfos[composite.BlockIndex].Hashes; int ci = composite.HashIndex; while (true) { if (hi >= hhashes.Count && ci >= chashes.Count) break; if (hi >= hhashes.Count) { if (handler.BlockSigInfos[handler.BlockIndex].EndsInRet) break; } if (hi >= hhashes.Count || ci >= chashes.Count) return false; var hhash = hhashes[hi++]; var chash = chashes[ci++]; if (chash != hhash) return false; } handler.HashIndex = hi; composite.HashIndex = ci; return true; }
/// <summary> /// This method is used to enable a configured <see cref="Association" /> object. If a normal operation is possible, the state changes into <see cref="HandlerState.Operational" /> state. /// In the case of an error situation, the state changes into <see cref="HandlerState.Error" />. The operation is rejected if the current <see cref="State" /> is not <see cref="HandlerState.Disabled" />. /// </summary> /// <exception cref="System.ArgumentException">Wrong state</exception> public void Enable() { if (State != HandlerState.Disabled) throw new ArgumentException("Wrong state"); State = HandlerState.Operational; m_Parent.OnEnable(); }
bool Matches(List<BlockSigInfo> handler, ref FindHandlerState findState) { HandlerState? nextState = null; stack.Clear(); stack.Push(new MatchState(new HandlerState(handler, 0, 0), findState.CompositeState)); while (stack.Count > 0) { var matchState = stack.Pop(); if (matchState.CompositeState.HashIndex == 0) { if (findState.VisitedCompositeBlocks.ContainsKey(matchState.CompositeState.BlockIndex)) continue; findState.VisitedCompositeBlocks[matchState.CompositeState.BlockIndex] = true; } else { if (!findState.VisitedCompositeBlocks.ContainsKey(matchState.CompositeState.BlockIndex)) throw new ApplicationException("Block hasn't been visited"); } if (!Compare(ref matchState.OtherState, ref matchState.CompositeState)) return false; var hblock = matchState.OtherState.BlockSigInfos[matchState.OtherState.BlockIndex]; var hinstrs = hblock.Hashes; int hi = matchState.OtherState.HashIndex; var cblock = matchState.CompositeState.BlockSigInfos[matchState.CompositeState.BlockIndex]; var cinstrs = cblock.Hashes; int ci = matchState.CompositeState.HashIndex; if (hi < hinstrs.Count) return false; if (ci < cinstrs.Count) { if (hblock.Targets.Count != 0) return false; if (hblock.EndsInRet) { if (nextState != null) return false; nextState = matchState.CompositeState; } } else { if (cblock.Targets.Count != hblock.Targets.Count) return false; if (cblock.HasFallThrough != hblock.HasFallThrough) return false; for (int i = 0; i < cblock.Targets.Count; i++) { var hs = new HandlerState(handler, hblock.Targets[i], 0); var cs = new HandlerState(findState.CompositeState.BlockSigInfos, cblock.Targets[i], 0); stack.Push(new MatchState(hs, cs)); } } } if (nextState == null && findState.VisitedCompositeBlocks.Count != findState.CompositeState.BlockSigInfos.Count) nextState = GetNextHandlerState(ref findState); if (nextState == null) { if (findState.VisitedCompositeBlocks.Count != findState.CompositeState.BlockSigInfos.Count) return false; findState.Done = true; return true; } else { if (findState.CompositeState.BlockIndex == nextState.Value.BlockIndex && findState.CompositeState.HashIndex == nextState.Value.HashIndex) return false; findState.CompositeState = nextState.Value; if (findState.CompositeState.HashIndex == 0) findState.VisitedCompositeBlocks.Remove(findState.CompositeState.BlockIndex); return true; } }
private void HotKeyPressed(object sender, HotKeyManager.HotKeyEventArgs e) { bool lockTaken = false; try { m_SpinLock.Enter(ref lockTaken); if (e.Modifiers == 0 && m_CurrentItem != null) { SpinWait.SpinUntil(() => !HotKeyManager.IsKeyPressed(e.Key)); if (m_KeyHook_KEYS.Contains(e.Key)) { long buyPrice = m_CurrentItem.BuyPrice + 1; if (CopperValue >= 0) { buyPrice = (long)((Math.Floor(m_CurrentItem.BuyPrice / 100.0) * 100) + CopperValue); if (buyPrice <= m_CurrentItem.BuyPrice + 1) buyPrice += 100; } long buyPriceC = (buyPrice % 100); long buyPriceS = (long)(Math.Floor(buyPrice / 100.0) % 100); long buyPriceG = (long)(Math.Floor(buyPrice / 10000.0)); switch (m_CurrentState) { case HandlerState.SEARCH: SendKeys.Send(m_CurrentItem.Name); m_CurrentState = HandlerState.ENTERG; break; case HandlerState.ENTERG: SendKeys.Send(buyPriceG.ToString()); m_CurrentState = HandlerState.ENTERS; break; case HandlerState.ENTERS: SendKeys.Send(buyPriceS.ToString()); m_CurrentState = HandlerState.ENTERC; break; case HandlerState.ENTERC: SendKeys.Send(buyPriceC.ToString()); m_CurrentState = HandlerState.NEXT; break; case HandlerState.NEXT: m_CurrentItem = null; m_CurrentState = HandlerState.SEARCH; break; } } else if (m_KeyHook_KEYS_SKIP.Contains(e.Key)) { m_CurrentItem = null; m_CurrentState = HandlerState.SEARCH; } } } finally { if (lockTaken) m_SpinLock.Exit(); } }
/// <summary> /// Connect to device and handle received packets from connected device. /// </summary> private void EstabilishBtConnection() { bool isConnected = false; while (State != HandlerState.Finished) { // Try listen. if (isConnected) { NetworkStream stream = _client.GetStream(); byte[] data = new byte[PacketSize]; // If device is disconnected... infinity loop, i guess. Because value of ReadTimeout is -1. stream.Read(data, 0, PacketSize); stream.Flush(); Action(data); } else // Try connect, if is not connected { isConnected = IsGlove ? ConnectArduino(ref _client, MacAddress) : ConnectAndroid(ref _listener, ref _client); if (isConnected) isConnected = _client != null && _client.Connected; } } if (_client != null) { _client.GetStream().Close(); _client.Dispose(); } if (_listener != null) { _listener.Server.Dispose(); _listener.Stop(); } State = HandlerState.Finished; }
/// <summary> /// Constructs and initializes the handler /// </summary> /// <param name="model"></param> public AbstractHandler(ComponentModel model) { this.model = model; state = HandlerState.Valid; customParameters = new HybridDictionary(true); }
public FindHandlerState(HandlerState compositeState) { this.CompositeState = compositeState; this.VisitedCompositeBlocks = new Dictionary<int, bool>(); this.Done = false; }
/// <summary> /// Continue to get data from external device to queue, but do not processing. /// Action`s data from external device is saved for future processing. /// </summary> public void Pause() { State = HandlerState.Pause; }
/// <summary> /// Get data but do not save actions in queue. Ignore = Save in SingleHandler, not MultiHandler. /// </summary> public void Ignore() { State = HandlerState.Ignoring; }
public MatchState(HandlerState OtherState, HandlerState CompositeState) { this.OtherState = OtherState; this.CompositeState = CompositeState; }
/// <summary> /// This method is used to disable an already enabled <see cref="Association" /> object. /// This method call shall be rejected if the current State is <see cref="HandlerState.Disabled" /> or <see cref="HandlerState.NoConfiguration" />. /// </summary> /// <exception cref="System.ArgumentException">Wrong state</exception> public void Disable() { if (State != HandlerState.Operational) throw new ArgumentException("Wrong state"); State = HandlerState.Disabled; }