當前位置: 首頁>>代碼示例>>C#>>正文


C# IsolatedStorageFile.CleanDirectory方法代碼示例

本文整理匯總了C#中System.IO.IsolatedStorage.IsolatedStorageFile.CleanDirectory方法的典型用法代碼示例。如果您正苦於以下問題:C# IsolatedStorageFile.CleanDirectory方法的具體用法?C# IsolatedStorageFile.CleanDirectory怎麽用?C# IsolatedStorageFile.CleanDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.IsolatedStorage.IsolatedStorageFile的用法示例。


在下文中一共展示了IsolatedStorageFile.CleanDirectory方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: FetchOrCreateStore

        [System.Security.SecurityCritical] // auto-generated
        #endif
        private static string FetchOrCreateStore(string groupName, string storeName, IsolatedStorageFile isf) {
            string groupRootPath = GetGroupPathFromName(groupName);
            string obfuscatedStoreName = GetHash(storeName);
            string obfuscatedGroupName = GetHash(groupName);
            string storeRootPath = Path.Combine(IsolatedStorageRoot, Path.Combine(s_StorePathPrefix, obfuscatedStoreName));

            FileLock rootLock = FileLock.GetFileLock(IsolatedStorageRoot);

            try {
                rootLock.Lock();

                if(Directory.UnsafeExists(storeRootPath)) {

                    if (!File.UnsafeExists(Path.Combine(storeRootPath, s_IdFileName))) {
                        File.UnsafeWriteAllText(Path.Combine(storeRootPath, s_IdFileName), storeName);
                    } else {
                        if (!storeName.Equals(File.UnsafeReadAllText(Path.Combine(storeRootPath, s_IdFileName)))) {
                            throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_Init"));
                        }
                    }

                    File.UnsafeWriteAllText(Path.Combine(storeRootPath, s_GroupFileName), obfuscatedGroupName);
                    

                    if (!Directory.UnsafeExists(Path.Combine(storeRootPath, s_FilesPathPrefix))) {
                        Directory.UnsafeCreateDirectory(Path.Combine(storeRootPath, s_FilesPathPrefix));
                    }

                    if(File.UnsafeExists(Path.Combine(storeRootPath, s_CleanupFileName))) {
                        bool removedAll = isf.CleanDirectory(Path.Combine(storeRootPath, s_FilesPathPrefix));

                        if(removedAll) {
                            File.UnsafeDelete(Path.Combine(storeRootPath, s_CleanupFileName));
                            return storeRootPath;
                        } else {
                            throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_Init"));
                        }
                    } else {
                        return storeRootPath;
                    }
                } else {
                    isf.Reserve(s_DirSize);
                    Directory.UnsafeCreateDirectory(storeRootPath);
                    TouchFile(Path.Combine(storeRootPath, s_CleanupFileName));

                    Directory.UnsafeCreateDirectory(Path.Combine(storeRootPath, s_FilesPathPrefix));
                    File.UnsafeWriteAllText(Path.Combine(storeRootPath, s_GroupFileName), obfuscatedGroupName);
                    File.UnsafeWriteAllText(Path.Combine(storeRootPath, s_IdFileName), storeName);
                    File.UnsafeDelete(Path.Combine(storeRootPath, s_CleanupFileName));
                    return storeRootPath;
                }
            } catch(IOException e) {
                throw GetIsolatedStorageException("IsolatedStorage_Init", e);
            } catch (UnauthorizedAccessException e) {
                throw GetIsolatedStorageException("IsolatedStorage_Init", e);
            } finally {
                if(rootLock != null) {
                    rootLock.Unlock();
                }
            }
        }
開發者ID:l1183479157,項目名稱:coreclr,代碼行數:63,代碼來源:IsolatedStorageFileSmall.cs


注:本文中的System.IO.IsolatedStorage.IsolatedStorageFile.CleanDirectory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。