System.Windows.Automation.ClientSettings.RegisterClientSideProviders C# (CSharp) Method

RegisterClientSideProviders() public static method

public static RegisterClientSideProviders ( ClientSideProviderDescription clientSideProviderDescription ) : void
clientSideProviderDescription ClientSideProviderDescription
return void
        public static void RegisterClientSideProviders(ClientSideProviderDescription[] clientSideProviderDescription)
        {
            Utility.ValidateArgumentNonNull(clientSideProviderDescription, "clientSideProviderDescription ");

            // Convert providers to native code representation
            List<UIAutomationClient.IUIAutomationProxyFactoryEntry> entriesList = 
                new List<UIAutomationClient.IUIAutomationProxyFactoryEntry>();           
            foreach (ClientSideProviderDescription provider in clientSideProviderDescription)
            {
                // Construct a wrapper for the proxy factory callback
                Utility.ValidateArgumentNonNull(provider.ClientSideProviderFactoryCallback, "provider.ClientSideProviderFactoryCallback");
                ProxyFactoryCallbackWrapper wrapper = new ProxyFactoryCallbackWrapper(provider.ClientSideProviderFactoryCallback);
                
                // Construct a factory entry
                UIAutomationClient.IUIAutomationProxyFactoryEntry factoryEntry =
                    Automation.Factory.CreateProxyFactoryEntry(wrapper);
                factoryEntry.AllowSubstringMatch = ((provider.Flags & ClientSideProviderMatchIndicator.AllowSubstringMatch) != 0) ? 1 : 0;
                factoryEntry.CanCheckBaseClass = ((provider.Flags & ClientSideProviderMatchIndicator.DisallowBaseClassNameMatch) != 0) ? 0 : 1;
                factoryEntry.ClassName = provider.ClassName;
                factoryEntry.ImageName = provider.ImageName;

                // Add it to the list
                entriesList.Add(factoryEntry);
            }

            // Get the proxy map from Automation and restore the default table
            UIAutomationClient.IUIAutomationProxyFactoryMapping map = Automation.Factory.ProxyFactoryMapping;
            map.RestoreDefaultTable();

            // Decide where to insert
            // MSDN recommends inserting after non-control and container proxies
            uint insertBefore;
            uint count = (uint)map.count;
            for (insertBefore = 0; insertBefore < count; ++insertBefore)
            {
                string proxyFactoryId = map.GetEntry(insertBefore).ProxyFactory.ProxyFactoryId;
                if (!proxyFactoryId.Contains("Non-Control") && !proxyFactoryId.Contains("Container"))
                {
                    break;
                }
            }

            // Insert our new entries
            map.InsertEntries(insertBefore, entriesList.ToArray());
        }
    }

Usage Example

Exemplo n.º 1
0
        // Methods
        public static void RegisterClientSideProviderAssembly(AssemblyName assemblyName)
        {
            Utility.ValidateArgumentNonNull(assemblyName, "assemblyName");

            // Load the assembly
            Assembly assembly = null;

            try
            {
                assembly = Assembly.Load(assemblyName);
            }
            catch (System.IO.FileNotFoundException)
            {
                throw new ProxyAssemblyNotLoadedException(String.Format("Assembly {0} not found", assemblyName));
            }

            // Find the official type
            string name = assemblyName.Name + ".UIAutomationClientSideProviders";
            Type   type = assembly.GetType(name);

            if (type == null)
            {
                throw new ProxyAssemblyNotLoadedException(String.Format("Could not find type {0} in assembly {1}", name, assemblyName));
            }

            // Find the descriptor table
            FieldInfo field = type.GetField("ClientSideProviderDescriptionTable", BindingFlags.Public | BindingFlags.Static);

            if ((field == null) || (field.FieldType != typeof(ClientSideProviderDescription[])))
            {
                throw new ProxyAssemblyNotLoadedException(String.Format("Could not find register method on type {0} in assembly {1}", name, assemblyName));
            }

            // Get the table value
            ClientSideProviderDescription[] clientSideProviderDescription = field.GetValue(null) as ClientSideProviderDescription[];

            // Write it through
            if (clientSideProviderDescription != null)
            {
                ClientSettings.RegisterClientSideProviders(clientSideProviderDescription);
            }
        }
All Usage Examples Of System.Windows.Automation.ClientSettings::RegisterClientSideProviders