Beispiel #1
0
        public async Task <DtoResult> UpdateFeatureStateAsync(ShellFeatureState featureState, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (featureState == null)
            {
                throw new ArgumentNullException(nameof(featureState));
            }

            var model = await ShellFeatureStates.SingleOrDefaultAsync(c => c.Id == featureState.Id);

            model.EnableState  = featureState.EnableState;
            model.InstallState = featureState.InstallState;
            Context.Update(model);
            try
            {
                await SaveChanges(cancellationToken);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(DtoResult.Failed(new DtoError
                {
                    Code = "ConcurrencyFailure",
                    Description = "并发故障"
                }));
            }
            return(DtoResult.Success);
        }
Beispiel #2
0
 public void UpdateInstalledState(ShellFeatureState featureState, ShellFeatureState.State value)
 {
     if (Logger.IsEnabled(LogLevel.Debug))
     {
         Logger.LogDebug("Feature {0} InstallState changed from {1} to {2}", featureState.Name, featureState.InstallState, value);
     }
 }
 private static bool IsRising(ShellFeatureState state)
 {
     if (state.get_InstallState() == 1)
     {
         return(true);
     }
     return(state.get_EnableState() == 1);
 }
        public Task UpdateInstalledStateAsync(ShellFeatureState featureState, ShellFeatureState.State value)
        {
            if (Logger.IsEnabled(LogLevel.Debug))
            {
                Logger.LogDebug("Feature {0} InstallState changed from {1} to {2}", featureState.Id, featureState.InstallState, value);
            }

            return(Task.CompletedTask);
        }
        public Task UpdateInstalledStateAsync(ShellFeatureState featureState, ShellFeatureState.State value)
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Feature '{FeatureName}' InstallState changed from '{FeatureState}' to '{FeatureState}'", featureState.Id, featureState.InstallState, value);
            }

            return(Task.CompletedTask);
        }
Beispiel #6
0
 private static bool FeatureIsChanging(ShellFeatureState shellFeatureState)
 {
     if (shellFeatureState.get_EnableState() == 1 || shellFeatureState.get_EnableState() == 3)
     {
         return(true);
     }
     if (shellFeatureState.get_InstallState() != 1 && shellFeatureState.get_InstallState() != 3)
     {
         return(false);
     }
     return(true);
 }
 public Task UpdateInstalledStateAsync(ShellFeatureState featureState, ShellFeatureState.State value)
 {
     if (this._logger.IsEnabled(1))
     {
         stackVariable6    = this._logger;
         stackVariable9    = new object[3];
         stackVariable9[0] = featureState.get_Id();
         stackVariable9[1] = featureState.get_InstallState();
         stackVariable9[2] = value;
         LoggerExtensions.LogDebug(stackVariable6, "Feature '{FeatureName}' InstallState changed from '{FeatureState}' to '{FeatureState}'", stackVariable9);
     }
     return(Task.get_CompletedTask());
 }
Beispiel #8
0
 private static bool FeatureIsChanging(ShellFeatureState shellFeatureState)
 {
     if (shellFeatureState.EnableState == ShellFeatureState.State.Rising ||
         shellFeatureState.EnableState == ShellFeatureState.State.Falling)
     {
         return(true);
     }
     if (shellFeatureState.InstallState == ShellFeatureState.State.Rising ||
         shellFeatureState.InstallState == ShellFeatureState.State.Falling)
     {
         return(true);
     }
     return(false);
 }
Beispiel #9
0
        public void UpdateInstalledState(ShellFeatureState featureState, ShellFeatureState.State value)
        {
            Logger.Debug("Feature {0} InstallState changed from {1} to {2}",
                         featureState.Name, featureState.InstallState, value);

            var featureStateRecord = FeatureRecord(featureState.Name);

            if (featureStateRecord.InstallState != featureState.InstallState)
            {
                Logger.Warning("Feature {0} prior InstallState was {1} when {2} was expected",
                               featureState.Name, featureStateRecord.InstallState, featureState.InstallState);
            }
            featureStateRecord.InstallState = value;
            featureState.InstallState       = value;
        }
Beispiel #10
0
        private ShellFeatureState GetOrCreateFeatureState(string name)
        {
            var featureState = GetShellStateAsync().Result.Features.FirstOrDefault(x => x.Name == name);

            if (featureState == null)
            {
                featureState = new ShellFeatureState()
                {
                    Name = name
                };
                _shellState.Features.Add(featureState);
            }

            return(featureState);
        }
