Пример #1
0
        public ScenarioSession ResumeScenario(string userSubject, int id)
        {
            _logger.Info($"{nameof(ResumeScenario)}({userSubject}, {id})");
            try
            {
                ScenarioSession scenarioSession = _dataAccessService.GetScenarioSessions(userSubject).FirstOrDefault(s => s.ScenarioId == id);

                if (scenarioSession == null)
                {
                    throw new ScenarioSessionNotFoundException(userSubject, id);
                }

                bool needInitialize = false;
                if (!_activeScenarios.TryGetValue(userSubject, out ScenarioMonitoringData scenarioMonitoringData))
                {
                    needInitialize = true;
                }
                else if (scenarioMonitoringData.ScenarioId != id)
                {
                    needInitialize = true;
                }

                if (needInitialize)
                {
                    scenarioMonitoringData = new ScenarioMonitoringData
                    {
                        ScenarioId        = id,
                        ScenarioSessionId = scenarioSession.ScenarioSessionId,
                        ActivationTime    = scenarioSession.StartTime,
                        LastUseTime       = DateTime.UtcNow
                    };
                    _activeScenarios.AddOrUpdate(userSubject, scenarioMonitoringData, (k, v) => v);


                    ScenarioDefinition scenarioDefinition = _scenarios[id];
                    IEnumerable <Client.DataLayer.Model.Scenarios.ScenarioAccount> scenarioAccounts = _dataAccessService.GetScenarioAccounts(scenarioSession.ScenarioSessionId);

                    foreach (var scenarioAccount in scenarioAccounts)
                    {
                        AccountDescriptor account = _accountsService.GetById(scenarioAccount.AccountId);
                        if (account.AccountType == AccountType.IdentityProvider || account.AccountType == AccountType.ServiceProvider)
                        {
                            AccountDescriptor accountDescriptor = _accountsService.Authenticate(scenarioAccount.AccountId, "qqq");
                            _executionContextManager.InitializeStateExecutionServices(accountDescriptor.AccountId, accountDescriptor.SecretSpendKey);
                        }
                    }
                }
                else
                {
                    scenarioMonitoringData.LastUseTime = DateTime.UtcNow;
                }

                return(scenarioSession);
            }
            catch (Exception ex)
            {
                _logger.Error($"Failed {nameof(ResumeScenario)}({userSubject}, {id})", ex);
                throw;
            }
        }
Пример #2
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;
            }
        }
Пример #3
0
        public void ProgressScenario(string userSubject, int id, bool forward = true)
        {
            _logger.Debug($"{nameof(ProgressScenario)}({userSubject}, {id}, {forward})");
            try
            {
                ScenarioSession scenarioSession = _dataAccessService.GetScenarioSessions(userSubject).FirstOrDefault(s => s.ScenarioId == id);

                if (scenarioSession == null)
                {
                    throw new ScenarioSessionNotFoundException(userSubject, id);
                }

                if (forward)
                {
                    _dataAccessService.UpdateScenarioSessionStep(scenarioSession.ScenarioSessionId, scenarioSession.CurrentStep + 1);
                }
                else
                {
                    _dataAccessService.UpdateScenarioSessionStep(scenarioSession.ScenarioSessionId, scenarioSession.CurrentStep - 1);
                }

                ScenarioMonitoringData scenarioMonitoringData = _activeScenarios.GetOrAdd(userSubject, u => new ScenarioMonitoringData
                {
                    ScenarioId        = id,
                    ScenarioSessionId = scenarioSession.ScenarioSessionId,
                    ActivationTime    = scenarioSession.StartTime,
                    LastUseTime       = DateTime.UtcNow
                });

                scenarioMonitoringData.LastUseTime = DateTime.UtcNow;
            }
            catch (Exception ex)
            {
                _logger.Error($"Failed {nameof(ProgressScenario)}({userSubject}, {id}, {forward})", ex);
                throw;
            }
        }