/// <summary> /// Delete the debt holder proper. /// </summary> protected override void DeleteDebtClass() { TradingSupportClient client = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint); base.DeleteDebtClass(); MethodResponseErrorCode response = client.DeleteDebtHolder(new TradingSupportReference.DebtHolder[] { new TradingSupportReference.DebtHolder { RowId = this.EntityId, RowVersion = this.RowVersion } }); if (!response.IsSuccessful) { if (response.Errors.Length > 0) { Entity.ThrowErrorInfo(response.Errors[0]); } else { Entity.ThrowErrorInfo(response.Result); } } client.Close(); }
/// <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(); }
/// <summary> /// Do actual delete. /// </summary> /// <param name="tradingSupport">The trading support client.</param> private void CommitDelete(TradingSupportClient tradingSupport) { if (this.DebtRuleId != null) { Boolean inUse = false; lock (DataModel.SyncRoot) inUse = DataModel.DebtClass.Any(row => !row.IsDebtRuleIdNull() && row.DebtRuleId == this.DebtRuleId); if (!inUse) { MethodResponseErrorCode response = tradingSupport.DeleteDebtRule(new TradingSupportReference.DebtRule[] { new TradingSupportReference.DebtRule() { RowId = this.DebtRuleId.Value, RowVersion = this.RowVersion } }); if (!response.IsSuccessful && (response.Errors.Length == 0 || response.Errors[0].ErrorCode != ErrorCode.Deadlock)) { GuardianObject.ThrowErrorInfo(response.Errors[0]); } } else { throw new DebtRuleInUseException(this.Name, "Cannot delete a debt rule that is currently in use."); } } }
/// <summary> /// /// </summary> /// <param name="consumers"></param> public static MethodResponseErrorCode UpdateConsumer(Consumer[] consumers) { MethodResponseErrorCode response = null; // Update the database. TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint); try { response = tradingSupportClient.UpdateConsumer(consumers); } catch (Exception exception) { // Any issues trying to communicate to the server are logged. EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } finally { if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened) { tradingSupportClient.Close(); } } return(response); }
/// <summary> /// Move several working orders from one blotter to another. /// </summary> /// <param name="objects">The list of working orders to move.</param> /// <param name="newParent">The new location of the working orders.</param> /// <param name="errors">The list of errors and at what index.</param> public void Move(List <IMovableObject> objects, GuardianObject newParent, List <ErrorInfo> errors) { try { Int32 tries = 0; bool retry = false; BaseRecord[] records = this.PopulateSecurityRecords(objects); MethodResponseErrorCode response = null; do { TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint); response = this.MoveSecurity(tradingSupportClient, records, newParent as Blotter); if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened) { tradingSupportClient.Close(); } tries += 1; if (!response.IsSuccessful) { List <BaseRecord> retryRecords = new List <BaseRecord>(); foreach (ErrorInfo errorInfo in response.Errors) { // If the error's "just" a deadlock, add it to the retry list we can attempt it again. if (errorInfo.ErrorCode == ErrorCode.Deadlock) { retryRecords.Add(records[errorInfo.BulkIndex]); } //No need to retry if the client does not have permission to move. else if (errorInfo.ErrorCode == ErrorCode.AccessDenied) { GuardianObject.ThrowErrorInfo(response.Errors[0]); } else { errors.Add(errorInfo); } } records = retryRecords.ToArray(); retry = retryRecords.Count > 0; } } while (retry && tries < WorkingOrder.TotalRetries); } 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; } }
/// <summary> /// Actual execute a move by moving the securities. /// </summary> /// <param name="client">The trading support client to use.</param> /// <param name="records">The security records to move.</param> /// <param name="newParent">The new blotter.</param> /// <returns>The server response</returns> protected override MethodResponseErrorCode MoveSecurity( TradingSupportClient client, BaseRecord[] records, Blotter newParent) { MethodResponseErrorCode response = null; response = client.MoveConsumerDebtToBlotter(newParent.BlotterId, records); return(response); }
private void UpdateField(object state) { Func <MethodResponseErrorCode> orderClient = state as Func <MethodResponseErrorCode>; try { // Call the handler to update the working order record. MethodResponseErrorCode returnCode = orderClient(); } catch (FaultException <OptimisticConcurrencyFault> optimisticConcurrencyException) { // The record is busy. this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action( delegate() { AlertMessageBox.Instance.Show(optimisticConcurrencyException); } )); } catch (FaultException <RecordNotFoundFault> recordNotFoundException) { // The record is busy. this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action( delegate() { AlertMessageBox.Instance.Show(recordNotFoundException); } )); } catch (CommunicationException) { // Log communication problems. this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action( delegate() { AlertMessageBox.Instance.Show(AlertMessageBoxType.LostConnectionToServer); } )); } catch (Exception exception) { // Log communication problems. EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } }
/// <summary> /// Commit the new link to the database. /// </summary> /// <param name="parent">The parent folder.</param> /// <param name="child">The child folder.</param> private void Commit(Entity parent, Entity child) { try { lock (DataModel.SyncRoot) { EntityTreeRow entityTreeRow = DataModel.EntityTree.EntityTreeKeyChildIdParentId.Find(child.EntityId, parent.EntityId); TradingSupportClient client = new TradingSupportClient(Properties.Settings.Default.TradingSupportEndpoint); MethodResponseErrorCode response = client.DeleteEntityTree( new EntityTree[] { new EntityTree() { RowId = entityTreeRow.EntityTreeId, RowVersion = entityTreeRow.RowVersion } }); if (!response.IsSuccessful) { if (response.Errors.Length > 0) { GuardianObject.ThrowErrorInfo(response.Errors[0]); } else { GuardianObject.ThrowErrorInfo(response.Result); } } client.Close(); } } catch (FaultException <RecordNotFoundFault> exception) { EventLog.Warning("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace); } catch (Exception exception) { EventLog.Error("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace); Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data => MessageBox.Show( Application.Current.MainWindow, String.Format(FluidTrade.Guardian.Properties.Resources.UnlinkFolderFailed, child, parent), Application.Current.MainWindow.Title)), DispatcherPriority.Normal); } }
public static void MoveConsumerDebtToBlotter(Guid blotterId, BaseRecord[] consumerDebt) { // Update the database. TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint); try { MethodResponseErrorCode response = tradingSupportClient.MoveConsumerDebtToBlotter(blotterId, consumerDebt); } catch (Exception exception) { // Any issues trying to communicate to the server are logged. EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } finally { if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened) { tradingSupportClient.Close(); } } }
/// <summary> /// /// </summary> /// <param name="workingOders"></param> public static MethodResponseErrorCode UpdateWorkingOrder(WorkingOrderRecord workingOrder) { MethodResponseErrorCode response = null; // Update the database. TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint); try { lock (DataModel.SyncRoot) { WorkingOrderRow row = DataModel.WorkingOrder.WorkingOrderKey.Find(workingOrder.RowId); if (TradingSupportWebService.ColumnChanged(row, workingOrder)) { response = tradingSupportClient.UpdateWorkingOrder(new WorkingOrderRecord[] { workingOrder }); } else { response = null; } } } catch (Exception exception) { // Any issues trying to communicate to the server are logged. EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } finally { if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened) { tradingSupportClient.Close(); } } return(response); }
/// <summary> /// Delete a list of credit card rows. /// </summary> /// <param name="state">The list to delete.</param> public void DestroyRecords(object state) { List <CreditCardRow> toDeleteRows = state as List <CreditCardRow>; TradingSupportClient tradingSupportClient = new TradingSupportClient(Guardian.Properties.Settings.Default.TradingSupportEndpoint); try { int recordsPerCall = 100; TradingSupportReference.CreditCard[] orders = null; int recordTotal = 0; int recordIndex = 0; foreach (CreditCardRow workingOrderRow in toDeleteRows) { if (recordIndex == 0) { orders = new TradingSupportReference.CreditCard[ toDeleteRows.Count - recordTotal < recordsPerCall ? toDeleteRows.Count - recordTotal : recordsPerCall]; } orders[recordIndex++] = new TradingSupportReference.CreditCard() { RowId = workingOrderRow.CreditCardId, RowVersion = workingOrderRow.RowVersion }; if (recordIndex == orders.Length) { MethodResponseErrorCode response = tradingSupportClient.DeleteCreditCard(orders); if (!response.IsSuccessful) { ErrorCode error = response.Result; if (response.Errors.Length > 0) { error = response.Errors[0].ErrorCode; } if (error == ErrorCode.RecordExists) { throw new IsSettledException(string.Format("{0} is settled", workingOrderRow.OriginalAccountNumber)); } else { throw new Exception(String.Format("Server error {0}", response.Result)); } } recordTotal += recordIndex; recordIndex = 0; } } } catch (IsSettledException exception) { EventLog.Information("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace); this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(Application.Current.MainWindow, "Cannot delete Credit Card: " + exception.Message, Application.Current.MainWindow.Title))); } 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); this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(Application.Current.MainWindow, "Cannot delete Credit Card", Application.Current.MainWindow.Title))); } finally { if (tradingSupportClient != null && tradingSupportClient.State == CommunicationState.Opened) { tradingSupportClient.Close(); } } }
/// <summary> /// Set the user's password to the new password. /// </summary> /// <param name="user">The user to change.</param> /// <param name="oldPassword">The current password.</param> /// <param name="password">The new password.</param> private void ResetPassword(User user, string oldPassword, string password) { try { AdminSupportClient adminSupportClient = new AdminSupportClient(Guardian.Properties.Settings.Default.AdminSupportEndpoint); AdminSupportReference.User userRecord = new AdminSupportReference.User(); MethodResponseErrorCode response = null; DataModel.IsReading = false; if (user.UserId == UserContext.Instance.UserId) { response = adminSupportClient.ChangePassword(oldPassword, password); if (response.IsSuccessful) { ChannelStatus.LoginEvent.Set(); ChannelStatus.IsPrompted = false; ChannelStatus.Secret = password; ChannelStatus.LogggedInEvent.Set(); } } else { response = adminSupportClient.ResetPassword(user.IdentityName, password); } if (!response.IsSuccessful) { GuardianObject.ThrowErrorInfo(response.Errors[0]); } adminSupportClient.Close(); } catch (FaultException <ArgumentFault> ) { this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(this, String.Format(Properties.Resources.ResetPasswordFailedPoorComplexity, user), this.Title))); } catch (SecurityAccessDeniedException) { this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(this, String.Format(Properties.Resources.UserNotFound, user), this.Title))); } catch (FaultException <RecordNotFoundFault> ) { this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(this, String.Format(Properties.Resources.ResetPasswordFailedPermissionDenied, user), this.Title))); } catch (Exception exception) { // Any issues trying to communicate to the server are logged. EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); this.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(this, String.Format(Properties.Resources.ResetPasswordFailed, user.Name), this.Title))); } finally { DataModel.IsReading = true; } }