/// <summary> /// <para>Creates an instance of the child node class and adds it as a child of the parent node. The node will be a <see cref="SymmetricAlgorithmProviderNode"/>.</para> /// </summary> /// <param name="node"> /// <para>The parent node to add the newly created <see cref="AddChildNodeCommand.ChildNode"/>.</para> /// </param> protected override void ExecuteCore(ConfigurationNode node) { TypeSelectorUI selector = new TypeSelectorUI( typeof(RijndaelManaged), typeof(SymmetricAlgorithm), TypeSelectorIncludes.None ); DialogResult typeResult = selector.ShowDialog(); if (typeResult == DialogResult.OK) { Type algorithmType = selector.SelectedType; CryptographicKeyWizard keyManager = new CryptographicKeyWizard(new SymmetricAlgorithmKeyCreator(algorithmType)); DialogResult keyResult = keyManager.ShowDialog(); if (keyResult == DialogResult.OK) { INodeNameCreationService service = ServiceHelper.GetNameCreationService(ServiceProvider); Debug.Assert(service != null, "Could not find the INodeNameCreationService"); base.ExecuteCore(node); SymmetricAlgorithmProviderNode providerNode = (SymmetricAlgorithmProviderNode)ChildNode; providerNode.AlgorithmType = selector.SelectedType; providerNode.Name = service.GetUniqueName(selector.SelectedType.Name, providerNode, providerNode.Parent); providerNode.Key = keyManager.KeySettings; } } }
protected override void ExecuteCore(ConfigurationNode node) { TypeSelectorUI selector = new TypeSelectorUI( typeof(RijndaelManaged), typeof(SymmetricAlgorithm), TypeSelectorIncludeFlags.Default ); DialogResult typeResult = selector.ShowDialog(); if (typeResult == DialogResult.OK) { KeySettings keySettings = new KeySettings(new SymmetricAlgorithmKeyCreator(selector.SelectedType.AssemblyQualifiedName)); KeyManagerEditorUI keyManager = new KeyManagerEditorUI(keySettings); DialogResult keyResult = keyManager.ShowDialog(); if (keyResult == DialogResult.OK) { INodeNameCreationService service = GetService(typeof(INodeNameCreationService)) as INodeNameCreationService; Debug.Assert(service != null, "Could not find the INodeNameCreationService"); base.ExecuteCore(node); SymmetricAlgorithmProviderNode providerNode = (SymmetricAlgorithmProviderNode)ChildNode; providerNode.AlgorithmType = selector.SelectedType.AssemblyQualifiedName; providerNode.Name = service.GetUniqueDisplayName(providerNode.Parent, selector.SelectedType.Name); providerNode.Key = keyManager.KeySettings; } } }
/// <summary> /// <para>Gets the registered <see cref="INodeNameCreationService"/>.</para> /// </summary> /// <param name="serviceProvider"> /// <para>The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</para> /// </param> /// <returns> /// <para>The registered <see cref="INodeNameCreationService"/>.</para> /// </returns> public static INodeNameCreationService GetNodeNameCreationService(IServiceProvider serviceProvider) { INodeNameCreationService nodeNameCreationService = serviceProvider.GetService(typeof(INodeNameCreationService)) as INodeNameCreationService; Debug.Assert(nodeNameCreationService != null, "Could not get the INodeNameCreationService"); return(nodeNameCreationService); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { Debug.Assert(provider != null, "No service provider; we cannot edit the value"); if (provider != null) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); Debug.Assert(edSvc != null, "No editor service; we cannot edit the value"); if (edSvc != null) { IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); string expression = (string)value; ConfigurationNode node = (ConfigurationNode)context.Instance; formUI.Expression = expression; formUI.RuleName = node.Name; DialogResult result = service.ShowDialog(formUI); if (result == DialogResult.OK) { expression = formUI.Expression; if (node.Name != formUI.RuleName) { INodeNameCreationService nameCreationService = node.Site.GetService(typeof(INodeNameCreationService)) as INodeNameCreationService; node.Name = nameCreationService.GetUniqueDisplayName(node, formUI.RuleName); } } return(expression); } } return(value); }
/// <summary> /// Gets the registered <see cref="INodeNameCreationService"/>. /// </summary> /// <param name="serviceProvider"> /// The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects. /// </param> /// <returns>The registered <see cref="INodeNameCreationService"/>.</returns> public static INodeNameCreationService GetNameCreationService(IServiceProvider serviceProvider) { if (null == serviceProvider) { throw new ArgumentNullException("serviceProvider"); } INodeNameCreationService nameCreationService = serviceProvider.GetService(typeof(INodeNameCreationService)) as INodeNameCreationService; return(nameCreationService); }
private void SetSiteName(string originalDisplayName, ConfigurationNode configurationNode) { INodeNameCreationService nodeNameCreationService = GetService(typeof(INodeNameCreationService)) as INodeNameCreationService; Debug.Assert(nodeNameCreationService != null, "The INodeNameCreationService needs to be implemented."); Debug.Assert(configurationNode.Site != null, "The Site was expeted not to be null"); //configurationNode.Site.Name = nodeNameCreationService.GetUniqueDisplayName(configurationNode.Parent, originalDisplayName); string name = nodeNameCreationService.GetUniqueDisplayName(configurationNode.Parent, originalDisplayName); configurationNode.Rename(name, DefaultNodeRename.ForceRename); }
private void SetUniqueComponentName(ConfigurationNode node) { INodeNameCreationService service = ServiceHelper.GetNameCreationService(serviceProvider); string nameToUse = node.Name; if (string.IsNullOrEmpty(nameToUse)) { nameToUse = node.GetType().Name; } ConfigurationNode parent = GetParentToBeUsed(node); string newName = service.GetUniqueName(nameToUse, node, parent); if (node.Name != newName) { node.Rename(newName, false); } }
/// <summary> /// <para>Creates an instance of the child node class and adds it as a child of the parent node. The node will be a <see cref="HashAlgorithmProviderNode"/>.</para> /// </summary> /// <param name="node"> /// <para>The parent node to add the newly created <see cref="AddChildNodeCommand.ChildNode"/>.</para> /// </param> protected override void ExecuteCore(ConfigurationNode node) { INodeNameCreationService service = ServiceHelper.GetNameCreationService(ServiceProvider); Debug.Assert(service != null, "Could not find the INodeNameCreationService"); TypeSelectorUI selector = new TypeSelectorUI( typeof(SHA1Managed), typeof(HashAlgorithm), TypeSelectorIncludes.None ); DialogResult typeResult = selector.ShowDialog(); if (typeResult == DialogResult.OK) { Type selectedAlgorithmType = selector.SelectedType; if (selector.SelectedType.IsSubclassOf(typeof(KeyedHashAlgorithm))) { CryptographicKeyWizard keyWizard = new CryptographicKeyWizard(new KeyedHashAlgorithmKeyCreator(selector.SelectedType)); DialogResult keyResult = keyWizard.ShowDialog(); if (keyResult == DialogResult.OK) { KeyedHashAlgorithmProviderNode providerNode = new KeyedHashAlgorithmProviderNode(); providerNode.Key = keyWizard.KeySettings; providerNode.AlgorithmType = selector.SelectedType; node.AddNode(providerNode); providerNode.Name = service.GetUniqueName(selector.SelectedType.Name, providerNode, providerNode.Parent); } } else { base.ExecuteCore(node); HashAlgorithmProviderNode providerNode = (HashAlgorithmProviderNode)ChildNode; providerNode.AlgorithmType = selectedAlgorithmType; providerNode.Name = service.GetUniqueName(selector.SelectedType.Name, providerNode, providerNode.Parent); } } }
public void AssertCanGetAllServices() { IContainer container = Host.GetService(typeof(IContainer)) as IContainer; Assert.IsNotNull(container); IComponentChangeService changeService = Host.GetService(typeof(IComponentChangeService)) as IComponentChangeService; Assert.IsNotNull(changeService); INodeNameCreationService nodeNameCreationService = Host.GetService(typeof(INodeNameCreationService)) as INodeNameCreationService; Assert.IsNotNull(nodeNameCreationService); INameCreationService nameCreationService = Host.GetService(typeof(INameCreationService)) as INameCreationService; Assert.IsNotNull(nameCreationService); IUIHierarchyService hierarchyService = Host.GetService(typeof(IUIHierarchyService)) as IUIHierarchyService; Assert.IsNotNull(hierarchyService); IDictionaryService dictionaryService = Host.GetService(typeof(IDictionaryService)) as IDictionaryService; Assert.IsNotNull(dictionaryService); IConfigurationErrorLogService configurationErrorLogService = Host.GetService(typeof(IConfigurationErrorLogService)) as IConfigurationErrorLogService; Assert.IsNotNull(configurationErrorLogService); INodeCreationService nodeCreationService = Host.GetService(typeof(INodeCreationService)) as INodeCreationService; Assert.IsNotNull(nodeCreationService); IXmlIncludeTypeService xmlIncludeTypeService = Host.GetService(typeof(IXmlIncludeTypeService)) as IXmlIncludeTypeService; Assert.IsNotNull(xmlIncludeTypeService); ILinkNodeService linkNodeService = Host.GetService(typeof(ILinkNodeService)) as ILinkNodeService; Assert.IsNotNull(linkNodeService); IMenuContainerService menuContainerService = Host.GetService(typeof(IMenuContainerService)) as IMenuContainerService; Assert.IsNotNull(menuContainerService); }