本文整理汇总了C#中System.IO.FileStream.ReadStream方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.ReadStream方法的具体用法?C# FileStream.ReadStream怎么用?C# FileStream.ReadStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileStream
的用法示例。
在下文中一共展示了FileStream.ReadStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadFileData
/// <summary>
/// Handles deserialization of file from disk; virtual method allows customization (e.g., pre-load decryption and/or data merge).
/// </summary>
/// <param name="fileStream"><see cref="FileStream"/> used to deserialize data.</param>
/// <returns>Deserialized file data.</returns>
/// <remarks>
/// Consumers overriding this method should not directly call <see cref="InterprocessCache.FileData"/> property to avoid potential dead-locks.
/// </remarks>
protected override byte[] LoadFileData(FileStream fileStream)
{
// Decrypt data that was encrypted local to this machine
byte[] serializedUserDataTable = ProtectedData.Unprotect(fileStream.ReadStream(), null, DataProtectionScope.LocalMachine);
Dictionary<string, UserData> userDataTable = DeserializeCache(serializedUserDataTable);
// Wait for thread level lock on user data table
lock (m_userDataTableLock)
{
// Merge new and existing key tables since new user information may have been queued for serialization, but not saved yet
m_userDataTable = userDataTable.Merge(m_userDataTable);
}
return serializedUserDataTable;
}
示例2: LoadFileData
/// <summary>
/// Handles deserialization of file from disk; virtual method allows customization (e.g., pre-load decryption and/or data merge).
/// </summary>
/// <param name="fileStream"><see cref="FileStream"/> used to deserialize data.</param>
/// <returns>Deserialized file data.</returns>
/// <remarks>
/// Consumers overriding this method should not directly call <see cref="InterprocessCache.FileData"/> property to avoid potential dead-locks.
/// </remarks>
protected override byte[] LoadFileData(FileStream fileStream)
{
// Decrypt data that was encrypted local to this machine
byte[] serializedKeyIVTable = ProtectedData.Unprotect(fileStream.ReadStream(), null, DataProtectionScope.LocalMachine);
Dictionary<string, byte[][]> keyIVTable = Serialization.Deserialize<Dictionary<string, byte[][]>>(serializedKeyIVTable, SerializationFormat.Binary);
// Wait for thread level lock on key table
lock (m_keyIVTableLock)
{
// Merge new and existing key tables since new keys may have been queued for serialization, but not saved yet
m_keyIVTable = keyIVTable.Merge(m_keyIVTable);
}
return serializedKeyIVTable;
}
示例3: LoadFileData
/// <summary>
/// Handles deserialization of file from disk; virtual method allows customization (e.g., pre-load decryption and/or data merge).
/// </summary>
/// <param name="fileStream"><see cref="FileStream"/> used to deserialize data.</param>
/// <returns>Deserialized file data.</returns>
/// <remarks>
/// Consumers overriding this method should not directly call <see cref="InterprocessCache.FileData"/> property to avoid potential dead-locks.
/// </remarks>
protected override byte[] LoadFileData(FileStream fileStream)
{
// Decrypt data that was encrypted local to this machine
byte[] serializedUserRoles = ProtectedData.Unprotect(fileStream.ReadStream(), null, DataProtectionScope.LocalMachine);
Dictionary<string, string[]> userRoles = Serialization.Deserialize<Dictionary<string, string[]>>(serializedUserRoles, SerializationFormat.Binary);
// Wait for thread level lock on user role dictionary
lock (m_userRolesLock)
{
// Merge new and existing dictionaries since new user roles may have been queued for serialization, but not saved yet
m_userRoles = userRoles.Merge(m_userRoles);
}
return serializedUserRoles;
}
示例4: LoadFileData
/// <summary>
/// Handles deserialization of file from disk; virtual method allows customization (e.g., pre-load decryption and/or data merge).
/// </summary>
/// <param name="fileStream"><see cref="FileStream"/> used to deserialize data.</param>
/// <returns>Deserialized file data.</returns>
/// <remarks>
/// Consumers overriding this method should not directly call <see cref="InterprocessCache.FileData"/> property to avoid potential dead-locks.
/// </remarks>
protected override byte[] LoadFileData(FileStream fileStream)
{
// Decrypt data that was encrypted local to this machine
byte[] serializedDataSet = ProtectedData.Unprotect(fileStream.ReadStream(), null, DataProtectionScope.LocalMachine);
DataSet dataSet;
using (MemoryStream stream = new MemoryStream(serializedDataSet))
{
dataSet = stream.DeserializeToDataSet();
}
// Wait for thread level lock on data set
lock (m_dataSetLock)
{
m_dataSet = dataSet;
}
return serializedDataSet;
}
示例5: LoadFileData
/// <summary>
/// Handles deserialization of file from disk; virtual method allows customization (e.g., pre-load decryption and/or data merge).
/// </summary>
/// <param name="fileStream"><see cref="FileStream"/> used to deserialize data.</param>
/// <returns>Deserialized file data.</returns>
/// <remarks>
/// Consumers overriding this method should not directly call <see cref="FileData"/> property to avoid potential dead-locks.
/// </remarks>
protected virtual byte[] LoadFileData(FileStream fileStream)
{
return fileStream.ReadStream();
}
示例6: DeserializeKeyIVTable
/// <summary>
/// Deserializes key and initialization vector table from local cache that was encrypted on local machine.
/// </summary>
private static Dictionary<string, byte[][]> DeserializeKeyIVTable()
{
Dictionary<string, byte[][]> keyIVTable;
string keyIVCacheFilePath = FilePath.GetAbsolutePath(KeyIVCacheFileName);
if (File.Exists(keyIVCacheFilePath))
{
// We need interprocess synchronization on the key & IV cache file so we create a system level mutex
Mutex fileLockMutex = GetSystemLevelMutex(KeyIVCacheMutexName);
try
{
// Wait for system level mutex lock before we work with key & IV cache file
fileLockMutex.WaitOne();
}
catch (AbandonedMutexException)
{
// Abnormal system terminations can leave mutexs abandoned, in this
// case we now own the mutex and can safely ignore this exception
}
try
{
FileStream keyIVCacheFile = new FileStream(keyIVCacheFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
byte[] serializedKeyIVTable = ProtectedData.Unprotect(keyIVCacheFile.ReadStream(), null, DataProtectionScope.LocalMachine);
keyIVTable = Serialization.GetObject<Dictionary<string, byte[][]>>(serializedKeyIVTable);
}
finally
{
fileLockMutex.ReleaseMutex();
}
}
else
{
// No crypto key cache file exists, create a blank crypto key table
keyIVTable = new Dictionary<string, byte[][]>();
}
return keyIVTable;
}