コード例 #1
0
        /// <summary>
        /// Handle the actual import call and error recording.
        /// </summary>
        /// <param name="records">The records to import</param>
        /// <param name="sentSize">The actual bulk size used.</param>
        /// <returns>The errors encountered.</returns>
        protected override Dictionary <object, string> ImportRecord(Array records, out Int32 sentSize)
        {
            Dictionary <object, string> errors = new Dictionary <object, string>();
            MethodResponseArrayOfguid   response;

            response = NetworkHelper.Attempt <MethodResponseArrayOfguid>(
                (client, a) =>
                client.ImportDebtHolderRecords(records as TradingSupportReference.DebtHolderRecord[]),
                records,
                false,
                out sentSize);

            foreach (TradingSupportReference.ErrorInfo error in response.Errors)
            {
                errors[records.GetValue(error.BulkIndex)] = error.Message;
            }

            return(errors);
        }
コード例 #2
0
        /// <summary>
        /// Delete an set of debt holders.
        /// </summary>
        /// <param name="debtHolders">The set of working orders.</param>
        /// <returns>The actual bulk size used.</returns>
        protected override Int32 Delete(List <GuardianObject> debtHolders)
        {
            Int32          attemptedBulkSize = debtHolders.Count;
            Int32          actualBulkSize    = attemptedBulkSize;
            GuardianObject failedObject      = null;

            TradingSupportReference.DebtHolder[] records = new TradingSupportReference.DebtHolder[debtHolders.Count];
            Dictionary <TradingSupportReference.DebtHolder, DebtHolder> recordsToHolders =
                new Dictionary <TradingSupportReference.DebtHolder, DebtHolder>();

            // Convert the GuardianObjects to records we can push up to the server.
            for (Int32 index = 0; index < records.Length; ++index)
            {
                DebtHolder debtHolder = debtHolders[0] as DebtHolder;

                records[index] = new TradingSupportReference.DebtHolder();
                debtHolder.PopulateRecord(records[index]);
                recordsToHolders[records[index]] = debtHolder;
                debtHolders.RemoveAt(0);
            }

            try
            {
                Int32 sentSize;
                MethodResponseErrorCode response;

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

                if (sentSize < attemptedBulkSize)
                {
                    actualBulkSize = sentSize;
                }

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

                    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 = recordsToHolders[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 how
                        // 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(actualBulkSize);
        }