本文整理汇总了C#中System.IO.IsolatedStorage.IsolatedStorageFile.Demand方法的典型用法代码示例。如果您正苦于以下问题:C# IsolatedStorageFile.Demand方法的具体用法?C# IsolatedStorageFile.Demand怎么用?C# IsolatedStorageFile.Demand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.IsolatedStorage.IsolatedStorageFile
的用法示例。
在下文中一共展示了IsolatedStorageFile.Demand方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsolatedStorageFileStream
//.........这里部分代码省略.........
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)(FileInfo.UnsafeCreateFileInfo(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;
}
if (fNewFile)
m_isf.ReserveOneBlock();
#endif // FEATURE_ISOLATED_STORAGE_QUOTA_ENFORCEMENT
try {
#if FEATURE_CORECLR
// Since FileStream's .ctor won't do a demand, we need to do our access check here.
m_isf.Demand(m_FullPath);
#endif
#if FEATURE_ISOSTORE_LIGHT
m_fs = new
FileStream(m_FullPath, mode, access, share, bufferSize,
FileOptions.None, m_GivenPath, true);
} catch (Exception e) {
#else
m_fs = new
FileStream(m_FullPath, mode, access, share, bufferSize,
FileOptions.None, m_GivenPath, true, true);
} catch {
#endif
#if FEATURE_ISOLATED_STORAGE_QUOTA_ENFORCEMENT
if (fNewFile)
m_isf.UnreserveOneBlock();
#endif // FEATURE_ISOLATED_STORAGE_QUOTA_ENFORCEMENT
#if FEATURE_ISOSTORE_LIGHT
// IsoStore generally does not let arbitrary exceptions flow out: a
// IsolatedStorageException is thrown instead (see examples in IsolatedStorageFile.cs
// Keeping this scoped to coreclr just because changing the exception type thrown is a
// breaking change and that should not be introduced into the desktop without deliberation.
//
// Note that GetIsolatedStorageException may set InnerException. To the real exception
// Today it always does this, for debug and chk builds, and for other builds asks the host
// if it is okay to do so.
throw IsolatedStorageFile.GetIsolatedStorageException("IsolatedStorage_Operation_ISFS", e);
#else
throw;
#endif // FEATURE_ISOSTORE_LIGHT
}
#if FEATURE_ISOLATED_STORAGE_QUOTA_ENFORCEMENT
// 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);
}
} finally {
if (fLock)
m_isf.Unlock();
}
#endif // FEATURE_ISOLATED_STORAGE_QUOTA_ENFORCEMENT
#if !FEATURE_CORECLR
CodeAccessPermission.RevertAll();
#endif
}
示例2: GetFileDirectoryNames
[System.Security.SecurityCritical] // auto-generated
#endif
private static String[] GetFileDirectoryNames(String path, String msg, bool file, IsolatedStorageFile isf) {
int hr;
if(path == null) throw new ArgumentNullException("path", Environment.GetResourceString("ArgumentNull_Path"));
Contract.EndContractBlock();
bool fEndsWithDirectory = false;
char lastChar = path[path.Length - 1];
if(lastChar == Path.DirectorySeparatorChar ||
lastChar == Path.AltDirectorySeparatorChar ||
lastChar == '.')
fEndsWithDirectory = true;
// Get an absolute path and do a security check
String fullPath = Path.GetFullPathInternal(path);
// GetFullPath() removes '\', "\." etc from path, we will restore
// it here. If path ends in a trailing slash (\), append a *
// or we'll get a "Cannot find the file specified" exception
if((fEndsWithDirectory) &&
(fullPath[fullPath.Length - 1] != lastChar))
fullPath += "\\*";
// Check for read permission to the directory, not to the contents.
String dir = Path.GetDirectoryName(fullPath);
if(dir != null)
dir += "\\";
if(isf != null) {
try {
isf.Demand(dir == null ? fullPath : dir);
} catch (Exception e) {
throw GetIsolatedStorageException("IsolatedStorage_Operation", e);
}
}
if(CompatibilitySwitches.IsAppEarlierThanWindowsPhoneMango)
{
// Pre Mango Windows Phone had very odd behavior for this function. It would take the parent directory of the search pattern and do a *
// in there. That means something like GetDirectories("Dir1") would be treated as GetDirectories("*") and GetDirectories("Dir2\Dir3") would be
// treated as GetDirectories("Dir2\*").
// This also means that GetDirectories("") returned "IsolatedStorage" since it was looking at the directory above the root of Isolated Storage.
fullPath = Path.Combine(Path.GetDirectoryName(fullPath), "*");
}
String[] list = new String[10];
int listSize = 0;
Win32Native.WIN32_FIND_DATA data = new Win32Native.WIN32_FIND_DATA();
// Open a Find handle
SafeFindHandle hnd = Win32Native.FindFirstFile(fullPath, data);
if(hnd.IsInvalid) {
// Calls to GetLastWin32Error overwrites HResult. Store HResult.
hr = Marshal.GetLastWin32Error();
if(hr == Win32Native.ERROR_FILE_NOT_FOUND)
return new String[0];
// Mango would throw DirectoryNotFoundException if we got ERROR_PATH_NOT_FOUND instead of IsolatedStorageException
if(CompatibilitySwitches.IsAppEarlierThanWindowsPhone8 && hr == Win32Native.ERROR_PATH_NOT_FOUND)
__Error.WinIOError(hr, msg);
#if FEATURE_ISOSTORE_LIGHT
throw GetIsolatedStorageException("IsolatedStorage_Operation", Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error(), new IntPtr(-1)));
#else
__Error.WinIOError(hr, msg);
#endif
}
// Keep asking for more matching files, adding file names to list
int numEntries = 0; // Number of directory entities we see.
do {
bool includeThis; // Should this file/directory be included in the output?
if(file)
includeThis = (0 == (data.dwFileAttributes & Win32Native.FILE_ATTRIBUTE_DIRECTORY));
else {
includeThis = (0 != (data.dwFileAttributes & Win32Native.FILE_ATTRIBUTE_DIRECTORY));
// Don't add "." nor ".."
if(includeThis && (data.cFileName.Equals(".") || data.cFileName.Equals("..")))
includeThis = false;
}
if(includeThis) {
numEntries++;
if(listSize == list.Length) {
String[] newList = new String[list.Length * 2];
Array.Copy(list, 0, newList, 0, listSize);
list = newList;
}
list[listSize++] = data.cFileName;
}
} while(Win32Native.FindNextFile(hnd, data));
// Make sure we quit with a sensible error.
hr = Marshal.GetLastWin32Error();
//.........这里部分代码省略.........