Exemple #1
0
        public Events(
            TType declaringType,
            IEventFactory <TEvent, TEventProperty, TType> eventFactory)
        {
            List <TEvent> events = new List <TEvent>();
            List <ExplicitInterfaceEventWithMonoCecil> explicitInterfaceEvents = new List <ExplicitInterfaceEventWithMonoCecil>();
            List <TEventProperty>             eventProperties = new List <TEventProperty>();
            List <AbstractEventWithMonoCecil> abstractEvents  = new List <AbstractEventWithMonoCecil>();

            foreach (EventDefinition eventDefinition in declaringType.TypeDefinition.Events)
            {
                if (eventDefinition.AddMethod.IsDefined(declaringType.Assembly, typeof(CompilerGeneratedAttribute)))
                {
                    events.Add(eventFactory.CreateEvent(declaringType, eventDefinition));
                }
                else if (eventDefinition.Name.Contains("."))
                {
                    explicitInterfaceEvents.Add(new ExplicitInterfaceEventWithMonoCecil(declaringType, eventDefinition));
                }
                else if (eventDefinition.AddMethod.IsAbstract)
                {
                    abstractEvents.Add(new AbstractEventWithMonoCecil(declaringType, eventDefinition));
                }
                else
                {
                    eventProperties.Add(eventFactory.CreateEventProperty(declaringType, eventDefinition));
                }
            }

            EventsWithMonoCecil                 = events;
            EventPropertiesWithMonoCecil        = eventProperties;
            ExplictInterfaceEventsWithMonoCecil = explicitInterfaceEvents;
            AbstractEventsWithMonoCecil         = abstractEvents;
        }
Exemple #2
0
        public static IEvent ConvertToDomain(this EventDto dto, IEventFactory eventFactory)

        {
            var @event = eventFactory.CreateEvent(dto.Name, dto.Description, dto.StartDate);

            return(@event);
        }
Exemple #3
0
        public Event Dispatch(string type)
        {
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(type));

            var evt = events.CreateEvent(type);

            if (evt == null)
            {
                throw new DOMException();
            }

            // dispatch event internally
            Dispatch(evt);

            return(evt);
        }
        public IEvent AssembleEvent(string eventName, string eventDescription, DateTime startDate, IEnumerable <string> sentInvitations)
        {
            List <IParticipant> participants = new List <IParticipant>();
            List <IInvitation>  invitations  = convertToInvitationList(sentInvitations);
            IEvent @event = _eventFactory.CreateEvent(Guid.NewGuid(), eventName, eventDescription, startDate, invitations, participants);

            throw new NotImplementedException();
        }
Exemple #5
0
        public IEvent DTOToEvent(EventDTO eventDTO)
        {
            List <IParticipant> participants = new List <IParticipant>();
            List <IInvitation>  invitations  = _invitationFactory.CreateInvitationEnumerable(eventDTO.SentInvitations);
            IEvent @event = _eventFactory.CreateEvent(Guid.NewGuid(), eventDTO.Name, eventDTO.Description, eventDTO.StartDate, invitations, participants);

            return(@event);
        }
        public IEvent Execute(IEvent @event)
        {
            //Göra Repository pattern???
            var myEvent = dbContext.Add(_eventFactory.CreateEvent(@event.Name, @event.Description, @event.StartDate));

            dbContext.SaveChanges();

            return(myEvent.Entity);
        }
Exemple #7
0
        public void Post(string eventName,
                         object context = null)
        {
            var @event = _eventFactory.CreateEvent(eventName, context);

            lock (_lockObject)
            {
                _eventQueue.Enqueue(@event);
            }
        }
        public void CreateEventShould()
        {
            List <IInvitation>  invitations  = SetUpInvitations();
            List <IParticipant> participants = SetUpParticipants();

            Guid   testGuid = Guid.NewGuid();
            IEvent @event   = _eventFactory.CreateEvent(testGuid, "Fredriks födelsedagskalas", "Ett vanligt födelsedagskalas", DateTime.Now, invitations, participants);

            Assert.NotEqual(@event.Participants[0].Id, @event.Participants[1].Id);
            Assert.Equal(@event.Participants[0].Id, @event.Participants[2].Id);
            Assert.Equal(testGuid, @event.Id);
            Assert.Equal("Fredriks födelsedagskalas", @event.Name);
            Assert.Equal("*****@*****.**", @event.SentInvitations[0].Email);
        }
Exemple #9
0
        private void MessageReceived(object sender, BasicDeliverEventArgs e)
        {
            string body = null;

            if (e.Body.Length > 0)
            {
                body = Encoding.UTF8.GetString(e.Body.ToArray());
            }

            try
            {
                var exchange = e.Exchange;

                IEvent ev = _eventFactory.CreateEvent(exchange);

                ev.Payload    = body;
                ev.RoutingKey = e.RoutingKey;
                ev.Context.Add("deliveryTag", e.DeliveryTag);
                ev.Context.Add("exchange", exchange);
                ev.EndpointId = e.BasicProperties.AppId;

                _jobDispatcher
                .DispatchAsync(ev, exchange, this)
                .ConfigureAwait(true)
                .GetAwaiter()
                .GetResult();
            }
            catch (EventNotSupportedException ex)
            {
                _logger?.LogError(ex, ex.Message);

                _readChannel.BasicNack(e.DeliveryTag, false, false);
            }
            catch (CouldNotFindAnyHandlerException ex)
            {
                _logger?.LogError(ex, ex.Message);

                _readChannel.BasicNack(e.DeliveryTag, false, false);
            }
            catch (System.Exception ex)
            {
                _logger?.LogError(ex, ex.Message);

                _readChannel.BasicNack(e.DeliveryTag, false, true);
            }
        }
Exemple #10
0
        public Events(
            TType declaringType,
            IEventFactory <TEvent, TEventProperty, TType> eventFactory,
            IDictionary <MethodInfo, Type> interfaceMethods)
        {
            List <TEvent> events = new List <TEvent>();
            List <ExplicitInterfaceEventWithReflection> explicitInterfaceEvents = new List <ExplicitInterfaceEventWithReflection>();
            List <TEventProperty> eventProperties             = new List <TEventProperty>();
            List <AbstractEventWithReflection> abstractEvents = new List <AbstractEventWithReflection>();

            foreach (EventInfo eventInfo in declaringType.Type.GetAllEvents())
            {
                Type interfaceType;
                if (eventInfo.AddMethod.IsDefined(typeof(CompilerGeneratedAttribute), false))
                {
                    events.Add(eventFactory.CreateEvent(declaringType, eventInfo));
                }
                else if (interfaceMethods.TryGetValue(eventInfo.AddMethod, out interfaceType))
                {
                    explicitInterfaceEvents.Add(new ExplicitInterfaceEventWithReflection(declaringType, interfaceType, eventInfo));
                }
                else if (eventInfo.AddMethod.IsAbstract)
                {
                    abstractEvents.Add(new AbstractEventWithReflection(declaringType, eventInfo));
                }
                else
                {
                    eventProperties.Add(eventFactory.CreateEventProperty(declaringType, eventInfo));
                }
            }

            EventsWithReflection                 = events;
            EventPropertiesWithReflection        = eventProperties;
            ExplictInterfaceEventsWithReflection = explicitInterfaceEvents;
            AbstractEventsWithReflection         = abstractEvents;
        }
Exemple #11
0
 public T CreateEvent <T>(string type)
     where T : Event
 {
     return(factory.CreateEvent <T>(type));
 }