コード例 #1
0
ファイル: GeneralUtils.cs プロジェクト: wflk/canape
        /// <summary>
        /// Extend selection syntax for nodes to handle global and meta parameters through
        /// # and $ prefixes
        /// </summary>
        /// <param name="path">The path to select</param>
        /// <param name="frame">The data frame to select off</param>
        /// <param name="node">The current node</param>
        /// <param name="globalMeta">Global meta</param>
        /// <param name="properties">Property bag</param>
        /// <param name="uuid">The uuid for private names</param>
        /// <param name="meta">Meta</param>
        /// <returns>An array of nodes</returns>
        public static DataNode[] SelectNodes(string path, DataFrame frame, MetaDictionary meta, MetaDictionary globalMeta, 
            PropertyBag properties, Guid uuid, BasePipelineNode node)
        {
            DataNode[] nodes = new DataNode[0];

            path = path.Trim();

            if (path.StartsWith("#"))
            {
                if (meta != null)
                {
                    string name = path.Substring(1);
                    object n = meta.GetMeta(MakePrivateMetaName(uuid, name));
                    if(n == null)
                    {
                        n = meta.GetMeta(name);
                    }

                    if (n != null)
                    {
                        nodes = new DataNode[1];
                        nodes[0] = new StringDataValue(path, n.ToString());
                    }
                }
            }
            else if (path.StartsWith("$"))
            {
                if (globalMeta != null)
                {
                    string name = path.Substring(1);
                    object n = globalMeta.GetMeta(MakePrivateMetaName(uuid, name));
                    if (n == null)
                    {
                        n = globalMeta.GetMeta(name);
                    }

                    if (n != null)
                    {
                        nodes = new DataNode[1];
                        nodes[0] = new StringDataValue(path, n.ToString());
                    }
                }
            }
            else if (path.StartsWith("~"))
            {
                if(properties != null)
                {
                    string name = path.Substring(1);
                    dynamic val = properties.GetRelativeValue(name);

                    if (val != null)
                    {
                        nodes = new DataNode[1];
                        nodes[0] = new StringDataValue(path, val.ToString());
                    }
                }
            }
            else if (path.StartsWith("&"))
            {
                DataNode n = null;

                if (path.Equals("&incount", StringComparison.OrdinalIgnoreCase))
                {
                    n = new GenericDataValue<int>(path, node != null ? node.InputPacketCount : 0);
                }
                else if (path.Equals("&outcount", StringComparison.OrdinalIgnoreCase))
                {
                    n = new GenericDataValue<int>(path, node != null ? node.OutputPacketCount : 0);
                }
                else if (path.Equals("&bytecount", StringComparison.OrdinalIgnoreCase))
                {
                    n = new GenericDataValue<long>(path, node != null ? node.ByteCount : 0);
                }
                else if (path.Equals("&length", StringComparison.OrdinalIgnoreCase))
                {
                    n = new GenericDataValue<long>(path, frame.Length);
                }
                else if (path.Equals("&md5", StringComparison.OrdinalIgnoreCase))
                {
                    n = new StringDataValue(path, frame.Hash);
                }
                else if (path.Equals("&display", StringComparison.OrdinalIgnoreCase))
                {
                    n = new StringDataValue(path, frame.ToString());
                }

                if (n != null)
                {
                    nodes = new DataNode[1];
                    nodes[0] = n;
                }
            }
            else
            {
                nodes = frame.SelectNodes(path);
            }

            return nodes;
        }