/// <summary> /// Handles the specified @event. /// </summary> /// <param name="event">The @event.</param> /// <returns></returns> public async Task Handle(TrialAddedEvent @event) { try { ScenarioQueryDto scenario = await this._scenarioQueryRepository.Get(@event.ScenarioId); ProcedureQueryDto procedure = await this._procedureQuery.GetProcedureByScenarioId(@event.ScenarioId); List <EventDto> events = @event.Events.OrderBy(e => e.Timestamp).ToList(); int currentTarget = 1; EventDto taskStartEvent = null; foreach (EventDto eventDto in events) { if (taskStartEvent == null) { taskStartEvent = eventDto; } if (taskStartEvent != null && eventDto.Name == "MOUSE_CLICKED") { dynamic taskStartProperties = taskStartEvent.Properties; dynamic eventProperties = eventDto.Properties; ScenarioAssetDto asset = scenario.Assets.First(a => a.Tag == $"Target {currentTarget}"); float distance = Vector2.Distance( new Vector2((float)taskStartProperties.MouseX, (float)taskStartProperties.MouseY), new Vector2((float)eventProperties.MouseX, (float)eventProperties.MouseY)); float width = asset.Scale.X / 2.0f; long milliseconds = eventDto.Timestamp - taskStartEvent.Timestamp; TrialAnalysis analysis = new TrialAnalysis { Distance = distance, Width = width, Milliseconds = milliseconds, TrialId = @event.TrialId, UserId = @event.UserId, ScenarioId = @event.ScenarioId, ProcedureId = procedure.Id }; await this._repository.Add(analysis); taskStartEvent = null; } } } catch (Exception ex) { this._logger.LogError(0, ex, ex.Message); throw; } }
/// <summary> /// Handles the specified event. /// </summary> /// <param name="event">The event.</param> /// <returns></returns> public async Task Handle(ScenarioRemovedEvent @event) { ProcedureQueryDto procedure = await this._procedureQueryRepository.Get(@event.ProcedureId); ScenarioQueryDto scenario = procedure.Scenarios.SingleOrDefault(s => s.Id == @event.ScenarioId); if (scenario != null) { procedure.Scenarios.Remove(scenario); await this._procedureQueryRepository.Update(procedure); } await this._scenarioQueryRepository.Remove(@event.ScenarioId); }
/// <summary> /// Handles the specified event. /// </summary> /// <param name="event">The event.</param> /// <returns></returns> public async Task Handle(ScenarioCreatedEvent @event) { ScenarioQueryDto scenario = new ScenarioQueryDto { Id = @event.ScenarioId, Name = @event.Name }; ProcedureQueryDto procedure = await this._procedureQueryRepository.Get(@event.ProcedureId); procedure.Scenarios.Add(scenario); await this._procedureQueryRepository.Update(procedure); await this._scenarioQueryRepository.Add(scenario); }
/// <summary> /// Handles the specified event. /// </summary> /// <param name="event">The event.</param> /// <returns></returns> public async Task Handle(ScenarioAssetAddedEvent @event) { ScenarioAssetDto asset = new ScenarioAssetDto { Tag = @event.Tag, Position = @event.Position, Rotation = @event.Rotation, Scale = @event.Scale }; ProcedureQueryDto procedure = await this._procedureQueryRepository.Get(@event.ProcedureId); ScenarioQueryDto scenario = procedure.Scenarios.SingleOrDefault(s => s.Id == @event.ScenarioId); scenario?.Assets.Add(asset); await this._procedureQueryRepository.Update(procedure); scenario = await this._scenarioQueryRepository.Get(@event.ScenarioId); scenario?.Assets.Add(asset); await this._scenarioQueryRepository.Update(scenario); }
/// <summary> /// Handles the specified event. /// </summary> /// <param name="event">The event.</param> /// <returns></returns> public async Task Handle(ScenarioAssetRemovedEvent @event) { ProcedureQueryDto procedure = await this._procedureQueryRepository.Get(@event.ProcedureId); ScenarioQueryDto scenario = procedure.Scenarios.SingleOrDefault(s => s.Id == @event.ScenarioId); ScenarioAssetDto scenarioAsset = scenario?.Assets.SingleOrDefault(a => a.Tag == @event.Tag); if (scenarioAsset != null) { scenario.Assets.Remove(scenarioAsset); await this._procedureQueryRepository.Update(procedure); } scenario = await this._scenarioQueryRepository.Get(@event.ScenarioId); ScenarioAssetDto asset = scenario.Assets.SingleOrDefault(a => a.Tag == @event.Tag); if (asset != null) { scenario.Assets.Remove(asset); await this._scenarioQueryRepository.Update(scenario); } }
public async Task <IActionResult> GetProcedure(Guid id) { ProcedureQueryDto procedure = await this._procedureQueries.GetProcedure(id); return(Ok(procedure)); }
/// <summary> /// Adds the specified procedure. /// </summary> /// <param name="procedure">The procedure.</param> /// <returns></returns> public async Task Add(ProcedureQueryDto procedure) { await this.Collection.InsertOneAsync(procedure); }
/// <summary> /// Updates the specified procedure. /// </summary> /// <param name="procedure">The procedure.</param> /// <returns></returns> public async Task Update(ProcedureQueryDto procedure) { await this.Collection.ReplaceOneAsync(p => p.Id == procedure.Id, procedure); }