Exemple #1
0
 protected WorkbenchBase(PluginApplicationContext applicationContext)
 {
     this.ApplicationContext = applicationContext ?? throw new ArgumentNullException(nameof(applicationContext));
     _status      = WorkbenchStatus.None;
     _title       = applicationContext.Title;
     _startupPath = PluginPath.Combine(applicationContext.Options.GetWorkbenchMountion(), "Startup");
     _semaphore   = new AutoResetEvent(true);
 }
        public static bool TryParse(string text, out PluginPath result)
        {
            result = null;

            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }

            result = ParseCore(text, null);
            return(result != null);
        }
        private object ResolveExtendedProperty(XmlReader reader, Plugin plugin, string path)
        {
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Text:
                    return(reader.Value);

                case XmlNodeType.Element:
                    string tempPath    = PluginPath.Combine("Temporary", plugin.Name.Replace(".", ""), path.Trim('/').Replace('/', '-'), Zongsoft.Common.RandomGenerator.GenerateString());
                    var    tempBuiltin = this.ResolveBuiltin(reader, plugin, tempPath);
                    return(tempBuiltin);
                }
            }

            return(null);
        }
        private object ResolveExtendedProperty(XmlReader reader, Plugin plugin, string path)
        {
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Text:
                    return(reader.Value);

                case XmlNodeType.Element:
                    string tempPath    = PluginPath.Combine("Temp", plugin.Name.Replace(".", ""), path.Trim('/').Replace('/', '-'), Guid.NewGuid().ToString("N"));
                    var    tempBuiltin = this.ResolveBuiltin(reader, plugin, tempPath);
                    return(tempBuiltin);
                }
            }

            return(null);
        }
        private void ResolveExtendedElement(XmlReader reader, Plugin plugin, string path)
        {
            var parts = reader.Name.Split('.');
            var node  = _pluginTree.EnsurePath(PluginPath.Combine(path, parts[0]));

            if (node == null)
            {
                throw new PluginException(string.Format("Invalid '{0}' ExtendedElement is not exists in '{1}' plugin.", path + "/" + parts[0], plugin.FilePath));
            }

            string propertyName = string.Join(".", parts, 1, parts.Length - 1);

            if (node.NodeType == PluginTreeNodeType.Builtin)
            {
                ((Builtin)node.Value).Properties.Set(propertyName, this.ResolveExtendedProperty(reader, plugin, node.FullPath));
            }
            else
            {
                node.Properties.Set(propertyName, this.ResolveExtendedProperty(reader, plugin, node.FullPath), plugin);
            }
        }
Exemple #6
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 void MountBuiltin(string path, Builtin builtin)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("path");
            }

            if (builtin == null)
            {
                throw new ArgumentNullException("builtin");
            }

            var fullPath = PluginPath.Combine(path, builtin.Name);

            //激发“Mounting”事件
            this.OnMounting(new PluginMountEventArgs(fullPath, builtin));

            //创建对应的构件节点
            this.MountItem(fullPath, builtin, builtin.Position);

            //激发“Mounted”事件
            this.OnMounted(new PluginMountEventArgs(fullPath, builtin));
        }
Exemple #8
0
        internal object ResolvePath(string pathText, PluginTreeNode origin)
        {
            ObtainMode mode;

            return(this.ResolvePath(PluginPath.PreparePathText(pathText, out mode), origin, mode));
        }
Exemple #9
0
        /// <summary>
        /// 根据指定的路径文本获取其对应的缓存对象或该对象的成员值。
        /// </summary>
        /// <param name="pathText">要获取的路径文本,该文本可以用过句点符号(.)表示缓存对象的成员名。</param>
        /// <returns>返回获取的缓存对象或其成员值。</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="pathText"/>参数为空或全空字符串。</exception>
        /// <remarks>
        /// 注意:成员名只能是公共的实例属性或字段。
        /// <example>/Workspace/Environment/ApplicationContext.ApplicationId</example>
        /// </remarks>
        public object ResolvePath(string pathText)
        {
            ObtainMode mode;

            return(this.ResolvePath(PluginPath.PreparePathText(pathText, out mode), this.PluginTree.RootNode, mode));
        }