System.IO.IsolatedStorage.Helper.GetRandomDirectory C# (CSharp) Méthode

GetRandomDirectory() static private méthode

static private GetRandomDirectory ( string rootDirectory, IsolatedStorageScope scope ) : string
rootDirectory string
scope IsolatedStorageScope
Résultat string
        internal static string GetRandomDirectory(string rootDirectory, IsolatedStorageScope scope)
        {
            string randomDirectory = GetExistingRandomDirectory(rootDirectory);
            if (string.IsNullOrEmpty(randomDirectory))
            {
                using (Mutex m = CreateMutexNotOwned(rootDirectory))
                {
                    if (!m.WaitOne())
                    {
                        throw new IsolatedStorageException(SR.IsolatedStorage_Init);
                    }

                    try
                    {
                        randomDirectory = GetExistingRandomDirectory(rootDirectory);
                        if (string.IsNullOrEmpty(randomDirectory))
                        {
                            // Someone else hasn't created the directory before we took the lock
                            randomDirectory = Path.Combine(rootDirectory, Path.GetRandomFileName(), Path.GetRandomFileName());
                            CreateDirectory(randomDirectory, scope);
                        }
                    }
                    finally
                    {
                        m.ReleaseMutex();
                    }
                }
            }

            return randomDirectory;
        }

Usage Example

Exemple #1
0
        static TestHelper()
        {
            s_rootDirectoryProperty = typeof(IsolatedStorageFile).GetProperty("RootDirectory", BindingFlags.NonPublic | BindingFlags.Instance);

            s_roots = new List <string>();

            string hash;
            object identity;

            Helper.GetDefaultIdentityAndHash(out identity, out hash, '.');

            string userRoot       = Helper.GetDataDirectory(IsolatedStorageScope.User);
            string randomUserRoot = Helper.GetRandomDirectory(userRoot, IsolatedStorageScope.User);

            s_roots.Add(Path.Combine(randomUserRoot, hash));

            // Application scope doesn't go under a random dir
            s_roots.Add(Path.Combine(userRoot, hash));

            // https://github.com/dotnet/runtime/issues/2092
            // https://github.com/dotnet/runtime/issues/21742
            if (OperatingSystem.IsWindows() &&
                !PlatformDetection.IsInAppContainer)
            {
                s_roots.Add(Helper.GetDataDirectory(IsolatedStorageScope.Machine));
            }

            // We don't expose Roaming yet
            // Helper.GetDataDirectory(IsolatedStorageScope.Roaming);
        }
All Usage Examples Of System.IO.IsolatedStorage.Helper::GetRandomDirectory