示例#1
0
        /// <summary>
        /// Commit any changes to the debt class to the server.
        /// </summary>
        protected override void CommitDebtClass()
        {
            TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint);

            TradingSupportReference.DebtNegotiator record = new TradingSupportReference.DebtNegotiator();

            this.PopulateRecord(record);

            if (this.EntityId == Guid.Empty)
            {
                MethodResponseArrayOfguid response = tradingSupportClient.CreateDebtNegotiator(new TradingSupportReference.DebtNegotiator[] { record });

                if (!response.IsSuccessful)
                {
                    Entity.ThrowErrorInfo(response.Errors[0]);
                }
            }
            else
            {
                MethodResponseErrorCode response = tradingSupportClient.UpdateDebtNegotiator(new TradingSupportReference.DebtNegotiator[] { record });

                if (!response.IsSuccessful)
                {
                    Entity.ThrowErrorInfo(response.Errors[0]);
                }
            }

            tradingSupportClient.Close();
        }
示例#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);
        }
示例#3
0
        /// <summary>
        /// Create a new DebtNegotiator in the data model.
        /// </summary>
        /// <param name="dataModel">The data model client to create the negotiator with.</param>
        /// <param name="typeId">The type-id of the DebtNegotiator type.</param>
        /// <param name="parentId">The entityId of the parent entity.</param>
        /// <param name="tenantId"></param>
        /// <returns>The entity-id of the new debt negotiator.</returns>
        public static new Guid Create(DataModelClient dataModel, Guid typeId, Guid parentId, Guid tenantId)
        {
            Guid entityId = Guid.Empty;
            TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint);

            try
            {
                TradingSupportReference.DebtNegotiator record = new TradingSupportReference.DebtNegotiator();

                lock (DataModel.SyncRoot)
                {
                    DebtClassRow parent = DataModel.DebtClass.DebtClassKey.Find(parentId);

                    record.ConfigurationId = "Default";
                    record.Name            = "New Debt Negotiator";
                    record.ParentId        = parentId;
                    record.TenantId        = tenantId;

                    if (parent != null)
                    {
                        record.Address1          = parent.IsAddress1Null() ? null : parent.Address1;
                        record.Address2          = parent.IsAddress2Null() ? null : parent.Address2;
                        record.BankAccountNumber = parent.IsBankAccountNumberNull() ? null : parent.BankAccountNumber;
                        record.BankRoutingNumber = parent.IsBankRoutingNumberNull() ? null : parent.BankRoutingNumber;
                        record.City         = parent.IsCityNull() ? null : parent.City;
                        record.CompanyName  = parent.IsCompanyNameNull() ? null : parent.CompanyName;
                        record.ContactName  = parent.IsContactNameNull() ? null : parent.ContactName;
                        record.Department   = parent.IsDepartmentNull() ? null : parent.Department;
                        record.Email        = parent.IsEmailNull() ? null : parent.Email;
                        record.Fax          = parent.IsFaxNull() ? null : parent.Fax;
                        record.ForBenefitOf = parent.IsForBenefitOfNull() ? null : parent.ForBenefitOf;
                        record.Phone        = parent.IsPhoneNull() ? null : parent.Phone;
                        record.PostalCode   = parent.IsPostalCodeNull() ? null : parent.PostalCode;
                        record.Province     = parent.IsProvinceIdNull() ? null : (Guid?)parent.ProvinceId;
                    }
                }

                MethodResponseArrayOfguid response = tradingSupportClient.CreateDebtNegotiator(new TradingSupportReference.DebtNegotiator[] { record });
                if (response.IsSuccessful)
                {
                    entityId = response.Result[0];
                }
                else
                {
                    throw new Exception(String.Format("Server error: {0}, {1}", response.Errors[0].ErrorCode, response.Errors[0].Message));
                }
            }
            catch (Exception exception)
            {
                // Any issues trying to communicate to the server are logged.
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
                throw;
            }
            finally
            {
                if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened)
                {
                    tradingSupportClient.Close();
                }
            }

            return(entityId);
        }