/// <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;
                }
            }
        }
Ejemplo n.º 2
0
        /// <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);
                }
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (null == context)
            {
                return(value);
            }
            if (null == provider)
            {
                return(value);
            }

            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.GetUniqueName(formUI.RuleName, node, node.Parent);
                    }
                }
                return(expression);
            }

            return(value);
        }