Пример #1
0
            /// <summary>
            /// Load the plugin.
            /// </summary>
            private void _load(object caller)
            {
                string file = this.File;

                System.Reflection.Assembly assembly = Manager._loadAssembly(file);
                this.Assembly = Assembly;
                if (null == assembly)
                {
                    return;
                }

                using (ClassFactoryHandle factory = new ClassFactoryHandle(Manager._createClassFactory(assembly, file)))
                {
                    if (false == factory.Valid)
                    {
                        return;
                    }

                    using (PluginHandle plugin = new PluginHandle(Manager._createInstance(factory.Value, file)))
                    {
                        this.Handle = plugin.Value;
                        if (false == plugin.Valid)
                        {
                            return;
                        }
                        plugin.Value.start(caller);
                    }
                }
            }
Пример #2
0
 /// <summary>
 /// Return a new class factory.
 /// </summary>
 private static CadKit.Interfaces.IClassFactory _createClassFactory(System.Reflection.Assembly assembly, string file)
 {
     try
     {
         object temp = assembly.CreateInstance("CadKit.Plugins.Factory");
         if (null == temp)
         {
             throw new System.Exception(System.String.Format("Error 3490341679: failed to create class factory in assembly file: {0}", file));
         }
         using (ClassFactoryHandle factory = new ClassFactoryHandle(temp as CadKit.Interfaces.IClassFactory))
         {
             if (false == factory.Valid)
             {
                 throw new System.Exception(System.String.Format("Error 1228345170: object created assembly file '{0}' is not a factory", file));
             }
             return(factory.release());
         }
     }
     catch (System.Exception e)
     {
         System.Console.WriteLine("Error 2104420766: Failed to create class factory in assembly file '{0}', {1}", file, e.Message);
         throw;
     }
 }