コード例 #1
0
ファイル: InstanceFactory.cs プロジェクト: killbug2004/WSProf
 private object CreateInstance(string extension, Type interfaceNeeded, DocumentClasses documentClass)
 {
     extension = FixExtension(extension);
     ImplementationKey key = new ImplementationKey(interfaceNeeded, extension, documentClass);
     ConstructorInfo ci = GetImplementation(key);
     if (ci == null)
         return null;
     return CreateObject(ci);
 }
コード例 #2
0
ファイル: InstanceFactory.cs プロジェクト: killbug2004/WSProf
        private ConstructorInfo GetImplementation(ImplementationKey key)
        {
            lock (cachedCtors)
            {
            if (cachedCtors.ContainsKey(key))
                return cachedCtors[key];
            }

            ConstructorInfo ci = FindImplementation(key);

            lock (cachedCtors)
            {
                if (ci != null && !cachedCtors.ContainsKey(key))
                cachedCtors.Add(key, ci);
            }

            return ci;
        }
コード例 #3
0
ファイル: InstanceFactory.cs プロジェクト: killbug2004/WSProf
        private static ConstructorInfo CheckModuleForImplementation(string sModule, ImplementationKey key)
        {
            try
            {
                Assembly newAss = Assembly.LoadFrom(sModule);
                if (newAss == null)
                    return null;

                if (!IsAssemblyAnFCSImplementation(newAss))
                    return null;

                Type[] types = newAss.GetTypes();
                foreach (Type t in types)
                {
                    if (!key.InterfaceType.IsAssignableFrom(t))
                        continue;

                    if (!CanHandle(t, key.Extension))
                        continue;

                    if (key.DocumentClass == DocumentClasses.Any || GetDocumentClass(t) == DocumentClasses.Any || GetDocumentClass(t) == key.DocumentClass)
                        return GetCtor(t);
                }

                return null;
            }
            catch (BadImageFormatException)
            {
                return null;
            }
            catch (FileLoadException)
            {
                return null;

            }
        }
コード例 #4
0
ファイル: InstanceFactory.cs プロジェクト: killbug2004/WSProf
        private ConstructorInfo FindImplementation(ImplementationKey key)
        {
            string[] locations = AssemblyLocation.FindInstalledFileLocations();
            foreach (string location in locations)
            {
                if (string.IsNullOrEmpty(location))
                    continue;

                try
                {
                    string[] files = System.IO.Directory.GetFiles(location, "*FCS*.dll");

                    foreach (string s in files)
                    {
                        string sLower = s.ToLower(CultureInfo.InvariantCulture);

                        if (sLower.Contains("workshare.fcs.base.dll"))
                            continue;

                        if (sLower.IndexOf("fcs.lite") != -1)
                            continue;

                        if (sLower.IndexOf("tests.dll") != -1)
                            continue;

                        ConstructorInfo ci = CheckModuleForImplementation(s, key);
                        if (ci != null)
                            return ci;
                    }
                }
                catch (Exception )
                {

                }
            }

            if( key.Extension != "*" )
                return GetImplementation(new ImplementationKey(key.InterfaceType, "*", key.DocumentClass));

            return null;
        }