// Parameters:
// assertPermissions - If true, then we'll assert all required permissions. Used by ClientSettingsConfigurationHost.
// to allow low-trust apps to use ClientSettingsStore.
static internal void StaticWriteCompleted(string streamName, bool success, object writeContext, bool assertPermissions)
{
WriteFileContext writeFileContext = (WriteFileContext)writeContext;
bool revertAssert = false;
if (assertPermissions)
{
// If asked to assert permissions, we will assert allAccess on the streamName, the temporary file
// created by WriteContext, and also the directory itself. The last one is needed because
// WriteFileContext will call TempFileCollection.Dispose, which will remove a .tmp file it created.
string dir = Path.GetDirectoryName(streamName);
string[] filePaths = new string[] { streamName, writeFileContext.TempNewFilename, dir };
FileIOPermission fileIOPerm = new FileIOPermission(FileIOPermissionAccess.AllAccess, AccessControlActions.View | AccessControlActions.Change, filePaths);
fileIOPerm.Assert();
revertAssert = true;
}
try {
writeFileContext.Complete(streamName, success);
}
finally {
if (revertAssert)
{
CodeAccessPermission.RevertAssert();
}
}
}