Пример #1
0
        protected override object OnExecute(CommandContext context)
        {
            if (context.Expression.Arguments.Length == 0)
            {
                throw new CommandException(ResourceUtility.GetString("Text.Message.MissingCommandArguments"));
            }

            var result = new PluginTreeNode[context.Expression.Arguments.Length];

            for (int i = 0; i < context.Expression.Arguments.Length; i++)
            {
                result[i] = _pluginContext.PluginTree.Find(context.Expression.Arguments[i]);

                if (result[i] == null)
                {
                    context.Output.WriteLine(CommandOutletColor.DarkRed, ResourceUtility.GetString("Text.Message.PluginNodeNotFound", context.Expression.Arguments[i]));
                }

                Utility.PrintPluginNode(context.Output, result[i],
                                        context.Expression.Options.GetValue <ObtainMode>("obtain"),
                                        context.Expression.Options.GetValue <int>("maxDepth"));
            }

            if (result.Length == 1)
            {
                return(result[0]);
            }

            return(result);
        }
        //注意:该方法不需要递归自调用,因为PluginTreeNode对象的Build方法会内部进行子节点的构建
        private void GeneratePageContent(Page page, PluginTreeNode ownerNode)
        {
            if (ownerNode == null)
            {
                return;
            }

            string place = string.Empty;

            foreach (PluginTreeNode childNode in ownerNode.Children)
            {
                if (childNode.NodeType == PluginTreeNodeType.Empty)
                {
                    continue;
                }

                //只有当前节点的目标类型为控件时,才需要构建它们
                if (typeof(System.Web.UI.Control).IsAssignableFrom(childNode.ValueType))
                {
                    place = childNode.Properties.GetValue <string>("place");

                    //if(childNode.NodeType == PluginTreeNodeType.Builtin)
                    //    place = ((Builtin)childNode.Value).Properties.GetValue<string>("place");

                    Control placeControl = this.FindPlaceControl(page, place);
                    if (placeControl != null)
                    {
                        childNode.UnwrapValue(ObtainMode.Alway);
                    }
                }
            }
        }
Пример #3
0
        private void GetServices(IList <System.ServiceProcess.ServiceBase> services, PluginTreeNode node)
        {
            if (services == null || node == null)
            {
                return;
            }

            if (node.NodeType != PluginTreeNodeType.Empty)
            {
                object value = node.UnwrapValue(ObtainMode.Auto, this, null);

                if (value is System.ServiceProcess.ServiceBase)
                {
                    services.Add((System.ServiceProcess.ServiceBase)value);
                }
                else if (value is IWorker)
                {
                    //注意:服务的运行时的名称与安装时注册使用的名称必须相同,但服务的注册名与Worker的Name属性并不确保一致!
                    //因此,运行时必须使用节点名作为后台服务的名称,以确保与服务安装过程中的注册名一致。
                    services.Add(new ServiceWrapper((IWorker)value, node.Name));
                }
            }

            foreach (PluginTreeNode child in node.Children)
            {
                this.GetServices(services, child);
            }
        }
Пример #4
0
        private object Build(Builtin builtin, object parameter, object owner, PluginTreeNode ownerNode)
        {
            //获取当前构件的构建器对象
            IBuilder builder = this.GetBuilder(builtin);

            return(this.BuildCore(builder, BuilderContext.CreateContext(builder, builtin, parameter, owner, ownerNode), null));
        }
Пример #5
0
        private void Initialize(string scheme, string text, Builtin builtin, PluginTreeNode node, string memberName, Type memberType, object parameter)
        {
            if (string.IsNullOrWhiteSpace(scheme))
            {
                throw new ArgumentNullException("scheme");
            }

            if (builtin == null && node == null)
            {
                throw new ArgumentException();
            }

            _scheme     = scheme;
            _text       = text ?? string.Empty;
            _parameter  = parameter;
            _memberName = memberName;
            _memberType = memberType;
            _builtin    = builtin;
            _node       = node ?? (builtin == null ? null : builtin.Node);

            if (builtin == null)
            {
                _plugin = node.Plugin;
            }
            else
            {
                _plugin = builtin.Plugin;
            }
        }
