void RegisterEvents(IUIAutomationProxyFactoryEntry factoryEntry)
 {
     foreach (var eventMapping in this._proxyDescription.EventMappings)
     {
         factoryEntry.SetWinEventsForAutomationEvent(eventId: eventMapping.EventId, propertyId: eventMapping.PropertyId, winEvents: eventMapping.WinEvents);
     }
 }
        public static void RegisterClientSideProviders(ClientSideProviderDescription[] clientSideProviderDescription)
        {
            Utility.ValidateArgumentNonNull(clientSideProviderDescription, "clientSideProviderDescription ");

            // Convert providers to native code representation
            List <IUIAutomationProxyFactoryEntry> entriesList =
                new List <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
                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
            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());
        }