BulkWriteError.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright 2010-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.Collections.ObjectModel;
  18. using System.Linq;
  19. using MongoDB.Bson;
  20. using MongoDB.Bson.Serialization.Attributes;
  21. using MongoDB.Driver.Support;
  22. namespace MongoDB.Driver
  23. {
  24. /// <summary>
  25. /// Represents the details of a write error for a particular request.
  26. /// </summary>
  27. #if NET452
  28. [Serializable]
  29. #endif
  30. public class BulkWriteError : WriteError
  31. {
  32. // private fields
  33. private readonly int _index;
  34. // constructors
  35. internal BulkWriteError(int index, ServerErrorCategory category, int code, string message, BsonDocument details)
  36. : base(category, code, message, details)
  37. {
  38. _index = index;
  39. }
  40. // public properties
  41. /// <summary>
  42. /// Gets the index of the request that had an error.
  43. /// </summary>
  44. public int Index
  45. {
  46. get { return _index; }
  47. }
  48. // internal static methods
  49. internal static BulkWriteError FromCore(Core.Operations.BulkWriteOperationError error)
  50. {
  51. return new BulkWriteError(error.Index, error.Category, error.Code, error.Message, error.Details);
  52. }
  53. // internal methods
  54. internal BulkWriteError WithMappedIndex(IndexMap indexMap)
  55. {
  56. var mappedIndex = indexMap.Map(_index);
  57. return (_index == mappedIndex) ? this : new BulkWriteError(mappedIndex, Category, Code, Message, Details);
  58. }
  59. }
  60. }