Пример #6
0
        private void BuildChildren(PluginTreeNode node, object parameter, object owner, PluginTreeNode ownerNode)
        {
            if (node == null)
            {
                return;
            }

            foreach (var child in node.Children)
            {
                switch (child.NodeType)
                {
                case PluginTreeNodeType.Builtin:
                    this.BuildChild((Builtin)child.Value, parameter, owner, ownerNode);
                    break;

                case PluginTreeNodeType.Empty:
                    this.BuildChildren(child, parameter, owner, ownerNode);
                    break;

                case PluginTreeNodeType.Custom:
                    this.BuildChildren(child, parameter, child.Value, child);
                    break;
                }
            }
        }
Пример #7
0
 public PluginPredicationContext(string parameter, Builtin builtin)
 {
     _parameter = parameter;
     _builtin   = builtin;
     _node      = builtin.Node;
     _plugin    = builtin.Plugin;
 }
Пример #8
0
        private static IParser GetParser(string scheme, PluginTreeNode node)
        {
            if (node.Plugin != null)
            {
                return(node.Plugin.GetParser(scheme));
            }

            foreach (var plugin in node.Tree.Plugins)
            {
                if (plugin.IsHidden)
                {
                    continue;
                }

                //通过插件向上查找指定的解析器
                var parser = plugin.GetParser(scheme);

                if (parser != null)
                {
                    return(parser);
                }
            }

            return(null);
        }
Пример #9
0
        public PluginHttpControllerDescriptor(HttpConfiguration configuration, PluginTreeNode controllerNode)
        {
            _controllerNode = controllerNode ?? throw new ArgumentNullException(nameof(controllerNode));

            this.Configuration  = configuration;
            this.ControllerName = controllerNode.Name;
            this.ControllerType = controllerNode.ValueType;
        }
Пример #10
0
		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);
			}
		}
Пример #11
0
        public static object Parse(string text, PluginTreeNode node, string memberName, Type memberType)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            return(ParseCore(text, node, (scheme, element) => GetParser(scheme, element), (scheme, expression, element) => new ParserContext(scheme, expression, element, memberName, memberType)));
        }
            internal PluginServiceEntry(PluginTreeNode node)
            {
                if (node == null)
                {
                    throw new ArgumentNullException("node");
                }

                _node = node;
            }
Пример #13
0
        internal ParserContext(string scheme, string text, PluginTreeNode node, string memberName, Type memberType)
        {
            if (node == null)
            {
                throw new ArgumentNullException("plugin");
            }

            this.Initialize(scheme, text, null, node, node.Plugin, memberName, memberType);
        }
Пример #14
0
        internal ParserContext(string scheme, string text, PluginTreeNode node, string memberName, Type memberType, object parameter = null)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            this.Initialize(scheme, text, node, memberName, memberType, parameter);
        }
Пример #15
0
        private void LoadPluginTreeView()
        {
            this.tvwPlugins.Nodes.Clear();

            foreach (Plugin plugin in this._plugins)
            {
                PluginTreeNode node = new PluginTreeNode(plugin);
                this.tvwPlugins.Nodes.Add(node);
            }
        }
		protected override Filter CreateFilter(PluginTreeNode node, FilterScope scope)
		{
			var value = node.UnwrapValue(ObtainMode.Auto, null);

			if(value is Filter)
				return (Filter)value;

			var filter = new Filter(value, this.GetFilterScope(scope), null);
			node.Tree.Mount(node, filter);
			return filter;
		}
Пример #17
0
        protected override IWorkbenchBase CreateWorkbench(string[] args)
        {
            PluginTreeNode node = this.PluginContext.PluginTree.Find(this.PluginContext.Settings.WorkbenchPath);

            if (node != null && node.NodeType == PluginTreeNodeType.Builtin)
            {
                return(base.CreateWorkbench(args));
            }

            return(new Workbench(this));
        }
Пример #18
0
 private void LoadPluginTreeView()
 {
     if (true)
     {
         foreach (Plugin plugin in this._plugins)
         {
             PluginTreeNode node = new PluginTreeNode(plugin);
             this.tvwPlugins.Nodes.Add(node);
         }
     }
 }
Пример #19
0
        private void Initialize(string scheme, string text, PluginTreeNode node, string memberName, Type memberType, object parameter)
        {
            if (string.IsNullOrWhiteSpace(scheme))
            {
                throw new ArgumentNullException(nameof(scheme));
            }

            _scheme     = scheme;
            _text       = text ?? string.Empty;
            _parameter  = parameter;
            _memberName = memberName;
            _memberType = memberType;
            _node       = node ?? throw new ArgumentNullException(nameof(node));
        }
