public async Task <ActionResult <bool> > AddEvents([FromBody] ApiEventMessage events) { if (!(await _store.Validate(events.ApiKey)).Ok) { return(Forbid()); } await _context.EventEntities.AddRangeAsync(events.DomainMessages.Where(e => e.EventType == EventType.Event).Select(dm => new { Event = dm.EventData, Message = dm }).Select(e => new EventEntity { Data = e.Event.ToString(), EventName = e.Message.EventName, EventType = e.Message.EventType ?? EventType.Unkowen, Id = e.Message.Id, OriginType = e.Message.TypeName, Version = e.Message.Version ?? -1, TimeStamp = e.Message.TimeStamp ?? DateTimeOffset.Now })); await _context.SaveChangesAsync(); return(true); }
public async Task <ActionResult <ObjectStade> > Get([FromBody] ApiObjectId id) { if (!(await _apiKeyStore.Validate(id.ApiKey)).Ok) { return(base.Forbid()); } string realId = id.Id; var entity = await _context.ObjectStades.AsNoTracking().FirstOrDefaultAsync(o => o.Identifer == realId); return(entity == null ? new ObjectStade { Identifer = realId } : new ObjectStade { Data = JToken.Parse(entity.Data), // TypeFactory.Create(entity.OriginType, entity.Data) as IObjectData, Identifer = entity.Identifer, OriginalType = entity.OriginType }); }
public async Task Subscribe(string eventName, string apiKey) { var(ok, serviceName) = await _keyStore.Validate(apiKey); if (!ok) { throw new HubException("Api Key Validation Failed"); } _logger.LogInformation($"Subscribe: {serviceName} -- {eventName}"); await Groups.AddToGroupAsync(Context.ConnectionId, eventName); await _connectionManager.AddToGroup(Context.ConnectionId, eventName); }