Ejemplo n.º 1
0
 /// <summary>
 /// Create a duplicate debt class.
 /// </summary>
 /// <param name="source">The original debt class.</param>
 public DebtNegotiator(DebtNegotiator source)
     : base(source)
 {
     this.rowVersion = source.RowVersion;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete an set of debt negotiators.
        /// </summary>
        /// <param name="debtNegotiators">The set of working orders.</param>
        /// <returns>The actual bulk size used.</returns>
        protected override Int32 Delete(List <GuardianObject> debtNegotiators)
        {
            GuardianObject failedObject = null;

            TradingSupportReference.DebtNegotiator[] records = new TradingSupportReference.DebtNegotiator[debtNegotiators.Count];
            Dictionary <TradingSupportReference.DebtNegotiator, DebtNegotiator> recordsToNegotiators =
                new Dictionary <TradingSupportReference.DebtNegotiator, DebtNegotiator>();
            Int32 sentSize;

            for (Int32 index = 0; index < records.Length; ++index)
            {
                DebtNegotiator debtNegotiator = debtNegotiators[0] as DebtNegotiator;

                records[index] = new TradingSupportReference.DebtNegotiator();
                debtNegotiator.PopulateRecord(records[index]);
                recordsToNegotiators[records[index]] = debtNegotiator;
                debtNegotiators.RemoveAt(0);
            }

            try
            {
                MethodResponseErrorCode response;

                response = NetworkHelper.Attempt <MethodResponseErrorCode>(
                    (client, a) =>
                    client.DeleteDebtNegotiator(a as TradingSupportReference.DebtNegotiator[]),
                    records,
                    true,
                    out sentSize);

                if (!response.IsSuccessful)
                {
                    List <TradingSupportReference.DebtNegotiator> retryRecords = new List <TradingSupportReference.DebtNegotiator>();

                    foreach (ErrorInfo errorInfo in response.Errors)
                    {
                        // The bulk index is an index into the set we sent, which may be smaller than the set passed in.
                        failedObject = recordsToNegotiators[records[errorInfo.BulkIndex]];

                        // If the error's "just" a deadlock, we should retry it.
                        if (errorInfo.ErrorCode == ErrorCode.Deadlock)
                        {
                            retryRecords.Add(records[errorInfo.BulkIndex]);
                        }
                        else if (errorInfo.ErrorCode == ErrorCode.RecordExists)
                        {
                            throw new HasSettlementsException(this.ToString() + " has settled accounts");
                        }
                        // We can safely ignore not-found errors (we are deleting after all), but if the error's more severe, forget the whole
                        // thing and throw up the error.
                        else if (errorInfo.ErrorCode != ErrorCode.RecordNotFound)
                        {
                            GuardianObject.ThrowErrorInfo(response.Errors[0]);
                        }
                    }

                    records = retryRecords.ToArray();
                }
            }
            catch (Exception exception)
            {
                // Any issues trying to communicate to the server are logged.
                EventLog.Error("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace);
                throw new DeleteException(failedObject, exception);
            }

            return(sentSize);
        }