GridFSUploadStream.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright 2016-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. using System.IO;
  17. using System.Threading;
  18. using System.Threading.Tasks;
  19. using MongoDB.Bson;
  20. namespace MongoDB.Driver.GridFS
  21. {
  22. /// <summary>
  23. /// Represents a Stream used by the application to write data to a GridFS file.
  24. /// </summary>
  25. /// <typeparam name="TFileId">The type of the file identifier.</typeparam>
  26. public abstract class GridFSUploadStream<TFileId> : Stream
  27. {
  28. // constructors
  29. internal GridFSUploadStream()
  30. {
  31. }
  32. // public properties
  33. /// <summary>
  34. /// Gets the id of the file being added to GridFS.
  35. /// </summary>
  36. /// <value>
  37. /// The id of the file being added to GridFS.
  38. /// </value>
  39. public abstract TFileId Id { get; }
  40. // public methods
  41. /// <summary>
  42. /// Aborts an upload operation.
  43. /// </summary>
  44. /// <remarks>
  45. /// Any partial results already written to the server are deleted when Abort is called.
  46. /// </remarks>
  47. /// <param name="cancellationToken">The cancellation token.</param>
  48. public abstract void Abort(CancellationToken cancellationToken = default(CancellationToken));
  49. /// <summary>
  50. /// Aborts an upload operation.
  51. /// </summary>
  52. /// <remarks>
  53. /// Any partial results already written to the server are deleted when AbortAsync is called.
  54. /// </remarks>
  55. /// <param name="cancellationToken">The cancellation token.</param>
  56. /// <returns>A Task.</returns>
  57. public abstract Task AbortAsync(CancellationToken cancellationToken = default(CancellationToken));
  58. #if NETSTANDARD1_5 || NETSTANDARD1_6
  59. /// <summary>
  60. /// Closes the GridFS stream.
  61. /// </summary>
  62. public virtual void Close()
  63. {
  64. Dispose(true);
  65. GC.SuppressFinalize(this);
  66. }
  67. #endif
  68. /// <summary>
  69. /// Closes the Stream and completes the upload operation.
  70. /// </summary>
  71. /// <remarks>
  72. /// Any data remaining in the Stream is flushed to the server and the GridFS files collection document is written.
  73. /// </remarks>
  74. /// <param name="cancellationToken">The cancellation token.</param>
  75. public abstract void Close(CancellationToken cancellationToken);
  76. /// <summary>
  77. /// Closes the Stream and completes the upload operation.
  78. /// </summary>
  79. /// <remarks>
  80. /// Any data remaining in the Stream is flushed to the server and the GridFS files collection document is written.
  81. /// </remarks>
  82. /// <param name="cancellationToken">The cancellation token.</param>
  83. /// <returns>A Task.</returns>
  84. public abstract Task CloseAsync(CancellationToken cancellationToken = default(CancellationToken));
  85. }
  86. }