|
| 1 | +/* Copyright 2010-2014 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 | + |
| 16 | +using System; |
| 17 | +using System.Collections.Generic; |
| 18 | +using System.Collections.ObjectModel; |
| 19 | +using System.Linq; |
| 20 | +using System.Runtime.Serialization; |
| 21 | + |
| 22 | +namespace MongoDB.Driver |
| 23 | +{ |
| 24 | + /// <summary> |
| 25 | + /// Represents a bulk write exception. |
| 26 | + /// </summary> |
| 27 | + [Serializable] |
| 28 | +#pragma warning disable 618 |
| 29 | + public class MongoBulkWriteException : BulkWriteException |
| 30 | +#pragma warning restore |
| 31 | + { |
| 32 | + // private fields |
| 33 | + private BulkWriteResult _result; |
| 34 | + private ReadOnlyCollection<WriteRequest> _unprocessedRequests; |
| 35 | + private WriteConcernError _writeConcernError; |
| 36 | + private ReadOnlyCollection<BulkWriteError> _writeErrors; |
| 37 | + |
| 38 | + // constructors |
| 39 | + /// <summary> |
| 40 | + /// Initializes a new instance of the <see cref="MongoBulkWriteException" /> class. |
| 41 | + /// </summary> |
| 42 | + /// <param name="result">The result.</param> |
| 43 | + /// <param name="writeErrors">The write errors.</param> |
| 44 | + /// <param name="unprocessedRequests">The unprocessed requests.</param> |
| 45 | + /// <param name="writeConcernError">The write concern error.</param> |
| 46 | + public MongoBulkWriteException( |
| 47 | + BulkWriteResult result, |
| 48 | + IEnumerable<BulkWriteError> writeErrors, |
| 49 | + WriteConcernError writeConcernError, |
| 50 | + IEnumerable<WriteRequest> unprocessedRequests) |
| 51 | + : base("A bulk write operation resulted in one or more errors.") |
| 52 | + { |
| 53 | + _result = result; |
| 54 | + _writeErrors = new ReadOnlyCollection<BulkWriteError>(writeErrors.ToList()); |
| 55 | + _writeConcernError = writeConcernError; |
| 56 | + _unprocessedRequests = new ReadOnlyCollection<WriteRequest>(unprocessedRequests.ToList()); |
| 57 | + } |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Initializes a new instance of the MongoBulkWriteException class (this overload supports deserialization). |
| 61 | + /// </summary> |
| 62 | + /// <param name="info">The SerializationInfo.</param> |
| 63 | + /// <param name="context">The StreamingContext.</param> |
| 64 | + public MongoBulkWriteException(SerializationInfo info, StreamingContext context) |
| 65 | + : base(info, context) |
| 66 | + { |
| 67 | + } |
| 68 | + |
| 69 | + // public properties |
| 70 | + /// <summary> |
| 71 | + /// Gets the result of the bulk write operation. |
| 72 | + /// </summary> |
| 73 | + public override BulkWriteResult Result |
| 74 | + { |
| 75 | + get { return _result; } |
| 76 | + } |
| 77 | + |
| 78 | + /// <summary> |
| 79 | + /// Gets the unprocessed requests. |
| 80 | + /// </summary> |
| 81 | + /// <value> |
| 82 | + /// The unprocessed requests. |
| 83 | + /// </value> |
| 84 | + /// <exception cref="System.NotImplementedException"></exception> |
| 85 | + public override ReadOnlyCollection<WriteRequest> UnprocessedRequests |
| 86 | + { |
| 87 | + get { return _unprocessedRequests; } |
| 88 | + } |
| 89 | + |
| 90 | + /// <summary> |
| 91 | + /// Gets the write concern error. |
| 92 | + /// </summary> |
| 93 | + /// <value> |
| 94 | + /// The write concern error. |
| 95 | + /// </value> |
| 96 | + public override WriteConcernError WriteConcernError |
| 97 | + { |
| 98 | + get { return _writeConcernError; } |
| 99 | + } |
| 100 | + |
| 101 | + /// <summary> |
| 102 | + /// Gets the write errors. |
| 103 | + /// </summary> |
| 104 | + /// <value> |
| 105 | + /// The write errors. |
| 106 | + /// </value> |
| 107 | + public override ReadOnlyCollection<BulkWriteError> WriteErrors |
| 108 | + { |
| 109 | + get { return _writeErrors; } |
| 110 | + } |
| 111 | + } |
| 112 | +} |
0 commit comments