GridFSFileInfoCompat.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. [BsonSerializer(typeof(GridFSFileInfoSerializer))]
  29. public sealed class GridFSFileInfo : BsonDocumentBackedClass
  30. {
  31. // constructors
  32. /// <summary>
  33. /// Initializes a new instance of the <see cref="GridFSFileInfo"/> class.
  34. /// </summary>
  35. /// <param name="backingDocument">The backing document.</param>
  36. public GridFSFileInfo(BsonDocument backingDocument)
  37. : base(backingDocument, GridFSFileInfoSerializer.Instance)
  38. {
  39. }
  40. // public properties
  41. /// <summary>
  42. /// Gets the aliases.
  43. /// </summary>
  44. /// <value>
  45. /// The aliases.
  46. /// </value>
  47. [Obsolete("Place aliases inside metadata instead.")]
  48. public IEnumerable<string> Aliases
  49. {
  50. get { return GetValue<string[]>("Aliases", null); }
  51. }
  52. /// <summary>
  53. /// Gets the backing document.
  54. /// </summary>
  55. /// <value>
  56. /// The backing document.
  57. /// </value>
  58. new public BsonDocument BackingDocument
  59. {
  60. get { return base.BackingDocument; }
  61. }
  62. /// <summary>
  63. /// Gets the size of a chunk.
  64. /// </summary>
  65. /// <value>
  66. /// The size of a chunk.
  67. /// </value>
  68. public int ChunkSizeBytes
  69. {
  70. get { return GetValue<int>("ChunkSizeBytes"); }
  71. }
  72. /// <summary>
  73. /// Gets the type of the content.
  74. /// </summary>
  75. /// <value>
  76. /// The type of the content.
  77. /// </value>
  78. [Obsolete("Place contentType inside metadata instead.")]
  79. public string ContentType
  80. {
  81. get { return GetValue<string>("ContentType", null); }
  82. }
  83. /// <summary>
  84. /// Gets the filename.
  85. /// </summary>
  86. /// <value>
  87. /// The filename.
  88. /// </value>
  89. public string Filename
  90. {
  91. get { return GetValue<string>("Filename"); }
  92. }
  93. /// <summary>
  94. /// Gets the identifier.
  95. /// </summary>
  96. /// <value>
  97. /// The identifier.
  98. /// </value>
  99. public ObjectId Id
  100. {
  101. get { return GetValue<BsonValue>("IdAsBsonValue").AsObjectId; }
  102. }
  103. /// <summary>
  104. /// Gets the identifier as a BsonValue.
  105. /// </summary>
  106. /// <value>
  107. /// The identifier as a BsonValue.
  108. /// </value>
  109. [Obsolete("All new GridFS files should use an ObjectId as the Id.")]
  110. public BsonValue IdAsBsonValue
  111. {
  112. get { return GetValue<BsonValue>("IdAsBsonValue"); }
  113. }
  114. /// <summary>
  115. /// Gets the length.
  116. /// </summary>
  117. /// <value>
  118. /// The length.
  119. /// </value>
  120. public long Length
  121. {
  122. get { return GetValue<long>("Length"); }
  123. }
  124. /// <summary>
  125. /// Gets the MD5 checksum.
  126. /// </summary>
  127. /// <value>
  128. /// The MD5 checksum.
  129. /// </value>
  130. [Obsolete("MD5 support will be removed soon.")]
  131. public string MD5
  132. {
  133. get { return GetValue<string>("MD5", null); }
  134. }
  135. /// <summary>
  136. /// Gets the metadata.
  137. /// </summary>
  138. /// <value>
  139. /// The metadata.
  140. /// </value>
  141. public BsonDocument Metadata
  142. {
  143. get { return GetValue<BsonDocument>("Metadata", null); }
  144. }
  145. /// <summary>
  146. /// Gets the upload date time.
  147. /// </summary>
  148. /// <value>
  149. /// The upload date time.
  150. /// </value>
  151. public DateTime UploadDateTime
  152. {
  153. get { return GetValue<DateTime>("UploadDateTime"); }
  154. }
  155. }
  156. }