public void On(RuleUpdated @event, EnvelopeHeaders headers) { UpdateRule(@event, headers, r => { r.RuleDef = r.RuleDef.Apply(@event); }); }
protected void On(RuleUpdated @event) { if (@event.Trigger != null) { RuleDef = RuleDef.Update(@event.Trigger); } if (@event.Action != null) { RuleDef = RuleDef.Update(@event.Action); } }
public static void Apply(this Rule rule, RuleUpdated @event) { if (@event.Trigger != null) { rule.Update(@event.Trigger); } if (@event.Action != null) { rule.Update(@event.Action); } }
protected async Task On(RuleUpdated @event, EnvelopeHeaders headers) { await EnsureRulesLoadedAsync(); await Collection.UpdateAsync(@event, headers, w => { w.Rule.Apply(@event); inMemoryRules.GetOrAddNew(w.AppId).RemoveAll(x => x.Id == w.Id); inMemoryRules.GetOrAddNew(w.AppId).Add(w); }); }
public static Rule Apply(this Rule rule, RuleUpdated @event) { if (@event.Trigger != null) { return(rule.Update(@event.Trigger)); } if (@event.Action != null) { return(rule.Update(@event.Action)); } return(rule); }
public void Handle(RuleUpdated @event) { using (var context = _contextFactory.Invoke()) { var rule = context.Find <RuleDetail>(@event.RuleId); rule.Name = @event.Name; rule.Message = @event.Message; rule.ZoneRequired = @event.ZoneRequired; rule.ExcludeCircularZone = @event.ExcludeCircularZone; rule.ExcludedCircularZoneLatitude = @event.ExcludedCircularZoneLatitude; rule.ExcludedCircularZoneLongitude = @event.ExcludedCircularZoneLongitude; rule.ExcludedCircularZoneRadius = @event.ExcludedCircularZoneRadius; rule.ZoneList = @event.ZoneList; rule.DaysOfTheWeek = (int)@event.DaysOfTheWeek; rule.StartTime = @event.StartTime.HasValue ? @event.StartTime < (DateTime)SqlDateTime.MinValue ? (DateTime)SqlDateTime.MinValue : @event.StartTime : null; rule.EndTime = @event.EndTime.HasValue ? @event.EndTime < (DateTime)SqlDateTime.MinValue ? (DateTime)SqlDateTime.MinValue : @event.EndTime : null; rule.ActiveFrom = @event.ActiveFrom.HasValue ? @event.ActiveFrom < (DateTime)SqlDateTime.MinValue ? (DateTime)SqlDateTime.MinValue : @event.ActiveFrom : null; rule.ActiveTo = @event.ActiveTo.HasValue ? @event.ActiveTo < (DateTime)SqlDateTime.MinValue ? (DateTime)SqlDateTime.MinValue : @event.ActiveTo : null; rule.Priority = @event.Priority; rule.AppliesToCurrentBooking = @event.AppliesToCurrentBooking; rule.AppliesToFutureBooking = @event.AppliesToFutureBooking; rule.AppliesToPickup = @event.AppliesToPickup; rule.AppliesToDropoff = @event.AppliesToDropoff; rule.IsActive = @event.IsActive; rule.Market = @event.Market; rule.DisableFutureBookingOnError = @event.DisableFutureBookingOnError; context.SaveChanges(); } }
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 } }
protected void On(RuleUpdated @event) { RuleDef = RuleDef.Update(@event.Trigger).Update(@event.Action); }
protected void On(RuleUpdated @event) { rule = rule.Apply(@event); }