示例#1
0
        async Task <CommandResultBase> UpdateShellFeatureVersionAsync(IShellFeature feature, string newVersion)
        {
            var result = new CommandResultBase();

            // Ensure the version is valid
            if (newVersion.ToVersion() == null)
            {
                return(result.Failed(
                           $"The version '{newVersion}' for feature '{feature.ModuleId}' is not a valid version. Versions must contain major, minor & build numbers. For example 1.0.0, 2.4.0 or 3.2.1"));
            }

            // Update version
            feature.Version = newVersion;

            // Update shell features
            var shellFeature = await _shellFeatureStore.UpdateAsync((ShellFeature)feature);

            // Ensure the update was successful before updating shell descriptor
            if (shellFeature == null)
            {
                return(result.Failed(
                           $"Could not update shell feature. An error occurred whilst updating the version for feature {feature.ModuleId} to version {newVersion}."));
            }

            // First get all existing enabled features
            var enabledFeatures = await _shellDescriptorManager.GetEnabledFeaturesAsync();

            // Update version for enabled feature
            var descriptor = new ShellDescriptor();

            foreach (var enabledFeature in enabledFeatures)
            {
                if (enabledFeature.ModuleId.Equals(feature.ModuleId, StringComparison.OrdinalIgnoreCase))
                {
                    enabledFeature.Version = newVersion;
                }
                descriptor.Modules.Add(new ShellModule(enabledFeature));
            }

            // Ensure we have a descriptor
            if (descriptor.Modules?.Count == 0)
            {
                return(result.Failed("A valid shell descriptor could not be constructed."));
            }

            // Update shell descriptor
            var updatedDescriptor = await _shellDescriptorStore.SaveAsync(descriptor);

            if (updatedDescriptor == null)
            {
                return(result.Failed(
                           $"Could not update shell descriptor. An error occurred whilst updating the version for feature {feature.ModuleId} to version {newVersion}."));
            }

            return(result.Success());
        }
示例#2
0
        async Task <IShellDescriptor> RemoveFeaturesAndSaveAsync(string[] featureIds)
        {
            // First get all existing enabled features
            var enabledFeatures = await _shellDescriptorManager.GetEnabledFeaturesAsync();

            // Add features minus our features to disable
            var descriptor = new ShellDescriptor();

            foreach (var feature in enabledFeatures)
            {
                var disable = featureIds.Any(f => f.Equals(feature.ModuleId, StringComparison.InvariantCultureIgnoreCase));
                if (!disable)
                {
                    descriptor.Modules.Add(new ShellModule(feature));
                }
            }

            return(await _shellDescriptorStore.SaveAsync(descriptor));
        }