Ejemplo n.º 1
0
 public void AddEventsToStream(int aggreggateId, IList <IEvent> events)
 {
     foreach (var @event in events)
     {
         EventData eventData = new EventData(Guid.NewGuid(), @event.GetType().FullName, true, Utf8Json.JsonSerializer.Serialize(@event), null);
         _connection.AppendToStreamAsync($"myaggregate-[{aggreggateId}]", ExpectedVersion.Any, eventData).GetAwaiter().GetResult();
     }
     _eventsDispatcher.Dispatch(events);
 }
Ejemplo n.º 2
0
        protected RavenModule(ISessionProvider sessionProvider, IDispatchEvents eventDispatcher, string modulePath)
            : base(modulePath)
        {
            _eventDispatcher = eventDispatcher;
            this.RequiresAuthentication();
            this.RequiresAnyClaim(new[] { "SuperAdmin", "ClientAdmin", "ClientUser" });

            Before += ctx =>
                {
                    ClientId = string.Format("clients/{0}", ctx.Parameters["id"]);
                    UncommitedEvents = new List<EventBase>();

                    if (ctx.CurrentUser.Claims.Any(x => x == "ClientAdmin"))
                    {
                        var seerefineIdentity = ctx.CurrentUser as SeerefineIdentity;
                        if (seerefineIdentity == null)
                            return HttpStatusCode.Unauthorized;

                        if (seerefineIdentity.ClientId != ClientId)
                            return HttpStatusCode.Unauthorized;

                    }

                    RavenSession = sessionProvider.GetSession();
                    return null;
                };

            After += ctx =>
                {
                    if (RavenSession != null)
                    {
                        if(RavenSession.Advanced.HasChanges)
                            RavenSession.SaveChanges();

                        RavenSession.Dispose();

                        if (UncommitedEvents.Any())
                            _eventDispatcher.Dispatch(UncommitedEvents.ToArray());
                    }
                };

            OnError += (ctx, ex) =>
                {
                    Trace.TraceError(ex.ToString());

                    if (ex is ConcurrencyException)
                    {
                        return Response.Conflict(ex.Message);
                    }

                    return HttpStatusCode.InternalServerError;
                };
        }
Ejemplo n.º 3
0
        public void AddEventsToStream(Guid aggregateId, IList <IEvent> events)
        {
            var eventsData = new List <EventData>();

            foreach (var @event in events)
            {
                eventsData.Add(_eventSerializer.Serialize(@event));

                _connection.AppendToStreamAsync(GetStreamNameFormAggregateId(aggregateId), ExpectedVersion.Any, eventsData).GetAwaiter().GetResult();
            }

            _eventsDispatcher.Dispatch(events);
        }
        public void AddEventsToStream(Guid aggregateId, IList <IEvent> events)
        {
            if (!store.ContainsKey(aggregateId))
            {
                store.Add(aggregateId, new EventStream(aggregateId));
            }

            var stream = store[aggregateId];

            foreach (var @event in events)
            {
                stream.AppendEventToStream(@event);
            }
            _eventsDispatcher.Dispatch(events);
        }
Ejemplo n.º 5
0
        public async Task Dispatch(DispatchStreamJob job, CancellationToken token = new CancellationToken())
        {
            if (job == null)
            {
                throw new ArgumentNullException(nameof(job));
            }
            var events = await _dispatching.Pull(job.StreamId, token);

            while (events.Any())
            {
                await _events.Dispatch(events, token);

                await _dispatched.Confirm(token);

                if (token.IsCancellationRequested)
                {
                    return;
                }
                events = await _dispatching.Pull(job.StreamId, token);
            }
        }
        public ProcessScheduleItemModule(ISessionProvider sessionProvider, IDispatchEvents eventDispatcher)
            : base(sessionProvider, eventDispatcher, "process/clients/{id}/scheduleItems/{scheduleItemId}")
        {
            string ScheduleItemId = "";

            Before += ctx =>
                {
                    if (string.IsNullOrWhiteSpace(ctx.Parameters["scheduleItemId"]) == false)
                        ScheduleItemId = string.Format("{0}/scheduleItems/{1}", ClientId, ctx.Parameters["scheduleItemId"]);

                    return null;
                };

            Post["/checkin"] = parameters =>
                {
                    var scheduleItem = RavenSession.Load<ScheduleItem>(ScheduleItemId);

                    var @event = this.Bind<ScheduleItemCheckedIn>();
                    @event.ScheduleItemId = ScheduleItemId;
                    @event.UtcCheckInTime = DateTime.UtcNow;
                    @event.TeamId = scheduleItem.TeamId;
                    @event.TeamName = scheduleItem.TeamName;

                    eventDispatcher.Dispatch(@event);

                    return HttpStatusCode.NoContent;
                };

            Post["/checkout"] = parameters =>
                {
                    var scheduledItem = RavenSession.Load<ScheduleItem>(ScheduleItemId);

                    var @event = this.Bind<ScheduleItemCheckedOut>();
                    @event.ScheduleItemId = ScheduleItemId;
                    @event.UtcCheckOutTime = DateTime.UtcNow;
                    @event.TeamId = scheduledItem.TeamId;
                    @event.TeamName = scheduledItem.TeamName;
                    @event.SiteId = scheduledItem.SiteId;
                    @event.SiteName = scheduledItem.SiteName;

                    eventDispatcher.Dispatch(@event);

                    return HttpStatusCode.NoContent;
                };

            Post["/tickdetail"] = parameters =>
                {
                    var @event = this.Bind<TickDetail>();
                    @event.ScheduleItemId = ScheduleItemId;
                    @event.UtcTickTime = DateTime.UtcNow;

                    eventDispatcher.Dispatch(@event);

                    return HttpStatusCode.NoContent;
                };

            Post["/report"] = parameters =>
                {
                    var @event = this.Bind<ScheduleItemReport>();

                    @event.ScheduleItemId = ScheduleItemId;
                    @event.UtcReportTime = DateTime.UtcNow;

                    var scheduleItem = RavenSession.Load<ScheduleItem>(ScheduleItemId);
                    if (scheduleItem != null)
                    {
                        @event.ClientId = scheduleItem.ClientId;
                        var team = RavenSession.Load<Team>(scheduleItem.TeamId);
                        if (team != null)
                        {
                            @event.TeamId = team.Id;
                            @event.TeamName = team.Name;

                            var teamMembers = RavenSession.Load<User>(team.Users);
                            if (teamMembers != null)
                                @event.TeamMembers = teamMembers.Select(x => DomainReference<User>.Create(x.Id, x.Name));
                        }
                    }

                    eventDispatcher.Dispatch(@event);

                    return HttpStatusCode.NoContent;
                };

            Post["/orderItem"] = paramaters =>
                {
                    System.Diagnostics.Debug.WriteLine(new StreamReader(Request.Body).ReadToEnd());
                    var @event = this.Bind<DetailOrderAdded>();

                    @event.ScheduleItemId = ScheduleItemId;
                    @event.UtcDetaliNotesTime = DateTime.UtcNow;

                    eventDispatcher.Dispatch(@event);

                    return HttpStatusCode.NoContent;
                };

            Post["/detailnotes"] = paramaters =>
                {

                    var @event = this.Bind<DetailNotesAdded>();
                    @event.ScheduleItemId = ScheduleItemId;
                    @event.UtcDetaliNotesTime = DateTime.UtcNow;

                    eventDispatcher.Dispatch(@event);

                    return HttpStatusCode.NoContent;
                };
        }