private void State_OnDownloadComplete(object sender, EventArgs e) { OSBLEStateEventArgs osea = e as OSBLEStateEventArgs; if (!osea.Success) { // Show/hide interface components MainProgressBar.Visibility = System.Windows.Visibility.Collapsed; OKButton.Visibility = System.Windows.Visibility.Visible; CancelButton.Visibility = System.Windows.Visibility.Visible; // Display an error message MessageBox.Show(osea.Message); } else { // If the stream is null then show the message if (null == osea.Stream) { Core.App.Workspace.DrawingCanvasReference.GetWorkspace().Clear(); MessageBox.Show(osea.Message); } else { Core.App.Workspace.DrawingCanvasReference.GetWorkspace().Load(osea.Stream); } // Dettach listener and set the state reference to null m_state.OnDownloadComplete -= this.State_OnDownloadCompleteCrossThread; m_state = null; this.DialogResult = true; } }
public AssignmentChooserWindow(OSBLEState state, bool showLoginMessage, bool saveMode) { InitializeComponent(); m_saveMode = saveMode; if (saveMode) { OKButton.Content = "Save"; } // Hide the "just-logged-in" message if need be if (!showLoginMessage) { JustLoggedInMsg.Visibility = System.Windows.Visibility.Collapsed; } m_state = state; if (null != m_state) { UpdateTree(); m_state.OnDownloadComplete -= this.State_OnDownloadCompleteCrossThread; m_state.OnDownloadComplete += this.State_OnDownloadCompleteCrossThread; } }
private void ChildWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (null != m_state) { // Detach listener and set the state reference to null m_state.OnDownloadComplete -= this.State_OnDownloadCompleteCrossThread; m_state = null; } }
private void CancelButton_Click(object sender, RoutedEventArgs e) { if (null != m_state) { // Detach listener and set the state reference to null m_state.OnDownloadComplete -= this.State_OnDownloadCompleteCrossThread; m_state = null; } this.DialogResult = false; }
public OSBLEOrDiskWindow(OSBLEState state, bool isSaving = false) { InitializeComponent(); m_state = state; m_saveMode = isSaving; OSBLECurrentAssignmentButton.Visibility = System.Windows.Visibility.Collapsed; LayoutRoot.RowDefinitions[0].Height = new GridLength(0.0); if (isSaving) { Title = "Save To..."; OSBLEButton.Content = "Save to an OSBLE assignment..."; DiskButton.Content = "Save to disk..."; if (null != state.CurrentAssignment && !state.CurrentAssignment.IsCriticalReview) { // Build some components for nice info formatting within the button StackPanel sp = new StackPanel(); sp.Children.Add(new TextBlock() { Text = "Save to current OSBLE assignment:", FontWeight = FontWeights.Bold }); sp.Children.Add(new TextBlock() { Text = state.CurrentAssignment.Name }); sp.Children.Add(new TextBlock() { Text = "Course: " + state.CurrentAssignment.CourseName }); OSBLECurrentAssignmentButton.Content = sp; LayoutRoot.RowDefinitions[0].Height = GridLength.Auto; OSBLECurrentAssignmentButton.Visibility = System.Windows.Visibility.Visible; } } }
private void OKButton_Click(object sender, RoutedEventArgs e) { // Ignore this click if they left out the user name or password if (string.IsNullOrEmpty(UserNameTextBox.Text) || string.IsNullOrEmpty(PasswordBox.Password)) { return; } // Save the user name and password if check box is checked if (RememberCredentialsCheckBox.IsChecked.HasValue && RememberCredentialsCheckBox.IsChecked.Value) { byte[] encUserName = Enc(UserNameTextBox.Text); byte[] encPwd = Enc(PasswordBox.Password); // Write the encrypted data to isolated storage using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream s = new IsolatedStorageFileStream(c_osbleLoginFileName, FileMode.OpenOrCreate, store)) { s.Position = 0; s.SetLength(0); byte len = (byte)encUserName.Length; s.WriteByte(len); len = (byte)encPwd.Length; s.WriteByte(len); s.Write(encUserName, 0, encUserName.Length); s.Write(encPwd, 0, encPwd.Length); } } } else { // Otherwise ensure that the file to save user name and password is deleted using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { try { store.DeleteFile(c_osbleLoginFileName); } catch (Exception) { } } } ErrorTextBlock.Visibility = System.Windows.Visibility.Collapsed; OKButton.Visibility = System.Windows.Visibility.Collapsed; LoadingProgressBar.Visibility = System.Windows.Visibility.Visible; m_state = new OSBLEState(UserNameTextBox.Text, PasswordBox.Password); m_state.OnLoginFailure += new EventHandler(OnLoginFailure); m_state.OnError += new EventHandler(OnError); m_state.OnRefreshComplete += new EventHandler(StateRefreshComplete); m_state.RefreshAsync(); #region DEBUG //WebClient wc = new WebClient(); //wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted); //wc.DownloadStringAsync(new Uri("https://osble.org/Services/AuthenticationService.svc")); #endregion }