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


C# FileStream.ReadStream方法代码示例

本文整理汇总了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;
        }
开发者ID:rmc00,项目名称:gsf,代码行数:23,代码来源:UserDataCache.cs

示例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;
            }
开发者ID:GridProtectionAlliance,项目名称:gsf,代码行数:23,代码来源:Cipher.cs

示例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;
        }
开发者ID:rmc00,项目名称:gsf,代码行数:23,代码来源:UserRoleCache.cs

示例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;
        }
开发者ID:rmc00,项目名称:gsf,代码行数:27,代码来源:AdoSecurityCache.cs

示例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();
 }
开发者ID:rmc00,项目名称:gsf,代码行数:12,代码来源:InterprocessCache.cs

示例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;
        }
开发者ID:avs009,项目名称:gsf,代码行数:44,代码来源:Cipher.cs


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