예제 #1
0
    /// <summary>
    /// Parses a plugin and create all the commands defined therein.
    /// </summary>
    /// <param name="pPlugIn">Plugin to harvest for commands.</param>
    /// <param name="pluginAssembly">Assembly associated with the plugin.</param>
    /// <returns>The number of newly created commands.</returns>
    public static int CreateCommands(IntPtr pPlugIn, System.Reflection.Assembly pluginAssembly)
    {
      int rc = 0;
      // This function must ONLY be called by Rhino_DotNet.Dll
      if (IntPtr.Zero == pPlugIn || null == pluginAssembly)
        return rc;

      Type[] exported_types = pluginAssembly.GetExportedTypes();
      if (null == exported_types)
        return rc;

      Type command_type = typeof(Commands.Command);
      for (int i = 0; i < exported_types.Length; i++)
      {
        if (exported_types[i].IsAbstract)
          continue;
        if (command_type.IsAssignableFrom(exported_types[i]))
        {
          if( Rhino.PlugIns.PlugIn.CreateCommandsHelper(null, pPlugIn, exported_types[i], null))
            rc++;
        }
      }

      return rc;
    }
예제 #2
0
 public static Type FindCompatibleType(string libraryfile, Type neededinterface)
 {
     System.Reflection.Assembly ass = null;
     try
     {
         ass = System.Reflection.Assembly.LoadFile(libraryfile);
         Type[] types = ass.GetExportedTypes();
         foreach (Type t in types)
         {
             foreach (Type ti in t.GetInterfaces())
             {
                 if (ti == neededinterface)
                 {
                     return(t);
                 }
             }
         }
     }
     catch (Exception x)
     {
         ass = null;
         MessageBox.Show(x.ToString(), "Error browsing types.", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     return(null);
 }
예제 #3
0
        public PackageContent Run()
        {
            PackageContent result = new PackageContent();

            foreach (string file in Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll"))
            {
                try {
                    System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(file);
                    foreach (System.Type type in assembly.GetExportedTypes())
                    {
                        if (type != typeof(IBootstrapper) && typeof(IBootstrapper).IsAssignableFrom(type))
                        {
                            result.Bootstrappers.Add(Contract.Type.FromType(type));
                        }
                        if (type != typeof(Updater) && typeof(Updater).IsAssignableFrom(type))
                        {
                            result.Updaters.Add(Contract.Type.FromType(type));
                        }
                    }
                } catch (Exception ex) {
                    Logger.Warn(this, "Could not scan " + file + " because: " + ex.GetRootCause().Message);
                }
            }
            Console.WriteLine("there are " + result.Bootstrappers.Count + " bootstrappers and " + result.Updaters.Count + " updaters");
            return(result);
        }
예제 #4
0
        private LibraryExceptions()
        {
            //add exceptions from dots_generated
            {
                System.Reflection.Assembly ass = System.Reflection.Assembly.Load("dots_generated-dotnet");
                System.Type[] exportedTypes    = ass.GetExportedTypes();
                foreach (System.Type type in exportedTypes)
                {
                    if (type.IsSubclassOf(typeof(System.Exception)))
                    {
                        System.IntPtr typename = Internal.InternalOperations.CStringOf(type.FullName);
                        m_exceptionNameTable.Add(Internal.Kernel.DotsC_TypeIdFromName(typename), type.FullName + ", dots_generated-dotnet");
                        Marshal.FreeHGlobal(typename);
                    }
                }
            }

            //add exceptions from dots_dotnet
            {
                System.Reflection.Assembly ass = System.Reflection.Assembly.Load("Safir.Dob.Typesystem");
                System.Type[] exportedTypes    = ass.GetExportedTypes();
                foreach (System.Type type in exportedTypes)
                {
                    if (type.IsSubclassOf(typeof(System.Exception)))
                    {
                        System.IntPtr typename = Internal.InternalOperations.CStringOf(type.FullName);
                        m_exceptionNameTable.Add(Internal.Kernel.DotsC_TypeIdFromName(typename), type.FullName + ", Safir.Dob.Typesystem");
                        Marshal.FreeHGlobal(typename);
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 在指定的模块中根据插件类型获取插件类
        /// </summary>
        /// <param name="model"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public static List <Type> GetTypesByType(this System.Reflection.Assembly model, string Type = "")
        {
            List <Type> lstType = new List <Type>();
            var         types   = model.GetExportedTypes();

            if (String.IsNullOrWhiteSpace(Type))
            {
                Type = model.GetAssemblyPluginAttribute().Type;
            }
            foreach (var type in types)
            {
                //System.Threading.Tasks.Parallel.ForEach(types, type =>
                //{
                var pluginAttribute = type.GetPluginAttribute();
                if (!String.IsNullOrWhiteSpace(Type) && pluginAttribute != null && pluginAttribute.Type.ToLower() == Type.ToLower())
                {
                    lstType.Add(type);
                }
                if (pluginAttribute != null && String.IsNullOrWhiteSpace(pluginAttribute.Type))
                {
                    lstType.Add(type);
                }
                //});
            }
            return(lstType);
        }
예제 #6
0
 public void RegisterAssemblyBrushes(System.Reflection.Assembly assembly)
 {
     Message("BrushManager: RegisterAssemblyBrushes...");
     foreach (System.Type type in assembly.GetExportedTypes())
     {
         bool hasAny = type.GetCustomAttributes(
             typeof(BrushAttribute), false
             ).Any();
         if (hasAny)
         {
             try
             {
                 object o     = System.Activator.CreateInstance(type);
                 Brush  brush = (Brush)(o);
                 brushes.Add(brush);
             }
             catch (System.Reflection.TargetInvocationException e)
             {
                 System.Diagnostics.Trace.TraceError(e.ToString());
                 if (e.InnerException != null)
                 {
                     System.Diagnostics.Trace.TraceError(e.InnerException.ToString());
                 }
             }
         }
     }
 }
예제 #7
0
        /// <summary>
        /// Creates a collection of all plug-ins that are available in the executing folder.
        /// </summary>
        /// <param name="pParent">Parent class <seealso cref="CommonBusControl"/></param>
        public PluginCollection(CommonBusControl pParent)
        {
            m_TraceSource = pParent.GetTraceSource;
            string ialphmFiltr = typeof(IDataProviderID).ToString();
            //Przeszukujemy katalog w poszykiwaniu odpowiedniego pluginu
            string lPathToScann = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            foreach (string fileOn in Directory.GetFiles(lPathToScann))
            {
                System.IO.FileInfo file = new System.IO.FileInfo(fileOn);
                //roszerzenie powinno byæ dll
                if (file.Extension.ToLower().Equals(".dll") && file.Name.ToLower().Contains("plugin"))
                {
                    m_TraceSource.TraceEvent
                        (TraceEventType.Verbose, 148, "NetworkConfiguration: Trying to find helper interface in file: {0}", fileOn);
                    try
                    {
                        //Create a new assembly from the plugin we're reading
                        System.Reflection.Assembly pluginAssembly = System.Reflection.Assembly.LoadFrom(fileOn);
                        //Gets a type object of the interface we need the plugins to match
                        foreach (Type pluginType in pluginAssembly.GetExportedTypes())
                        {
                            m_TraceSource.TraceEvent
                                (TraceEventType.Verbose, 158, "NetworkConfiguration: Checking if {0} implements the helper interface", pluginType.ToString());
                            if (pluginType.IsPublic && !pluginType.IsAbstract && pluginType.GetInterface(ialphmFiltr) != null) //Only look at public types
                            {
                                m_TraceSource.TraceEvent
                                    (TraceEventType.Verbose, 162, "NetworkConfiguration: Trying to create helper.");
                                IDataProviderID lHelper = (IDataProviderID)Activator.CreateInstance(pluginType);
                                m_SortedDic.Add(lHelper.GetDataProviderDescription.Identifier, lHelper);
                                m_TraceSource.TraceEvent
                                    (TraceEventType.Verbose, 158, "NetworkConfiguration: {0} has benn added to the plugins collection.", pluginType.ToString());
                            }
                            else
                            {
                                m_TraceSource.TraceEvent
                                    (TraceEventType.Verbose, 158, "NetworkConfiguration: {0} does not implement the helper interface", pluginType.ToString());
                            }
                        } //foreach (Type pluginType in pluginAssembly.GetTypes())
                    }     //try
                    catch (BadImageFormatException)//w przypadku biblioteki nie .NET - np WtOPCSvr.dll
                    {
                        m_TraceSource.TraceEvent
                            (TraceEventType.Warning, 211, "NetworkConfiguration: The file {0} image is invalid.", fileOn);
                    }
                    catch (LicenseException ex)
                    {
                        m_TraceSource.TraceEvent
                            (TraceEventType.Warning, 217,
                            "NetworkConfiguration: The component cannot be granted a license for the type: {0}.", ex.LicensedType.ToString());
                    }
                    catch (Exception ex)
                    {
                        m_TraceSource.TraceEvent
                            (TraceEventType.Warning, 223,
                            "Some problem encountered while trying to connect a plugin in file {0}. An exception was thrown: {1}", fileOn, ex.Message);
                    }
                } //if(file.Extension.Equals(".dll"))
            }     //foreach(string fileOn in System.IO.Directory.GetFiles(Win32API.Application.Path))
        }
예제 #8
0
        /// <summary>
        /// 在指定的模块中根据插件ID获取插件类
        /// </summary>
        /// <param name="model"></param>
        /// <param name="PluginId"></param>
        /// <returns></returns>
        public static Type GetTypeByPluginId(this System.Reflection.Assembly model, string PluginId = "")
        {
            var types = model.GetExportedTypes();

            if (String.IsNullOrWhiteSpace(PluginId))
            {
                PluginId = model.GetAssemblyPluginAttribute().DefaultPluginID;
            }
            if (String.IsNullOrWhiteSpace(PluginId))
            {
                return(null);
            }
            var existType = types.FirstOrDefault(type =>
            {
                var pluginAttribute = type.GetPluginAttribute();
                if (pluginAttribute != null)
                {
                    return(pluginAttribute.ID.ToLower() == PluginId.ToLower());
                }
                else
                {
                    return(false);
                }
            });

            return(existType);
        }
예제 #9
0
        public static System.Text.StringBuilder GetClassHierarchyForAssembly(System.Reflection.Assembly assembly)
        {
            var classTypes     = assembly.GetExportedTypes().Where(type => type.IsClass);
            var classTreeNodes = new Dictionary <string, ClassTreeNode>();

            foreach (Type classType in classTypes)
            {
                var newTreeNode      = new ClassTreeNode(classType.Name);
                var parentIdentifier = classType.BaseType.Name;
                if (!classTreeNodes.TryGetValue(parentIdentifier, out ClassTreeNode parentNode))
                {
                    parentNode = new ClassTreeNode(parentIdentifier);
                    classTreeNodes.Add(parentIdentifier, parentNode);
                }
                classTreeNodes.Add(newTreeNode.TypeName, newTreeNode);
                parentNode.AddChild(newTreeNode);
            }

            var builder = new System.Text.StringBuilder();

            foreach (var node in classTreeNodes.Values.Where(it => it.Parent == null).OrderBy(it => it.TypeName))
            {
                Display(builder, "", node);
            }

            return(builder);
        }
예제 #10
0
        public IStore RegisterIndexes(System.Reflection.Assembly assembly)
        {
            var exportedTypes = assembly.GetExportedTypes();
            var indexes       = exportedTypes.Where(x => typeof(IIndexProvider).IsAssignableFrom(x));

            return(RegisterIndexes(indexes));
        }
예제 #11
0
        public static int initManager()
        {
            bool bb = AppCommon.Log.UMCLog.Enable;//使用静态变量触发类的静态构造函数(get√)

            #region  务注册
            GalaSoft.MvvmLight.Ioc.SimpleIoc.Default.Register <FunctionService>(true);//注入ioc,并立即实例化
            #endregion
            DirectoryInfo AppFolder = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
            foreach (FileInfo NextFile in AppFolder.GetFiles())
            {
                bool b = NextFile.Name.StartsWith("UMC");
                if (NextFile.Extension.ToUpper() == ".DLL" && NextFile.Name.StartsWith("UMC"))
                {
                    Loghelper.WriteLogTrace("正在加载:" + NextFile.FullName.ToString());
                    System.Reflection.Assembly assemblyInfo = null;
                    try
                    {
                        assemblyInfo = System.Reflection.Assembly.LoadFrom(NextFile.FullName);
                    }
                    catch
                    {
                        assemblyInfo = null;
                    }
                    if (assemblyInfo == null)
                    {
                        continue;
                    }
                    //获取所有公开类型
                    Type[] TempTArray = assemblyInfo.GetExportedTypes();
                    foreach (Type type in TempTArray)
                    {
                        object[] TypeAttributes = type.GetCustomAttributes(typeof(AppModel.UMCAttributes.UMCAttribute), false);
                        if (TypeAttributes != null && TypeAttributes.Length > 0)
                        {
                            //程序集里面不是所有的公共类型都是自定义特性的,所以在此做个判断
                            try
                            {
                                //特性只有一个,所以是0
                                AppModel.UMCAttributes.UMCAttribute temp = TypeAttributes[0] as AppModel.UMCAttributes.UMCAttribute;
                                switch (temp.CurrentType)
                                {
                                case AppModel.UMCAttributes.FuncType.Func:
                                    //↓先从容器中获取Service实例,然后调用service的自定义注入方法
                                    GalaSoft.MvvmLight.Ioc.SimpleIoc.Default.GetInstance <FunctionService>().RegisterFunction(temp.ClassType, temp.Key);
                                    break;

                                default: break;
                                }
                            }
                            catch (Exception ex)
                            { Loghelper.WriteLogException(ex); }
                        }
                    }
                }
            }
            return(-1);
        }
예제 #12
0
 public static Regulus.Remote.IProtocol Create(System.Reflection.Assembly protocol_assembly)
 {
     System.Type[] types        = protocol_assembly.GetExportedTypes();
     System.Type   protocolType = types.Where(type => type.GetInterface(nameof(Regulus.Remote.IProtocol)) != null).FirstOrDefault();
     if (protocolType == null)
     {
         throw new System.Exception($"找不到{nameof(Regulus.Remote.IProtocol)}的實作");
     }
     return(System.Activator.CreateInstance(protocolType) as Regulus.Remote.IProtocol);
 }
예제 #13
0
        public static System.Collections.Generic.IEnumerable <Regulus.Remote.IProtocol> Create(System.Reflection.Assembly protocol_assembly)
        {
            System.Type[] types         = protocol_assembly.GetExportedTypes();
            var           protocolTypes = types.Where(type => type.GetInterface(nameof(Regulus.Remote.IProtocol)) != null);

            foreach (var type in protocolTypes)
            {
                yield return(System.Activator.CreateInstance(type) as Regulus.Remote.IProtocol);
            }
        }
예제 #14
0
 public static void AppendFromAssembly(System.Reflection.Assembly assembly)
 {
     foreach (Type t in assembly.GetExportedTypes())
     {
         Measure proxy = Measure.TryRetrieveFrom(t);
         if (proxy != null)
         {
             Add(proxy);
         }
     }
 }
예제 #15
0
 private static Type[] TryGetExportedTypes(System.Reflection.Assembly asm)
 {
     try
     {
         return(asm.GetExportedTypes());
     }
     catch (Exception)
     {
         tracer.Warn("Failed to retrieve exported types from assembly {0}.", asm.FullName);
         return(new Type[0]);
     }
 }
예제 #16
0
        /// <summary>
        /// Finds all Extension methods defined in an assembly
        /// </summary>
        /// <param name="asm"></param>
        /// <returns></returns>
        public static IEnumerable <ExtensionMethodRecord> EnumExtensionMethods(System.Reflection.Assembly asm)
        {
            var exported_types = asm.GetExportedTypes();

            foreach (var extending_type in exported_types)
            {
                foreach (var emi in EnumExtensionMethods(extending_type))
                {
                    yield return(emi);
                }
            }
        }
 private void btTest_Click(object sender, System.EventArgs e)
 {
     this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
     try
     {
         string sExe = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "TestLoadWin.exe");
         if (System.IO.File.Exists(sExe))
         {
             string sType = "";
             System.Reflection.Assembly a = System.Reflection.Assembly.LoadFile(frmPerformerImport.WizardInfo.CompiledFile);
             System.Type[] tps            = a.GetExportedTypes();
             if (tps != null)
             {
                 for (int i = 0; i < tps.Length; i++)
                 {
                     if (tps[i].GetInterface("EPControl.IPerformer") != null)
                     {
                         sType = tps[i].AssemblyQualifiedName;
                         break;
                     }
                 }
             }
             if (sType.Length > 0)
             {
                 System.Diagnostics.Process pr = new System.Diagnostics.Process();
                 pr.StartInfo = new System.Diagnostics.ProcessStartInfo(sExe, "\"" + sType + "\"");
                 Microsoft.Win32.RegistryKey reg = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Longflow\\Limnor");
                 reg.SetValue("TestLoad", "");
                 reg.Close();
                 pr.Start();
                 pr.WaitForExit();
                 reg = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("Software\\Longflow\\Limnor");
                 string s = (string)reg.GetValue("TestLoad");
                 txtMsg.Text = s;
                 pr.Dispose();
             }
             else
             {
                 txtMsg.Text = "No Performer found in this file";
             }
         }
         else
         {
             txtMsg.Text = "File not found:" + sExe;
         }
     }
     catch (Exception er)
     {
         txtMsg.Text = "Failed:\r\n" + ImportException.FormExceptionText(er);
     }
     this.Cursor    = System.Windows.Forms.Cursors.Default;
     btSave.Enabled = true;
 }
예제 #18
0
 public bool HasPlugins(string path)
 {
     AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
     System.Reflection.Assembly a = System.Reflection.Assembly.ReflectionOnlyLoadFrom(path);
     foreach (Type t in a.GetExportedTypes())
     {
         if (MetaPlugin.IsPlugin(t))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #19
0
 private AbstractPlatform GetPlatformInstance(System.Reflection.Assembly assembly)
 {
     foreach (System.Type type in assembly.GetExportedTypes())
     {
         // TODO: check to make sure it inherits from AbstractPlatform
         // Perhaps make that the only qualification instead of going by name?
         if (type.Name == "PlatformImpl" && !type.IsAbstract)
         {
             return((AbstractPlatform)assembly.CreateInstance(type.FullName));
         }
     }
     throw new System.InvalidOperationException("This assembly does not define a PlatformImpl type: " + assembly.FullName);
 }
예제 #20
0
            public string Value(byte[] rawAssembly)
            {
                string s = "";

                try
                {
                    System.Reflection.Assembly assy = System.Reflection.Assembly.Load(rawAssembly);
                    string h = String.Format("\n---------\n---------\n{0}: Assembly\n---------\n", assy.GetType().Name);
                    string t = "---------\n";
                    s += h;
                    s += assy.ToString() + "\n";

                    foreach (var p in typeof(System.Reflection.Assembly).GetProperties())
                    {
                        try { s += string.Format("  {0}: {1}\n", p.Name, "" + p.GetValue(assy, null)); }
                        catch (Exception ex) { s += string.Format("  {0}: Error reading Value: {1}\n", p.Name, ex.Message); }
                    }

                    s += "\nReferences:\n";
                    foreach (var p in assy.GetReferencedAssemblies())
                    {
                        s += string.Format("  Ref: {0}\n", p.ToString());
                    }

                    s += "\nExported Types:\n";
                    try
                    {
                        Type[] exportedTypes = assy.GetExportedTypes();
                        foreach (var p in exportedTypes)
                        {
                            s += string.Format("  Type: {0}\n", p.ToString());
                        }
                    }
                    catch (Exception ex) { s += "  Cannot get Exported Types: " + ex.Message + "\n"; }

                    s += t;
                }
                catch (Exception ex)
                {
                    s = "\n---------\n---------\n Assembly\n---------\n";
                    for (Exception inex = ex; inex != null; inex = inex.InnerException)
                    {
                        s += "\n" + inex.Message;
                        s += "\n" + inex.StackTrace;
                        s += "\n-----";
                    }
                    s += "---------\n";
                }
                return(s);
            }
예제 #21
0
        /// <summary>
        /// Register a group of services from the specified assembly
        /// </summary>
        /// <param name="container"></param>
        /// <param name="repositoryAssembly"></param>
        /// <param name="endString"></param>
        public static void RegisterSpecial(this Container container, System.Reflection.Assembly repositoryAssembly, string endString)
        {
            var registrations =
                from type in repositoryAssembly.GetExportedTypes()
                where type.Name.ToLower().EndsWith(endString.ToLower())
                where type.GetInterfaces().Any()
                where !type.IsInterface
                select new { Service = type.GetInterfaces().Where(t => !t.IsGenericType).FirstOrDefault(), Implementation = type };

            foreach (var reg in registrations)
            {
                container.Register(reg.Service, reg.Implementation, Lifestyle.Scoped);
            }
        }
예제 #22
0
        /// <summary>
        /// Call this method once from your plug-ins OnLoad override for each
        /// assembly containing a custom mesh provider.  Only publicly exported
        /// classes derived from CustomRenderMeshProvider with a public constructor
        /// that has no parameters will get registered.
        /// </summary>
        /// <param name="assembly">
        /// Assembly to search for valid CustomRenderMeshProvider derived classes.
        /// </param>
        /// <param name="pluginId">
        /// The plug-in that owns the custom mesh providers.
        /// </param>
        public static void RegisterProviders(System.Reflection.Assembly assembly, Guid pluginId)
        {
            var plugin = PlugIns.PlugIn.GetLoadedPlugIn(pluginId);

            if (plugin == null)
            {
                return;
            }

            var exported_types = assembly.GetExportedTypes();
            var provider_types = new List <Type>();
            var custom_type    = typeof(CustomRenderMeshProvider);
            var options        = new Type[] {};

            foreach (var type in exported_types)
            {
                if (!type.IsAbstract && type.IsSubclassOf(custom_type) && type.GetConstructor(options) != null)
                {
                    provider_types.Add(type);
                }
            }

            if (provider_types.Count == 0)
            {
                return;
            }

            var rdk_plugin = RdkPlugIn.GetRdkPlugIn(plugin);

            if (rdk_plugin == null)
            {
                return;
            }

            foreach (var type in provider_types)
            {
                var provider = Activator.CreateInstance(type) as CustomRenderMeshProvider;
                if (provider == null)
                {
                    continue;
                }
                var cpp_object = provider.CreateCppObject(pluginId);
                if (cpp_object == IntPtr.Zero)
                {
                    continue;
                }
                g_all_providers.Add(provider.m_runtime_serial_number, provider);
                UnsafeNativeMethods.Rdk_RegisterCRMProvider(cpp_object);
            }
        }
        public static void RegisterProviders(System.Reflection.Assembly assembly, System.Guid pluginId)
        {
            Rhino.PlugIns.PlugIn plugin = Rhino.PlugIns.PlugIn.GetLoadedPlugIn(pluginId);
            if (plugin == null)
            {
                return;
            }

            Type[] exported_types = assembly.GetExportedTypes();

            if (exported_types != null)
            {
                List <Type> provider_types = new List <Type>();
                for (int i = 0; i < exported_types.Length; i++)
                {
                    Type t = exported_types[i];
                    if (!t.IsAbstract && t.IsSubclassOf(typeof(Rhino.Render.CustomRenderMesh.Provider)) && t.GetConstructor(new Type[] { }) != null)
                    {
                        provider_types.Add(t);
                    }
                }

                if (provider_types.Count == 0)
                {
                    return;
                }

                RdkPlugIn rdk_plugin = RdkPlugIn.GetRdkPlugIn(plugin);
                if (rdk_plugin == null)
                {
                    return;
                }

                foreach (Type t in provider_types)
                {
                    Provider p = System.Activator.CreateInstance(t) as Provider;
                    if (p == null)
                    {
                        continue;
                    }
                    IntPtr pCppObject = p.CreateCppObject(pluginId);
                    if (pCppObject != IntPtr.Zero)
                    {
                        //rdk_plugin.AddRegisteredCRMProvider(p);
                        m_all_providers.Add(p.m_runtime_serial_number, p);
                        UnsafeNativeMethods.Rdk_RegisterCRMProvider(pCppObject);
                    }
                }
            }
        }
        public static void RegisterSpecialDecorator(this Container container, System.Reflection.Assembly repositoryAssembly, string endString)
        {
            //var repositoryAssembly = type.Assembly;
            var registrations =
                from type in repositoryAssembly.GetExportedTypes()
                //where type.Namespace == "MyComp.MyProd.BL.SqlRepositories"
                where type.Name.ToLower().EndsWith(endString.ToLower())
                where type.GetInterfaces().Any()
                select new { Service = type.GetInterfaces().Single(), Implementation = type };

            foreach (var reg in registrations)
            {
                container.RegisterDecorator(reg.Service, reg.Implementation);
            }
        }
예제 #25
0
        public static void SearchFactor(System.Reflection.Assembly ass)
        {
            Type Factor = typeof(ISerializationFactory <SerializationType>);

            foreach (Type type in ass.GetExportedTypes())
            {
                foreach (Type inter in type.GetInterfaces())
                {
                    if (inter == Factor)
                    {
                        Add(ass.CreateInstance(type.ToString()) as ISerializationFactory <SerializationType>);
                    }
                }
            }
        }
예제 #26
0
        /// <summary>
        /// Gets all migrations that should be executed, ordered by name.
        /// </summary>
        public IEnumerable <IMigration> GetMigrations(IContextManager contextManager, IUpgradeLog log)
        {
            var availableMigrations = _assemblyContainingMigrations
                                      .GetExportedTypes()
                                      .Where(candidateType => typeof(IMigration).IsAssignableFrom(candidateType) &&
                                             !candidateType.IsAbstract &&
                                             candidateType.IsClass &&
                                             candidateType.GetConstructor(Type.EmptyTypes) != null)
                                      .Where(migrationType => _filter(migrationType.FullName))
                                      .Select(migrationType => (IMigration)Activator.CreateInstance(migrationType))
                                      .OrderBy(migration => migration.Name)
                                      .ToList();

            return(availableMigrations);
        }
 public FormToolbox()
 {
     InitializeComponent();
     TopLevel = false;
     Type[] tpsD = this.GetType().Assembly.GetExportedTypes();
     for (int i = 0; i < tpsD.Length; i++)
     {
         if (!tpsD[i].IsAbstract)
         {
             if (tpsD[i].IsSubclassOf(typeof(DrawingItem)))
             {
                 listBox1.AddDrawItem(tpsD[i]);
             }
         }
     }
     //
     //load additional drawings
     string[] ss = System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "drawing*.dll");
     if (ss != null)
     {
         for (int i = 0; i < ss.Length; i++)
         {
             System.Reflection.Assembly a = null;
             try
             {
                 a = System.Reflection.Assembly.LoadFile(ss[i]);
                 if (a != null)
                 {
                     System.Type[] tps = a.GetExportedTypes();
                     if (tps != null)
                     {
                         for (int j = 0; j < tps.Length; j++)
                         {
                             if (!tps[j].IsAbstract && tps[j].IsSubclassOf(typeof(DrawingItem)))
                             {
                                 listBox1.AddDrawItem(tps[j]);
                             }
                         }
                     }
                 }
             }
             catch
             {
             }
         }
     }
 }
예제 #28
0
        static EnumExtensions()
        {
            //let's collect the enums we care about
            List <Type> enumTypeList = new List <Type>();

            //probe this assembly for all enums
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            Type[] exportedTypes = assembly.GetExportedTypes();
            foreach (Type type in exportedTypes)
            {
                if (type.IsEnum)
                {
                    enumTypeList.Add(type);
                }
            }
            //for each enum in our list, populate the appropriate dictionaries
            foreach (Type type in enumTypeList)
            {
                //add dictionaries for this type
                EnumExtensions.enumToStringDictionary.Add(type, new Dictionary <object, string>());
                EnumExtensions.stringToEnumDictionary.Add(type, new Dictionary <string, object>());
                Array values = Enum.GetValues(type);

                //its ok to manipulate 'value' as object, since when we convert we're given the type to cast to
                foreach (object value in values)
                {
                    System.Reflection.FieldInfo fieldInfo = type.GetField(value.ToString());

                    //check for an attribute
                    System.ComponentModel.DescriptionAttribute attribute =
                        Attribute.GetCustomAttribute(fieldInfo,
                                                     typeof(System.ComponentModel.DescriptionAttribute)) as System.ComponentModel.DescriptionAttribute;
                    //populate our dictionaries
                    if (attribute != null)
                    {
                        EnumExtensions.enumToStringDictionary[type].Add(value, attribute.Description);
                        EnumExtensions.stringToEnumDictionary[type].Add(attribute.Description, value);
                    }
                    else
                    {
                        EnumExtensions.enumToStringDictionary[type].Add(value, value.ToString());
                        EnumExtensions.stringToEnumDictionary[type].Add(value.ToString(), value);
                    }
                }
            }
        }
예제 #29
0
 void InsertUnitsFromAssembly(System.Reflection.Assembly assembly)
 {
     Type[] types = assembly.GetExportedTypes();
     foreach (Type type in types)
     {
         if (typeof(CapeOpen.ICapeUnit).IsAssignableFrom(type) && !type.IsAbstract &&
             type != typeof(UnitOperationWrapper))
         {
             UnitOperationInformation unit = new UnitOperationInformation();
             object[] attributes           = type.GetCustomAttributes(true);
             for (int i = 0; i < attributes.Length; i++)
             {
                 if (attributes[i] is CapeNameAttribute)
                 {
                     unit.Name = ((CapeNameAttribute)attributes[i]).Name;
                 }
                 if (attributes[i] is CapeDescriptionAttribute)
                 {
                     unit.Description = ((CapeDescriptionAttribute)attributes[i]).Description;
                 }
                 if (attributes[i] is CapeVersionAttribute)
                 {
                     unit.CapeVersion = ((CapeVersionAttribute)attributes[i]).Version;
                 }
                 if (attributes[i] is CapeVendorURLAttribute)
                 {
                     unit.VendorURL = ((CapeVendorURLAttribute)attributes[i]).VendorURL;
                 }
                 if (attributes[i] is CapeHelpURLAttribute)
                 {
                     unit.HelpURL = ((CapeHelpURLAttribute)attributes[i]).HelpURL;
                 }
                 if (attributes[i] is CapeAboutAttribute)
                 {
                     unit.About = ((CapeAboutAttribute)attributes[i]).About;
                 }
                 unit.ProgID   = type.FullName;
                 unit.Assembly = assembly.FullName;
             }
             unit.Type = type;
             m_UnitOperations.Add(unit);
             m_DotNetUnitOperations.Add(unit);
         }
     }
 }
 public void LoadData(bool bHotspotsOnly)
 {
     Type[] tpsD = this.GetType().Assembly.GetExportedTypes();
     for (int i = 0; i < tpsD.Length; i++)
     {
         if (!tpsD[i].IsAbstract)
         {
             if (tpsD[i].IsSubclassOf(typeof(DrawingItem)))
             {
                 addType(tpsD[i], bHotspotsOnly);
             }
         }
     }
     //
     //load additional drawings
     string[] ss = System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "drawing*.dll");
     if (ss != null)
     {
         for (int i = 0; i < ss.Length; i++)
         {
             System.Reflection.Assembly a = null;
             try
             {
                 a = System.Reflection.Assembly.LoadFile(ss[i]);
                 if (a != null)
                 {
                     System.Type[] tps = a.GetExportedTypes();
                     if (tps != null)
                     {
                         for (int j = 0; j < tps.Length; j++)
                         {
                             if (!tps[j].IsAbstract && tps[j].IsSubclassOf(typeof(DrawingItem)))
                             {
                                 addType(tps[j], bHotspotsOnly);
                             }
                         }
                     }
                 }
             }
             catch
             {
             }
         }
     }
 }