Exemple #1
0
 private void EventServiceOnItemChannelLinkRemoved(object sender, ItemChannelLinkRemovedEvent eventObject)
 {
     if (Channels?.FirstOrDefault(c => c.Uid == eventObject.ChannelUid) != null)
     {
         ItemChannelLinkRemoved?.Invoke(this, eventObject);
     }
 }
Exemple #2
0
        private void RaiseEvent(string data)
        {
            var typeTemplate = new Regex(@",""type"":""(.*?)""}");

            var json = Json.Fix(data);
            var type = typeTemplate.Match(data).Groups[1].Value;

            //Debug.WriteLine($"{type} occured.");

            switch (type) //TODO this is not a complete list of events
            {
                #region Items

            case "ItemStateEvent":
                var itemStateEvent = AssembleEvent <ItemStateEvent>(json);
                ItemStateEventOccured?.Invoke(OpenHab.RestClient, itemStateEvent);
                break;

            case "ItemStateChangedEvent":
                var itemStateChangedEvent = AssembleEvent <ItemStateChangedEvent>(json);
                ItemStateChanged?.Invoke(OpenHab.RestClient, itemStateChangedEvent);
                break;

            case "ItemCommandEvent":
                var itemCommandEvent = AssembleEvent <ItemCommandEvent>(json);
                ItemCommandEventOccured?.Invoke(OpenHab.RestClient, itemCommandEvent);
                break;

            case "ItemAddedEvent":
                var itemAddedEvent = AssembleEvent <ItemAddedEvent>(json);
                ItemAdded?.Invoke(OpenHab.RestClient, itemAddedEvent);
                break;

            case "ItemRemovedEvent":
                var itemRemovedEvent = AssembleEvent <ItemRemovedEvent>(json);
                ItemRemoved?.Invoke(OpenHab.RestClient, itemRemovedEvent);
                break;

            case "ItemUpdatedEvent":
                var itemUpdatedEvent = AssembleEvent <ItemUpdatedEvent>(json);
                ItemUpdated?.Invoke(OpenHab.RestClient, itemUpdatedEvent);
                break;

                #endregion

                #region Things

            case "ThingStatusInfoEvent":
                var thingStatusInfoEvent = AssembleEvent <ThingStatusInfoEvent>(json);
                ThingStatusInfoEventOccured?.Invoke(OpenHab.RestClient, thingStatusInfoEvent);
                break;

            case "ThingStatusInfoChangedEvent":
                var thingStatusInfoChangedEvent = AssembleEvent <ThingStatusInfoChangedEvent>(json);
                ThingStatusInfoChanged?.Invoke(OpenHab.RestClient, thingStatusInfoChangedEvent);
                break;

            case "ThingAddedEvent":
                var thingAddedEvent = AssembleEvent <ThingAddedEvent>(json);
                ThingAdded?.Invoke(OpenHab.RestClient, thingAddedEvent);
                break;

            case "ThingUpdatedEvent":
                var thingUpdatedEvent = AssembleEvent <ThingUpdatedEvent>(json);
                ThingUpdated?.Invoke(OpenHab.RestClient, thingUpdatedEvent);
                break;

            case "ThingRemovedEvent":
                var thingRemovedEvent = AssembleEvent <ThingRemovedEvent>(json);
                ThingRemoved?.Invoke(OpenHab.RestClient, thingRemovedEvent);
                break;

            case "ItemChannelLinkAddedEvent":
                var itemChannelLinkAddedEvent = AssembleEvent <ItemChannelLinkAddedEvent>(json);
                ItemChannelLinkAdded?.Invoke(OpenHab.RestClient, itemChannelLinkAddedEvent);
                break;

            case "ItemChannelLinkRemovedEvent":
                var itemChannelLinkRemovedEvent = AssembleEvent <ItemChannelLinkRemovedEvent>(json);
                ItemChannelLinkRemoved?.Invoke(OpenHab.RestClient, itemChannelLinkRemovedEvent);
                break;

                #endregion

                #region Inbox

            case "InboxAddedEvent":
                var inboxAddedEvent = AssembleEvent <InboxAddedEvent>(json);
                InboxAdded?.Invoke(OpenHab.RestClient, inboxAddedEvent);
                break;

            case "InboxRemovedEvent":
                var inboxRemovedEvent = AssembleEvent <InboxRemovedEvent>(json);
                InboxRemoved?.Invoke(OpenHab.RestClient, inboxRemovedEvent);
                break;

                #endregion

                #region Rules

            case "RuleStatusInfoEvent":
                var ruleStatusInfo = AssembleEvent <RuleStatusInfoEvent>(json);
                RuleStatusInfoEventOccured?.Invoke(OpenHab.RestClient, ruleStatusInfo);
                break;

            case "RuleAddedEvent":
                var ruleAddedEvent = AssembleEvent <RuleAddedEvent>(json);
                RuleAdded?.Invoke(OpenHab.RestClient, ruleAddedEvent);
                break;

            case "RuleUpdatedEvent":
                var ruleUpdatedEvent = AssembleEvent <RuleUpdatedEvent>(json);
                RuleUpdated?.Invoke(OpenHab.RestClient, ruleUpdatedEvent);
                break;

            case "RuleRemovedEvent":
                var ruleRemovedEvent = AssembleEvent <RuleRemovedEvent>(json);
                RuleRemoved?.Invoke(OpenHab.RestClient, ruleRemovedEvent);
                break;

                #endregion

                #region Miscellaneous

            case "ConfigStatusInfoEvent":
                var configStatusInfoEvent = AssembleEvent <ConfigStatusInfoEvent>(json);
                ConfigStatusInfoEventOccured?.Invoke(OpenHab.RestClient, configStatusInfoEvent);
                break;

            case "PlayURLEvent":
                var playUrlEvent = AssembleEvent <PlayUrlEvent>(json);
                PlayUrlEventOccured?.Invoke(OpenHab.RestClient, playUrlEvent);
                break;

            default:
                var unknownEvent = AssembleEvent <UnknownEvent>(json);
                UnknownEventOccured?.Invoke(OpenHab.RestClient, unknownEvent);
                break;

                #endregion
            }
        }