Ejemplo n.º 1
0
        public static Task publishToReadModel(ResolvedEvent eS_Event)
        {
            EventFromES normal = NormalizeESEvent(eS_Event);

            EventDistributor.Publish(normal);
            return(Task.FromResult(0));
        }
Ejemplo n.º 2
0
 public override void Hydrate(EventFromES evt)
 {
     if (evt.EventType == "ExampleEvent")
     {
         _onExampleEvent(evt);
     }
 }
Ejemplo n.º 3
0
        public override dynamic EventPublish(EventFromES anEvent, List <dynamic> calendar)
        {
            var data = anEvent.Data;

            switch (anEvent.EventType)
            {
            case "NewBookAdded":
                NewBookAdded create = data.ToObject <NewBookAdded>();
                BookListData table  = new BookListData
                {
                    Id = Guid.Parse(create.Id),
                    PublicationDate = create.PublicationDate,
                    PublishingHouse = create.PublishingHouse,
                    Status          = "Active",
                    Title           = create.Title
                };
                return(table);

            case "BookRemoved":
                BookRemoved removed = data.ToObject <BookRemoved>();
                table        = GetRemodelData(Guid.Parse(removed.Id));
                table.Status = "Closed";
                return(table);
            }
            return(null);
        }
Ejemplo n.º 4
0
        public EventFromES Get(EventFromES eventToGet)
        {
            EventFromES eventGotten = null;

            if (events.Contains(eventToGet))
            {
                eventGotten = events.Find(x => x.Id == eventToGet.Id);
            }
            return(eventGotten);
        }
Ejemplo n.º 5
0
 public override void Hydrate(EventFromES evt)
 {
     if (evt.EventType == "NewBookAdded")
     {
         _newBookAdded(evt);
     }
     if (evt.EventType == "BookRemoved")
     {
         _bookRemoved(evt);
     }
 }
Ejemplo n.º 6
0
        public static List <EventFromES> HydrateFromES(string streamId)
        {
            var eventStream = connection.ReadStreamEventsForwardAsync(streamId, 0, 256, false).Result.Events;
            List <EventFromES> theWetList = new List <EventFromES>();

            foreach (var eS_Event in eventStream)
            {
                EventFromES normalized = NormalizeESEvent(eS_Event);
                theWetList.Add(normalized);
            }
            return(theWetList);
        }
Ejemplo n.º 7
0
        private static EventFromES NormalizeESEvent(ResolvedEvent eS_Event)
        {
            string      eventData = System.Text.Encoding.UTF8.GetString(eS_Event.Event.Data);
            dynamic     body      = JsonConvert.DeserializeObject <dynamic>(eventData);
            EventFromES fromES    = new EventFromES
            {
                StreamId  = eS_Event.OriginalStreamId,
                Id        = eS_Event.OriginalStreamId,
                Data      = body,
                EventType = eS_Event.Event.EventType,
                TimeStamp = eS_Event.Event.Created.ToString()
            };

            return(fromES);
        }
Ejemplo n.º 8
0
        public override dynamic EventPublish(EventFromES anEvent)
        {
            var readModelCollection = Book.book;
            var data = anEvent.Data;

            switch (anEvent.EventType)
            {
            case "ExampleEvent":
                //Event Data that is not defined in the base class comes through the read model as a JObject, carried by a JArray
                string Id   = data["Id"];
                string name = data["Name"];
                return(readModelCollection);
            }
            return(null);
        }
Ejemplo n.º 9
0
        public static void Publish(EventFromES anEvent)
        {
            dynamic readmodelData;
            string  nspace = "ES_SQL_DDD_CQRS.src.ReadModels";
            var     q      = from t in Assembly.GetExecutingAssembly().GetTypes()
                             where t.IsClass && t.Namespace == nspace
                             select t;

            foreach (var readModel in q)
            {
                string[] hksd = readModel.Name.ToString().Split("Data");
                if (hksd.Length == 1)
                {
                    try
                    {
                        MethodInfo theMethod  = typeof(ReadModels.ReadModel).GetMethod("EventPublish", new[] { typeof(EventFromES) });
                        string     methodName = readModel.Name.ToString();
                        string     nameSpace  = readModel.Namespace.ToString();
                        string     key        = methodName.Split("Read")[0];
                        if (Book.book.ContainsKey(key))
                        {
                            string fullClassName     = nameSpace + "." + methodName;
                            object readModelToInvoke = Activator.CreateInstance(Type.GetType(fullClassName));
                            readmodelData = theMethod.Invoke(readModelToInvoke, new EventFromES[] { anEvent });
                        }
                        else
                        {
                            Book.book.Add(key, new List <ReadModelData>());
                            string fullClassName     = nameSpace + "." + methodName;
                            object readModelToInvoke = Activator.CreateInstance(Type.GetType(fullClassName));
                            readmodelData = theMethod.Invoke(readModelToInvoke, new EventFromES[] { anEvent });
                        }
                        TableReadmodelInterface.UpdateTable(readmodelData, key);
                    }
                    catch (Exception e)
                    {
                        Console.Write(e);
                    }
                }
            }
        }
