예제 #1
0
        private void UpdateEntity(IHandlerRegistration entity)
        {
            using (var ctx = new HappyDogShowContext())
            {
                HandlerRegistration foundEntity = ctx.HandlerRegistrations.Where(d => d.ID == entity.Id).First();

                if (foundEntity != null)
                {
                    Sex entitySex = ctx.Sexes.Where(g => g.ID == entity.SexId).First();

                    foundEntity.Sex         = entitySex;
                    foundEntity.DateOfBirth = entity.DateOfBirth;
                    foundEntity.Surname     = entity.Surname;
                    foundEntity.Title       = entity.Title;
                    foundEntity.FirstName   = entity.FirstName;
                    foundEntity.Address     = entity.Address;
                    foundEntity.PostalCode  = entity.PostalCode;
                    foundEntity.Tel         = entity.Tel;
                    foundEntity.Cell        = entity.Cell;
                    foundEntity.Fax         = entity.Fax;
                    foundEntity.Email       = entity.Email;

                    ctx.SaveChanges();
                }
            }
        }
예제 #2
0
        private int CreateEntity(IHandlerRegistration entity)
        {
            int newid = -1;

            using (var ctx = new HappyDogShowContext())
            {
                Sex entitySex = ctx.Sexes.Where(g => g.ID == entity.SexId).First();

                HandlerRegistration newEntity = new HandlerRegistration()
                {
                    Sex         = entitySex,
                    DateOfBirth = entity.DateOfBirth,
                    Surname     = entity.Surname,
                    Title       = entity.Title,
                    FirstName   = entity.FirstName,
                    Address     = entity.Address,
                    PostalCode  = entity.PostalCode,
                    Tel         = entity.Tel,
                    Cell        = entity.Cell,
                    Fax         = entity.Fax,
                    Email       = entity.Email
                };

                ctx.HandlerRegistrations.Add(newEntity);
                ctx.SaveChanges();

                newid = newEntity.ID;
            }

            return(newid);
        }
예제 #3
0
        private IHandlerRegistration GetItem <T>(int id) where T : IHandlerRegistration, new()
        {
            IHandlerRegistration item = null;

            using (var ctx = new HappyDogShowContext())
            {
                var foundHandler = ctx.HandlerRegistrations.Where(d => d.ID == id).Include(b => b.Sex).First();

                if (foundHandler != null)
                {
                    item = new T()
                    {
                        Id          = foundHandler.ID,
                        SexId       = foundHandler.Sex.ID,
                        SexName     = foundHandler.Sex.Name,
                        DateOfBirth = foundHandler.DateOfBirth,
                        Surname     = foundHandler.Surname,
                        Title       = foundHandler.Title,
                        FirstName   = foundHandler.FirstName,
                        Address     = foundHandler.Address,
                        PostalCode  = foundHandler.PostalCode,
                        Tel         = foundHandler.Tel,
                        Cell        = foundHandler.Cell,
                        Fax         = foundHandler.Fax,
                        Email       = foundHandler.Email
                    }
                }
                ;
            }

            return(item);
        }
    }
        /// <summary>
        /// Add an asynchronous handler
        /// </summary>
        /// <typeparam name="T">The message type</typeparam>
        /// <param name="handlerRegistration">The handler registration</param>
        /// <param name="handler">The handler</param>
        /// <returns></returns>
        public static IHandlerRegistration Add <T>(
            this IHandlerRegistration handlerRegistration, Func <IMessage <T>, MessageReceivedInfo, Task> handler
            )
        {
            Preconditions.CheckNotNull(handlerRegistration, "handlerRegistration");

            return(handlerRegistration.Add <T>((m, i, c) => handler(m, i)));
        }
예제 #5
0
        public Task UpdateEntityAsync(IHandlerRegistration entity)
        {
            Task t = Task <int> .Run(() =>
            {
                UpdateEntity(entity);
            });

            return(t);
        }
        /// <summary>
        /// Add an asynchronous handler
        /// </summary>
        /// <typeparam name="T">The message type</typeparam>
        /// <param name="handlerRegistration">The handler registration</param>
        /// <param name="handler">The handler</param>
        /// <returns></returns>
        public static IHandlerRegistration Add <T>(
            this IHandlerRegistration handlerRegistration, Action <IMessage <T>, MessageReceivedInfo> handler
            )
        {
            Preconditions.CheckNotNull(handlerRegistration, "handlerRegistration");

            var asyncHandler = TaskHelpers.FromAction <IMessage <T>, MessageReceivedInfo>((m, i, c) => handler(m, i));

            return(handlerRegistration.Add(asyncHandler));
        }
