当前位置: 首页>>代码示例>>C#>>正文


C# IEventSource.GetType方法代码示例

本文整理汇总了C#中IEventSource.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IEventSource.GetType方法的具体用法?C# IEventSource.GetType怎么用?C# IEventSource.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEventSource的用法示例。


在下文中一共展示了IEventSource.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NcqrsEventSource

 public NcqrsEventSource(IEventSource source)
     : base("Source_" + source.EventSourceId.ToString(),
         "Source_" + source.EventSourceId.ToString())
 {
     Timestamp = DateTime.UtcNow;
     Version = source.Version;
     Name = source.GetType().ToString();
 }
开发者ID:VincentSchippefilt,项目名称:ncqrs,代码行数:8,代码来源:NcqrsEventSource.cs

示例2: CreateFromEventSource

        public static EventSourceEntity CreateFromEventSource(IEventSource source)
        {
            Contract.Requires<ArgumentNullException>(source != null, "The source cannot be null.");

            return new EventSourceEntity
            {
                RowKey = source.EventSourceId.ToString(),
                PartitionKey = source.GetType().FullName,
                Version = source.Version
            };
        }
开发者ID:SzymonPobiega,项目名称:ncqrs,代码行数:11,代码来源:EventSourceEntity.cs

示例3: GetEventHandlersFromAggregateRoot

        public IEnumerable<ISourcedEventHandler> GetEventHandlersFromAggregateRoot(IEventSource eventSource)
        {
            Contract.Requires<ArgumentNullException>(eventSource != null, "The eventSource cannot be null.");
            Contract.Ensures(Contract.Result<IEnumerable<ISourcedEventHandler>>() != null, "The result should never be null.");

            var targetType = eventSource.GetType();
            var handlers = new List<ISourcedEventHandler>();

            Logger.DebugFormat("Trying to get all event handlers based by convention for {0}.", targetType);

            var methodsToMatch = targetType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            var matchedMethods = from method in methodsToMatch
                                 let parameters = method.GetParameters()
                                 let noEventHandlerAttributes =
                                     method.GetCustomAttributes(typeof(NoEventHandlerAttribute), true)
                                 where
                                     // Get only methods where the name matches.
                                    Regex.IsMatch(method.Name, _regexPattern, RegexOptions.CultureInvariant) &&
                                     // Get only methods that have 1 parameter.
                                    parameters.Length == 1 &&
                                     // Get only methods where the first parameter is an event.
                                    typeof(IEvent).IsAssignableFrom(parameters[0].ParameterType) &&
                                     // Get only methods that are not marked with the no event handler attribute.
                                    noEventHandlerAttributes.Length == 0
                                 select
                                    new { MethodInfo = method, FirstParameter = method.GetParameters()[0] };

            foreach (var method in matchedMethods)
            {
                var methodCopy = method.MethodInfo;
                Type firstParameterType = methodCopy.GetParameters().First().ParameterType;

                Action<IEvent> invokeAction = (e) => methodCopy.Invoke(eventSource, new object[] { e });

                Logger.DebugFormat("Created event handler for method {0} based on convention.", methodCopy.Name);

                var handler = new TypeThresholdedActionBasedDomainEventHandler(invokeAction, firstParameterType, true);
                handlers.Add(handler);
            }

            return handlers;
        }
开发者ID:abombss,项目名称:ncqrs,代码行数:43,代码来源:ConventionBasedSourcedEventHandlerMappingStrategy.cs

示例4: GetEventHandlersFromAggregateRoot

        /// <summary>
        /// Gets the event handlers from aggregate root based on attributes.
        /// </summary>
        /// <param name="eventSource">The aggregate root.</param>
        /// <see cref="AttributeBasedDomainSourcedEventHandlerMappingStrategy"/>
        /// <returns>All the <see cref="IDomainEventHandler"/>'s created based on attribute mapping.</returns>
        public IEnumerable<ISourcedEventHandler> GetEventHandlersFromAggregateRoot(IEventSource eventSource)
        {
            Contract.Requires<ArgumentNullException>(eventSource != null, "The eventSource cannot be null.");

            var targetType = eventSource.GetType();
            var handlers = new List<ISourcedEventHandler>();

            foreach (var method in targetType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static))
            {
                EventHandlerAttribute attribute;

                if (IsMarkedAsEventHandler(method, out attribute))
                {
                    if (method.IsStatic) // Handlers are never static. Since they need to update the internal state of an eventsource.
                    {
                        var message = String.Format("The method {0}.{1} could not be mapped as an event handler, since it is static.", method.DeclaringType.Name, method.Name);
                        throw new InvalidEventHandlerMappingException(message);
                    }
                    if (NumberOfParameters(method) != 1) // The method should only have one parameter.
                    {
                        var message = String.Format("The method {0}.{1} could not be mapped as an event handler, since it has {2} parameters where 1 is required.", method.DeclaringType.Name, method.Name, NumberOfParameters(method));
                        throw new InvalidEventHandlerMappingException(message);
                    }
                    if (!typeof(IEvent).IsAssignableFrom(FirstParameterType(method))) // The parameter should be an IEvent.
                    {
                        var message = String.Format("The method {0}.{1} could not be mapped as an event handler, since it the first parameter is not an event type.", method.DeclaringType.Name, method.Name);
                        throw new InvalidEventHandlerMappingException(message);
                    }

                    var handler = CreateHandlerForMethod(eventSource, method, attribute);
                    handlers.Add(handler);
                }
            }

            return handlers;
        }
开发者ID:SzymonPobiega,项目名称:ncqrs,代码行数:42,代码来源:AttributeBasedDomainSourcedEventHandlerMappingStrategy.cs

示例5: AddEventSource

 /// <summary>
 /// Adds the event source to the event store.
 /// </summary>
 /// <param name="eventSource">The event source to add.</param>
 /// <param name="transaction">The transaction.</param>
 private static void AddEventSource(IEventSource eventSource, SqlTransaction transaction)
 {
     using (var command = new SqlCommand(InsertNewProviderQuery, transaction.Connection))
     {
         command.Transaction = transaction;
         command.Parameters.AddWithValue("Id", eventSource.Id);
         command.Parameters.AddWithValue("Type", eventSource.GetType().ToString());
         command.Parameters.AddWithValue("Version", eventSource.Version);
         command.ExecuteNonQuery();
     }
 }
开发者ID:Andrea,项目名称:ncqrs,代码行数:16,代码来源:SimpleSqlEventStore.cs

示例6: AddEventSource

 private void AddEventSource(IEventSource eventSource, SQLiteTransaction transaction)
 {
     using (var cmd = new SQLiteCommand(Query.InsertNewProviderQuery, transaction.Connection))
     {
         cmd.SetTransaction(transaction)
             .AddParam("Id", eventSource.EventSourceId)
             .AddParam("Type", eventSource.GetType().ToString())
             .AddParam("Version", eventSource.Version);
         cmd.ExecuteNonQuery();
     }
 }
开发者ID:SzymonPobiega,项目名称:ncqrs,代码行数:11,代码来源:SQLiteEventStore.cs


注:本文中的IEventSource.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。