Ejemplo n.º 10
0
 private void _onExampleEvent(EventFromES evt)
 {
     _Id = evt.Data["Id"];
 }
Ejemplo n.º 11
0
 private void _bookRemoved(EventFromES evt)
 {
     Active = false;
 }
Ejemplo n.º 12
0
 private void _newBookAdded(EventFromES evt)
 {
     Id     = evt.Data.Id;
     Active = true;
 }
Ejemplo n.º 13
0
 public abstract void Hydrate(EventFromES evt);
Ejemplo n.º 14
0
 public void Set(EventFromES eventToAdd)
 {
     events.Add(eventToAdd);
 }
Ejemplo n.º 15
0
 public abstract dynamic EventPublish(EventFromES anEvent);
Ejemplo n.º 16
0
        public static void Publish(EventFromES anEvent)
        {
            try
            {
                DateTime LastPublishedTime =
                    Connection.Book.From("EventLog", new { Id = 1 }).ToObject <EventLog>().Execute().LastEvent;
                DateTime eventTime = Convert.ToDateTime(anEvent.TimeStamp);
                int      timeing   = DateTime.Compare(eventTime, LastPublishedTime);
                dynamic  readmodelData;
                //if(false)
                if (timeing != -1)
                //if(true)
                {
                    string nspace = typeof(EventDistributor).Namespace.Split('.')[0] + ".Readmodels";
                    var    q      = from t in Assembly.GetExecutingAssembly().GetTypes()
                                    where t.IsClass && t.Namespace == nspace
                                    select t;
                    foreach (var readModel in q)
                    {
                        string[] rMName  = readModel.Name.ToString().Split("Data");
                        string[] rMName2 = readModel.Name.ToString().Split("Read");
                        if (rMName.Length == 1 && rMName2.Length > 1)
                        {
                            try
                            {
                                MethodInfo theMethod  = typeof(ReadModel).GetMethod("EventPublish", new[] { typeof(EventFromES), typeof(List <dynamic>) });
                                string     methodName = readModel.Name.ToString();
                                string     nameSpace  = readModel.Namespace.ToString();
                                string     key        = methodName.Split("Read")[0];

                                string         fullClassName     = nameSpace + "." + methodName;
                                object         readModelToInvoke = Activator.CreateInstance(Type.GetType(fullClassName));
                                List <dynamic> book = new List <dynamic>();
                                readmodelData = theMethod.Invoke(readModelToInvoke, new object[] { anEvent, book });
                                if (readmodelData != null)
                                {
                                    TableReadmodelInterface.UpdateTable(readmodelData, key);
                                }
                            }
                            catch (Exception e)
                            {
                                Console.Write(e);
                            }
                        }
                    }
                    EventLog log = Connection.Book.From("EventLog", new { Id = 1 }).ToObject <EventLog>().Execute();
                    if (anEvent.TimeStamp != null)
                    {
                        log.EventCount++;
                        log.LastEventRan = anEvent.StreamId;
                        log.LastEvent    = Convert.ToDateTime(anEvent.TimeStamp);
                        try
                        {
                            Connection.Book.Upsert("EventLog", new
                                                   { log.EventCount, log.LastEventRan, log.LastEvent, Id = log.Id }).Execute();
                        }
                        catch (Exception e)
                        {
                            string msg = e.Message;
                        }
                    }
                }
                else
                {
                    string help;
                }
            }
            catch (Exception e)
            {
                string message = e.Message;
            }
        }