コード例 #1
0
ファイル: CmdletIndex.cs プロジェクト: johanste/MamlToText
        /// <summary>
        /// Recursively index each discriminator in the given command keys.
        /// </summary>
        /// <param name="keys">The command discriminator list from which key needs to be derived</param>
        /// <param name="level">The discriminator level</param>
        /// <param name="value">The value</param>
        private void Add(List<string> keys, int level, string value)
        {
            Entries.Add(string.Join(Constants.CmdletIndexWordSeparator, keys), value);
            if (level < keys.Count)
            {
                CmdletIndex childIndex;
                if (!Children.TryGetValue(keys[level], out childIndex))
                {
                    childIndex = new CmdletIndex { Name = keys[level] };
                    Children.Add(keys[level], childIndex);
                }

                childIndex.Add(keys, level + 1, value);
            }
        }
コード例 #2
0
ファイル: CmdletIndex.cs プロジェクト: johanste/MamlToText
        /// <summary>
        /// Load the index.
        /// </summary>
        /// <param name="keys">The command discriminator list identifying the index to be loaded</param>
        /// <param name="path">The index file path</param>
        /// <param name="recursive">
        ///  True  - If the index for all command discriminator in the discriminator list needs to be loaded
        ///  False - Only the index of the root discriminator needs to be loaded</param>
        /// <returns></returns>
        public static CmdletIndex Load(IEnumerable<string> keys, string path, bool recursive)
        {
            Debug.Assert(keys != null);
            Debug.Assert(!string.IsNullOrEmpty(path));

            var indexName = keys.FirstOrDefault();
            var indexFullPath = Path.Combine(path, Constants.CmdletsIndexFileName);

            var cmdletIndex = new CmdletIndex { Name = indexName };
            if (File.Exists(indexFullPath))
            {
                cmdletIndex.Entries = ConfigurationDictionary.Load(indexFullPath);
            }

            if (recursive)
            {
                foreach (var dir in Directory.EnumerateDirectories(path))
                {
                    cmdletIndex.Children.Add(indexName, Load(keys.Skip(1), Path.Combine(path, indexName), true));
                }
            }

            return cmdletIndex;
        }