Beispiel #1
0
        /// <summary>
        /// Appends stream to storage file, respecting previous append requests
        /// </summary>
        /// <param name="data">stream to be written to the file</param>
        /// <param name="key">search key</param>
        /// <param name="info">stream info related to stream being appended</param>
        /// <param name="token">cancellation token for asynchronous operation</param>
        /// <returns>Task object that will be completed once stream data is written</returns>
        public void Write(Stream data, string key, StreamInfo info, CancellationToken token)
        {
            if (binaryStorageIndex.Contains(key))
            {
                throw new ArgumentException(nameof(key));
            }

            var newInfo = PreValidateStream(data, info);

            var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, cancellationOnDispose.Token);

            linkedTokenSource.Token.ThrowIfCancellationRequested();

            if (!linkedTokenSource.IsCancellationRequested)
            {
                ManualResetEvent result = null;
                lock (writeLock)
                {
                    if (!linkedTokenSource.IsCancellationRequested)
                    {
                        result = InternalWrite(data, key, newInfo, linkedTokenSource.Token);
                    }
                }

                if (!linkedTokenSource.IsCancellationRequested)
                {
                    result?.WaitOne();
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Check if key is present in the storage
 /// </summary>
 /// <param name="key">Unique identifier of the stream</param>
 /// <returns>true if key is present and false otherwise</returns>
 public bool Contains(string key)
 {
     return binaryStorageIndex.Contains(key);
 }