Esempio n. 1
0
        /// <summary>
        /// Returns true if specified <paramref name="path"/> is share regular path and returns result due to <paramref name="parsePathResult"/>
        /// </summary>
        /// <param name="path">QuickIOShareInfo regular path to parse</param>
        /// <param name="parsePathResult"><see cref="PathResult"/></param>
        /// <returns>True if parse succeeded and <paramref name="parsePathResult"/> is filled</returns>
        public static Boolean TryParseShareRegularPath(String path, out PathResult parsePathResult)
        {
            if (!IsShareRegularPath(path))
            {
                parsePathResult = null;
                return(false);
            }

            parsePathResult = new PathResult {
                PathLocation = LocalOrShare.Share, PathType = UncOrRegular.Regular
            };

            var cleanedPath = path.TrimEnd('\\');

            var pathElements = cleanedPath.Substring(RegularSharePathPrefixLength).Split('\\');

            var server = pathElements[0];
            var name   = pathElements[1];

            var rootPath = RegularSharePathPrefix + server + @"\" + name;

            var completePath = rootPath;

            for (int i = 2; i < pathElements.Length; i++)
            {
                completePath += "\\" + pathElements[i];
            }

            // set
            parsePathResult.IsRoot = (cleanedPath == rootPath);

            if (parsePathResult.IsRoot)
            {
                parsePathResult.ParentPath  = null;
                parsePathResult.RootPath    = null;
                parsePathResult.Name        = null;
                parsePathResult.FullNameUnc = UncSharePathPrefix + server + @"\" + name;
                parsePathResult.FullName    = RegularSharePathPrefix + server + @"\" + name;
            }
            else
            {
                parsePathResult.FullName    = cleanedPath;
                parsePathResult.FullNameUnc = UncSharePathPrefix + cleanedPath.Substring(2);
                parsePathResult.ParentPath  = completePath.Substring(0, completePath.LastIndexOf(Path.DirectorySeparatorChar));
                parsePathResult.RootPath    = rootPath;

                parsePathResult.Name = pathElements[pathElements.Length - 1];
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Transfers properties from result to current instance
        /// </summary>
        /// <param name="parsePathResult"></param>
        private void TransferParseResult(PathResult parsePathResult)
        {
            FullNameUnc    = parsePathResult.FullNameUnc;
            FullName       = parsePathResult.FullName;
            ParentFullName = parsePathResult.ParentPath;
            RootFullName   = parsePathResult.RootPath;
            IsRoot         = parsePathResult.IsRoot;
            PathLocation   = parsePathResult.PathLocation;
            PathType       = parsePathResult.PathType;

            if (PathLocation == LocalOrShare.Local)
            {
                var testRoot = IsRoot ? FullName : RootFullName;

                if (!Array.Exists(Environment.GetLogicalDrives(), drve => drve.Equals(testRoot, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new Exception("UnsupportedDriveType " + testRoot);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Returns true if specified <paramref name="path"/> is local UNC path and returns result due to <paramref name="parsePathResult"/>
        /// </summary>
        /// <param name="path">Local UNC path to parse</param>
        /// <param name="parsePathResult"><see cref="PathResult"/></param>
        /// <returns>True if parse succeeded and <paramref name="parsePathResult"/> is filled</returns>
        public static Boolean TryParseLocalUncPath(String path, out PathResult parsePathResult)
        {
            if (!IsLocalUncPath(path))
            {
                parsePathResult = null;
                return(false);
            }

            parsePathResult = new PathResult {
                PathLocation = LocalOrShare.Local, PathType = UncOrRegular.UNC
            };

            if (path.Length == 7)
            {
                parsePathResult.IsRoot     = true;
                parsePathResult.ParentPath = null;
                parsePathResult.RootPath   = null;

                parsePathResult.FullNameUnc = path;
                parsePathResult.FullName    = path.Substring(4);
                parsePathResult.Name        = null;
            }
            else
            {
                parsePathResult.IsRoot      = false;
                parsePathResult.FullNameUnc = path.TrimEnd(Path.DirectorySeparatorChar);
                parsePathResult.FullName    = parsePathResult.FullNameUnc.Substring(4);

                parsePathResult.ParentPath = parsePathResult.FullName.Substring(0, parsePathResult.FullName.LastIndexOf(Path.DirectorySeparatorChar));
                parsePathResult.RootPath   = path.Substring(4, 3);

                parsePathResult.Name = parsePathResult.FullName.Substring(parsePathResult.FullName.LastIndexOf(Path.DirectorySeparatorChar) + 1);
            }

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Transfers properties from result to current instance
        /// </summary>
        /// <param name="parsePathResult"></param>
        private void TransferParseResult(PathResult parsePathResult)
        {
            FullNameUnc = parsePathResult.FullNameUnc;
            FullName = parsePathResult.FullName;
            ParentFullName = parsePathResult.ParentPath;
            RootFullName = parsePathResult.RootPath;
            IsRoot = parsePathResult.IsRoot;
            PathLocation = parsePathResult.PathLocation;
            PathType = parsePathResult.PathType;

            if (PathLocation == LocalOrShare.Local)
            {
                var testRoot = IsRoot ? FullName : RootFullName;

                if (!Array.Exists(Environment.GetLogicalDrives(), drve => drve.Equals(testRoot, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new Exception("UnsupportedDriveType "+testRoot);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Returns true if specified <paramref name="path"/> is share UNC path and returns result due to <paramref name="parsePathResult"/>
        /// </summary>
        /// <param name="path">QuickIOShareInfo UNC path to parse</param>
        /// <param name="parsePathResult"><see cref="PathResult"/></param>
        /// <returns>True if parse succeeded and <paramref name="parsePathResult"/> is filled</returns>
        public static Boolean TryParseShareUncPath(String path, out PathResult parsePathResult)
        {
            if (!IsShareUncPath(path))
            {
                parsePathResult = null;
                return false;
            }

            parsePathResult = new PathResult { PathLocation = LocalOrShare.Share, PathType = UncOrRegular.UNC };

            var cleanedPath = path.TrimEnd('\\');

            var pathElements = cleanedPath.Substring(UncSharePathPrefixLength).Split('\\');

            var server = pathElements[0];
            var name = pathElements[1];

            var completeRelativePath = server + @"\" + name;
            for (int i = 2; i < pathElements.Length; i++)
            {
                completeRelativePath += "\\" + pathElements[i];
            }

            // set
            parsePathResult.IsRoot = (cleanedPath == (UncSharePathPrefix + server + @"\" + name));

            if (parsePathResult.IsRoot)
            {
                parsePathResult.ParentPath = null;
                parsePathResult.RootPath = null;
                parsePathResult.Name = null;
                parsePathResult.FullNameUnc = UncSharePathPrefix + server + @"\" + name;
                parsePathResult.FullName = RegularSharePathPrefix + server + @"\" + name;
            }
            else
            {
                parsePathResult.FullName = RegularSharePathPrefix + completeRelativePath;
                parsePathResult.FullNameUnc = UncSharePathPrefix + completeRelativePath;
                parsePathResult.ParentPath = RegularSharePathPrefix + completeRelativePath.Substring(0, completeRelativePath.LastIndexOf(Path.DirectorySeparatorChar));
                parsePathResult.RootPath = RegularSharePathPrefix + server + @"\" + name;

                parsePathResult.Name = pathElements[pathElements.Length - 1];
            }

            return true;
        }
Esempio n. 6
0
        /// <summary>
        /// Try to parse path
        /// </summary>
        /// <param name="path">Path to parse</param>
        /// <param name="parsePathResult">result</param>
        /// <param name="supportRelativePath">true to support relative path</param>
        /// <returns>True on success. <paramref name="parsePathResult"/> is set.</returns>
        public static Boolean TryParsePath(String path, out PathResult parsePathResult, bool supportRelativePath = true)
        {
            if (TryParseLocalRegularPath(path, out parsePathResult))
            {
                return true;
            }
            if (TryParseLocalUncPath(path, out parsePathResult))
            {
                return true;
            }
            if (TryParseShareRegularPath(path, out parsePathResult))
            {
                return true;
            }
            if (TryParseShareUncPath(path, out parsePathResult))
            {
                return true;
            }

            if (supportRelativePath && TryParseLocalRegularPath(Path.GetFullPath(path), out parsePathResult))
            {
                return true;
            }

            return false;
        }
Esempio n. 7
0
        /// <summary>
        /// Returns true if specified <paramref name="path"/> is local UNC path and returns result due to <paramref name="parsePathResult"/>
        /// </summary>
        /// <param name="path">Local UNC path to parse</param>
        /// <param name="parsePathResult"><see cref="PathResult"/></param>
        /// <returns>True if parse succeeded and <paramref name="parsePathResult"/> is filled</returns>
        public static Boolean TryParseLocalUncPath(String path, out PathResult parsePathResult)
        {
            if (!IsLocalUncPath(path))
            {
                parsePathResult = null;
                return false;
            }

            parsePathResult = new PathResult { PathLocation = LocalOrShare.Local, PathType = UncOrRegular.UNC };

            if (path.Length == 7)
            {
                parsePathResult.IsRoot = true;
                parsePathResult.ParentPath = null;
                parsePathResult.RootPath = null;

                parsePathResult.FullNameUnc = path;
                parsePathResult.FullName = path.Substring(4);
                parsePathResult.Name = null;
            }
            else
            {
                parsePathResult.IsRoot = false;
                parsePathResult.FullNameUnc = path.TrimEnd(Path.DirectorySeparatorChar);
                parsePathResult.FullName = parsePathResult.FullNameUnc.Substring(4);

                parsePathResult.ParentPath = parsePathResult.FullName.Substring(0, parsePathResult.FullName.LastIndexOf(Path.DirectorySeparatorChar));
                parsePathResult.RootPath = path.Substring(4, 3);

                parsePathResult.Name = parsePathResult.FullName.Substring(parsePathResult.FullName.LastIndexOf(Path.DirectorySeparatorChar) + 1);
            }

            return true;
        }