예제 #7
0
        public Task <int> CreateEntityAsync(IHandlerRegistration entity)
        {
            Task <int> t = Task <int> .Run(() =>
            {
                int newid = CreateEntity(entity);
                return(newid);
            });

            return(t);
        }
예제 #8
0
        public Task <IHandlerRegistration> GetHandlerRegistrationAsync <T>(int id) where T : IHandlerRegistration, new()
        {
            Task <IHandlerRegistration> t = Task <IHandlerRegistration> .Run(() =>
            {
                IHandlerRegistration item = GetItem <T>(id);
                return(item);
            });

            return(t);
        }
        /// <summary>
        /// Add an asynchronous handler
        /// </summary>
        /// <typeparam name="T">The message type</typeparam>
        /// <param name="handlerRegistration">The handler registration</param>
        /// <param name="handler">The handler</param>
        /// <returns></returns>
        public static IHandlerRegistration Add <T>(
            this IHandlerRegistration handlerRegistration,
            Func <IMessage <T>, MessageReceivedInfo, CancellationToken, Task> handler
            )
        {
            Preconditions.CheckNotNull(handlerRegistration, "handlerRegistration");

            return(handlerRegistration.Add <T>(async(m, i, c) =>
            {
                await handler(m, i, c).ConfigureAwait(false);
                return AckStrategies.Ack;
            }));
        }
예제 #10
0
        private IHandlerRegistration AddHandlers(IHandlerRegistration handlerReg, IQueue queue)
        {
            //This is gonna be a bit NASTY
            //For this queue we need to find all the types we're currently holding handlers for
            //then add the internal onMessageReceived handler for each type
            //The reason for all this is calling consume on a queue with existing handlers for types
            //wipes them out and we have to add all type handlers again - so each time a type is added to be subscribed to
            //the whole previous set need to be re-added

            foreach (Type requestType in EntityTypes.EntityRequestAndResponseTypes)
            {
                foreach (Type entityType in EntityTypes.EntityBaseTypes)
                {
                    var requestWithEntityType   = requestType.MakeGenericType(entityType);
                    var queueMessageHandlerType = typeof(QueueMessageHandler <>).MakeGenericType(requestWithEntityType);
                    var queueMessageHandlerList = GenericHelpers.InvokeGenericMethod(_handlerManager, requestWithEntityType, typeof(IList), "GetHandlersForType", queue.Name);
                    var list = queueMessageHandlerList as IList;

                    if (list != null && list.Count > 0)
                    {
                        var messageType    = typeof(IMessage <>).MakeGenericType(requestWithEntityType);
                        var addParamType   = typeof(Action <,>).MakeGenericType(messageType, typeof(MessageReceivedInfo));
                        var addMethod      = GenericHelpers.GetMethodExt(handlerReg.GetType(), "Add", handlerReg.GetType(), addParamType);
                        var addMethodTyped = addMethod.MakeGenericMethod(requestWithEntityType);

                        var onMessageMethod      = GenericHelpers.GetMethodExt(this.GetType(), "OnMessageReceived", typeof(void), new Type[] { messageType, typeof(MessageReceivedInfo) });
                        var onMessageMethodTyped = onMessageMethod.MakeGenericMethod(requestWithEntityType);

                        var action = Delegate.CreateDelegate(addParamType, this, onMessageMethodTyped);

                        handlerReg = (IHandlerRegistration)addMethodTyped.Invoke(handlerReg, new object[] { action });
                    }
                }
            }

            return(handlerReg);
        }
예제 #11
0
 public HandlerAdder(IHandlerRegistration handlerRegistration)
 {
     this.handlerRegistration = handlerRegistration;
 }
 /// <summary>
 /// This method must be provided by classes derived from <see cref="RabbitMqConsumer{T}"/>, in order to provide
 /// a message handler per expected message type.
 /// </summary>
 /// <param name="handlers"></param>
 /// <remarks>
 /// When the <see cref="UntypedMessageSerializationStrategy"/> is used, then it only makes sense to provide a
 /// handler for the <see cref="string"/> type.
 /// </remarks>
 protected abstract void RegisterMessageHandlers(IHandlerRegistration handlers);
예제 #13
0
 public Wiring(IHandlerRegistration handlerRegister)
 {
     this.handlerRegister = handlerRegister;
 }
 internal HandlerRegistrar(IHandlerRegistration handlers, IIncomingMessageInterceptor incomingMessageInterceptor)
 {
     _handlers = handlers;
     _incomingMessageInterceptor = incomingMessageInterceptor;
 }