public void OnEventReceived(IDeviceEvent deviceEvent) { var mouseEvent = (IMouseEvent)deviceEvent; lock (_mouseEvents) { _mouseEvents.AddMouseEvent(mouseEvent); } }
private bool IsAMatch(IDeviceHistory history, IDeviceEvent candidate) { var previousEvent = GetEventBefore(history, candidate); var previousValue = GetMeasurement(previousEvent?.State); var currentValue = GetMeasurement(candidate?.State); if (previousValue == null || currentValue == null) { return(false); } return(IsAMatch(previousValue, currentValue)); }
public void AddEvent(IDeviceEvent @event) { var threadPool = Context.ThreadPool; var message = this.BuildVirtualAddress(false, false) + " " + @event.Type.Name + ". Current State: " + @event.State.Describe(); threadPool.Print(message); Context.History.Add(@event); Context.Triggers.CheckAndAct(); if (Context.WebHookPresent) { var syncScript = Context.SyncWithCloudCommand(Network); threadPool.AddCommands(syncScript); } }
public void AddEvent(IDeviceEvent deviceEvent) { if (!IsRecording) { return; } var currentTime = DateTime.Now; EventsOnTime.Add(new DeviceEventTimer { ExecutingEvent = deviceEvent, TimerSpanBeforeStart = currentTime - TimeMarker }); TimeMarker = currentTime; }
protected static IDeviceEvent GetEventBefore(IDeviceHistory history, IDeviceEvent target) { IDeviceEvent lastMatch = null; foreach (var @event in history) { if (@event == target) { return(lastMatch); } if (@event.Device == target.Device && @event.Type.Matches(target.Type)) { lastMatch = @event; } } return(null); }
protected void PowerChanged() { //TODO: improve this logic //TODO: read from event history in making powered on/off decision IDeviceEvent @event = null; IEventSource source = null; //TODO: fill this in if (IsConnected == true) { if (Type.Equals(DeviceType.BinarySensor)) { @event = DeviceEvent.BinarySensorValueChanged(this, source); } else if (Type.Equals(DeviceType.BinarySwitch)) { switch (BinarySwitch.Power) { case BinarySwitchPower.On: @event = DeviceEvent.PoweredOn(this, source); break; case BinarySwitchPower.Off: @event = DeviceEvent.PoweredOff(this, source); break; } } } else { @event = DeviceEvent.Lost(this, source); } if (@event == null) { @event = DeviceEvent.PowerChanged(this, source); } AddEvent(@event); }
public void RegisterEvent(IDeviceEvent deviceEventHappened) { EventHappened?.Invoke(deviceEventHappened); }