Beispiel #11
0
        private async Task <ShellFeatureState> GetOrCreateFeatureStateAsync(string id)
        {
            var shellState = await GetShellStateAsync();

            var featureState = shellState.Features.FirstOrDefault(x => x.Id == id);

            if (featureState == null)
            {
                featureState = new ShellFeatureState()
                {
                    Id = id
                };
                _shellState.Features.Add(featureState);
            }

            return(featureState);
        }
        private ShellFeatureState GetOrAddFeatureState(string featureName)
        {
            var shellState = GetShellState();

            var feature = shellState.Features.SingleOrDefault(f => f.Name == featureName);

            if (feature == null)
            {
                feature = new ShellFeatureState {
                    Name = featureName
                };
                shellState.Features = shellState.Features.Union(new[] { feature });
            }

            ShellState = shellState;

            return(feature);
        }
Beispiel #13
0
        void IShellDescriptorManagerEventHandler.Changed(ShellDescriptor descriptor, string tenant)
        {
            // deduce and apply state changes involved
            var shellState = _stateManager.GetShellState();

            foreach (var feature in descriptor.Features)
            {
                var featureName  = feature.Name;
                var featureState = shellState.Features.SingleOrDefault(f => f.Name == featureName);
                if (featureState == null)
                {
                    featureState = new ShellFeatureState
                    {
                        Name = featureName
                    };
                    shellState.Features = shellState.Features.Concat(new[] { featureState });
                }
                if (!featureState.IsInstalled)
                {
                    _stateManager.UpdateInstalledState(featureState, ShellFeatureState.State.Rising);
                }
                if (!featureState.IsEnabled)
                {
                    _stateManager.UpdateEnabledState(featureState, ShellFeatureState.State.Rising);
                }
            }
            foreach (var featureState in shellState.Features)
            {
                var featureName = featureState.Name;
                if (descriptor.Features.Any(f => f.Name == featureName))
                {
                    continue;
                }
                if (!featureState.IsDisabled)
                {
                    _stateManager.UpdateEnabledState(featureState, ShellFeatureState.State.Falling);
                }
            }

            FireApplyChangesIfNeeded();
        }
Beispiel #14
0
        public async Task <ShellFeatureState> GetOrCreateFeatureStateAsync(string id, CancellationToken cancellationToken)
        {
            var shellState = await GetOrCreateAsync(cancellationToken);

            var featureState = shellState.Features.FirstOrDefault(x => x.Id == id);

            if (featureState == null)
            {
                featureState = new ShellFeatureState()
                {
                    Id = id
                };
                //ShellFeatureStateSet.Add(featureState);
                //await SaveChanges(cancellationToken);

                shellState.Features.Add(featureState);
                await SaveChanges(cancellationToken);
            }

            return(featureState);
        }
        async Task IShellDescriptorManagerEventHandler.Changed(ShellDescriptor descriptor, string tenant)
        {
            // deduce and apply state changes involved
            var shellState = await _stateManager.GetShellStateAsync();

            foreach (var feature in descriptor.Features)
            {
                var featureId    = feature.Id;
                var featureState = shellState.Features.SingleOrDefault(f => f.Id == featureId);
                if (featureState == null)
                {
                    featureState = new ShellFeatureState
                    {
                        Id = featureId
                    };
                }
                if (!featureState.IsInstalled)
                {
                    await _stateManager.UpdateInstalledStateAsync(featureState, ShellFeatureState.State.Rising);
                }
                if (!featureState.IsEnabled)
                {
                    await _stateManager.UpdateEnabledStateAsync(featureState, ShellFeatureState.State.Rising);
                }
            }
            foreach (var featureState in shellState.Features)
            {
                var featureId = featureState.Id;
                if (descriptor.Features.Any(f => f.Id == featureId))
                {
                    continue;
                }
                if (!featureState.IsDisabled)
                {
                    await _stateManager.UpdateEnabledStateAsync(featureState, ShellFeatureState.State.Falling);
                }
            }

            FireApplyChangesIfNeeded();
        }
