Esempio n. 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.DebtHolder record = new TradingSupportReference.DebtHolder();

            this.PopulateRecord(record);

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

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

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

            tradingSupportClient.Close();
        }
Esempio n. 2
0
        /// <summary>
        /// Create a new DebtHolder in the data model.
        /// </summary>
        /// <param name="dataModel">The data model client to create the debt holder with.</param>
        /// <param name="typeId">The type-id of the DebtHolder type.</param>
        /// <param name="parentId">The entityId of the parent entity.</param>
        /// <param name="tenantId"></param>
        /// <returns>The entity-id of the new debt holder.</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.DebtHolder record = new TradingSupportReference.DebtHolder();

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

                    record.ConfigurationId   = "Default";
                    record.Name              = "New Debt Holder";
                    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.ParentId     = parent.DebtClassId;
                    record.Phone        = parent.IsPhoneNull()? null : parent.Phone;
                    record.PostalCode   = parent.IsPostalCodeNull()? null : parent.PostalCode;
                    record.Province     = parent.IsProvinceIdNull() ? null : (Guid?)parent.ProvinceId;
                }
                record.TenantId = tenantId;
                MethodResponseArrayOfguid response = tradingSupportClient.CreateDebtHolder(new TradingSupportReference.DebtHolder[] { 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);
        }
Esempio n. 3
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);
        }