internal object Resolve(string pathText = null, ObtainMode obtainMode = ObtainMode.Auto, Type targetType = null) { var node = this; Reflection.Expressions.IMemberExpression accessor = null; if (!string.IsNullOrWhiteSpace(pathText)) { var expression = Collections.HierarchicalExpression.Parse(pathText); node = this.Find(expression.Path) ?? throw new PluginException($"Not found the PluginTreeNode with '{expression.Path}' path."); accessor = expression.Accessor; } //获取指定路径的目标对象 object target = node.UnwrapValue(obtainMode, targetType == null ? null : new Builders.BuilderSettings(targetType)); if (target != null && accessor != null) { return(Reflection.Expressions.MemberExpressionEvaluator.Default.GetValue(accessor, target)); } return(target); }
public object GetValue(ObtainMode obtainMode, Builders.BuilderSettings settings = null) { switch (obtainMode) { case ObtainMode.Alway: //注意:当获取方式为始终创建新的实例时,必须忽略后续的追加操作, //以避免将重复新建的实例追加到所有者集合中可能导致的集合项键冲突的错误。 if (settings == null) { settings = Builders.BuilderSettings.Ignores(Builders.BuilderSettingsFlags.IgnoreAppending); } else { settings.SetFlags(Builders.BuilderSettingsFlags.IgnoreAppending); } return(this.Build(settings)); case ObtainMode.Auto: if (_value == null) { lock (_syncRoot) { if (_value == null) { return(this.Build(settings)); } } } break; } return(_value); }
public object GetValue(ObtainMode obtainMode, object parameter = null, Action <Builders.BuilderContext> build = null) { switch (obtainMode) { case ObtainMode.Alway: //注意:当获取方式为始终创建新的实例时,必须忽略后续的追加操作(即设置上下文的追加器属性为空), //以避免将重复新建的实例追加到所有者集合中可能导致的集合项键冲突的错误。 return(this.Build(parameter, build, ctx => ctx.Appender = null)); case ObtainMode.Auto: if (_value == null) { lock (_syncRoot) { if (_value == null) { return(this.Build(parameter, build)); } } } break; } return(_value); }
public static void WritePluginNode(ITerminal terminal, PluginTreeNode node, ObtainMode obtainMode, int maxDepth) { if(node == null) return; terminal.Write(TerminalColor.DarkYellow, "[{0}]", node.NodeType); terminal.WriteLine(node.FullPath); terminal.Write(TerminalColor.DarkYellow, "Plugin File: "); if(node.Plugin == null) terminal.WriteLine(TerminalColor.Red, "N/A"); else terminal.WriteLine(node.Plugin.FilePath); terminal.Write(TerminalColor.DarkYellow, "Node Properties: "); terminal.WriteLine(node.Properties.Count); if(node.Properties.Count > 0) { terminal.WriteLine(TerminalColor.Gray, "{"); foreach(PluginExtendedProperty property in node.Properties) { terminal.Write(TerminalColor.DarkYellow, "\t" + property.Name); terminal.Write(" = "); terminal.Write(property.RawValue); if(property.Value != null) { terminal.Write(TerminalColor.DarkGray, " ["); terminal.Write(TerminalColor.Blue, property.Value.GetType().FullName); terminal.Write(TerminalColor.DarkGray, "]"); } terminal.WriteLine(); } terminal.WriteLine(TerminalColor.Gray, "}"); } terminal.WriteLine(TerminalColor.DarkYellow, "Children: {0}", node.Children.Count); if(node.Children.Count > 0) { terminal.WriteLine(); foreach(var child in node.Children) { terminal.WriteLine(child); } } object value = node.UnwrapValue(obtainMode, null); if(value != null) { terminal.WriteLine(); Zongsoft.Runtime.Serialization.Serializer.Text.Serialize(terminal.OutputStream, value); } }
public object UnwrapValue(ObtainMode obtainMode, object parameter, Action <Builders.BuilderContext> build) { if (_nodeType == PluginTreeNodeType.Builtin) { return(((Builtin)_value).GetValue(obtainMode, parameter, build)); } return(_value); }
public object UnwrapValue(ObtainMode obtainMode, Builders.BuilderSettings settings = null) { if (_nodeType == PluginTreeNodeType.Builtin) { return(((Builtin)_value).GetValue(obtainMode, settings)); } return(_value); }
internal string ResolveText(string text, out ObtainMode mode) { mode = ObtainMode.Auto; if (string.IsNullOrWhiteSpace(text)) { return(text); } var parts = text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { Enum.TryParse <ObtainMode>(parts[1], true, out mode); } return(parts[0]); }
internal object ResolvePath(string pathText, PluginTreeNode origin, ObtainMode obtainMode) { if (string.IsNullOrWhiteSpace(pathText)) { throw new ArgumentNullException(nameof(pathText)); } var expression = PluginPath.Parse(pathText); var node = origin.Find(expression.Path); if (node == null) { throw new PluginException($"Not found the PluginTreeNode with '{expression.Path}' path."); } try { //获取指定路径的目标对象 object target = node.UnwrapValue(obtainMode, this, null); if (target != null && expression.Members.Length > 0) { return(Reflection.MemberAccess.GetMemberValue <object>(target, expression.Members)); } return(target); } catch (Exception ex) { var fileName = string.Empty; if (origin != null && origin.Plugin != null) { fileName = System.IO.Path.GetFileName(origin.Plugin.FilePath); } throw new PluginException(string.Format("Resolve target error from '{0}' path in '{1}' plugin file.", pathText, fileName), ex); } }
internal static string PreparePathText(string text, out ObtainMode mode) { mode = ObtainMode.Auto; if (string.IsNullOrEmpty(text)) { return(string.Empty); } var index = text.LastIndexOf(','); if (index < 0) { return(text); } if (index < text.Length - 1) { Enum.TryParse <ObtainMode>(text.Substring(index + 1), true, out mode); } return(text.Substring(0, index)); }
public object GetValue(ObtainMode obtainMode, object parameter, Action <Builders.BuilderContext> build) { switch (obtainMode) { case ObtainMode.Alway: return(this.Build(parameter, build)); case ObtainMode.Auto: if (_value == null) { lock (_syncRoot) { if (_value == null) { return(this.Build(parameter, build)); } } } break; } return(_value); }
public object ResolvePath(string pathText, ObtainMode obtainMode) { return(this.ResolvePath(pathText, null, obtainMode)); }
public T UnwrapValue <T>(ObtainMode obtainMode, object parameter, Action <Builders.BuilderContext> build) { return(Tiandao.Common.Converter.ConvertValue <T>(this.UnwrapValue(obtainMode, parameter, build))); }
public T UnwrapValue <T>(ObtainMode obtainMode, object parameter) { return(this.UnwrapValue <T>(obtainMode, parameter, null)); }
public static void PrintPluginNode(ICommandOutlet output, PluginTreeNode node, ObtainMode obtainMode, int maxDepth) { if (node == null) { return; } output.Write(CommandOutletColor.DarkYellow, "[{0}]", node.NodeType); output.WriteLine(node.FullPath); output.Write(CommandOutletColor.DarkYellow, "Plugin File: "); if (node.Plugin == null) { output.WriteLine(CommandOutletColor.Red, "N/A"); } else { output.WriteLine(node.Plugin.FilePath); } output.Write(CommandOutletColor.DarkYellow, "Node Properties: "); output.WriteLine(node.Properties.Count); if (node.Properties.Count > 0) { output.WriteLine(CommandOutletColor.Gray, "{"); foreach (PluginExtendedProperty property in node.Properties) { output.Write(CommandOutletColor.DarkYellow, "\t" + property.Name); output.Write(" = "); output.Write(property.RawValue); if (property.Value != null) { output.Write(CommandOutletColor.DarkGray, " ["); output.Write(CommandOutletColor.Blue, property.Value.GetType().FullName); output.Write(CommandOutletColor.DarkGray, "]"); } output.WriteLine(); } output.WriteLine(CommandOutletColor.Gray, "}"); } output.WriteLine(CommandOutletColor.DarkYellow, "Children: {0}", node.Children.Count); if (node.Children.Count > 0) { output.WriteLine(); foreach (var child in node.Children) { output.WriteLine(child); } } object value = node.UnwrapValue(obtainMode); if (value != null) { var json = JsonSerializer.Serialize(value, new JsonSerializerOptions() { MaxDepth = maxDepth, WriteIndented = true, ReferenceHandler = ReferenceHandler.Preserve, }); output.WriteLine(); output.WriteLine(json); } }
public T UnwrapValue <T>(ObtainMode obtainMode, object parameter = null, Action <Builders.BuilderContext> build = null) { return(Zongsoft.Common.Convert.ConvertValue <T>(this.UnwrapValue(obtainMode, parameter, build))); }
public object GetValue(ObtainMode obtainMode, object parameter = null) { return(this.GetValue(obtainMode, parameter, null)); }
public static void PrintPluginNode(ICommandOutlet output, PluginTreeNode node, ObtainMode obtainMode, int maxDepth) { if (node == null) { return; } output.Write(CommandOutletColor.DarkYellow, "[{0}]", node.NodeType); output.WriteLine(node.FullPath); output.Write(CommandOutletColor.DarkYellow, "Plugin File: "); if (node.Plugin == null) { output.WriteLine(CommandOutletColor.Red, "N/A"); } else { output.WriteLine(node.Plugin.FilePath); } output.Write(CommandOutletColor.DarkYellow, "Node Properties: "); output.WriteLine(node.Properties.Count); if (node.Properties.Count > 0) { output.WriteLine(CommandOutletColor.Gray, "{"); foreach (PluginExtendedProperty property in node.Properties) { output.Write(CommandOutletColor.DarkYellow, "\t" + property.Name); output.Write(" = "); output.Write(property.RawValue); if (property.Value != null) { output.Write(CommandOutletColor.DarkGray, " ["); output.Write(CommandOutletColor.Blue, property.Value.GetType().FullName); output.Write(CommandOutletColor.DarkGray, "]"); } output.WriteLine(); } output.WriteLine(CommandOutletColor.Gray, "}"); } output.WriteLine(CommandOutletColor.DarkYellow, "Children: {0}", node.Children.Count); if (node.Children.Count > 0) { output.WriteLine(); foreach (var child in node.Children) { output.WriteLine(child); } } object value = node.UnwrapValue(obtainMode, null); if (value != null) { output.WriteLine(); output.WriteLine(Zongsoft.Runtime.Serialization.Serializer.Text.Serialize(value)); } }
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); } }