Beispiel #16
0
        public async Task UpdateInstalledStateAsync(ShellFeatureState featureState, ShellFeatureState.State value)
        {
            if (Logger.IsEnabled(LogLevel.Debug))
            {
                Logger.LogDebug("Feature {0} InstallState changed from {1} to {2}", featureState.Id, featureState.InstallState, value);
            }

            var previousFeatureState = await GetOrCreateFeatureStateAsync(featureState.Id);

            if (previousFeatureState.InstallState != featureState.InstallState)
            {
                if (Logger.IsEnabled(LogLevel.Warning))
                {
                    Logger.LogWarning("Feature {0} prior InstallState was {1} when {2} was expected",
                                      featureState.Id, previousFeatureState.InstallState, featureState.InstallState);
                }
            }

            previousFeatureState.InstallState = value;
            featureState.InstallState         = value;

            UpdateShellState();
        }
Beispiel #17
0
        public async Task UpdateInstalledStateAsync(ShellFeatureState featureState, ShellFeatureState.State value)
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Feature '{FeatureName}' InstallState changed from '{FeatureState}' to '{FeatureState}'", featureState.Id, featureState.InstallState, value);
            }

            var previousFeatureState = await GetOrCreateFeatureStateAsync(featureState.Id);

            if (previousFeatureState.InstallState != featureState.InstallState)
            {
                if (_logger.IsEnabled(LogLevel.Warning))
                {
                    _logger.LogWarning("Feature '{FeatureName}' prior InstallState was '{FeatureState}' when '{FeatureState}' was expected",
                                       featureState.Id, previousFeatureState.InstallState, featureState.InstallState);
                }
            }

            previousFeatureState.InstallState = value;
            featureState.InstallState         = value;

            UpdateShellState();
        }
Beispiel #18
0
        public async Task UpdateEnabledStateAsync(ShellFeatureState featureState, ShellFeatureState.State value)
        {
            if (Logger.IsEnabled(LogLevel.Debug))
            {
                Logger.LogDebug("Feature {0} EnableState changed from {1} to {2}",
                                featureState.Id, featureState.EnableState, value);
            }

            var previousFeatureState = await Store.GetOrCreateFeatureStateAsync(featureState.Id, CancellationToken);

            if (previousFeatureState.EnableState != featureState.EnableState)
            {
                if (Logger.IsEnabled(LogLevel.Warning))
                {
                    Logger.LogWarning("Feature {0} prior EnableState was {1} when {2} was expected",
                                      featureState.Id, previousFeatureState.EnableState, featureState.EnableState);
                }
            }

            previousFeatureState.EnableState = value;
            featureState.EnableState         = value;

            await Store.UpdateFeatureStateAsync(previousFeatureState, CancellationToken);
        }
Beispiel #19
0
        public void UpdateEnabledState(ShellFeatureState featureState, ShellFeatureState.State value)
        {
            if (Logger.IsEnabled(LogLevel.Debug))
            {
                Logger.LogDebug("Feature {0} EnableState changed from {1} to {2}",
                                featureState.Name, featureState.EnableState, value);
            }

            var previousFeatureState = GetOrCreateFeatureState(featureState.Name);

            if (previousFeatureState.EnableState != featureState.EnableState)
            {
                if (Logger.IsEnabled(LogLevel.Warning))
                {
                    Logger.LogWarning("Feature {0} prior EnableState was {1} when {2} was expected",
                                      featureState.Name, previousFeatureState.EnableState, featureState.EnableState);
                }
            }

            previousFeatureState.EnableState = value;
            featureState.EnableState         = value;

            UpdateShellState();
        }
Beispiel #20
0
 static bool IsRising(ShellFeatureState state)
 {
     return(state.InstallState == ShellFeatureState.State.Rising ||
            state.EnableState == ShellFeatureState.State.Rising);
 }
Beispiel #21
0
 private static bool FeatureShouldBeLoadedForStateChangeNotifications(ShellFeatureState shellFeatureState)
 {
     return(FeatureIsChanging(shellFeatureState) || shellFeatureState.EnableState == ShellFeatureState.State.Up);
 }
        public void UpdateEnabledState(ShellFeatureState featureState, ShellFeatureState.State value)
        {
            GetOrAddFeatureState(featureState.Name).EnableState = value;

            featureState.EnableState = value;
        }
        public void UpdateInstalledState(ShellFeatureState featureState, ShellFeatureState.State value)
        {
            GetOrAddFeatureState(featureState.Name).InstallState = value;

            featureState.InstallState = value;
        }