GridFSChunkException.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 GridFSChunk exception.
  25. /// </summary>
  26. #if NET452
  27. [Serializable]
  28. #endif
  29. public class GridFSChunkException : GridFSException
  30. {
  31. #region static
  32. private static string FormatMessage(BsonValue id, long n, string reason)
  33. {
  34. Ensure.IsNotNull(id, nameof(id));
  35. Ensure.IsGreaterThanOrEqualToZero(n, nameof(n));
  36. Ensure.IsNotNull(reason, nameof(reason));
  37. return string.Format("GridFS chunk {0} of file id {1} is {2}.", n, id, reason);
  38. }
  39. #endregion
  40. // constructors
  41. /// <summary>
  42. /// Initializes a new instance of the <see cref="GridFSChunkException" /> class.
  43. /// </summary>
  44. /// <param name="id">The file id.</param>
  45. /// <param name="n">The chunk number.</param>
  46. /// <param name="reason">The reason.</param>
  47. public GridFSChunkException(BsonValue id, long n, string reason)
  48. : base(FormatMessage(id, n, reason))
  49. {
  50. }
  51. #if NET452
  52. /// <summary>
  53. /// Initializes a new instance of the <see cref="GridFSChunkException"/> class.
  54. /// </summary>
  55. /// <param name="info">The SerializationInfo.</param>
  56. /// <param name="context">The StreamingContext.</param>
  57. public GridFSChunkException(SerializationInfo info, StreamingContext context)
  58. : base(info, context)
  59. {
  60. }
  61. #endif
  62. }
  63. }