static Func <TMessage, Guid> GetCorrelationIdSelector(IEventBinder <TSaga> binder) { Func <TMessage, Guid> correlationIdSelector = binder.GetCorrelationIdSelector <TMessage>(); if (correlationIdSelector != null) { return(correlationIdSelector); } var visitor = new CorrelationExpressionToSagaIdVisitor <TSaga, TMessage>(); Expression <Func <TMessage, Guid> > exp = visitor.Build(binder.GetBindExpression <TMessage>()); if (exp != null) { return(exp.Compile()); } if (typeof(TMessage).Implements <ICorrelatedBy <Guid> >()) { Type genericType = typeof(Correlated <>).MakeGenericType(typeof(TSaga), typeof(TMessage), typeof(TMessage)); var correlated = (ICorrelated <TMessage>)Activator.CreateInstance(genericType); return(correlated.CorrelationIdSelector); } return(x => NewIds.NewId.NextGuid()); }
private static void EmitEvent(string eventName, IEventBinder binder, string jsonMessage, Dictionary <string, object> message) { if (binder.HasListeners) { if (binder is PusherEventEmitter pusherEventEmitter) { PusherEvent pusherEvent = new PusherEvent(message, jsonMessage); if (pusherEvent != null) { pusherEventEmitter.EmitEvent(eventName, pusherEvent); } } else if (binder is TextEventEmitter textEventEmitter) { string textEvent = jsonMessage; if (textEvent != null) { textEventEmitter.EmitEvent(eventName, textEvent); } } else if (binder is DynamicEventEmitter dynamicEventEmitter) { var template = new { @event = string.Empty, data = string.Empty, channel = string.Empty, user_id = string.Empty }; dynamic dynamicEvent = JsonConvert.DeserializeAnonymousType(jsonMessage, template); if (dynamicEvent != null) { dynamicEventEmitter.EmitEvent(eventName, dynamicEvent); } } } }
private void EmitEvent(string eventName, string jsonMessage, Dictionary <string, object> message) { foreach (string key in EventEmitter.EmitterKeys) { IEventBinder binder = _pusher.GetEventBinder(key); EmitEvent(eventName, binder, jsonMessage, message); } }
IEventBinder IPusher.GetChannelEventBinder(string eventBinderKey, string channelName) { IEventBinder result = null; if (Channels.TryGetValue(channelName, out Channel channel)) { result = channel.GetEventBinder(eventBinderKey); } return(result); }
public static bool TryGetEventBinder(Event targetEvent, out IEventBinder <T> expression) { if (_binders.Has(targetEvent)) { expression = _binders[targetEvent]; return(true); } expression = null; return(false); }
public PropertySagaSubscriptionConnector(ISagaRepository <TSaga> sagaRepository, DataEvent <TSaga, TMessage> dataEvent, IEnumerable <State> states, ISagaPolicyFactory policyFactory, Expression <Func <TSaga, bool> > removeExpression, IEventBinder <TSaga> eventBinder) { _sagaRepository = sagaRepository; _dataEvent = dataEvent; _bindExpression = eventBinder.GetBindExpression <TMessage>(); Func <TMessage, Guid> correlationIdSelector = GetCorrelationIdSelector(eventBinder); _policy = policyFactory.GetPolicy(states, correlationIdSelector, removeExpression); }
/// <summary> /// 加载菜单 /// </summary> protected virtual void LoadMenu() { IEventBinder binder = Lemon.GetInstance <EventBinderToModule>(typeof(EventBinderToModule), new object[] { this }); IMenuItemFactory itemfac = this.Envir.BllConfig.GetConfig <ILemonEnvironment>().MenuItemFactory; itemfac.Eventbinder = binder; itemfac.Mainform = this; //itemfac.Regidit(this); MenuFactory menuFac = new MenuFactory(this, itemfac); menuFac.SetMenuStrip(); Thread newThrd = null; ThreadStart thrdStart = delegate { AddMenuControl(menuFac); }; newThrd = new Thread(thrdStart); newThrd.IsBackground = true; newThrd.Start(); }
/// <summary> /// 从xml创建菜单 /// </summary> public MenuItemsForXml(IEventBinder Binder, IMainForm RunMainForm) { //this.xmlfilepath = XmlFilePath; this.Mainform = RunMainForm; this.Eventbinder = Binder; }
public static IEventBinder <TSaga, TMessage> UseNewId <TSaga, TMessage>(this IEventBinder <TSaga, TMessage> binder) { return(binder.UseId(x => NewIds.NewId.NextGuid())); }