Beispiel #1
0
        /// <summary>
        /// Gets a list of providers installed on the current machine.
        /// </summary>
        /// <returns></returns>
        public static async Task <IEnumerable <IOleDbProvider> > Providers()
        {
            // ***
            // *** Get a list of all providers.
            // ***
            IEnumerable <IOleDbProvider> providers = await JetDatabase.GetOleDbProvidersAsync();

            // ***
            // *** Filter Access drivers.
            // ***
            return(providers.Where(t => t.Description.Contains("Jet") | t.Description.Contains("Access Database")));
        }
Beispiel #2
0
        /// <summary>
        /// Perform the check for the current provider.
        /// </summary>
        /// <returns></returns>
        public static async Task <IOleDbProvider> CheckForAccessProviderAsync(string preferredProvider = JetDatabase.Providers.AccessEngine12)
        {
            IOleDbProvider returnValue = null;

            // ***
            // *** Get a list of all providers.
            // ***
            IEnumerable <IOleDbProvider> providers = await JetDatabase.GetOleDbProvidersAsync();

            // ***
            // *** Filter Access drivers.
            // ***
            IEnumerable <IOleDbProvider> filtered = providers.Where(t => t.Description.Contains("Jet") | t.Description.Contains("Access Database"));

            // ***
            // *** Check for the preferred provider
            // ***
            IOleDbProvider preferred = filtered.Where(t => t.Name == preferredProvider).SingleOrDefault();

            if (preferred != null)
            {
                MicrosoftAccessProvider.Current     = preferred;
                MicrosoftAccessProvider.IsPreferred = true;
                returnValue = preferred;
            }
            else
            {
                // ***
                // *** Get the first driver in the filtered list.
                // ***
                IOleDbProvider secondary = filtered.FirstOrDefault();

                if (secondary != null)
                {
                    MicrosoftAccessProvider.Current     = secondary;
                    MicrosoftAccessProvider.IsPreferred = true;
                    returnValue = secondary;
                }
                else
                {
                    MicrosoftAccessProvider.Current     = null;
                    MicrosoftAccessProvider.IsPreferred = false;
                    returnValue = null;
                }
            }

            return(returnValue);
        }