Beispiel #1
0
        /// <summary>
        /// Factory method to get a VssFileStorage instance ensuring that we don't have two instances for the same file.
        /// </summary>
        /// <param name="fullPath">The full path to the storage file.  Ensure that the path used is in an appropriately secure location for the data you are storing.</param>
        /// <param name="pathSeparatorForKeys">The separator to use between the path segments of the storage keys.</param>
        /// <param name="ignoreCaseInPaths">If true the dictionary will use the OrdinalIgnoreCase StringComparer to compare keys.</param>
        /// <returns></returns>
        public static IVssClientStorage GetVssLocalFileStorage(string fullPath, char pathSeparatorForKeys = c_defaultPathSeparator, bool ignoreCaseInPaths = c_defaultIgnoreCaseInPaths)
        {
            string         normalizedFullPath = Path.GetFullPath(fullPath);
            VssFileStorage storage            = s_storages.GetOrAdd(normalizedFullPath, (key) => new VssFileStorage(key, pathSeparatorForKeys, ignoreCaseInPaths));

            // we need to throw on mismatch if the cache contains a conflicting instance
            if (storage.PathSeparator != pathSeparatorForKeys)
            {
                throw new ArgumentException(CommonResources.ConflictingPathSeparatorForVssFileStorage(pathSeparatorForKeys, normalizedFullPath, storage.PathSeparator));
            }

            StringComparer pathComparer = GetAppropriateStringComparer(ignoreCaseInPaths);

            {
                if (storage.PathComparer != pathComparer)
                {
                    string caseSensitive   = "Ordinal";
                    string caseInsensitive = "OrdinalIgnoreCase";
                    string requested       = ignoreCaseInPaths ? caseInsensitive : caseSensitive;
                    string previous        = ignoreCaseInPaths ? caseSensitive : caseInsensitive;
                    throw new ArgumentException(CommonResources.ConflictingStringComparerForVssFileStorage(requested, normalizedFullPath, previous));
                }
            }

#if DEBUG
            Debug.Assert(fullPath.Equals(storage.m_filePath), string.Format("The same storage file is being referenced with different casing.  This will cause issues when running in cross patform environments where the file system may be case sensitive.  {0} != {1}", storage.m_filePath, normalizedFullPath));
#endif
            return(storage);
        }