Пример #20
0
        internal ParserContext(string scheme, string text, PluginTreeNode node, string memberName, Type memberType, object parameter = null)
        {
            if (string.IsNullOrEmpty(scheme))
            {
                throw new ArgumentNullException(nameof(scheme));
            }

            this.Scheme     = scheme;
            this.Text       = text ?? string.Empty;
            this.Parameter  = parameter;
            this.MemberName = memberName;
            this.MemberType = memberType;
            this.Node       = node ?? throw new ArgumentNullException(nameof(node));
        }
Пример #21
0
        private void tvwPlugins_AfterCheck(object sender, TreeViewEventArgs e)
        {
            PluginTreeNode node = e.Node as PluginTreeNode;

            PluginVersionTreeNode selectedNode = node.LastVersion as PluginVersionTreeNode;

            if (node.Checked && !this.SelectedNodes.Contains(selectedNode))
            {
                this.SelectedNodes.Add(selectedNode);
            }
            else if (!node.Checked)
            {
                this.SelectedNodes.Remove(selectedNode);
            }
        }
Пример #22
0
        private void tvwPlugins_BeforeCheck(object sender, TreeViewCancelEventArgs e)
        {
            this.tvwPlugins.SelectedNode = e.Node;

            this.Cursor = Cursors.WaitCursor;

            PluginTreeNode pluginNode = this.tvwPlugins.SelectedNode as PluginTreeNode;

            if (pluginNode != null)
            {
                this.SelectPluginTreeNode();
            }

            this.Cursor = Cursors.Default;
        }
Пример #23
0
        private BuilderContext(IBuilder builder, Builtin builtin, object parameter, object owner, PluginTreeNode ownerNode)
        {
            _builder  = builder ?? throw new ArgumentNullException(nameof(builder));
            _builtin  = builtin ?? throw new ArgumentNullException(nameof(builtin));
            _appender = builder as IAppender;

            _parameter = parameter;
            _owner     = owner;
            _ownerNode = ownerNode;

            if (builtin.HasBehaviors)
            {
                _cancel = builtin.Behaviors.GetBehaviorValue <bool>(builtin.BuilderName + ".break");
            }

            _syncRoot = new object();
        }
Пример #24
0
        private void BuildChild(Builtin builtin, object parameter, object owner, PluginTreeNode ownerNode)
        {
            //获取当前构件的构建器对象
            IBuilder builder = this.GetBuilder(builtin);

            if (builtin.IsBuilded)
            {
                if (owner != null && builder is IAppender appender)
                {
                    appender.Append(new AppenderContext(builtin.Context, builtin.Value, builtin.Node, owner, ownerNode, AppenderBehavior.Append));
                }
            }
            else
            {
                this.BuildCore(builder, BuilderContext.CreateContext(builder, builtin, parameter, owner, ownerNode), null, null);
            }
        }
Пример #25
0
        private void tvwPlugins_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.ManagerControls();

            this.Cursor = Cursors.WaitCursor;

            this.tvwPlugins.SelectedNode = e.Node;

            PluginVersionTreeNode pluginVersionNode = this.tvwPlugins.SelectedNode as PluginVersionTreeNode;
            PluginTreeNode        pluginNode        = this.tvwPlugins.SelectedNode as PluginTreeNode;

            if (pluginNode != null)
            {
                this.LoadSelectPluginTreeNode();
            }

            this.Cursor = Cursors.Default;
        }
Пример #26
0
        private BuilderContext(IBuilder builder, Builtin builtin, BuilderSettings settings, int depth, object owner, PluginTreeNode ownerNode)
        {
            _builder  = builder ?? throw new ArgumentNullException(nameof(builder));
            _builtin  = builtin ?? throw new ArgumentNullException(nameof(builtin));
            _appender = builder as IAppender;
            _settings = settings;

            _depth     = depth;
            _owner     = owner;
            _ownerNode = ownerNode;

            if (builtin.HasBehaviors)
            {
                _cancel = builtin.Behaviors.GetBehaviorValue <bool>(builtin.Scheme + ".break");
            }

            _syncRoot = new object();
        }
        protected override FilterInfo CreateFilter(PluginTreeNode node, FilterScope scope)
        {
            var value = node.UnwrapValue(ObtainMode.Auto, null);

            if (value is FilterInfo)
            {
                return((FilterInfo)value);
            }

            if (value is IFilter)
            {
                var filterInfo = new FilterInfo((IFilter)value, this.GetFilterScope(scope));
                node.Tree.Mount(node, filterInfo);
                return(filterInfo);
            }

            return(null);
        }
