示例#1
0
        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));
        }
示例#3
0
        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);
        }
示例#6
0
        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);
 }
示例#8
0
文件: Device.cs 项目: Mavtak/roomie
        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);
            }
        }