Ejemplo n.º 1
0
 public static void NotOutOfLength(string arg, int maxLength, string argName)
 {
     if (arg.Trim().Length > maxLength)
     {
         throw ErrorHelper.Argument(argName, "Argument '{0}' cannot be more than {1} characters long.", argName, maxLength);
     }
 }
Ejemplo n.º 2
0
 public static void NotEmpty <T>(ICollection <T> arg, string argName)
 {
     if (arg == null || !arg.Any())
     {
         throw ErrorHelper.Argument(argName, "Collection cannot be null and must have at least one item.");
     }
 }
Ejemplo n.º 3
0
 public static void NotEmpty(Guid arg, string argName)
 {
     if (arg == Guid.Empty)
     {
         throw ErrorHelper.Argument(argName, "Argument '{0}' cannot be an empty guid.", argName);
     }
 }
Ejemplo n.º 4
0
 public static void NotEmpty(string arg, string argName)
 {
     if (arg.IsEmpty())
     {
         throw ErrorHelper.Argument(argName, "String parameter '{0}' cannot be null or all whitespace.", argName);
     }
 }
Ejemplo n.º 5
0
 public static void IsTrue(bool arg, string argName, string message = IsTrueMessage)
 {
     if (!arg)
     {
         throw ErrorHelper.Argument(argName, message.FormatInvariant(argName));
     }
 }
Ejemplo n.º 6
0
        public void Save(T eventSourced)
        {
            var correlationId = eventSourced.CorrelationId;

            if (correlationId == Guid.Empty)
            {
                throw ErrorHelper.Argument("eventSourced", "CorrelationId不能为空的Guid");
            }

            if (snapshotPlicy.ShouldCreateSnapshot(eventSourced))
            {
                this.snapshotRepo.SaveSnapshot(eventSourced);
            }

            // TODO: guarantee that only incremental versions of the event are stored
            var events = eventSourced.PendingEvents.ToList();

            events.ForEach(p => p.CorrelationId = correlationId);
            domainEventRepo.SaveEvents(events);

            var topic          = eventSourced.Topic;
            var envelopeEvents = events.Select(e => new Envelope <IEvent>(e)
            {
                CorrelationId = e.CorrelationId,
                Topic         = topic
            });

            // TODO: guarantee delivery or roll back, or have a way to resume after a system crash
            this.eventBus.Publish(envelopeEvents.ToList());
        }
        public IEnumerable <IDomainEvent> LoadEvents(Guid id)
        {
            List <EventDescriptor> eventDescriptors;

            if (!current.TryGetValue(id, out eventDescriptors))
            {
                throw ErrorHelper.Argument("id", "Aggregate Not Found");
            }

            return(eventDescriptors.Select(desc => desc.EventData).ToList());
        }
Ejemplo n.º 8
0
        public NullableConverter(Type type)
            : base(type)
        {
            NullableType   = type;
            UnderlyingType = Nullable.GetUnderlyingType(type);

            if (UnderlyingType == null)
            {
                throw ErrorHelper.Argument("type", "Type is not a nullable type.");
            }

            _underlyingTypeIsConvertible = typeof(IConvertible).IsAssignableFrom(UnderlyingType) && !UnderlyingType.GetTypeInfo().IsEnum;
            UnderlyingTypeConverter      = TypeConverterFactory.GetConverter(UnderlyingType);
        }