Esempio n. 1
0
        public ScenarioSession SetupScenario(string userSubject, int id)
        {
            _logger.Info($"{nameof(SetupScenario)}({userSubject}, {id})");
            try
            {
                if (!_scenarios.ContainsKey(id))
                {
                    throw new ArgumentOutOfRangeException(nameof(id));
                }

                if (_activeScenarios.TryRemove(userSubject, out ScenarioMonitoringData scenarioMonitoringData))
                {
                    AbandonScenario(userSubject, scenarioMonitoringData.ScenarioId);
                }

                ScenarioDefinition scenarioDefinition = _scenarios[id];

                long scenarioSessionId = _dataAccessService.AddNewScenarionSession(userSubject, id);
                _dataAccessService.UpdateScenarioSessionStep(scenarioSessionId, 1);
                ScenarioSession scenarioSession = _dataAccessService.GetScenarioSession(scenarioSessionId);

                scenarioMonitoringData = new ScenarioMonitoringData
                {
                    ScenarioId        = id,
                    ScenarioSessionId = scenarioSessionId,
                    ActivationTime    = scenarioSession.StartTime,
                    LastUseTime       = DateTime.UtcNow
                };

                _activeScenarios.AddOrUpdate(userSubject, scenarioMonitoringData, (k, v) => scenarioMonitoringData);

                SetupIdentityProviders(scenarioDefinition, scenarioSessionId);

                SetupServiceProviders(scenarioDefinition, scenarioSessionId);

                SetupUsers(scenarioDefinition, scenarioSessionId);

                return(scenarioSession);
            }
            catch (Exception ex)
            {
                _logger.Error($"Failed {nameof(ResumeScenario)}({userSubject}, {id})", ex);
                throw;
            }
        }