/// <summary> /// Handles the specified event. /// </summary> /// <param name="event">The event.</param> /// <returns></returns> public async Task Handle(ScenarioRemovedFromTrialEvent @event) { TrialSetQueryDto trialSetQuery = await this._repository.GetTrialSet(@event.TrialSetId); ScenarioQueryDto scenarioQuery = trialSetQuery.Scenarios.FirstOrDefault(s => s.Id == @event.ScenarioId); trialSetQuery.Scenarios.Remove(scenarioQuery); await this._repository.Update(trialSetQuery); }
/// <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(ScenarioAddedToTrialSetEvent @event) { TrialSetQueryDto trialSetQuery = await this._repository.GetTrialSet(@event.TrialSetId); ScenarioQueryDto scenarioQuery = await this._service.GetScenario(@event.ScenarioId); if (trialSetQuery.Scenarios == null) { trialSetQuery.Scenarios = new List <ScenarioQueryDto>(); } trialSetQuery.Scenarios.Add(scenarioQuery); await this._repository.Update(trialSetQuery); }
/// <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); } }
/// <summary> /// Updates the specified scenario. /// </summary> /// <param name="scenario">The scenario.</param> /// <returns></returns> public async Task Update(ScenarioQueryDto scenario) { await this.Collection.ReplaceOneAsync(s => s.Id == scenario.Id, scenario); }
/// <summary> /// Adds the specified scenario. /// </summary> /// <param name="scenario">The scenario.</param> /// <returns></returns> public async Task Add(ScenarioQueryDto scenario) { await this.Collection.InsertOneAsync(scenario); }
public async Task <IActionResult> GetScenario(Guid scenarioId) { ScenarioQueryDto scenario = await this._scenarioQueries.GetScenario(scenarioId); return(Ok(scenario)); }