Exemplo n.º 1
0
        private void RemoveFromHandler(EventHandler handler, string identity, IEnumerable <string> codes, bool isOut)
        {
            IDatabase         db     = this.redis.Get();
            IList <EventData> events = isOut ? handler.Out : new[] { handler.In };

            foreach (var code in codes)
            {
                var e = events.FirstOrDefault(x => x.EventCode == code);
                if (e != null)
                {
                    events.Remove(e);
                }

                if (isOut)
                {
                    var senders = GetEventSenders(code);
                    var sender  = senders.FirstOrDefault(x => x.ServiceIdentity == identity);
                    if (sender != null)
                    {
                        senders.Remove(sender);
                        db.StringSet(GetEventSendersKey(code), JsonConvert.SerializeObject(senders));
                    }
                }
                else
                {
                    var listeners = GetEventListeners(code);
                    var listener  = listeners.FirstOrDefault(x => x.ServiceIdentity == identity);
                    if (listener != null)
                    {
                        listeners.Remove(listener);
                        db.StringSet(GetEventListenersKey(code), JsonConvert.SerializeObject(listeners));
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void SaveHandler(EventHandler handler, string serviceIdentity)
        {
            IDatabase db       = this.redis.Get();
            var       handlers = GetServiceHandlers(serviceIdentity) ?? new List <EventHandler>();

            var exist = handlers.FirstOrDefault(x => x.Name == handler.Name);

            if (exist == null)
            {
                handlers.Add(new EventHandler()
                {
                    Out  = new List <EventData>(),
                    Name = handler.Name,
                    HandlerStackPlace = handler.HandlerStackPlace,
                    CodeBase          = handler.CodeBase,
                    HandlerClassName  = handler.HandlerClassName,
                    Script            = handler.Script
                });
            }

            db.StringSet(GetHandlersKey(serviceIdentity), JsonConvert.SerializeObject(handlers));
        }
Exemplo n.º 3
0
 private void ClearHandler(EventHandler handler, string identity)
 {
     RemoveFromHandler(handler, identity, handler.Out.Select(x => x.EventCode).ToList(), true);
     RemoveFromHandler(handler, identity, new[] { handler.In.EventCode }, false);
 }