コード例 #1
0
ファイル: EventStore.cs プロジェクト: ahoglind/Eveneum
        private EventData Deserialize(EventDocument document)
        {
            object metadata = DeserializeObject(document.MetadataType, document.Metadata);
            object body     = DeserializeObject(document.BodyType, document.Body);

            return(new EventData(document.StreamId, body, metadata, document.Version));
        }
コード例 #2
0
        public JsonResult DeleteFile(string id)
        {
            if (String.IsNullOrEmpty(id))
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { Result = "Error" }));
            }
            try
            {
                EventDocument fileDetail = _eventDocumentService.Get(Convert.ToInt32(id));
                if (fileDetail == null)
                {
                    Response.StatusCode = (int)HttpStatusCode.NotFound;
                    return(Json(new { Result = "Error" }));
                }

                //Remove from database
                _eventDocumentService.Delete(fileDetail);


                //Delete file from the file system
                //  var path = Path.Combine(Server.MapPath("~/App_Data/Upload/"), fileDetail.Id + fileDetail.Extension);
                //if (System.IO.File.Exists(path))
                //{
                //    System.IO.File.Delete(path);
                //}
                return(Json(new { Result = "OK" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
コード例 #3
0
        public async Task Save(IEnumerable <IEvent> events, CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var session = _client.StartSession())
            {
                foreach (var @event in events)
                {
                    session.StartTransaction();
                    try
                    {
                        EventDocument eventDocument = @event.ToEventDocument();
                        _collection.InsertOne(eventDocument);

                        await _mediator.Publish((INotification)@event);

                        session.CommitTransaction();
                    }
                    catch
                    {
                        session.AbortTransaction();
                        throw;
                    }
                    //TODO Add a property in event
                }
            }
        }
コード例 #4
0
        public static IEvent ToEvent(this EventDocument eventDocument, Type eventType)
        {
            var eventDataJson = eventDocument.EventData.ToJson();
            var eventObject   = JsonConvert.DeserializeObject(eventDataJson, eventType);

            return((IEvent)eventObject);
        }
コード例 #5
0
 public EventDocument Add(EventDocument entity)
 {
     using (var context = new ToplantiTakipContext())
     {
         context.EventDocuments.Add(entity);
         context.SaveChanges();
         return(entity);
     }
 }
コード例 #6
0
        async Task <IExecutionResult> IOperationHandler <AppendToStreamAsync, IExecutionResult> .Handle(AppendToStreamAsync operation, CancellationToken cancellationToken)
        {
            var id         = CosmosStreamNameStrategy.GetStreamIdentifier(operation.StreamId);
            var streamType = CosmosStreamNameStrategy.GetStreamType(operation.StreamId);

            long eventPosition = EventPosition.Start;

            if (operation.ExpectedVersion == ExpectedVersion.NoStream || operation.ExpectedVersion == ExpectedVersion.Any)
            {
                await _operationDispatcher.Dispatch(new CreateNewStream(id, streamType, operation.Events)).ConfigureAwait(false);

                eventPosition++;
            }
            else
            {
                var streamDoc = await _operationDispatcher
                                .Dispatch <GetStreamDocumentByIdAsync, Optional <StreamDocument> >(new GetStreamDocumentByIdAsync(id)).ConfigureAwait(false);

                streamDoc.ThrowsIf(stream => !stream.HasValue, new AggregateNotFoundException(operation.StreamId));

                var existingStream = streamDoc.Value.ToCosmosStream();

                existingStream.ThrowsIf(stream => operation.ExpectedVersion.Value != stream.Version.Value && operation.ExpectedVersion != ExpectedVersion.SafeStream,
                                        new WrongExpectedStreamVersionException(operation.ExpectedVersion.Value.ToString(),
                                                                                existingStream.Version.Value.ToString()));

                var streamEvents = await _operationDispatcher
                                   .Dispatch <GetEventDocumentsForward, IEnumerable <EventDocument> >
                                   (
                    new GetEventDocumentsForward(eDoc => eDoc.StreamId == id, Convert.ToInt32(StreamPosition.Start), _cosmosDBConfigurations.ReadBatchSize)
                                   ).ConfigureAwait(false);

                existingStream = existingStream.AppendEvents(streamEvents.Select(e => e.ToCosmosEvent()));

                operation.ExpectedVersion = operation.ExpectedVersion.WithVersion(operation.ExpectedVersion + operation.Events.Length);

                var newVersionedStream = existingStream.ChangeVersion(operation.ExpectedVersion);

                await _cosmosClient.UpdateItemAsync(id, _cosmosDBConfigurations.StreamContainerName, newVersionedStream.ToCosmosStreamDocument(),
                                                    operation.ExpectedVersion.MetaData).ConfigureAwait(false);

                eventPosition = newVersionedStream.NextEventNumber;
            }

            foreach (var @event in operation.Events)
            {
                var newEvent = new EventDocument(@event.EventId, id, eventPosition, this._eventSerializer.Serialize(@event.Data),
                                                 @event.EventMetadata, @event.EventType);

                await _cosmosClient.CreateItemAsync(newEvent, this._cosmosDBConfigurations.EventContainerName).ConfigureAwait(false);

                eventPosition++;
            }

            return(ExecutionResult.Success);
        }
コード例 #7
0
        public ICommittedEvent Deserialize(EventDocument doc)
        {
            var eventType = Type.GetType(doc.Metadata[MetadataKeys.EventClrType].AsString);
            var data      = JsonConvert.DeserializeObject(doc.EventData.ToJson(), eventType, JsonSettings);

            var metadata = BsonSerializer.Deserialize <Dictionary <string, object> >(doc.Metadata.ToJson());
            var version  = doc.Metadata[MetadataKeys.EventVersion].AsInt32;

            return(new MongoCommittedEvent(doc.AggregateId, version, data, new MetadataCollection(metadata)));
        }
コード例 #8
0
 public static Dal.Model.EventDocument ConvertBackToDalModel(this EventDocument doc)
 {
     return(new Dal.Model.EventDocument
     {
         Id = doc.Id,
         Data = doc.Data,
         EventId = doc.EventId,
         FileName = doc.FileName,
         FileType = doc.FileType
     });
 }
コード例 #9
0
 public void Delete(EventDocument entity)
 {
     using (var context = new ToplantiTakipContext())
     {
         var room = context.EventDocuments.Find(entity.EventDocumentId);
         if (room != null)
         {
             context.EventDocuments.Remove(room);
             context.SaveChanges();
         }
     }
 }
コード例 #10
0
        private static EventDocument BuildEventDoc(EventModel @event, string streamId,
                                                   long timeStamp, long streamVersion
                                                   )
        {
            var document = new EventDocument
            {
                StreamId  = streamId,
                Version   = streamVersion,
                TimeStamp = timeStamp,
                DataType  = @event.Data.GetType().AssemblyQualifiedName,
                Data      = @event.Data
            };

            return(document);
        }
コード例 #11
0
        public async Task <bool> Append(EventDocument <TPrimaryKey> document)
        {
            var entity = new EventEntity <TPrimaryKey>
            {
                FlowId    = document.FlowId,
                ActorId   = document.ActorId,
                Data      = document.Data,
                Name      = document.Name,
                Timestamp = document.Timestamp,
                Version   = document.Version
            };
            var box = new AskInputBox <EventEntity <TPrimaryKey>, bool>(entity);

            await this.mpscChannel.WriteAsync(box);

            return(await box.TaskSource.Task);
        }
コード例 #12
0
        public EventDocument Update(EventDocument entity)
        {
            using (var context = new ToplantiTakipContext())
            {
                var room = context.EventDocuments.FirstOrDefault(d => d.EventDocumentId == entity.EventDocumentId);
                room.Document     = entity.Document;
                room.DocumentName = entity.DocumentName;
                room.DocumentType = entity.DocumentType;

                room.EventId = entity.EventId;


                //context.Entry(entity).State = EntityState.Modified;
                context.SaveChanges();
                return(room);
            }
        }
コード例 #13
0
        public IActionResult Edit(int EventId, int EventDocumentId, [Bind("EventDocumentId,Title,URL,Type")] EventDocument @EventDocument)
        {
            var eventlist = GetList();

            var @event   = eventlist.Where(e => e.EventId == EventId).First();
            var EventDoc = @event.EventDocuments.Where(ed => ed.EventDocumentId == EventDocumentId).First();

            eventlist.Remove(@event);
            @event.EventDocuments.Remove(EventDoc);
            @event.EventDocuments.Add(@EventDocument);
            @event.EventDocuments = @event.EventDocuments.OrderBy(ed => ed.EventDocumentId).ToList();
            eventlist.Add(@event);
            eventlist = eventlist.OrderBy(e => e.EventId).ToList();

            SetList(eventlist);
            return(RedirectToAction("Index", "Home"));
        }
コード例 #14
0
        public static EventDocument ToEventDocument(this IEvent @event)
        {
            var settings = new JsonSerializerSettings
            {
                ContractResolver  = new CamelCasePropertyNamesContractResolver(),
                NullValueHandling = NullValueHandling.Ignore
            };

            var serializedEvent = JsonConvert.SerializeObject(@event, settings);

            EventDocument eventDocument = JsonConvert.DeserializeObject(serializedEvent, typeof(EventDocument)) as EventDocument;

            eventDocument.EventType = @event.GetType().Name;

            eventDocument.EventData = BsonSerializer.Deserialize <BsonDocument>(serializedEvent);

            return(eventDocument);
        }
コード例 #15
0
ファイル: EventStore.cs プロジェクト: lulzzz/Eveneum
        private EventData Deserialize(EventDocument document)
        {
            object metadata = null;

            if (!string.IsNullOrEmpty(document.MetadataType))
            {
                metadata = document.Metadata.ToObject(this.TypeCache.Resolve(document.MetadataType), this.JsonSerializer);
            }

            object body = null;

            if (!string.IsNullOrEmpty(document.BodyType))
            {
                body = document.Body.ToObject(this.TypeCache.Resolve(document.BodyType), this.JsonSerializer);
            }

            return(new EventData(body, metadata, document.Version));
        }
コード例 #16
0
ファイル: EventStore.cs プロジェクト: lulzzz/Eveneum
        private EventDocument Serialize(EventData @event, string streamId)
        {
            var document = new EventDocument
            {
                Partition = this.Partition,
                StreamId  = streamId,
                Version   = @event.Version,
                BodyType  = @event.Body.GetType().AssemblyQualifiedName,
                Body      = JToken.FromObject(@event.Body, this.JsonSerializer)
            };

            if (@event.Metadata != null)
            {
                document.MetadataType = @event.Metadata.GetType().AssemblyQualifiedName;
                document.Metadata     = JToken.FromObject(@event.Metadata, this.JsonSerializer);
            }

            return(document);
        }
コード例 #17
0
        private EventDocument BuildEventDocument()
        {
            var eventDocumentObj = new EventDocument();

            eventDocumentObj.Id    = 1;
            eventDocumentObj.Event = new Event()
            {
                Id = 1
            };
            eventDocumentObj.DocumentType = new DocumentType()
            {
                Id = 1
            };
            eventDocumentObj.DocumentName    = "test doc name";
            eventDocumentObj.PathAndFileName = "c:\\pathandfilename";
            eventDocumentObj.LastUpdatedBy   = "edm";
            eventDocumentObj.LastUpdatedDate = DateTime.Now;
            eventDocumentObj.Notes           = "notes for doctype";

            return(eventDocumentObj);
        }
コード例 #18
0
        public EventDocument Serialize(IUncommittedEvent eventToSerialize)
        {
            var id        = eventToSerialize.Metadata.GetValue(MetadataKeys.EventId, value => Guid.Parse(value.ToString()));
            var eventType = eventToSerialize.Metadata.GetValue(MetadataKeys.EventName, value => value.ToString());
            var timestamp = eventToSerialize.Metadata.GetValue(MetadataKeys.Timestamp, value => (DateTime)value);

            var dataJson     = JsonConvert.SerializeObject(eventToSerialize.Data, JsonSettings);
            var metadataJson = JsonConvert.SerializeObject(eventToSerialize.Metadata, JsonSettings);

            var @event = new EventDocument
            {
                Id          = id,
                Timestamp   = timestamp,
                EventType   = eventType,
                AggregateId = eventToSerialize.AggregateId,
                Version     = eventToSerialize.Version,
                EventData   = BsonDocument.Parse(dataJson),
                Metadata    = BsonDocument.Parse(metadataJson)
            };

            return(@event);
        }
コード例 #19
0
        private async Task <string> putEvent2CosmosDb(string deviceId, DocDBHelper docDBHelper, EventMessageModel eventMessageModel)
        {
            EventDocument eventDocument = new EventDocument
            {
                companyId                   = _companyId,
                iotDeviceId                 = deviceId,
                messageCatalogId            = eventMessageModel.MessageId,
                messageType                 = DocumentType.EventDocument,
                eventRuleCatalogId          = eventMessageModel.EventRuleId,
                eventRuleCatalogName        = eventMessageModel.EventRuleName,
                eventRuleCatalogDescription = eventMessageModel.EventRuleDescription,
                triggeredTime               = eventMessageModel.TriggeredTime, // Machine Local Time
                eventSent                   = eventMessageModel.EventSent,
                messageDocumentId           = eventMessageModel.MessageDocumentId,
                messageContent              = eventMessageModel.Payload
            };

            Document document = await docDBHelper.putDocumentAsync(eventDocument);

            //_consoleLog.Info("Event Document.Id={0}", document.Id);

            return(document.Id);
        }
コード例 #20
0
        public IActionResult Create(int EventId, [Bind("EventDocumentId,Title,URL,Type")] EventDocument @EventDocument)
        {
            var eventlist = GetList();

            var @event = eventlist.Where(e => e.EventId == EventId).First();

            if (@event.EventDocuments.LastOrDefault() == null)
            {
                @EventDocument.EventDocumentId = 0;
            }
            else
            {
                @EventDocument.EventDocumentId = @event.EventDocuments.LastOrDefault().EventDocumentId + 1;
            }

            eventlist.Remove(@event);
            @event.EventDocuments.Add(@EventDocument);
            @event.EventDocuments = @event.EventDocuments.OrderBy(ed => ed.EventDocumentId).ToList();
            eventlist.Add(@event);
            eventlist = eventlist.OrderBy(e => e.EventId).ToList();

            SetList(eventlist);
            return(RedirectToAction("Index", "Home"));
        }
コード例 #21
0
        public async Task SaveEventAsync <TAggregate>(IDomainEvent @event, int?expectedVersion = null) where TAggregate : IAggregateRoot
        {
            await Task.CompletedTask;

            EnsureAggregateExists <TAggregate>(@event.AggregateRootId);

            var currentVersion = Events.Where(x => x.AggregateId == @event.AggregateRootId).Count();
            var nextVersion    = VersionService.GetNextVersion(@event.AggregateRootId, currentVersion, expectedVersion);

            var eventDocument = new EventDocument()
            {
                Id          = @event.Id,
                AggregateId = @event.AggregateRootId,
                CommandId   = @event.CommandId,
                Sequence    = nextVersion,
                Type        = @event.GetType().AssemblyQualifiedName,
                Data        = JsonConvert.SerializeObject(@event),
                TimeStamp   = @event.TimeStamp,
                UserId      = @event.UserId,
                Source      = @event.Source
            };

            Events.Add(eventDocument);
        }
コード例 #22
0
        public ActionResult Create(Event @event)
        {
            if (ModelState.IsValid)
            {
                List <EventDocument> files = new List <EventDocument>();
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    if (file != null && file.ContentLength > 0)
                    {
                        var           fileName = Path.GetFileName(file.FileName);
                        EventDocument document = new EventDocument()
                        {
                            Document     = new byte[file.ContentLength],
                            DocumentType = Path.GetExtension(fileName),
                            DocumentName = fileName
                        };
                        files.Add(document);

                        // var path = Path.Combine(Server.MapPath("~/App_Data/Upload/"), fileDetail.Id + fileDetail.Extension);
                        //  file.SaveAs(path);
                    }
                }
                @event.Status          = EventStatus.Bekliyor;
                @event.ThemeColor      = "orange";
                @event.EventDocument   = files;
                @event.ReservationDate = DateTime.Now;
                @event.ApproveDate     = null;
                @event.UserId          = User.Identity.GetUserId();
                _evetService.Add(@event);
                return(RedirectToAction("Index"));
            }
            ViewBag.RoomId = new SelectList(_roomService.GetAll(), "RoomId", "RoomName", @event.RoomId);
            return(View(@event));
        }
コード例 #23
0
 public EventDocument Update(EventDocument entity)
 {
     return(_eventDocumentDal.Update(entity));
 }
コード例 #24
0
        public ActionResult Edit(Event _event)
        {
            if (ModelState.IsValid)
            {
                //if (image != null)
                //{
                //    //_event.DocumentType = image.ContentType;
                //    //_event.EventDocument = new byte[image.ContentLength];
                //    //image.InputStream.Read(_event.EventDocument, 0, image.ContentLength);
                //    EventDocument e = new EventDocument()
                //    {
                //        EventDocumentId = _event.EventId,
                //        Document = new byte[image.ContentLength],
                //        DocumentType = image.ContentType
                //    };
                //    image.InputStream.Read(e.Document, 0, image.ContentLength);
                //    _event.EventDocument.Add(e);
                //}
                List <EventDocument> files = new List <EventDocument>();
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    if (file != null && file.ContentLength > 0)
                    {
                        var           fileName = Path.GetFileName(file.FileName);
                        EventDocument document = new EventDocument()
                        {
                            Document     = new byte[file.ContentLength],
                            DocumentType = Path.GetExtension(fileName),
                            DocumentName = fileName,
                            EventId      = _event.EventId
                        };
                        files.Add(document);

                        // var path = Path.Combine(Server.MapPath("~/App_Data/Upload/"), fileDetail.Id + fileDetail.Extension);
                        //  file.SaveAs(path);
                        _event.EventDocument = files;
                    }
                }

                if (_event.Status == EventStatus.Onaylandı)
                {
                    _event.ThemeColor    = "green";
                    _event.ApproveDate   = DateTime.Now;
                    _event.ApproveUserId = User.Identity.GetUserId();
                }
                else if (_event.Status == EventStatus.Bekliyor)
                {
                    _event.ThemeColor = "orange";
                }
                else if (_event.Status == EventStatus.Reddedildi)
                {
                    _event.ThemeColor = "red";
                }

                _evetService.Update(_event);
                return(RedirectToAction("Index"));
            }
            //  PopulateAssignedPostTag(post);
            ViewBag.RoomId = new SelectList(_roomService.GetAll(), "RoomId", "RoomName", _event.RoomId);
            return(View(_event));
        }
コード例 #25
0
 public EventDocument Add(EventDocument entity)
 {
     return(_eventDocumentDal.Add(entity));
 }
コード例 #26
0
 private CarContract GenerateContract(EventDocument eventDocument) =>
コード例 #27
0
 public void Delete(EventDocument entity)
 {
     _eventDocumentDal.Delete(entity);
 }
コード例 #28
0
ファイル: CosmosDbContext.cs プロジェクト: OpsOwns/SuperCar
 public async Task Insert(EventDocument eventDocument, PartitionKey partitionKey,
                          CancellationToken cancellationToken = default) =>
 await _container.CreateItemAsync(eventDocument, partitionKey, cancellationToken : cancellationToken);
コード例 #29
0
 private static bool ExcludeMetaDataChanges(EventDocument doc)
 => doc is not null;
コード例 #30
0
 public static CosmosEvent ToCosmosEvent(this EventDocument document) =>
 CosmosEvent.Create(document.StreamId, document.OriginalId, document.Position, document.Type,
                    document.Data, document.EventMetadata, DateTime.Now);