Пример #1
0
        /// <summary>
        /// 停止依赖该服务的其它服务。
        /// </summary>
        /// <param name="service">主服务。</param>
        internal void StopDependencies(IService service)
        {
            if (!_isInit)
            {
                throw new InvalidOperationException("Need initialize");
            }
            AddinDescriptor descriptor = AddinDescriptor.FindAddinDescriptor(service);

            if (descriptor == null)
            {
                throw new InvalidOperationException("This service is out of control");
            }
            Collection <AddinDescriptor> children = AddinDescriptor.GetDependencies(descriptor.Owner.FullPath);

            if (children == null)
            {
                return;
            }
            AddinDescriptor temp = null;
            IService        s    = null;

            for (Int32 i = 0; i < children.Count; i++)
            {
                temp = children[i];
                if (temp.BuildState != AddinBuildState.Build)
                {
                    continue;
                }
                s = temp.Addin as IService;
                if (s != null && s.State == AddinState.IncludeOrRuning)
                {
                    s.Stop();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 向其它插件发送消息。
        /// </summary>
        /// <param name="message">消息。</param>
        private void SendMessageImpl <TContent>(MessageArgs <TContent> message)
        {
            if (!_isInit)
            {
                throw new InvalidOperationException("Need initialize");
            }
            IEnumerable <AddinNode> nodes = GetNode(message.Destination).OfType <AddinNode>();

            if (nodes == null)
            {
                return;
            }
            foreach (AddinNode node in nodes)
            {
                if (node == message.Sender)
                {
                    continue;
                }
                AddinDescriptor descriptor = node.Descriptor.IsValueCreated ? node.Descriptor.Value : null;
                if (descriptor != null && descriptor.BuildState == AddinBuildState.Build)
                {
                    IHandler <TContent> handler = descriptor.Addin as IHandler <TContent>;
                    if (handler == null)
                    {
                        return;
                    }
                    handler.Handle(message);
                }
            }
        }
Пример #3
0
 /// <summary>
 /// 初始化类型 Tumbler.Addin.Core.AddinNode 实例。
 /// </summary>
 /// <param name="mountTo">要挂载到的节点。</param>
 /// <param name="mountExpose">要挂载到的节点中的挂载点。</param>
 /// <param name="id">插件Id。</param>
 /// <param name="guid">插件的Guid。</param>
 /// <param name="exposes">向外提供的挂载点。</param>
 /// <param name="addinConfigFile">插件的配置文件。</param>
 public AddinNode(String mountTo, String mountExpose, String id, Guid guid, String[] exposes, String addinConfigFile)
     : base(mountTo, mountExpose, id, exposes)
 {
     if (String.IsNullOrWhiteSpace(addinConfigFile))
     {
         throw new ArgumentNullException("configFile");
     }
     Guid            = guid;
     AddinConfigFile = addinConfigFile;
     Descriptor      = new Lazy <AddinDescriptor>(() => AddinDescriptor.Parse(AddinConfigFile, this));
 }
Пример #4
0
        /// <summary>
        /// 获取插件的暴露点。
        /// </summary>
        /// <param name="addin">插件。</param>
        /// <returns>插件的暴露点。</returns>
        internal String[] GetExposes(IAddin addin)
        {
            if (!_isInit)
            {
                throw new InvalidOperationException("Need initialize");
            }
            AddinDescriptor descriptor = AddinDescriptor.FindAddinDescriptor(addin);

            if (descriptor == null)
            {
                return(null);
            }
            return(descriptor.Owner.Exposes);
        }
Пример #5
0
        /// <summary>
        /// 销毁插件。
        /// </summary>
        /// <param name="addin">插件。</param>
        internal void Destroy(IAddin addin)
        {
            if (!_isInit)
            {
                throw new InvalidOperationException("Need initialize");
            }
            AddinDescriptor descriptor = AddinDescriptor.FindAddinDescriptor(addin);

            if (descriptor == null)
            {
                throw new InvalidOperationException("This addin is out of control");
            }
            descriptor.Destroy();
        }
Пример #6
0
        /// <summary>
        /// 获取插件的子插件列表。
        /// </summary>
        /// <param name="addin">插件。</param>
        /// <returns>子插件列表。</returns>
        internal IAddin[] GetChildAddins(IAddin addin)
        {
            if (!_isInit)
            {
                throw new InvalidOperationException("Need initialize");
            }
            AddinDescriptor descriptor = AddinDescriptor.FindAddinDescriptor(addin);

            if (descriptor == null)
            {
                throw new InvalidOperationException("This addin is out of control");
            }
            String[] exposes = descriptor.Owner.Exposes;
            return(GetChildsImpl(descriptor.Owner));
        }
Пример #7
0
        /// <summary>
        /// 构建指定插件的下一级插件列表。
        /// </summary>
        /// <param name="addin">下一级插件的父级插件。</param>
        /// <returns>下一级插件列表。</returns>
        internal IAddin[] BuildChildAddins(IAddin addin)
        {
            if (!_isInit)
            {
                throw new InvalidOperationException("Need initialize");
            }
            AddinDescriptor descriptor = AddinDescriptor.FindAddinDescriptor(addin);

            if (descriptor == null)
            {
                throw new InvalidOperationException("This addin is out of control");
            }
            IList <IAddin> addins = new List <IAddin>();

            BuildImpl(descriptor.Owner, ref addins);
            return(addins.ToArray());
        }
Пример #8
0
        /// <summary>
        /// 通知插件数据已经改变。
        /// </summary>
        /// <param name="addin">状态改变的插件。</param>
        /// <param name="name">数据名称。</param>
        /// <param name="newData">新数据。</param>
        /// <param name="oldData">旧数据。</param>
        internal void NotifyDataChanged(IAddin addin, String name, Object newData, Object oldData)
        {
            if (!_isInit)
            {
                throw new InvalidOperationException("Need initialize");
            }
            AddinDescriptor descriptor = AddinDescriptor.FindAddinDescriptor(addin);
            String          fullPath   = descriptor.Owner.FullPath;
            Collection <AddinDescriptor> descriptors = AddinDescriptor.GetDependencies(fullPath);

            if (descriptors == null || descriptors.Count == 0)
            {
                return;
            }
            for (Int32 i = 0; i < descriptors.Count; i++)
            {
                if (descriptors[i].BuildState == AddinBuildState.Build)
                {
                    descriptors[i].Addin.OnDataChanged(fullPath, name, newData, oldData);
                }
            }
        }