Ejemplo n.º 1
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="modID">The unique ID of the relevant mod.</param>
 /// <param name="registry">The underlying mod registry.</param>
 /// <param name="proxyBuilder">Generates proxy classes to access mod APIs through an arbitrary interface.</param>
 /// <param name="monitor">Encapsulates monitoring and logging for the mod.</param>
 public ModRegistryHelper(string modID, ModRegistry registry, InterfaceProxyBuilder proxyBuilder, IMonitor monitor)
     : base(modID)
 {
     this.Registry     = registry;
     this.ProxyBuilder = proxyBuilder;
     this.Monitor      = monitor;
 }
Ejemplo n.º 2
0
        public PluginLoader(string targetAssembly, string pluginPath)
            : base(targetAssembly, pluginPath)
        {
            var pluginImpl = ((RemotePluginLoader <T>)remoteTypeLoader).Plugin;
            //if (false) // 没有发现需要序列化的对象
            //{
            //枚举每个函数, 检查返回值类型定义, 如果标记 DomainSerializableAttribute ,
            ///生成代理类型,里面含有序列化反序列化相对应的信息
            Type targetType = typeof(T);



            T proxyProxy = InterfaceProxyBuilder <T> .CreateProxy(pluginImpl, typeof(LoaderHost <>).MakeGenericType(targetType), true, typeof(SerializableObject <>),
                                                                  proxyType =>
            {
                return(proxyType.GetConstructor(new Type[] { targetType, typeof(RemotePluginLoader <T>) }).Invoke(new object[] { pluginImpl, remoteTypeLoader }) as T);
            });

            this.Plugin = proxyProxy;

            //}
            //else
            //{
            //    this.Plugin = pluginImpl;
            //}
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 构造一个代理类,保存在 ProxyPlugin 属性中
        /// </summary>
        /// <param name="loader"></param>
        public PluginCallerProxy(PluginLoader <T> loader)
        {
            this.PluginLoader = loader;
            this.TargetPlugin = loader.Plugin;

            //从函数生成代理类
            this._proxyPlugin = InterfaceProxyBuilder <T> .CreateFuncProxy(() => this.TargetPlugin, typeof(object));
        }
Ejemplo n.º 4
0
        private void button5_Click(object sender, EventArgs e)
        {
            var proxy = InterfaceProxyBuilder <IPlugin> .CreateProxy(new TestPlugin(), typeof(object));

            proxy.Run(DateTime.Now.ToString());
            proxy.Run(DateTime.Now.ToString(), () => { Debug.Print("OK"); });
            proxy.Run(DateTime.Now.ToString(), () => { Debug.Print("OK"); return("OK"); });

            var proxy2 = InterfaceProxyBuilder <IPlugin> .CreateFuncProxy(() => new TestPlugin(), typeof(object));

            proxy2.Run(DateTime.Now.ToString());
            proxy2.Run(DateTime.Now.ToString(), () => { Debug.Print("OK"); });
            proxy2.Run(DateTime.Now.ToString(), () => { Debug.Print("OK"); return("OK"); });
        }
Ejemplo n.º 5
0
        protected override System.Reflection.Assembly LoadAssembly(string assemblyPath)
        {
            var ass = base.LoadAssembly(assemblyPath);

            //查找插件
            Type typePlugin = typeof(T);

            this.pluginType = ass.GetTypes().Where(t => typePlugin.IsAssignableFrom(t)).FirstOrDefault();

            if (this.pluginType == null)
            {
                throw new DssPluginException("找不到实现" + typePlugin.FullName + "的类型");
            }

            //生成代理插件类,并从MarshalByRefObject继承以支持AppDomain通信
            this.Plugin = InterfaceProxyBuilder <T> .CreateProxy((T)System.Activator.CreateInstance(pluginType),
                                                                 typeof(MarshalByRefObject), true, typeof(SerializableMarshalByRefObject <>));

            return(ass);
        }
        public void InterfaceProxyBuilder_CreateInterfaceProxy()
        {
            var t = InterfaceProxyBuilder.BuildProxyType <ITest, TestClass>();

            Assert.IsNotNull(t);
        }
 public void InterfaceProxyBuilder_CreateInterfaceProxy_Throws_WhenTypeIsNotDerivedFromInterface()
 {
     Assert.Throws <ArgumentException>(delegate { InterfaceProxyBuilder.BuildProxyType(typeof(IGenericTest <int>), typeof(TestClass)); });
 }
 public void InterfaceProxyBuilder_CreateInterfaceProxy_Throws_WhenNotInterface()
 {
     Assert.Throws <ArgumentException>(delegate { InterfaceProxyBuilder.BuildProxyType(typeof(void), typeof(void)); });
 }