private void LoadDatabaseList() { var app = (App)Application.Current; var loginModel = (LoginModel)this.DataContext; if (app.ClientService == null) { app.ClientService = new SlipStreamClient(new Uri(loginModel.Address)); } try { app.ClientService.ListDatabases((dbs, error) => { this.listDatabases.ItemsSource = dbs; if (dbs.Length >= 1) { this.buttonSignIn.IsEnabled = true; this.listDatabases.SelectedIndex = 0; } }); } catch (System.Security.SecurityException) { ErrorWindow.CreateNew( "安全错误:无法连接服务器,或服务器缺少 '/crossdomain.xml'文件。", StackTracePolicy.OnlyWhenDebuggingOrRunningLocally); } }
void wc_WS_GetTreeCompleted(object sender, WS_Link.WS_GetTreeCompletedEventArgs e) { tree.set_ParentTree(e.Result); try { tree.refresh_Nodes(2, 0); box_Nodes_1.ItemsSource = tree.Node_1; if (box_Nodes_1.Items.Count > 1) { box_Nodes_1.SelectedIndex = 1; } box_Nodes_2.ItemsSource = tree.Node_2; if (box_Nodes_2.Items.Count > 0) { box_Nodes_2.SelectedIndex = 0; } box_Nodes_3.ItemsSource = tree.Node_3; if (box_Nodes_3.Items.Count > 0) { box_Nodes_3.SelectedIndex = 0; } } catch (Exception err) { ErrorWindow.CreateNew(err); } }
/// <summary> /// Completion handler for a <see cref="LoginOperation"/>. If operation succeeds, /// it closes the window. If it has an error, we show an <see cref="ErrorWindow"/> /// and mark the error as handled. If it was not canceled, but login failed, it must /// have been because credentials were incorrect so we add a validation error to /// to notify the user. /// </summary> private void LoginOperation_Completed(LoginOperation loginOperation) { if (loginOperation.LoginSuccess) { this.parentWindow.Close(); } else if (loginOperation.HasError) { ErrorWindow.CreateNew(loginOperation.Error); loginOperation.MarkErrorAsHandled(); } else if (!loginOperation.IsCanceled) { this.loginInfo.ValidationErrors.Add(new ValidationResult(ErrorResources.ErrorBadUserNameOrPassword, new string[] { "UserName", "Password" })); } var userService = IoC.Resolve <IApplicationUserService>(); userService.ApplicationUserRetrieved += (sender, e) => { if (e.Value is ApplicationUser) { ApplicationUser.CurrentUser = e.Value as ApplicationUser; } }; userService.ApplicationUserRetrievalError += (sender, e) => { WebContext.Current.Authentication.Logout(true); ErrorWindow.CreateNew("Error occured creating the application user"); }; userService.RetrieveApplicationUser(loginInfo.UserName); }
/// <summary> /// Completion handler for the registration operation. If there was an error, an /// <see cref="ErrorWindow"/> is displayed to the user. Otherwise, this triggers /// a login operation that will automatically log in the just registered user. /// </summary> private void RegistrationOperation_Completed(InvokeOperation <CreateUserStatus> operation) { if (!operation.IsCanceled) { if (operation.HasError) { ErrorWindow.CreateNew(operation.Error); operation.MarkErrorAsHandled(); } else if (operation.Value == CreateUserStatus.Success) { this.registrationData.CurrentOperation = WebContext.Current.Authentication.Login(this.registrationData.ToLoginParameters(), this.LoginOperation_Completed, null); this.parentWindow.AddPendingOperation(this.registrationData.CurrentOperation); } else if (operation.Value == CreateUserStatus.DuplicateUserName) { this.registrationData.ValidationErrors.Add(new ValidationResult(ErrorResources.CreateUserStatusDuplicateUserName, new string[] { "UserName" })); } else if (operation.Value == CreateUserStatus.DuplicateEmail) { this.registrationData.ValidationErrors.Add(new ValidationResult(ErrorResources.CreateUserStatusDuplicateEmail, new string[] { "Email" })); } else { ErrorWindow.CreateNew(ErrorResources.ErrorWindowGenericError); } } }
private void box_Nodes_1_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { int n1 = 0; TreeItem selectedItem = box_Nodes_1.SelectedItem as TreeItem; if (selectedItem != null) { n1 = selectedItem.ID; } tree.refresh_Nodes(n1, 0); box_Nodes_2.ItemsSource = tree.Node_2; if (box_Nodes_2.Items.Count > 0) { box_Nodes_2.SelectedIndex = 0; } box_Nodes_3.ItemsSource = tree.Node_3; if (box_Nodes_3.Items.Count > 0) { box_Nodes_3.SelectedIndex = 0; } tree.Node_1_SelectedID = n1; } catch (Exception err) { ErrorWindow.CreateNew(err); } }
/// <summary> /// Handles the DispatcherUnhandledException event of the App control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Threading.DispatcherUnhandledExceptionEventArgs"/> instance containing the event data.</param> static void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } e.Handled = true; ErrorWindow.CreateNew(e.Exception, StackTracePolicy.Always); }
private void LogoutButton_Click(object sender, RoutedEventArgs e) { this.authService.Logout(logoutOperation => { if (logoutOperation.HasError) { ErrorWindow.CreateNew(logoutOperation.Error); logoutOperation.MarkErrorAsHandled(); } }, /* userState */ null); }
private void LogoutButton_Click(object sender, RoutedEventArgs e) { WebContext.Current.Authentication.Logout(logoutOperation => { if (logoutOperation.HasError) { ErrorWindow.CreateNew(logoutOperation.Error); logoutOperation.MarkErrorAsHandled(); } }, /* userState */ null); }
void InsertDevice_Loaded(object sender, RoutedEventArgs e) { try { wc.WS_GetTreeCompleted += new EventHandler <WS_Link.WS_GetTreeCompletedEventArgs>(wc_WS_GetTreeCompleted); wc.WS_GetTreeAsync(); } catch (Exception err) { ErrorWindow.CreateNew(err); } }
/// <summary> /// Handles <see cref="SubmitOperation.Completed"/> for a userRegistrationContext /// operation. If there was an error, an <see cref="ErrorWindow"/> is /// displayed to the user. Otherwise, this triggers a <see cref="LoginOperation"/> /// that will automatically log in the just registered user /// </summary> private void RegistrationOperation_Completed(SubmitOperation asyncResult) { if (asyncResult.HasError) { ErrorWindow.CreateNew(asyncResult.Error); asyncResult.MarkErrorAsHandled(); this.registerForm.BeginEdit(); } else { LoginOperation loginOperation = WebContext.Current.Authentication.Login(this.registrationData.ToLoginParameters(), this.LoginOperation_Completed, null); this.BindUIToOperation(loginOperation); this.parentWindow.AddPendingOperation(loginOperation); } }
/// <summary> /// Completion handler for the registration operation. /// If there was an error, an <see cref="ErrorWindow"/> is displayed to the user. /// Otherwise, this triggers a login operation that will automatically log in the just registered user. /// </summary> private void RegistrationOperation_Completed(InvokeOperation operation) { if (!operation.IsCanceled) { if (operation.HasError) { ErrorWindow.CreateNew(operation.Error); operation.MarkErrorAsHandled(); } else { this.parentWindow.Close(); } } }
/// <summary> /// Handles <see cref="LoginOperation.Completed"/> event for /// the login operation that is sent right after a successful /// userRegistrationContext. This will close the window. On the unexpected /// event that this operation failed (the user was just added so /// why wouldn't it be authenticated successfully) an /// <see cref="ErrorWindow"/> is created and will display the /// error message. /// </summary> /// <param name="loginOperation"></param> private void LoginOperation_Completed(LoginOperation loginOperation) { this.parentWindow.Close(); if (loginOperation.HasError) { ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ApplicationStrings.ErrorLoginAfterRegistrationFailed, loginOperation.Error.Message)); loginOperation.MarkErrorAsHandled(); } else if (loginOperation.LoginSuccess == false) { // ApplicationStrings.ErrorBadUserNameOrPassword is the correct error message as operation succeeded but login failed ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ApplicationStrings.ErrorLoginAfterRegistrationFailed, ApplicationStrings.ErrorBadUserNameOrPassword)); } }
/// <summary> /// Completion handler for a <see cref="LoginOperation"/>. /// If operation succeeds, it closes the window. /// If it has an error, it displays an <see cref="ErrorWindow"/> and marks the error as handled. /// If it was not canceled, but login failed, it must have been because credentials were incorrect so a validation error is added to notify the user. /// </summary> private void LoginOperation_Completed(LoginOperation loginOperation) { if (loginOperation.LoginSuccess) { this.parentWindow.DialogResult = true; } else if (loginOperation.HasError) { ErrorWindow.CreateNew(loginOperation.Error); loginOperation.MarkErrorAsHandled(); } else if (!loginOperation.IsCanceled) { this.loginInfo.ValidationErrors.Add(new ValidationResult(ErrorResources.ErrorBadUserNameOrPassword, new string[] { "UserName", "Password" })); } }
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { // If the app is running outside of the debugger then report the exception using // the browser's exception mechanism. On IE this will display it a yellow alert // icon in the status bar and Firefox will display a script error. if (!System.Diagnostics.Debugger.IsAttached) { // NOTE: This will allow the application to continue running after an exception has been thrown // but not handled. // For production applications this error handling should be replaced with something that will // report the error to the website and stop the application. e.Handled = true; ErrorWindow.CreateNew(e.ExceptionObject); //Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); }); } }
void wc_WS_GetTreeCompleted(object sender, WS_Link.WS_GetTreeCompletedEventArgs e) { WS_Link.Parent FreshParentTree = new WS_Link.Parent(); try { FreshParentTree = e.Result; treeView.ItemsSource = FreshParentTree.ListChild; } catch (Exception err) { HeaderText.Text += "Исключение в WS_GetTree: "; //HeaderText.Text += err.ToString(); ErrorWindow.CreateNew(err); //InfoWindow iw = new InfoWindow("Ошибка в дереве!",); } }
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { //If the app is running outside of the debugger then report the exception using //the browser's exception mechanism. On IE this will display it a yellow alert //icon in the status bar and Firefox will display a script error. if (!System.Diagnostics.Debugger.IsAttached) { try { if (e.ExceptionObject.StackTrace != null && e.ExceptionObject.StackTrace.StartsWith("at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.Control_Raise(Control control, IManagedPeerBase arguments, Byte nDelegate) at System.Windows.Controls.TextBox.OnKeyDown(KeyEventArgs e) at System.Windows.Controls.Control.OnKeyDown(Control ctrl, EventArgs e) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)")) { e.Handled = true; return; } var exceptionObject = e.ExceptionObject as IsolatedStorageException; int sizeToAdd = 25 * 1024 * 1024; if (exceptionObject != null) { if (exceptionObject.Message == "IsolatedStorage_UsageWillExceedQuota") { e.Handled = true; IncreaseIsolatedStoreage(sizeToAdd); return; } else if (exceptionObject.Message == "There is not enough free space to perform the operation.") { e.Handled = true; IncreaseIsolatedStoreage(sizeToAdd); return; } } if (!(e.ExceptionObject is PageException)) { e.Handled = true; ErrorWindow.CreateNew(e.ExceptionObject, StackTracePolicy.Always); TraceExceptionLog(e.ExceptionObject); } } catch { } } }
private void LogoutButton_Click(object sender, RoutedEventArgs e) { MainPage.GoHome(); WebContext.Current.Authentication.Logout(logoutOperation => { if (logoutOperation.HasError) { ErrorWindow.CreateNew(logoutOperation.Error); logoutOperation.MarkErrorAsHandled(); } else { //force login again LoginButton_Click(sender, e); } }, /* userState */ null); }
/// <summary> /// Completion handler for the login operation that occurs after a successful /// registration and login attempt. This will close the window. On the unexpected /// event that this operation failed (the user was just added so why wouldn't it /// be authenticated successfully) an <see cref="ErrorWindow"/> is created and /// will display the error message. /// </summary> /// <param name="loginOperation">The <see cref="LoginOperation"/> that has completed.</param> private void LoginOperation_Completed(LoginOperation loginOperation) { if (!loginOperation.IsCanceled) { this.parentWindow.Close(); if (loginOperation.HasError) { ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ErrorResources.ErrorLoginAfterRegistrationFailed, loginOperation.Error.Message)); loginOperation.MarkErrorAsHandled(); } else if (loginOperation.LoginSuccess == false) { // The operation was successful, but the actual login was not ErrorWindow.CreateNew(string.Format(System.Globalization.CultureInfo.CurrentUICulture, ErrorResources.ErrorLoginAfterRegistrationFailed, ErrorResources.ErrorBadUserNameOrPassword)); } } }
private void DeleteDatabase(string password, string dbName) { var app = (App)Application.Current; app.IsBusy = true; app.ClientService.DeleteDatabase(password, dbName, (error) => { app.IsBusy = false; if (error != null) { ErrorWindow.CreateNew(error); return; } this.LoadDatabaseList(); }); }
private void treeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { try { WS_Link.BaseItem bt = treeView.SelectedItem as WS_Link.BaseItem; WS_Link.WServiceClient wc = new WS_Link.WServiceClient(); wc.WS_GetDevicesCompleted += new EventHandler <WS_Link.WS_GetDevicesCompletedEventArgs>(wc_WS_GetDevicesCompleted); //if (bt.lastchild == 1) //{ wc.WS_GetDevicesAsync(bt.ID); //} } catch (Exception err) { HeaderText.Text = "Исключение в WS_GetDevices: "; ErrorWindow.CreateNew(err); } }
/// <summary> /// Completion handler for the registration operation. If there was an error, an /// <see cref="ErrorWindow"/> is displayed to the user. Otherwise, this triggers /// a login operation that will automatically log in the just registered user. /// </summary> private void RegistrationOperation_Completed(InvokeOperation <CreateUserStatus> operation) { if (!operation.IsCanceled) { if (operation.HasError) { ErrorWindow.CreateNew(operation.Error); operation.MarkErrorAsHandled(); } else if (operation.Value == CreateUserStatus.Success) { var userService = IoC.Resolve <IApplicationUserService>(); userService.ApplicationUserRetrieved += (sender, e) => { if (e.Value is ApplicationUser) { ApplicationUser.CurrentUser = e.Value as ApplicationUser; } }; userService.ApplicationUserRetrievalError += (sender, e) => { ErrorWindow.CreateNew("Error occured retrieving the application user"); }; userService.RetrieveApplicationUser(registrationData.UserName); this.registrationData.CurrentOperation = WebContext.Current.Authentication.Login(this.registrationData.ToLoginParameters(), this.LoginOperation_Completed, null); this.parentWindow.AddPendingOperation(this.registrationData.CurrentOperation); } else if (operation.Value == CreateUserStatus.DuplicateUserName) { this.registrationData.ValidationErrors.Add(new ValidationResult(ErrorResources.CreateUserStatusDuplicateUserName, new string[] { "UserName" })); } else if (operation.Value == CreateUserStatus.DuplicateEmail) { this.registrationData.ValidationErrors.Add(new ValidationResult(ErrorResources.CreateUserStatusDuplicateEmail, new string[] { "Email" })); } else { ErrorWindow.CreateNew(ErrorResources.ErrorWindowGenericError); } } }
/// <summary> /// Handles <see cref="LoginOperation.Completed"/> event. If operation /// succeeds, it closes the window. If it has an error, we show an <see cref="ErrorWindow"/> /// and mark the error as handled. If it was not canceled, succeded but login failed, /// it must have been because credentials were incorrect so we add a validation error /// to notify the user /// </summary> private void LoginOperation_Completed(LoginOperation loginOperation) { if (loginOperation.LoginSuccess) { this.parentWindow.Close(); } else { if (loginOperation.HasError) { ErrorWindow.CreateNew(loginOperation.Error); loginOperation.MarkErrorAsHandled(); } else if (!loginOperation.IsCanceled) { this.loginForm.ValidationSummary.Errors.Add(new ValidationSummaryItem(ErrorResources.ErrorBadUserNameOrPassword)); } this.loginForm.BeginEdit(); } }
private void LoadDatabaseList() { var app = (App)Application.Current; app.ClientService.ListDatabases((dbs, error) => { if (error != null) { if (error is System.Security.SecurityException) { ErrorWindow.CreateNew( "安全错误:无法连接服务器,或服务器缺少 '/crossdomain.xml'文件。", StackTracePolicy.OnlyWhenDebuggingOrRunningLocally); } else { ErrorWindow.CreateNew(error); } return; } this.databases.ItemsSource = dbs; }); }
/// <summary> /// If an error occurs during navigation, show an error window /// </summary> private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e) { e.Handled = true; ErrorWindow.CreateNew(e.Exception); }
public Exception HandleException(Exception exception, Guid handlingInstanceId) { // TODO: May need to consider executing this on the UI thread as per reference implementation. ErrorWindow.CreateNew(exception, handlingInstanceId, errorMessageType == ErrorMessageType.TechnicalErrorMessage); return(exception); }