Пример #28
0
        public void WritePluginTree(ICommandOutlet output, PluginTreeNode node, int maxDepth, int depth, int index, bool isFullPath)
        {
            if (node == null)
            {
                return;
            }

            var indent = depth > 0 ? new string('\t', depth) : string.Empty;

            if (depth > 0)
            {
                output.Write(CommandOutletColor.DarkMagenta, indent + "[{0}.{1}] ", depth, index);
            }

            output.Write(isFullPath ? node.FullPath : node.Name);
            output.Write(CommandOutletColor.DarkGray, " [{0}]", node.NodeType);

            if (node.Plugin == null)
            {
                output.WriteLine();
            }
            else
            {
                output.Write(CommandOutletColor.DarkGreen, "@");
                output.WriteLine(CommandOutletColor.DarkGray, node.Plugin.Name);
            }

            var target = node.UnwrapValue(ObtainMode.Never, null);

            if (target != null)
            {
                output.WriteLine(CommandOutletColor.DarkYellow, "{0}{1}", indent, target.GetType().FullName);
            }

            if (maxDepth > 0 && depth >= maxDepth)
            {
                return;
            }

            for (int i = 0; i < node.Children.Count; i++)
            {
                WritePluginTree(output, node.Children[i], maxDepth, depth + 1, i + 1, isFullPath);
            }
        }
Пример #29
0
        private void LoadSelectPluginTreeNode()
        {
            PluginTreeNode node   = this.tvwPlugins.SelectedNode as PluginTreeNode;
            Plugin         plugin = node.Plugin;

            if (plugin.Versions.Count == 0)
            {
                plugin.LoadAll();
            }

            if (node.Nodes.Count == 0)
            {
                foreach (PluginVersion version in node.Plugin.Versions)
                {
                    PluginVersionTreeNode versionNode = new PluginVersionTreeNode(version);
                    node.Nodes.Add(versionNode);
                }
            }
        }
Пример #30
0
        private BuilderContext(Builtin builtin, object parameter, object owner, PluginTreeNode ownerNode)
        {
            if (builtin == null)
            {
                throw new ArgumentNullException("builtin");
            }

            _builtin   = builtin;
            _parameter = parameter;
            _owner     = owner;
            _ownerNode = ownerNode;

            if (builtin.HasBehaviors)
            {
                _cancel = builtin.Behaviors.GetBehaviorValue <bool>(builtin.BuilderName + ".break");
            }

            _syncRoot = new object();
        }
Пример #31
0
        private void SelectPluginTreeNode()
        {
            PluginTreeNode node   = this.tvwPlugins.SelectedNode as PluginTreeNode;
            Plugin         plugin = node.Plugin;

            if (plugin.Versions.Count == 0)
            {
                plugin.Load();
            }

            if (node.Nodes.Count == 0)
            {
                foreach (PluginVersion version in node.Plugin.Versions)
                {
                    if (node.LastVersion == null)
                    {
                        node.LastVersion = new PluginVersionTreeNode(version);
                        if (node.Plugin.Versions.Count == 1)
                        {
                            node.Text = node.Plugin.Name + " (Current: 1.0.0)";
                        }
                    }
                    else
                    {
                        node.Text = node.Plugin.Name + " (Last Version: " + version.VersionNumber + ")";
                    }
                }
            }
            else
            {
                return;
            }

            PluginVersion pluginVersion = node.LastVersion.PluginVersion as PluginVersion;

            if (!pluginVersion.BetaData.Created || !pluginVersion.PluginData.Created)
            {
                pluginVersion.Load();
            }

            this.UpdatePropertyGrid();
        }
