当前位置: 首页>>代码示例>>C#>>正文


C# IsolatedStorageFile.Reserve方法代码示例

本文整理汇总了C#中System.IO.IsolatedStorage.IsolatedStorageFile.Reserve方法的典型用法代码示例。如果您正苦于以下问题:C# IsolatedStorageFile.Reserve方法的具体用法?C# IsolatedStorageFile.Reserve怎么用?C# IsolatedStorageFile.Reserve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.IsolatedStorage.IsolatedStorageFile的用法示例。


在下文中一共展示了IsolatedStorageFile.Reserve方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsolatedStorageFileStream

        /// <include file='doc\IsolatedStorageFileStream.uex' path='docs/doc[@for="IsolatedStorageFileStream.IsolatedStorageFileStream7"]/*' />
        public IsolatedStorageFileStream(String path, FileMode mode, 
            FileAccess access, FileShare share, int bufferSize,  
            IsolatedStorageFile isf) 
        {
            if (path == null)
                throw new ArgumentNullException("path");

            if (s_BackSlash == null)
                s_BackSlash = new String(System.IO.Path.DirectorySeparatorChar,1);

            if ((path.Length == 0) || path.Equals(s_BackSlash))
                throw new ArgumentException(
                    Environment.GetResourceString(
                        "IsolatedStorage_path"));

            ulong oldFileSize=0, newFileSize;
            bool fNewFile = false;
            FileInfo fOld;
 
            if (isf == null)
            {
                m_OwnedStore = true;
                isf = IsolatedStorageFile.GetUserStoreForDomain();
            }

            m_isf = isf;

            FileIOPermission fiop = 
                new FileIOPermission(FileIOPermissionAccess.AllAccess,
                    m_isf.RootDirectory);

            fiop.Assert();

            m_GivenPath = path;
            m_FullPath  = m_isf.GetFullPath(m_GivenPath);

            // Cache the old file size if the file size could change
            // Also find if we are going to create a new file.

            switch (mode) {
            case FileMode.CreateNew:        // Assume new file
                fNewFile = true;
                break;

            case FileMode.Create:           // Check for New file & Unreserve
            case FileMode.OpenOrCreate:     // Check for new file
            case FileMode.Truncate:         // Unreserve old file size
            case FileMode.Append:           // Check for new file

                try {
                    fOld = new FileInfo(m_FullPath);
                    oldFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)fOld.Length);
                } catch (Exception e) {
                    if (e is FileNotFoundException)
                        fNewFile = true;
                }

                break;

            case FileMode.Open:             // Open existing, else exception
                break;

            default:
                throw new ArgumentException(
                    Environment.GetResourceString(
                        "IsolatedStorage_FileOpenMode"));
            }

            if (fNewFile)
                m_isf.ReserveOneBlock();

            try {
                m_fs = new 
                    FileStream(m_FullPath, mode, access, share, bufferSize, 
                        false, m_GivenPath, true);
            } catch (Exception) {

                if (fNewFile)
                    m_isf.UnreserveOneBlock();

                throw;
            }

            // make adjustment to the Reserve / Unreserve state

            if ((fNewFile == false) &&
                ((mode == FileMode.Truncate) || (mode == FileMode.Create)))
            {
                newFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)m_fs.Length);
    
                if (oldFileSize > newFileSize)
                    m_isf.Unreserve(oldFileSize - newFileSize);
                else if (newFileSize > oldFileSize)     // Can this happen ?
                    m_isf.Reserve(newFileSize - oldFileSize);
            }
        }
开发者ID:ArildF,项目名称:masters,代码行数:97,代码来源:isolatedstoragefilestream.cs

示例2: IsolatedStorageFileStream

        public IsolatedStorageFileStream(String path, FileMode mode, 
            FileAccess access, FileShare share, int bufferSize, 
            IsolatedStorageFile isf)
        { 
            if (path == null)
                throw new ArgumentNullException("path");
            Contract.EndContractBlock();
 
#if FEATURE_PAL
            if (s_BackSlash == null) 
                s_BackSlash = new String(System.IO.Path.DirectorySeparatorChar,1); 
#endif // FEATURE_PAL
 
            if ((path.Length == 0) || path.Equals(s_BackSlash))
                throw new ArgumentException(
                    Environment.GetResourceString(
                        "IsolatedStorage_Path")); 

            ulong oldFileSize=0, newFileSize; 
            bool fNewFile = false, fLock=false; 

            if (isf == null) 
            {
#if FEATURE_ISOSTORE_LIGHT
                throw new ArgumentNullException("isf");
#else // !FEATURE_ISOSTORE_LIGHT 
                m_OwnedStore = true;
                isf = IsolatedStorageFile.GetUserStoreForDomain(); 
#endif // !FEATURE_ISOSTORE_LIGHT 
            }
 
            if (isf.Disposed)
                throw new ObjectDisposedException(null, Environment.GetResourceString("IsolatedStorage_StoreNotOpen"));

 
            m_isf = isf;
 
            FileIOPermission fiop = 
                new FileIOPermission(FileIOPermissionAccess.AllAccess,
                    m_isf.RootDirectory); 

            fiop.Assert();
            fiop.PermitOnly();
 
            m_GivenPath = path;
            m_FullPath  = m_isf.GetFullPath(m_GivenPath); 
 
            RuntimeHelpers.PrepareConstrainedRegions();
            try { // for finally Unlocking locked store 

                // Cache the old file size if the file size could change
                // Also find if we are going to create a new file.
 
                switch (mode) {
                case FileMode.CreateNew:        // Assume new file 
#if FEATURE_ISOSTORE_LIGHT 
                    // We are going to call Reserve so we need to lock the store.
                    m_isf.Lock(ref fLock); 
#endif
                    fNewFile = true;
                    break;
 
                case FileMode.Create:           // Check for New file & Unreserve
                case FileMode.OpenOrCreate:     // Check for new file 
                case FileMode.Truncate:         // Unreserve old file size 
                case FileMode.Append:           // Check for new file
 
                    m_isf.Lock(ref fLock);      // oldFileSize needs to be
                                                // protected

                    try { 
#if FEATURE_ISOSTORE_LIGHT
                        oldFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)(new FileInfo(m_FullPath).Length)); 
#else 
                        oldFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)LongPathFile.GetLength(m_FullPath));
#endif 
                    } catch (FileNotFoundException) {
                        fNewFile = true;
                    } catch {
                    } 

                    break; 
 
                case FileMode.Open:             // Open existing, else exception
                    break; 

                default:
                    throw new ArgumentException(
                        Environment.GetResourceString( 
                            "IsolatedStorage_FileOpenMode"));
                } 
 
                if (fNewFile)
                    m_isf.ReserveOneBlock(); 

                try {
#if FEATURE_ISOSTORE_LIGHT
                    m_fs = new 
                        FileStream(m_FullPath, mode, access, share, bufferSize,
                            FileOptions.None, m_GivenPath, true); 
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:IsolatedStorageFileStream.cs

示例3: 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.Reserve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。