예제 #1
0
        static public string ApplyCaseComparison(string path, PathCaseComparison caseComparison)
        {
            if (path == null)
            {
                throw new ArgumentNullException();
            }

            switch (caseComparison)
            {
            case PathCaseComparison.EnvironmentDefault:
                if (IsEnvironmentCaseSensitive())
                {
                    goto default;
                }
                else
                {
                    goto case PathCaseComparison.IgnoreCase;
                }

            case PathCaseComparison.IgnoreCase:
                return(path.ToLowerInvariant());

            default:
                return(path);
            }
        }
예제 #2
0
        static public bool Equals(string first, string second, PathCaseComparison caseComparison, FolderPathEquality folderEquality)
        {
            if (first == null && second == null)
            {
                return(true);
            }
            if (first == null ^ second == null)
            {
                return(false);
            }

            return(string.Equals(ApplyFolderEquality(PathUtils.Normalize(first), folderEquality), ApplyFolderEquality(PathUtils.Normalize(second), folderEquality), GetStringComparison(caseComparison)));
        }
예제 #3
0
        static public string UniqueFile(string path, PathCaseComparison caseComparison)
        {
            if (!IsValidPath(path))
            {
                throw new ArgumentException();
            }
            if (IsExplicitFolderPath(path))
            {
                throw new ArgumentException();
            }

            // Normalize
            path = Normalize(path);

            // Change case if necessary
            return(PathComparer.ApplyCaseComparison(Normalize(path), caseComparison));
        }
예제 #4
0
        static public int Compare(string first, string second, PathCaseComparison caseComparison, FolderPathEquality folderEquality)
        {
            if (first == null && second == null)
            {
                return(0);
            }
            if (first == null)
            {
                return(-1);
            }
            if (second == null)
            {
                return(1);
            }

            return(string.Compare(ApplyFolderEquality(PathUtils.Normalize(first), folderEquality), ApplyFolderEquality(PathUtils.Normalize(second), folderEquality), GetStringComparison(caseComparison)));
        }
예제 #5
0
        static public StringComparison GetStringComparison(PathCaseComparison caseComparison)
        {
            switch (caseComparison)
            {
            case PathCaseComparison.EnvironmentDefault:
                return(IsEnvironmentCaseSensitive() ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);

            case PathCaseComparison.RespectCase:
                return(StringComparison.Ordinal);

            case PathCaseComparison.IgnoreCase:
                return(StringComparison.OrdinalIgnoreCase);

            default:
                throw new NotSupportedException();
            }
        }
예제 #6
0
        static public string UniqueFolder(string path, PathCaseComparison caseComparison)
        {
            if (!IsValidPath(path))
            {
                throw new ArgumentException();
            }

            // Normalize
            path = Normalize(path, out char separator);

            // Change case if necessary
            path = PathComparer.ApplyCaseComparison(path, caseComparison);

            // Add end separator
            if (!IsExplicitFolderPath(path, separator))
            {
                path += separator;
            }

            return(path);
        }
예제 #7
0
            public PathHandlersBase(string uniquePath, SharedWatcher sharedWatcher, bool subscribeToChanged)
            {
                UniquePath  = uniquePath;
                PathPattern = new PathPattern(uniquePath, sharedWatcher.FileSystem.PathsCaseSensitive);

                SharedWatcher       = sharedWatcher;
                _subscribeToChanged = subscribeToChanged;

                SharedWatcher.Increment();
                SharedWatcher.FolderCreated += OnParentFolderCreated;
                SharedWatcher.FolderDeleted += OnParentFolderDeleted;

                PathCaseComparison caseComparison = sharedWatcher.FileSystem.PathsCaseSensitive
                    ? PathCaseComparison.RespectCase
                    : PathCaseComparison.IgnoreCase;

                var existingPathComparer = new PathComparer(caseComparison, FolderPathEquality.RespectAmbiguity);

                _matchingPaths = new ConcurrentDictionary <string, bool>(existingPathComparer);

                RefreshExistingMatchingPaths();
                SubscribeToWatcher();
            }
예제 #8
0
        static private bool MatchSimplePath(string path, string pattern, bool caseSensitive = true)
        {
            PathCaseComparison pathCaseComparison = caseSensitive ? PathCaseComparison.RespectCase : PathCaseComparison.IgnoreCase;

            return(PathComparer.Equals(path, pattern, pathCaseComparison, FolderPathEquality.RespectAmbiguity));
        }
예제 #9
0
 public PathComparer(PathCaseComparison caseComparison, FolderPathEquality folderEquality)
 {
     CaseComparison = caseComparison;
     FolderEquality = folderEquality;
 }