public void Apply(IReadModelContext context, IDomainEvent <BankStatementAggregate, BankStatementId, BankStatementTextMatched3Event> domainEvent) { AggregateId = domainEvent.AggregateIdentity.Value; if (context.ReadModelId == AggregateId.ToString()) { throw new ApplicationException(); } var id = context.ReadModelId; if (string.IsNullOrEmpty(id)) { Logger.Warning($"read model no id found {context.ReadModelId}"); return; } var rm = domainEvent.AggregateEvent.Matched.SingleOrDefault(x => x.Key.Request.Id.ToString() == context.ReadModelId.ToVitaGuid().ToString()); var request = rm.Key ?? domainEvent.AggregateEvent.Unmatched.Single(x => x.Request.Id.ToString() == context.ReadModelId.ToVitaGuid().ToString()); var subcategory = rm.Key != null?GetSubCategory(rm.Value.Classifier?.SubCategory) : SubCategories.Uncategorised; RequestId = id; Category = CategoryTypeConverter.FromSubcategory(subcategory).GetDescription(); SubCategory = subcategory; Description = request.Request.Description; Amount = Convert.ToDecimal(request.Request.Amount); Method = PredictionMethod.KeywordMatch; TransactionUtcDate = request.Request.TransactionUtcDate; }
//public IEnumerable<PredictionResult> PredictionResults { get; set; } //public IEnumerable<PredictionResult> Unmatched { get; set; } //public Dictionary<Guid,TextClassificationResult> Matched { get; set; } //public void Apply(IReadModelContext context, // IDomainEvent<BankStatementAggregate, BankStatementId, BankStatementExtracted1Event> domainEvent) //{ // AggregateId = domainEvent.AggregateIdentity.Value; // var rm = domainEvent.AggregateEvent.PredictionRequests.Single(x => // x.Id.ToString() == context.ReadModelId.ToVitaGuid().ToString()); // var id = context.ReadModelId; // RequestId = id; // Category = CategoryType.Uncategorised.GetDescription(); // SubCategory = SubCategories.Uncategorised; // Description = rm.Description; // Amount = Convert.ToDecimal(rm.Amount); // Method = PredictionMethod.MultiClassClassifier; // TransactionUtcDate = rm.TransactionUtcDate; //} public void Apply(IReadModelContext context, IDomainEvent <BankStatementAggregate, BankStatementId, BankStatementPredicted2Event> domainEvent) { AggregateId = domainEvent.AggregateIdentity.Value; if (context.ReadModelId == AggregateId.ToString()) { throw new ApplicationException(); } var rm = domainEvent.AggregateEvent.PredictionResults.Single(x => x.Request.Id.ToString() == context.ReadModelId.ToVitaGuid().ToString()); if (rm == null) { Logger.Warning($"read model not found {context.ReadModelId}"); return; } var id = context.ReadModelId; var subcategory = GetSubCategory(rm.PredictedValue); RequestId = id; Category = CategoryTypeConverter.FromSubcategory(subcategory).GetDescription(); SubCategory = GetSubCategory(subcategory); Description = rm.Request.Description; Amount = Convert.ToDecimal(rm.Request.Amount); Method = PredictionMethod.MultiClassClassifier; TransactionUtcDate = rm.Request.TransactionUtcDate; }
public virtual PersistenceEvent ToPersistenceEvent(DomainEventSerializer serializer) { return(new PersistenceEvent { Timestamp = Timestamp, AggregateId = AggregateId.ToString(), EventName = GetType().Name, SerializedEvent = serializer.Serialize(this) }); }
public async Task SendMessageAsync(AggregateId toUserId, AggregateId pairId, string message, int messageNo) { await _hubContext.Clients.User(toUserId.ToString()).SendAsync("messageArrived", new PairMessageReceivedResponse() { FromUserId = _correlationContext.CurrentUser.UserId.Value.ToGuid(), Message = message, PairId = pairId.ToGuid(), ToUserId = toUserId.ToGuid(), PairMessageNo = messageNo }); }
public async Task SendPairCreatedNotificationAsync(AggregateId pairId, AggregateId firstUserId, AggregateId secondUserId) { var firstUser = await _userRepository.GetAsync(firstUserId); var secondUser = await _userRepository.GetAsync(secondUserId); await _hubContext.Clients.Users(firstUserId.ToString(), secondUserId.ToString()).SendAsync("pairCreated", new PairCreatedResponse() { PairId = pairId.Id, FirstUserFirstName = firstUser?.FirstName, FirstUserId = firstUserId.Id, SecondUserFirstName = secondUser?.FirstName, SecondUserId = secondUserId.Id }); }
public virtual async Task <bool> ValidateAsync(string purpose, string token, AggregateId userId, string securityStamp) { try { var bytes = Base64UrlEncoder.DecodeBytes(token); var unprotectedData = Protector.Unprotect(bytes); var ms = new MemoryStream(unprotectedData); using var reader = ms.CreateReader(); var creationTime = reader.ReadDateTimeOffset(); var expirationTime = creationTime + TimeSpan.FromMinutes(_tokenOptions.ExpiryMinutes); if (expirationTime < DateTimeOffset.UtcNow) { return(false); } var usrId = reader.ReadString(); if (usrId != userId.ToString()) { // invalid userId return(false); } var purp = reader.ReadString(); if (!string.Equals(purp, purpose)) { // invalidPurpose return(false); } var stamp = reader.ReadString(); if (!string.Equals(stamp, securityStamp)) { //Invalid stamp return(false); } return(true); } catch { // Do not leak exception } return(false); }
public virtual async Task <string> GenerateAsync(string purpose, AggregateId userId, string securityStamp) { if (userId == null) { throw new ArgumentNullException(nameof(userId)); } var ms = new MemoryStream(); using (var writer = ms.CreateWriter()) { writer.Write(DateTimeOffset.UtcNow); writer.Write(userId.ToString()); writer.Write(purpose ?? ""); writer.Write(securityStamp ?? ""); } var protectedBytes = Protector.Protect(ms.ToArray()); return(Base64UrlEncoder.Encode(protectedBytes)); }
public T Retrieve <T>(Guid guid) where T : Aggregate { var aggregateId = new AggregateId(typeof(T), guid); var result = Endpoint.Connection.ReadStreamEventsForwardAsync(aggregateId.ToString(), 0, -1, false).GetAwaiter().GetResult(); var aggregate = Factory.Create <T>(guid); foreach (var resEvent in result.Events) { var evt = resEvent.Event; var reconstructedEvent = ReconstructEvent(Encoding.UTF8.GetString(evt.Data), Encoding.UTF8.GetString(evt.Metadata)); var metadata = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(evt.Metadata)); //aggregate.Mutate(); //Console.WriteLine(Encoding.UTF8.GetString(evt.Event.Data)); throw new NotImplementedException(); } return(aggregate); }
private void AddAggregateToReasonCode() { var typeId = Aggregate?.GetAggregateTypeID() ?? new TAggregate().GetAggregateTypeID(); ReasonCode = $"{reasonCodePrefix}{typeId}{AggregateId.ToString().ToUpper().Substring(0, 5)}{ReasonCode.Substring(reasonCodePrefix.Length)}"; }
public override string ToString() { return(string.Format("{0}...{1}", AggregateId.ToString().Substring(0, 4), ETag)); }
public override string ToString() { return(GetType().Name + " [Id=" + AggregateId.ToString() + "]"); }