예제 #1
0
 /// <summary>
 /// The insert into event store.
 /// </summary>
 public IWriteEvent InsertIntoEventStore(IWriteEvent writeEvent)
 {
     try
     {
         return this.repository.Insert((WriteEvent)writeEvent);
     }
     catch (Exception ex)
     {
         this.logger.Error(ex);
         throw new WriteToStoreException(ex.Message, ex);
     }
 }
예제 #2
0
        /// <summary>
        /// Set sent to read to a new number.
        /// </summary>
        public bool SetSentToRead(IWriteEvent writeEvent, int sentToRead)
        {
            try
            {
                writeEvent.SentToRead = sentToRead;

                return this.repository.SaveAllChanges();
            }
            catch (Exception ex)
            {
                this.logger.Error(ex);
                throw;
            }
        }
예제 #3
0
        /// <summary>
        /// Register one event in the read database.
        /// </summary>
        private int RegisterOneEvent(DateTime timestamp, IWriteEvent writeEvent, int result)
        {
            var gdto = this.writeEventService.DeserializeGdto(writeEvent.Payload);

            var namePropertyValue = this.writeEventService.GetPropertyValue(gdto.Properties, "Name");

            if (string.IsNullOrWhiteSpace(namePropertyValue))
            {
                return result;
            }

            switch (writeEvent.CommandType)
            {
                case CommandType.Insert:
                    this.InsertRegistration(timestamp, gdto, namePropertyValue, writeEvent.Id);
                    break;

                case CommandType.Update:
                    this.UpdateRegistration(timestamp, gdto, namePropertyValue);
                    break;

                case CommandType.Delete:
                    this.DeleteRegistration(gdto.Properties);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }

            if (this.writeToReadRepository.SaveAllChanges())
            {
                result++;
                this.writeEventService.SetSentToRead(writeEvent, 1);
            }

            return result;
        }