private static ShellDescriptor GetShellDecriptorForCacheText(string p) { string[] fields = p.Trim().Split(new[] { "|" }, StringSplitOptions.None); var shellDescriptor = new ShellDescriptor { ApplicationName = fields[0] }; string[] features = fields[1].Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries); shellDescriptor.DisabledFeatures = features; string[] parameters = fields[2].Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries); shellDescriptor.Parameters = parameters.Select(parameter => parameter.Split(new[] { "," }, StringSplitOptions.None)).Select(parameterFields => new ShellParameter { Component = parameterFields[0], Name = parameterFields[1], Value = parameterFields[2] }).ToList(); return(shellDescriptor); }
private static string GetCacheTextForShellDescriptor(ShellDescriptor descriptor) { var sb = new StringBuilder(); sb.Append(descriptor.ApplicationName + "|"); foreach (var feature in descriptor.DisabledFeatures) { sb.Append(feature + ";"); } sb.Append("|"); foreach (var parameter in descriptor.Parameters) { sb.Append(parameter.Component + "," + parameter.Name + "," + parameter.Value); sb.Append(";"); } return(sb.ToString()); }
/// <summary> /// Lists all enabled features that depend on a given feature. /// </summary> /// <param name="featureName">Name of the feature to check.</param> /// <returns>An enumeration with dependent feature names.</returns> public IEnumerable <string> GetDependentFeatures(string featureName) { var getEnabledDependants = new Func <string, IDictionary <FeatureDescriptor, bool>, IDictionary <FeatureDescriptor, bool> >( (currentFeatureId, fs) => fs .Where(f => f.Value && f.Key.Dependencies != null && f.Key.Dependencies .Select(s => s.ToLower()) .Contains(currentFeatureId.ToLower())) .ToDictionary(f => f.Key, f => f.Value)); ShellDescriptor shellDescriptor = _shellDescriptorManager.GetShellDescriptor(); List <String> disabledFeatures = shellDescriptor.DisabledFeatures.ToList(); IDictionary <FeatureDescriptor, bool> availableFeatures = GetAvailableFeatureDescriptors() .ToDictionary(featureDescriptor => featureDescriptor, featureDescriptor => !disabledFeatures.Any(shellFeature => shellFeature.Equals(featureDescriptor.Name))); return(GetAffectedFeatures(featureName, availableFeatures, getEnabledDependants)); }
public void Store(string name, ShellDescriptor descriptor) { if (Disabled) { return; } lock (_synLock) { VerifyCacheFile(); var text = _appDataFolder.ReadFile(DescriptorCacheFileName); bool tenantCacheUpdated = false; Schubert.Helpers.ToolHelper.WriteUtf8Xml(saveWriter => { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(text); XmlNode rootNode = xmlDocument.DocumentElement; if (rootNode != null) { foreach (XmlNode tenantNode in rootNode.ChildNodes) { if (String.Equals(tenantNode.Name, name, StringComparison.OrdinalIgnoreCase)) { tenantNode.InnerText = GetCacheTextForShellDescriptor(descriptor); tenantCacheUpdated = true; break; } } if (!tenantCacheUpdated) { XmlElement newTenant = xmlDocument.CreateElement(name); newTenant.InnerText = GetCacheTextForShellDescriptor(descriptor); rootNode.AppendChild(newTenant); } } xmlDocument.Save(saveWriter); _appDataFolder.CreateFile(DescriptorCacheFileName, saveWriter.ToString()); }); } }
/// <summary> /// Disables a list of features. /// </summary> /// <param name="featureNames">The names for the features to be disabled.</param> /// <param name="force">Boolean parameter indicating if the feature should disable the features which depend on it if required or fail otherwise.</param> /// <returns>An enumeration with the disabled feature names.</returns> public IEnumerable <string> DisableFeatures(IEnumerable <string> featureNames, bool force) { ShellDescriptor shellDescriptor = _shellDescriptorManager.GetShellDescriptor(); List <string> disabledFeatures = shellDescriptor.DisabledFeatures.ToList(); IEnumerable <string> featuresToDisable = featureNames .Select(featureId => DisableFeature(featureId, force)).ToList() .SelectMany(ies => ies.Select(s => s)); if (featuresToDisable.Any()) { foreach (string featureName in featuresToDisable) { disabledFeatures.Add(featureName); Logger.WriteInformation("{0} was disabled", featureName); } _shellDescriptorManager.UpdateShellDescriptor(disabledFeatures, shellDescriptor.Parameters); } return(featuresToDisable); }
public void Store(string shellName, ShellDescriptor descriptor) { }
public static IEnumerable <FeatureDescriptor> GetEnabledFeatures(this IModuleManager m, ShellDescriptor descriptor) { return(m.GetAvailableFeatures().Where(fd => !descriptor.DisabledFeatures.Any(sf => sf == fd.Name))); }