• 大小: 128KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: C#
  • 标签: 插件平台  

资源简介

【京华志】【www.jinghuazhi.com】C# 动态链接机制 插件平台 利用AppDomain实现对DLL的动态加载和卸载。.rar

资源截图

代码片段和文件信息

namespace Plugin
{
    /********************************************************************
    *           Copyright:       2009-2010
    *           Company:         CFO
    *           CRL Version :    4.0.30319.1
    *           Created by XUYI at 2010/8/10 16:39:15
    *                   mailto:xuyi_71@qq.com
    *                          研发中心
    ********************************************************************/

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class SmartPluginContainer : ISmartPluginContainer
    {
        private static object _syncobject = new object();
        private IDictionary domainContainer;
        private IDictionary pluginContainer;

        public SmartPluginContainer()
        {
            pluginContainer = new Dictionary();
            domainContainer = new Dictionary();
        }

        public void AddDomain(string key ISmartPluginDomainConnector item)
        {
            lock (_syncobject)
            {
                if (!domainContainer.ContainsKey(key))
                    domainContainer.Add(key item);

                foreach (var domain in item.Plugins)
                {
                    if (!pluginContainer.ContainsKey(domain.Key))
                        pluginContainer.Add(domain);
                }
            }
        }

        public ISmartPluginDomainConnector GetDomain(string key)
        {
            if (domainContainer.ContainsKey(key))
                return domainContainer[key];
            return null;
        }

        public void Unload(string key)
        {
            lock (_syncobject)
            {
                if (!domainContainer.ContainsKey(key))
                    return;
                foreach (var item in domainContainer[key].Plugins)
                {
                    if (pluginContainer.ContainsKey(item.Key))
                        pluginContainer.Remove(item.Key);
                }
                domainContainer[key].Dispose();
                domainContainer.Remove(key);
#if DEBUG
                Console.WriteLine(“     unload {0} done ...“ key);
#endif
            }
        }

        public void UnloadAll()
        {
            lock (_syncobject)
            {
                foreach (var key in domainContainer.Keys)
                {
                    domainContainer[key].Dispose();
#if DEBUG
                    Console.WriteLine(“     unload {0} done ...“ key);
#endif
                }
                domainContainer.Clear();
                pluginContainer.Clear();
            }
        }

        public IDictionary Plugins
        {
            get { return pluginContainer; }
        }

        public IList

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      11776  2011-08-01 14:29  PluginSample\bin\Debug\Plugin.dll

     文件      52736  2011-08-01 14:29  PluginSample\bin\Debug\Plugin.pdb

     文件       4096  2011-08-01 14:29  PluginSample\bin\Debug\PluginSample.dll

     文件      13824  2011-08-01 14:29  PluginSample\bin\Debug\PluginSample.pdb

     文件       5846  2011-08-01 14:29  PluginSample\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1033  2011-08-01 14:27  PluginSample\obj\Debug\PluginSample.csproj.FileListAbsolute.txt

     文件       4096  2011-08-01 14:29  PluginSample\obj\Debug\PluginSample.dll

     文件      13824  2011-08-01 14:29  PluginSample\obj\Debug\PluginSample.pdb

     文件       3223  2011-04-21 22:25  PluginSample\obj\Debug\ResolveAssemblyReference.cache

     文件       2473  2011-04-21 21:20  PluginSample\PluginSample.csproj

     文件       1356  2011-04-21 21:15  PluginSample\Properties\AssemblyInfo.cs

     文件        965  2011-04-21 22:25  PluginSample\Sample1.cs

     文件      11776  2011-08-01 14:29  PluginSample1\bin\Debug\Plugin.dll

     文件      52736  2011-08-01 14:29  PluginSample1\bin\Debug\Plugin.pdb

     文件       4608  2011-08-01 14:29  PluginSample1\bin\Debug\PluginSample1.dll

     文件      13824  2011-08-01 14:29  PluginSample1\bin\Debug\PluginSample1.pdb

     文件       1095  2011-04-21 22:35  PluginSample1\Class1.cs

     文件       5848  2011-08-01 14:29  PluginSample1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1055  2011-08-01 14:27  PluginSample1\obj\Debug\PluginSample1.csproj.FileListAbsolute.txt

     文件       4608  2011-08-01 14:29  PluginSample1\obj\Debug\PluginSample1.dll

     文件      13824  2011-08-01 14:29  PluginSample1\obj\Debug\PluginSample1.pdb

     文件       2474  2011-04-21 22:35  PluginSample1\PluginSample1.csproj

     文件       1358  2011-04-21 22:34  PluginSample1\Properties\AssemblyInfo.cs

     文件       4948  2011-08-01 14:27  PluginConnector.sln

     文件      11776  2011-08-01 14:29  Plugin\bin\Debug\Plugin.dll

     文件      52736  2011-08-01 14:29  Plugin\bin\Debug\Plugin.pdb

     文件        634  2011-04-21 21:31  Plugin\Interfaces\ISmartPlugin.cs

     文件        804  2011-04-21 21:31  Plugin\Interfaces\ISmartPluginConnector.cs

     文件        997  2011-04-21 21:38  Plugin\Interfaces\ISmartPluginContainer.cs

     文件        954  2011-04-21 21:31  Plugin\Interfaces\ISmartPluginDomainConnector.cs

............此处省略70个文件信息

评论

共有 条评论

相关资源