GridFSFileNotFoundException.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #if NET452
  17. using System.Runtime.Serialization;
  18. #endif
  19. using MongoDB.Bson;
  20. using MongoDB.Driver.Core.Misc;
  21. namespace MongoDB.Driver.GridFS
  22. {
  23. /// <summary>
  24. /// Represents a GridFSFileNotFound exception.
  25. /// </summary>
  26. #if NET452
  27. [Serializable]
  28. #endif
  29. public class GridFSFileNotFoundException : GridFSException
  30. {
  31. #region static
  32. private static string FormatMessage(BsonValue id)
  33. {
  34. Ensure.IsNotNull(id, nameof(id));
  35. return string.Format("GridFS file not found: file id {0}.", id);
  36. }
  37. private static string FormatMessage(string filename, int revision)
  38. {
  39. Ensure.IsNotNull(filename, nameof(filename));
  40. return string.Format("GridFS file not found: revision {0} of filename \"{1}\".", revision, filename);
  41. }
  42. #endregion
  43. // constructors
  44. /// <summary>
  45. /// Initializes a new instance of the <see cref="GridFSFileNotFoundException"/> class.
  46. /// </summary>
  47. /// <param name="id">The file id.</param>
  48. public GridFSFileNotFoundException(BsonValue id)
  49. : base(FormatMessage(id))
  50. {
  51. }
  52. /// <summary>
  53. /// Initializes a new instance of the <see cref="GridFSFileNotFoundException" /> class.
  54. /// </summary>
  55. /// <param name="filename">The filename.</param>
  56. /// <param name="revision">The revision.</param>
  57. public GridFSFileNotFoundException(string filename, int revision)
  58. : base(FormatMessage(filename, revision))
  59. {
  60. }
  61. #if NET452
  62. /// <summary>
  63. /// Initializes a new instance of the <see cref="GridFSFileNotFoundException"/> class.
  64. /// </summary>
  65. /// <param name="info">The SerializationInfo.</param>
  66. /// <param name="context">The StreamingContext.</param>
  67. public GridFSFileNotFoundException(SerializationInfo info, StreamingContext context)
  68. : base(info, context)
  69. {
  70. }
  71. #endif
  72. }
  73. }