예제 #1
0
        public bool TryParseNamesAndValues(string path, out List <string> names, out List <string> values)
        {
            names  = null;
            values = null;

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

            var dirs = PartitionedPathUtils.SplitDirectories(path);

            dirs = dirs.Take(dirs.Count() - 1); // Ignore last directory which is the file name.

            names  = new List <string>(dirs.Count());
            values = new List <string>(dirs.Count());

            foreach (var dir in dirs)
            {
                if (!TryParseNameValueFromDir(dir, out string name, out string value))
                {
                    return(false);
                }

                names.Add(name);
                values.Add(value);
            }

            return(true);
        }
예제 #2
0
        public IEnumerable <string> ParseValues(string path)
        {
            Contracts.AssertNonEmpty(path);

            var dirs = PartitionedPathUtils.SplitDirectories(path);

            return(dirs.Take(dirs.Count() - 1)); // Ignore last directory which is the file name.
        }
            /// <summary>
            /// Truncate path to the specified number of trailing directories.
            /// </summary>
            /// <param name="dirCount">Number of directories to retain.</param>
            /// <param name="path">Path to truncate.</param>
            /// <param name="truncPath">The resulting truncated path.</param>
            /// <returns>true if the truncation was successful.</returns>
            private bool TryTruncatePath(int dirCount, string path, out string truncPath)
            {
                truncPath = null;

                // Remove directories that shouldn't be parsed.
                var segments = PartitionedPathUtils.SplitDirectories(path);
                segments = segments.Skip(segments.Count() - dirCount - 1);

                if (segments.Count() < dirCount - 1)
                {
                    Ch.Warning($"Path {path} did not have {dirCount} directories necessary for parsing.");
                    return false;
                }

                // Rejoin segments to create a valid path.
                truncPath = String.Join(Path.DirectorySeparatorChar.ToString(), segments);
                return true;
            }
예제 #4
0
 /// <summary>
 /// Get the number of directories in the file path.
 /// </summary>
 /// <param name="path">A file path.</param>
 /// <returns>The number of directories</returns>
 private int GetDirectoryCount(string path)
 {
     return(PartitionedPathUtils.SplitDirectories(path).Count() - 1);
 }