/// <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; } }
/// <summary> /// Copies the data from one entity to another. /// </summary> /// <param name="entity">The source entity.</param> public override void Copy(GuardianObject entity) { base.Copy(entity); this.rowVersion = (entity as DebtHolder).RowVersion; }
/// <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); }
/// <summary> /// Move this working order from one blotter to another. /// </summary> /// <param name="newParent">The new location of the working order.</param> /// <param name="errors">The list of errors and at what index.</param> public void Move(GuardianObject newParent, List <ErrorInfo> errors) { this.Move(new List <IMovableObject> { this }, newParent, errors); }
/// <summary> /// Update this entity with contents of another one. /// </summary> /// <param name="entity">The entity to update from.</param> public override void Copy(GuardianObject entity) { base.Copy(entity); this.tenant = (entity as RightsHolder).Tenant; }
/// <summary> /// Copies the data from one entity to another. /// </summary> /// <param name="obj">The source entity.</param> public virtual void Copy(GuardianObject obj) { this.modified = obj.Modified; }
/// <summary> /// Update this object based on another. /// </summary> /// <param name="obj">The object to draw updates from.</param> public abstract void Update(GuardianObject obj);
/// <summary> /// Move the move list, updating the progress bar as we go. /// </summary> private void Move(GuardianObject target) { List <IMovableObject> objects = null; List <FluidTrade.Guardian.TradingSupportReference.ErrorInfo> errors = new List <FluidTrade.Guardian.TradingSupportReference.ErrorInfo>(); try { // Run through the delete list in LIFO order, maintaining the integrity of the entity tree as we delete. while (this.moveList.Count > 0) { objects = this.GetBatch(); this.Dispatcher.BeginInvoke(new WaitCallback(name => this.Message = String.Format(FluidTrade.Guardian.Properties.Resources.MovingObject, name as String)), DispatcherPriority.Normal, objects[0].ToString()); if (objects.Count == 1) { objects[0].Move(target, errors); } else { objects[0].Move(objects, target, errors); } // The progress bar properties belong to the foreground, so toss the increment up to the main thread. this.Dispatcher.BeginInvoke(new WaitCallback( delegate(object count) { this.TimeLeftVisibility = Visibility.Visible; this.Value += (Int32)count; TimeSpan left = new TimeSpan((long)((this.Maximum - this.Value) * ((DateTime.Now - this.startTime).Ticks / this.Value))); this.TimeLeft = left < TimeSpan.Zero ? TimeSpan.Zero : left; }), DispatcherPriority.Normal, objects.Count); } } catch (SecurityAccessDeniedException exception) { Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data => MessageBox.Show( Application.Current.MainWindow, String.Format(FluidTrade.Guardian.Properties.Resources.MoveFailedAccessDenied, data), Application.Current.MainWindow.Title)), DispatcherPriority.Normal, objects[0]); EventLog.Warning("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace); } catch (Exception exception) { Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data => MessageBox.Show( Application.Current.MainWindow, String.Format(FluidTrade.Guardian.Properties.Resources.MoveFailed, data), Application.Current.MainWindow.Title)), DispatcherPriority.Normal, objects[0]); EventLog.Warning("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace); } if (errors.Count > 0) { Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data => MessageBox.Show( Application.Current.MainWindow, FluidTrade.Guardian.Properties.Resources.MovePartialFail, Application.Current.MainWindow.Title)), DispatcherPriority.Normal, objects[0]); } // We're done. Windows Explorer doesn't throw up an alert, so we won't either. this.Dispatcher.BeginInvoke(new Action(this.Close), DispatcherPriority.Normal); }
/// <summary> /// Delete the delete list, updating the progress bar as we go. /// </summary> private void Delete() { List <GuardianObject> objects = null; GuardianObject failedObject = null; try { try { // Run through the delete list in LIFO order, maintaining the integrity of the entity tree as we delete. while (this.deleteList.Count > 0) { objects = this.GetBatch(); this.Dispatcher.BeginInvoke(new WaitCallback(name => this.Message = String.Format(FluidTrade.Guardian.Properties.Resources.DeletingObject, name as String)), DispatcherPriority.Normal, objects[0].ToString()); if (objects.Count == 1) { objects[0].Commit(); } else { Int32 attemptedSize = objects.Count; Int32 sentSize = objects[0].Commit(objects); if (sentSize < attemptedSize) { this.batchSize = sentSize; } } // The progress bar properties belong to the foreground, so toss the increment up to the main thread. this.Dispatcher.BeginInvoke(new WaitCallback(delegate(object count) { this.TimeLeftVisibility = Visibility.Visible; this.Value += (Int32)count; TimeSpan left = new TimeSpan((long)((this.Maximum - this.Value) * ((DateTime.Now - this.startTime).Ticks / this.Value))); this.TimeLeft = left < TimeSpan.Zero ? TimeSpan.Zero : left; }), DispatcherPriority.Normal, objects.Count); } } catch (DeleteException capturedException) { failedObject = capturedException.FailedObject; throw capturedException.InnerException; } } catch (IsSettledException exception) { Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data => MessageBox.Show( Application.Current.MainWindow, String.Format(FluidTrade.Guardian.Properties.Resources.DeleteFailedIsSettledAccount, data), Application.Current.MainWindow.Title)), DispatcherPriority.Normal, failedObject); EventLog.Warning("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace); } catch (HasSettlementsException exception) { Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data => MessageBox.Show( Application.Current.MainWindow, String.Format(FluidTrade.Guardian.Properties.Resources.DeleteFailedHasSettledAccounts, data), Application.Current.MainWindow.Title)), DispatcherPriority.Normal, failedObject); EventLog.Warning("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace); } catch (SecurityAccessDeniedException exception) { Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data => MessageBox.Show( Application.Current.MainWindow, String.Format(FluidTrade.Guardian.Properties.Resources.DeleteFailedAccessDenied, data), Application.Current.MainWindow.Title)), DispatcherPriority.Normal, failedObject); EventLog.Warning("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace); } catch (CommunicationObjectFaultedException exception) { Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data => MessageBox.Show( Application.Current.MainWindow, String.Format(FluidTrade.Guardian.Properties.Resources.DeleteFailedConnectionDropped), Application.Current.MainWindow.Title)), DispatcherPriority.Normal); EventLog.Warning("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace); } catch (Exception exception) { if (failedObject != null) { Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data => MessageBox.Show( Application.Current.MainWindow, String.Format(FluidTrade.Guardian.Properties.Resources.DeleteFailed, data), Application.Current.MainWindow.Title)), DispatcherPriority.Normal, failedObject); } else { Application.Current.Dispatcher.BeginInvoke(new WaitCallback(data => MessageBox.Show( Application.Current.MainWindow, String.Format(FluidTrade.Guardian.Properties.Resources.DeleteFailedCompletely), Application.Current.MainWindow.Title)), DispatcherPriority.Normal); } EventLog.Warning("{0}: {1}\n{2}", exception.GetType(), exception.Message, exception.StackTrace); } // We're done. Windows Explorer doesn't throw up an alert, so we won't either. this.Dispatcher.BeginInvoke(new Action(this.Close), DispatcherPriority.Normal); }
/// <summary> /// Commit any changes to this user to the server. /// </summary> public override void Commit() { AdminSupportClient client = new AdminSupportClient(Guardian.Properties.Settings.Default.AdminSupportEndpoint); AdminSupportReference.User user = new AdminSupportReference.User(); MethodResponseErrorCode response; this.PopulateRecord(user); if (this.Deleted) { response = client.DeleteUserAccount(user.LookupId); if (this.GetFirstErrorCode(response) == ErrorCode.RecordNotFound) { throw new UserNotFoundException(this, "User not found"); } } else { response = client.UpdateUser(new AdminSupportReference.User[] { user }); if (this.GetFirstErrorCode(response) == ErrorCode.RecordNotFound) { throw new UserNotFoundException(this, "User not found"); } if (response.IsSuccessful) { if (this.AccountDisabled) { response = client.DisableUserAccount(this.IdentityName); } } if (response.IsSuccessful) { lock (DataModel.SyncRoot) { List <Group> newGroups = this.Groups.ToList(); List <Guid> add = new List <Guid>(); List <Guid> del = new List <Guid>(); GroupUsersRow[] oldGroups = DataModel.User.UserKey.Find(this.UserId).GetGroupUsersRows(); ErrorCode firstError; foreach (GroupUsersRow groupUsersRow in oldGroups) { Group group = newGroups.FirstOrDefault(g => g.GroupId == groupUsersRow.GroupId); if (group == null) { del.Add(groupUsersRow.GroupId); } else { if (group.Deleted) { del.Add(group.GroupId); } newGroups.Remove(group); } } foreach (Group group in newGroups) { response = client.AddUserToGroup(this.IdentityName, group.GroupId, this.TenantId); firstError = this.GetFirstErrorCode(response); if (firstError == ErrorCode.RecordNotFound) { throw new GroupNotFoundException(this.DefaultGroup, "Group not found"); } else if (firstError != ErrorCode.Success) { break; } } foreach (Guid group in del) { response = client.RemoveUserFromGroup(this.IdentityName, group); firstError = this.GetFirstErrorCode(response); if (firstError != ErrorCode.RecordNotFound && firstError != ErrorCode.Success) { break; } } } } } if (!response.IsSuccessful) { GuardianObject.ThrowErrorInfo(response.Errors[0]); } client.Close(); this.Modified = false; }