예제 #1
0
        private static IABProviderFactory GetProviderFactory(string providerName)
        {
            if (string.IsNullOrEmpty(providerName))
            {
                throw new ArgumentNullException("providerName");
            }
            ExTraceGlobals.FrameworkTracer.TraceDebug <string>(0L, "Getting provider factor for provider '{0}'.", providerName);
            IABProviderFactory iabproviderFactory;

            if (!ABFactory.addressBookProviders.TryGetValue(providerName, out iabproviderFactory))
            {
                lock (ABFactory.loadABProviderSync)
                {
                    if (!ABFactory.addressBookProviders.TryGetValue(providerName, out iabproviderFactory))
                    {
                        string assemblyFullPath = ABFactory.GetAssemblyFullPath(Assembly.GetExecutingAssembly().Location, providerName);
                        ExTraceGlobals.FrameworkTracer.TraceDebug <string, string>(0L, "First time to create a session for AB Provider '{0}', loading it from '{1}'.", providerName, assemblyFullPath);
                        iabproviderFactory = ABFactory.LoadProviderFactory(providerName, assemblyFullPath);
                        Dictionary <string, IABProviderFactory> dictionary = new Dictionary <string, IABProviderFactory>(ABFactory.addressBookProviders, StringComparer.OrdinalIgnoreCase);
                        dictionary[providerName]       = iabproviderFactory;
                        ABFactory.addressBookProviders = dictionary;
                    }
                }
            }
            return(iabproviderFactory);
        }
예제 #2
0
        internal static ABProviderCapabilities GetProviderCapabilities(IABSessionSettings addressBookSessionSettings)
        {
            if (addressBookSessionSettings == null)
            {
                throw new ArgumentNullException("addressBookSessionSettings");
            }
            string providerName = ABFactory.GetProviderName(addressBookSessionSettings);

            ExTraceGlobals.FrameworkTracer.TraceDebug <string>(0L, "Getting provider capabilities for provider '{0}'.", providerName);
            IABProviderFactory providerFactory = ABFactory.GetProviderFactory(providerName);

            return(providerFactory.GetProviderCapabilities(addressBookSessionSettings));
        }
예제 #3
0
        internal static ABSession CreateABSession(IABSessionSettings addressBookSessionSettings)
        {
            if (addressBookSessionSettings == null)
            {
                throw new ArgumentNullException("addressBookSessionSettings");
            }
            string providerName = ABFactory.GetProviderName(addressBookSessionSettings);

            ExTraceGlobals.FrameworkTracer.TraceDebug <string>(0L, "Creating session for provider '{0}'.", providerName);
            ABFactory.ThrowIfDisabled(addressBookSessionSettings);
            IABProviderFactory providerFactory = ABFactory.GetProviderFactory(providerName);

            return(providerFactory.Create(addressBookSessionSettings));
        }
예제 #4
0
        private static IABProviderFactory LoadProviderFactory(string providerName, string assemblyPath)
        {
            Assembly assembly;

            try
            {
                assembly = Assembly.LoadFrom(assemblyPath);
            }
            catch (FileNotFoundException ex)
            {
                ExTraceGlobals.FrameworkTracer.TraceError(0L, "Failed to load ABProvider: FileNotFound exception.");
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_UnableToLoadABProvider, assemblyPath, new object[]
                {
                    providerName,
                    assemblyPath,
                    ex
                });
                throw new ABProviderLoadException(DirectoryStrings.ProviderFileNotFoundLoadException(providerName, assemblyPath), ex);
            }
            catch (FileLoadException ex2)
            {
                ExTraceGlobals.FrameworkTracer.TraceError(0L, "Failed to load ABProvider: FileLoadException exception.");
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_UnableToLoadABProvider, assemblyPath, new object[]
                {
                    providerName,
                    assemblyPath,
                    ex2
                });
                throw new ABProviderLoadException(DirectoryStrings.ProviderFileLoadException(providerName, assemblyPath), ex2);
            }
            catch (BadImageFormatException ex3)
            {
                ExTraceGlobals.FrameworkTracer.TraceError(0L, "Failed to load ABProvider: BadImageFormatException exception.");
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_UnableToLoadABProvider, assemblyPath, new object[]
                {
                    providerName,
                    assemblyPath,
                    ex3
                });
                throw new ABProviderLoadException(DirectoryStrings.ProviderBadImpageFormatLoadException(providerName, assemblyPath), ex3);
            }
            string             abfactoryClassNameFromProviderName = ABFactory.GetABFactoryClassNameFromProviderName(providerName);
            IABProviderFactory iabproviderFactory = (IABProviderFactory)assembly.CreateInstance(abfactoryClassNameFromProviderName, true);

            if (iabproviderFactory == null)
            {
                string text = string.Format(CultureInfo.InvariantCulture, "Failed to load ABProvider: Factory class '{0}' not found.", new object[]
                {
                    abfactoryClassNameFromProviderName
                });
                ExTraceGlobals.FrameworkTracer.TraceError(0L, text);
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_UnableToLoadABProvider, assemblyPath, new object[]
                {
                    providerName,
                    assemblyPath,
                    text
                });
                throw new ABProviderLoadException(DirectoryStrings.ProviderFactoryClassNotFoundLoadException(providerName, assemblyPath, abfactoryClassNameFromProviderName));
            }
            return(iabproviderFactory);
        }
예제 #5
0
 private static string GetAssemblyFullPath(string executingAssemblyPath, string providerName)
 {
     return(Path.Combine(Path.GetDirectoryName(executingAssemblyPath), ABFactory.GetAssemblyNameFromProviderName(providerName)));
 }