Esempio n. 1
0
        internal object ResolvePath(string text, PluginTreeNode current, ObtainMode obtainMode)
        {
            PluginPathType pathType;
            string         path;

            string[] memberNames;

            if (!PluginPath.TryResolvePath(text, out pathType, out path, out memberNames))
            {
                throw new PluginException(string.Format("Resolve ‘{0}’ plugin-path was failed.", text));
            }

            PluginTreeNode node = null;

            switch (pathType)
            {
            case PluginPathType.Rooted:
                node = _pluginTree.RootNode;
                break;

            case PluginPathType.Parent:
                node = current.Parent;
                break;

            case PluginPathType.Current:
                node = current;
                break;
            }

            if (node != null && (!string.IsNullOrWhiteSpace(path)))
            {
                node = node.Find(path);
            }

            //注意:如果没有找到指定路径的对象不需要写日志,在ServicesParser解析中需要先在默认工厂查询指定路径的服务如果查找失败则查找服务工厂集
            if (node == null)
            {
                return(null);
            }

            try
            {
                //获取指定路径的目标对象
                object target = node.UnwrapValue(obtainMode, this, null);

                if (target != null && memberNames.Length > 0)
                {
                    return(Tiandao.Common.Converter.GetValue(target, memberNames));
                }

                return(target);
            }
            catch (Exception ex)
            {
                var fileName = string.Empty;

                if (current != null && current.Plugin != null)
                {
                    fileName = System.IO.Path.GetFileName(current.Plugin.FilePath);
                }

                throw new PluginException(FailureCodes.InvalidPath, string.Format("Resolve target error from '{0}' path in '{1}' plugin file.", text, fileName), ex);
            }
        }