GridFSFileInfo.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* Copyright 2015-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.Collections.Generic;
  17. using System.Linq;
  18. using MongoDB.Bson;
  19. using MongoDB.Bson.Serialization;
  20. using MongoDB.Bson.Serialization.Attributes;
  21. using MongoDB.Bson.Serialization.Serializers;
  22. using MongoDB.Driver.Core.Misc;
  23. namespace MongoDB.Driver.GridFS
  24. {
  25. /// <summary>
  26. /// Represents information about a stored GridFS file (backed by a files collection document).
  27. /// </summary>
  28. /// <typeparam name="TFileId">The type of the file identifier.</typeparam>
  29. [BsonSerializer(typeof(GridFSFileInfoSerializer<>))]
  30. public sealed class GridFSFileInfo<TFileId> : BsonDocumentBackedClass
  31. {
  32. // constructors
  33. /// <summary>
  34. /// Initializes a new instance of the <see cref="GridFSFileInfo" /> class.
  35. /// </summary>
  36. /// <param name="backingDocument">The backing document.</param>
  37. /// <param name="fileInfoSerializer">The fileInfo serializer.</param>
  38. public GridFSFileInfo(BsonDocument backingDocument, IGridFSFileInfoSerializer<TFileId> fileInfoSerializer)
  39. : base(backingDocument, fileInfoSerializer)
  40. {
  41. }
  42. // public properties
  43. /// <summary>
  44. /// Gets the aliases.
  45. /// </summary>
  46. /// <value>
  47. /// The aliases.
  48. /// </value>
  49. [Obsolete("Place aliases inside metadata instead.")]
  50. public IEnumerable<string> Aliases
  51. {
  52. get { return GetValue<string[]>("Aliases", null); }
  53. }
  54. /// <summary>
  55. /// Gets the backing document.
  56. /// </summary>
  57. /// <value>
  58. /// The backing document.
  59. /// </value>
  60. new public BsonDocument BackingDocument
  61. {
  62. get { return base.BackingDocument; }
  63. }
  64. /// <summary>
  65. /// Gets the size of a chunk.
  66. /// </summary>
  67. /// <value>
  68. /// The size of a chunk.
  69. /// </value>
  70. public int ChunkSizeBytes
  71. {
  72. get { return GetValue<int>("ChunkSizeBytes"); }
  73. }
  74. /// <summary>
  75. /// Gets the type of the content.
  76. /// </summary>
  77. /// <value>
  78. /// The type of the content.
  79. /// </value>
  80. [Obsolete("Place contentType inside metadata instead.")]
  81. public string ContentType
  82. {
  83. get { return GetValue<string>("ContentType", null); }
  84. }
  85. /// <summary>
  86. /// Gets the filename.
  87. /// </summary>
  88. /// <value>
  89. /// The filename.
  90. /// </value>
  91. public string Filename
  92. {
  93. get { return GetValue<string>("Filename"); }
  94. }
  95. /// <summary>
  96. /// Gets the identifier.
  97. /// </summary>
  98. /// <value>
  99. /// The identifier.
  100. /// </value>
  101. public TFileId Id
  102. {
  103. get { return GetValue<TFileId>("Id"); }
  104. }
  105. // public properties
  106. /// <summary>
  107. /// Gets the length.
  108. /// </summary>
  109. /// <value>
  110. /// The length.
  111. /// </value>
  112. public long Length
  113. {
  114. get { return GetValue<long>("Length"); }
  115. }
  116. /// <summary>
  117. /// Gets the MD5 checksum.
  118. /// </summary>
  119. /// <value>
  120. /// The MD5 checksum.
  121. /// </value>
  122. public string MD5
  123. {
  124. get { return GetValue<string>("MD5", null); }
  125. }
  126. /// <summary>
  127. /// Gets the metadata.
  128. /// </summary>
  129. /// <value>
  130. /// The metadata.
  131. /// </value>
  132. public BsonDocument Metadata
  133. {
  134. get { return GetValue<BsonDocument>("Metadata", null); }
  135. }
  136. /// <summary>
  137. /// Gets the upload date time.
  138. /// </summary>
  139. /// <value>
  140. /// The upload date time.
  141. /// </value>
  142. public DateTime UploadDateTime
  143. {
  144. get { return GetValue<DateTime>("UploadDateTime"); }
  145. }
  146. }
  147. }