public static ErrorLogEntry OurRaise(this CustomErrorSignal signal, Exception ex)
        {
            if (!(ex is DbEntityValidationException))
            {
                return(signal.Raise(ex));
            }

            var e = ex as DbEntityValidationException;

            var errorStringBilder = new StringBuilder();

            foreach (var entityValidationError in e.EntityValidationErrors)
            {
                errorStringBilder.Append(
                    string.Format("Entity \"{0}\" in state \"{1}\", errors:",
                                  entityValidationError.Entry.Entity.GetType().Name,
                                  entityValidationError.Entry.State));

                foreach (var error in entityValidationError.ValidationErrors)
                {
                    errorStringBilder.Append(
                        string.Format(" (Property: \"{0}\", Error: \"{1}\")",
                                      error.PropertyName, error.ErrorMessage));
                }
            }

            e.Data.Add("EntityValidationErrors", errorStringBilder.ToString());
            return(signal.Raise(ex));
        }
        public void Process <TCommand>(TCommand command) where TCommand : CommandBase
        {
            var subscriber = new DomainEventSubscriberForProcess(command.ProcessId);

            DomainEventPublisher.Instance.Subscribe(subscriber);

            try
            {
                var aggregateService = ServiceLocator.Current.GetInstance <ICommandHandler <TCommand> >();

                if (aggregateService == null)
                {
                    throw new ArgumentException(typeof(TCommand).FullName);
                }

                aggregateService.When(command);
            }
            catch (Exception ex)
            {
                CustomErrorSignal.Handle(ex);
            }
            finally
            {
                DomainEventPublisher.Instance.UnSubscribe(subscriber);
            }

            DomainEvents.AddRange(subscriber.DomainEvents);
        }
Beispiel #3
0
        public StoredEvent Append(IDomainEvent domainEvent)
        {
            var storedEvent = new StoredEvent(
                domainEvent.GetType().FullName + ", " + domainEvent.GetType().Assembly.GetName().Name,
                domainEvent.OccurredOn,
                domainEvent.ToString(),
                domainEvent.EventId,
                StoredEvent.ToStorePayload(domainEvent),
                domainEvent.UserId,
                domainEvent.ProcessId,
                domainEvent.UserId);

            try
            {
                _appendOnlyStore.Append(storedEvent);

                return(storedEvent);
            }
            catch (Exception e)
            {
                CustomErrorSignal.Handle(e);
            }

            return(null);
        }
Beispiel #4
0
        private DuplicateDealMetadata ExtractDuplicateDealMetadata(string line, DealMetadata deal, Dictionary <string, int> columnHeaders)
        {
            try
            {
                var duplicateDeal = new DuplicateDealMetadata();
                var values        = ParsePBNHelpers.ParseTableLine(line, columnHeaders);

                duplicateDeal.NSPairIndex = Int32.Parse(values["PairId_NS"]);
                duplicateDeal.EWPairIndex = Int32.Parse(values["PairId_EW"]);
                duplicateDeal.Contract    = values["Contract"];

                SysPlayer declarer;
                duplicateDeal.Declarer = Enum.TryParse(values["Declarer"], true, out declarer) ? (int)declarer : (int)SysPlayer.N;

                if (duplicateDeal.Contract == "-")
                {
                    return(null);
                }

                var position = PlayerPosition.North;
                switch (duplicateDeal.Declarer)
                {
                case (int)SysPlayer.S:
                    position = PlayerPosition.South;
                    break;

                case (int)SysPlayer.E:
                    position = PlayerPosition.East;
                    break;

                case (int)SysPlayer.W:
                    position = PlayerPosition.West;
                    break;
                }

                var contract = new Contract(duplicateDeal.Contract, position);

                int tricks;
                duplicateDeal.Result = Int32.TryParse(values["Result"], out tricks)
                    ? _scoreCalculator.CalculateScore(contract, tricks, (SysVulnerabilityEnum)deal.SysVulnerabilityId)
                    : _scoreCalculator.CalculateScore(contract, values["Result"], (SysVulnerabilityEnum)deal.SysVulnerabilityId);

                duplicateDeal.NSPercentage    = Int32.Parse(values.ContainsKey("Percentage_NS") ? values["Percentage_NS"] : values["IMP_NS"]);
                duplicateDeal.EWPercentage    = Int32.Parse(values.ContainsKey("Percentage_EW") ? values["Percentage_EW"] : values["IMP_EW"]);
                duplicateDeal.ContractDisplay = contract.Display();
                duplicateDeal.HandViewerInput = deal.HandViewerInput + ParsePBNHelpers.ConvertToPbnBiddingSequence(contract, deal.Dealer);
                duplicateDeal.Tricks          = values["Result"];

                return(duplicateDeal);
            }
            catch (Exception ex)
            {
                CustomErrorSignal.Handle(ex);
                return(null);
            }
        }
        public static void PrepareAttemptedEvent(IDomainEventError errorEvent, Exception ex, CommandBase command)
        {
            errorEvent.EventId    = command.Id;
            errorEvent.ProcessId  = command.ProcessId;
            errorEvent.OccurredOn = DateTime.Now;
            errorEvent.UserId     = command.UserId;
            errorEvent.Errors     = GetErrorFromException(ex);

            var error = CustomErrorSignal.Handle(ex);

            errorEvent.ErrorId = new Guid(error.Id);
        }
Beispiel #6
0
        public IDomainEvent ForResult(double miliseconds = 10000)
        {
            CancellationToken.CancelAfter(TimeSpan.FromMilliseconds(miliseconds));

            try
            {
                For.Wait();
            }
            catch (Exception ex)
            {
                CustomErrorSignal.Handle(ex);
            }

            return(_listenFor);
        }
Beispiel #7
0
        public async Task <IHttpActionResult> Post(int year, int month, int day)
        {
            try
            {
                var command = await _eventProvider.ExtractEventMetadata(new DateTime(year, month, day));

                return(ProcessCommand(command));
            }
            catch (WebException)
            {
                return(InternalServerError(new ApplicationException("The event was not found")));
            }
            catch (Exception ex)
            {
                CustomErrorSignal.Handle(ex);
                return(InternalServerError());
            }
        }
        protected void Apply(Action <TAggregate> action)
        {
            try
            {
                var aggregate = ServiceLocator.Current.GetInstance <TAggregate>();

                action(aggregate);

                if (aggregate.DomainEvents != null && aggregate.DomainEvents.Any())
                {
                    DomainEventPublisher.Instance.PublishAll(aggregate.DomainEvents);
                }
            }
            catch (Exception ex)
            {
                CustomErrorSignal.Handle(ex);
            }
        }
Beispiel #9
0
        public void Publish <T>(T domainEvent) where T : class, IDomainEvent
        {
            try
            {
                if (HasSubscribers())
                {
                    var eventType  = domainEvent.GetType();
                    var enumerator = Subscribers.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        var subscribedToType = enumerator.Current.SubscribedToEventType();
                        if (eventType == subscribedToType || subscribedToType == typeof(IDomainEvent))
                        {
                            enumerator.Current.HandleEvent(domainEvent);
                        }
                    }
                }

                var ds = HasDomainSubscribers(domainEvent);

                if (!ds.Any())
                {
                    return;
                }

                foreach (var service in ds)
                {
                    ((dynamic)service).ApplyEvent(((dynamic)domainEvent));
                }
            }
            catch (Exception ex)
            {
                CustomErrorSignal.Handle(ex);
            }
        }