Пример #32
0
		private void GetServices(IList<System.ServiceProcess.ServiceBase> services, PluginTreeNode node)
		{
			if(services == null || node == null)
				return;

			if(node.NodeType != PluginTreeNodeType.Empty)
			{
				object value = node.UnwrapValue(ObtainMode.Auto, this, null);

				if(value is System.ServiceProcess.ServiceBase)
					services.Add((System.ServiceProcess.ServiceBase)value);
				else if(value is IWorker)
				{
					//注意:服务的运行时的名称与安装时注册使用的名称必须相同,但服务的注册名与Worker的Name属性并不确保一致!
					//因此,运行时必须使用节点名作为后台服务的名称,以确保与服务安装过程中的注册名一致。
					services.Add(new ServiceWrapper((IWorker)value, node.Name));
				}
			}

			foreach(PluginTreeNode child in node.Children)
				this.GetServices(services, child);
		}
		public PluginHttpControllerDescriptor(HttpConfiguration configuration, PluginTreeNode controllerNode)
		{
			if(configuration == null)
				throw new ArgumentNullException("configuration");

			if(controllerNode == null)
				throw new ArgumentNullException("controllerNode");

			_controllerNode = controllerNode;
			this.Configuration = configuration;
			this.ControllerName = controllerNode.Name;

			switch(controllerNode.NodeType)
			{
				case PluginTreeNodeType.Builtin:
					this.ControllerType = ((Builtin)controllerNode.Value).BuiltinType.Type;
					break;
				case PluginTreeNodeType.Custom:
					if(controllerNode.Value != null)
						this.ControllerType = controllerNode.Value.GetType();
					break;
			}
		}
		private Filter GetFilter(PluginTreeNode node, FilterScope scope)
		{
			return node.UnwrapValue<Filter>(ObtainMode.Auto, null, ctx =>
			{
				var instance = PluginUtility.BuildBuiltin(ctx.Builtin, new string[]{ "order", "action", "method"});

				if(instance == null)
					return;

				ctx.Result = new Filter(instance,
				                 scope,
				                 ctx.Builtin.Properties.GetValue<int>("order", Filter.DefaultOrder));
			});
		}
		//注意:该方法不需要递归自调用,因为PluginTreeNode对象的Build方法会内部进行子节点的构建
		private void GeneratePageContent(Page page, PluginTreeNode ownerNode)
		{
			if(ownerNode == null)
				return;

			string place = string.Empty;

			foreach(PluginTreeNode childNode in ownerNode.Children)
			{
				if(childNode.NodeType == PluginTreeNodeType.Empty)
					continue;

				//只有当前节点的目标类型为控件时,才需要构建它们
				if(typeof(System.Web.UI.Control).IsAssignableFrom(childNode.ValueType))
				{
					place = childNode.Properties.GetValue<string>("place");

					//if(childNode.NodeType == PluginTreeNodeType.Builtin)
					//    place = ((Builtin)childNode.Value).Properties.GetValue<string>("place");

					Control placeControl = this.FindPlaceControl(page, place);
					if(placeControl != null)
						childNode.Build(placeControl);
				}
			}
		}
		private void GetServiceInstallers(IList<ServiceInstaller> installers, PluginTreeNode node)
		{
			if(installers == null || node == null)
				return;

			if(node.NodeType != PluginTreeNodeType.Empty)
			{
				Type serviceType = null;
				bool disabled = false;
				string serviceName = node.Name;

				if(node.NodeType == PluginTreeNodeType.Custom)
				{
					var worker = node.UnwrapValue<Zongsoft.Services.IWorker>(ObtainMode.Auto, this, null);

					if(worker != null)
					{
						serviceName = worker.Name;
						serviceType = worker.GetType();
						disabled = worker.Disabled;
					}
				}
				else
				{
					if(typeof(IWorker).IsAssignableFrom(node.ValueType))
						serviceType = node.ValueType;

					disabled = ((Builtin)node.Value).Properties.GetValue<bool>("disabled", false);
				}

				if(serviceType != null)
				{
					ServiceInstaller installer = new ServiceInstaller();

					installer.DelayedAutoStart = false;
					installer.ServiceName = serviceName;
					installer.StartType = (disabled ? ServiceStartMode.Disabled : ServiceStartMode.Automatic);

					//设置安装服务的描述文本
					var descriptionAttribute = (DescriptionAttribute)Attribute.GetCustomAttribute(serviceType, typeof(DescriptionAttribute));
					if(descriptionAttribute != null)
						installer.Description = Resources.ResourceUtility.GetString(descriptionAttribute.Description, serviceType.Assembly);

					//设置安装服务的显示名称
					var displayAttribute = (DisplayNameAttribute)Attribute.GetCustomAttribute(serviceType, typeof(DisplayNameAttribute));
					if(displayAttribute != null)
						installer.DisplayName = Resources.ResourceUtility.GetString(displayAttribute.DisplayName, serviceType.Assembly) + " (" + serviceName + ")";

					installers.Add(installer);
				}
			}

			foreach(PluginTreeNode child in node.Children)
				this.GetServiceInstallers(installers, child);
		}