コード例 #1
0
 /// <summary>
 /// Opens or creates a stream, initializing with bytes 0xFF if <paramref name="initialDataSize"/> is greater than zero.
 /// </summary>
 /// <param name="storageLocation">Location of the stream.</param>
 /// <param name="initialDataSize">Initial data size of the stream (in bytes).</param>
 /// <returns>The stream, initialized.</returns>
 /// <remarks>The capacity of the stream will be rounded up to the nearest multiple of 64 bytes.</remarks>
 public Stream OpenOrCreate(string storageLocation, int initialDataSize)
 {
     lock (FileSystem)
     {
         return(TestStorageStream.OpenOrCreate(FileSystem, storageLocation, initialDataSize));
     }
 }
コード例 #2
0
 /// <inheritdoc />
 public Stream Open(string storageLocation)
 {
     lock (FileSystem)
     {
         return(TestStorageStream.OpenOrCreate(FileSystem, storageLocation, -1));
     }
 }
コード例 #3
0
            }                                                                                // << REALLY do not like this!

            public static TestStorageStream OpenOrCreate(ConcurrentDictionary <string, TestStorageStream> fileSystem, string location, int initialSizeInBytes)
            {
                TestStorageStream stream;

                if (!fileSystem.TryGetValue(location, out stream))
                {
                    if (initialSizeInBytes > 0)
                    {
                        stream = new TestStorageStream(fileSystem, location, initialSizeInBytes);
                    }
                    else
                    {
                        stream = new TestStorageStream(fileSystem, location);
                    }
                    if (!fileSystem.TryAdd(location, stream))
                    {
                        throw new InvalidOperationException();
                    }
                }
                stream.Open();
                return(stream);
            }