Beispiel #1
0
        /// <summary>
        /// Start a Shell and register its settings in RunningShellTable
        /// </summary>
        private void ActivateShell(ShellContext context)
        {
            Logger.Debug("Activating context for tenant {0}", context.Settings.Name);
            context.Shell.Activate();

            _shellContexts = (_shellContexts ?? Enumerable.Empty <ShellContext>()).Union(new [] { context });
            _runningShellTable.Add(context.Settings);
        }
        /// <summary>
        /// Starts a Shell and registers its settings in RunningShellTable
        /// </summary>
        private void ActivateShell(ShellContext context)
        {
            Logger.Debug("Activating context for tenant {0}", context.Settings.Name);
            context.Shell.Activate();

            _shellContexts = (_shellContexts ?? Enumerable.Empty <ShellContext>())
                             .Where(c => c.Settings.Name != context.Settings.Name)
                             .Concat(new[] { context })
                             .ToArray();

            _runningShellTable.Add(context.Settings);
        }
        /// <summary>
        /// Starts a Shell and registers its settings in RunningShellTable
        /// </summary>
        private void ActivateShell(ShellContext context)
        {
            Logger.Debug("Activating shell context");
            context.Shell.Activate();

            lock (_shellContextsWriteLock)
            {
                _shellContexts = (_shellContexts ?? Enumerable.Empty <ShellContext>())
                                 .Where(c => c.Settings.Name != context.Settings.Name)
                                 .Concat(new[] { context })
                                 .ToArray();
            }

            _runningShellTable.Add(context.Settings);
        }
 public StandaloneEnvironmentWorkContextScopeWrapper(IWorkContextScope workContextScope, ShellContext shellContext)
 {
     _workContextScope = workContextScope;
     _shellContext     = shellContext;
 }
Beispiel #5
0
        void CreateAndActivateShells()
        {
            Logger.Information("Start creation of shells");

            // Is there any tenant right now?
            var allSettings = _shellSettingsManager.LoadSettings()
                              .Where(settings => settings.State == TenantState.Running || settings.State == TenantState.Uninitialized || settings.State == TenantState.Initializing)
                              .ToArray();

            // Load all tenants, and activate their shell.
            if (allSettings.Any())
            {
                Parallel.ForEach(allSettings, settings => {
                    _processingEngine.Initialize();
                    ShellContext context = null;

                    for (var i = 0; i <= Retries; i++)
                    {
                        // Not the first attempt, wait for a while ...
                        if (DelayRetries && i > 0)
                        {
                            // Wait for i^2 which means 1, 2, 4, 8 ... seconds
                            Thread.Sleep(TimeSpan.FromSeconds(Math.Pow(i, 2)));
                        }

                        try {
                            context = CreateShellContext(settings);
                            ActivateShell(context);

                            // If everything went well, break the retry loop
                            break;
                        }
                        catch (Exception ex) {
                            if (i == Retries)
                            {
                                Logger.Fatal("A tenant could not be started: {0} after {1} retries.", settings.Name, Retries);
                                return;
                            }
                            else
                            {
                                Logger.Error(ex, "A tenant could not be started: " + settings.Name + " Attempt number: " + i);
                            }
                        }
                    }

                    if (_processingEngine.AreTasksPending())
                    {
                        context.Shell.Sweep.Terminate();

                        while (_processingEngine.AreTasksPending())
                        {
                            Logger.Debug("Processing pending task after activate Shell");
                            _processingEngine.ExecuteNextTask();
                        }

                        context.Shell.Sweep.Activate();
                    }
                });
            }
            // No settings, run the Setup.
            else
            {
                var setupContext = CreateSetupContext();
                ActivateShell(setupContext);
            }

            Logger.Information("Done creating shells");
        }