Esempio n. 1
0
        /// <summary>
        /// 根据插件的配置文件得到插件的描述。
        /// </summary>
        /// <param name="configFile">插件的置文件。</param>
        /// <param name="owner">拥有此描述符的插件节点。</param>
        /// <returns>插件的描述。</returns>
        public static AddinDescriptor Parse(String configFile, AddinNode owner)
        {
            if (!File.Exists(configFile))
            {
                throw new FileNotFoundException(configFile);
            }
            XElement xml = XElement.Load(configFile)?.Element("Runtimes");

            if (xml == null)
            {
                throw new FileLoadException("Invalid addin config file");
            }
            IEnumerable <XAttribute> referencesAttr = xml.Element("Assemblies")?.Elements("Reference")?.Attributes("Path");

            String[] references = null;
            if (referencesAttr != null && referencesAttr.Count() != 0)
            {
                references = referencesAttr.Select(x => x.Value).ToArray();
            }
            IEnumerable <XAttribute> dependenciesAttr = xml.Element("Dependencies")?.Elements("Dependency")?.Attributes("Path");

            String[] dependencies = null;
            if (dependenciesAttr != null && dependenciesAttr.Count() != 0)
            {
                dependencies = dependenciesAttr.Select(x => x.Value).ToArray();
            }
            return(new AddinDescriptor(xml.Attribute("Type")?.Value, owner, references, dependencies));
        }
Esempio n. 2
0
        /// <summary>
        /// 卸载插件。
        /// </summary>
        /// <param name="addinNode">插件树节点。</param>
        public void Uninstall(AddinNode addinNode)
        {
            if (!_isInit)
            {
                throw new InvalidOperationException("Need initialize");
            }
            String addinConfigFile = addinNode.AddinConfigFile;

            UninstalImpl(addinConfigFile);
        }
Esempio n. 3
0
 /// <summary>
 /// 初始化类型 Tumbler.Addin.Core.AddinDescriptor 实例。
 /// </summary>
 /// <param name="type">实现了IAddin接口的类型名称。</param>
 /// <param name="owner">拥有此描述符的插件节点。</param>
 /// <param name="references"></param>
 /// <param name="depedencies"></param>
 private AddinDescriptor(String type, AddinNode owner, String[] references, String[] depedencies)
 {
     if (String.IsNullOrWhiteSpace(type))
     {
         throw new ArgumentNullException("type");
     }
     if (owner == null)
     {
         throw new ArgumentNullException("owner");
     }
     Owner      = owner;
     Type       = type;
     References = references;
     if (depedencies != null)
     {
         Dependencies = depedencies.Select(x => AddinTreeNode.CompletePath(x)).ToArray();
     }
 }
Esempio n. 4
0
        /// <summary>
        /// 初始化插件状态。
        /// </summary>
        private void InitializeAddinState()
        {
            if (Dependencies == null)
            {
                return;
            }
            AddinState state;
            AddinNode  node = null;

            for (Int32 i = 0; i < Dependencies.Length; i++)
            {
                node = AddinManager.Instance.GetNode(Dependencies[i]) as AddinNode;
                if (node == null)
                {
                    state = AddinState.Unknow;
                }
                else
                {
                    state = node.Descriptor.IsValueCreated ? node.Descriptor.Value.Addin.State : AddinState.Unknow;
                }
                Addin.OnDependencyStateChanged(Dependencies[i], state);
            }
        }