public OnlineAddView() { InitializeComponent(); Task.Run(() => { sharePointInformation = ApplicationState.GetValue <SharePointInformation>("SharePointInformation"); if (sharePointInformation != null && !string.IsNullOrEmpty(sharePointInformation?.Username)) { password = PortableCryptography.Decrypt(sharePointInformation.EncryptedPassword, sharePointInformation.Username); username = sharePointInformation.Username; siteUrl = sharePointInformation.SiteUrl; isOnlineSite = sharePointInformation.IsSharePointOnline; // create SharePoint Client sharePointDataService = new SharePointDataService(username, password, siteUrl, isOnlineSite); var listCollection = sharePointDataService.GetAllLists() as ListCollection; Dispatcher.Invoke(() => { dtSharePointLists.ItemsSource = listCollection; grdLoadingOverlay.Visibility = Visibility.Hidden; }); } else { Dispatcher.Invoke(() => { // For now, if we get to this screen without credentials, just push backwards. btnBackNav_Click(this, null); }); } }); }
private void btnRefresh_Click(object sender, RoutedEventArgs e) { grdLoadingOverlay.Visibility = Visibility.Visible; Task.Run(() => { if (sharePointInformation != null && !string.IsNullOrEmpty(sharePointInformation?.Username)) { password = PortableCryptography.Decrypt(sharePointInformation.EncryptedPassword, sharePointInformation.Username); username = sharePointInformation.Username; siteUrl = sharePointInformation.SiteUrl; isOnlineSite = sharePointInformation.IsSharePointOnline; // create SharePoint Client sharePointDataService = new SharePointDataService(username, password, siteUrl, isOnlineSite); var listCollection = sharePointDataService.GetAllLists() as ListCollection; Dispatcher.Invoke(() => { dtSharePointLists.ItemsSource = listCollection; grdLoadingOverlay.Visibility = Visibility.Hidden; }); } }); }
private void CheckForSharePointInfo() { // start with a false remember me value ApplicationState.SetValue("RememberMe", false); // Check IO var currDirectory = Environment.CurrentDirectory; var directoryPath = currDirectory + App.Directory; var fileName = directoryPath + App.Filename; var encryptedJson = string.Empty; try { encryptedJson = File.ReadAllText(fileName); } catch { ApplicationState.SetValue("ShowOnlineButton", false); return; } var decryptedJson = PortableCryptography.Decrypt(encryptedJson, "StoredValues"); var sharePointInfo = JsonConvert.DeserializeObject <SharePointInformation>(decryptedJson); if (sharePointInfo != null && !string.IsNullOrEmpty(sharePointInfo?.Username)) { ApplicationState.SetValue("SharePointInformation", sharePointInfo); ApplicationState.SetValue("RememberMe", true); ApplicationState.SetValue("ShowOnlineButton", true); } }
public SettingsView() { InitializeComponent(); var spInfo = ApplicationState.GetValue <SharePointInformation>("SharePointInformation"); // we only need to check if one exists, as this form only submits data if all three are provided. if (spInfo != null && !string.IsNullOrEmpty(spInfo?.Username)) { tbSPPasssword.Password = PortableCryptography.Decrypt(spInfo.EncryptedPassword, spInfo.Username); tbSPUsername.Text = spInfo.Username; tbSiteURL.Text = spInfo.SiteUrl; chkOnline.IsChecked = spInfo.IsSharePointOnline; chkRemember.IsChecked = ApplicationState.GetValue <bool>("RememberMe"); ApplicationState.SetValue("ShowOnlineButton", true); } }
private void SetUpSharePointDataService(bool synchronous) { if (!synchronous) { Task.Run(() => { var sharePointInformation = ApplicationState.GetValue <SharePointInformation>("SharePointInformation"); if (sharePointInformation != null && !string.IsNullOrEmpty(sharePointInformation?.Username)) { var password = PortableCryptography.Decrypt(sharePointInformation.EncryptedPassword, sharePointInformation.Username); var username = sharePointInformation.Username; var siteUrl = sharePointInformation.SiteUrl; var isOnlineSite = sharePointInformation.IsSharePointOnline; // create SharePoint Client try { SharePointDataService = new SharePointDataService(username, password, siteUrl, isOnlineSite); } catch (Exception ex) { //IdcrlException: The sign-in name or password does not match one in the Microsoft account system. var innerEx = ex.InnerException?.Message; if (!string.IsNullOrEmpty(innerEx)) { RootWindow.MessageQueue.Enqueue("Failed attempting to connect to SharePoint isntance: " + innerEx); } } Dispatcher.Invoke(() => { // make a note of our failed lists. miLeftSubmitToSharePoint.IsEnabled = true; miRightSubmitToSharePoint.IsEnabled = true; }); } else { Dispatcher.Invoke(() => { // make a note of our failed lists. miLeftSubmitToSharePoint.IsEnabled = false; miRightSubmitToSharePoint.IsEnabled = false; }); } }); } else { var sharePointInformation = ApplicationState.GetValue <SharePointInformation>("SharePointInformation"); if (sharePointInformation != null && !string.IsNullOrEmpty(sharePointInformation?.Username)) { var password = PortableCryptography.Decrypt(sharePointInformation.EncryptedPassword, sharePointInformation.Username); var username = sharePointInformation.Username; var siteUrl = sharePointInformation.SiteUrl; var isOnlineSite = sharePointInformation.IsSharePointOnline; // create SharePoint Client try { SharePointDataService = new SharePointDataService(username, password, siteUrl, isOnlineSite); } catch (Exception ex) { //IdcrlException: The sign-in name or password does not match one in the Microsoft account system. var innerEx = ex.InnerException?.Message; if (!string.IsNullOrEmpty(innerEx)) { RootWindow.MessageQueue.Enqueue("Failed attempting to connect to SharePoint isntance: " + innerEx); } } // make a note of our failed lists. miLeftSubmitToSharePoint.IsEnabled = true; miRightSubmitToSharePoint.IsEnabled = true; } else { // make a note of our failed lists. miLeftSubmitToSharePoint.IsEnabled = false; miRightSubmitToSharePoint.IsEnabled = false; } } }
private void btnSave_Click(object sender, RoutedEventArgs e) { tbSPPasssword.IsEnabled = false; tbSPUsername.IsEnabled = false; tbSiteURL.IsEnabled = false; if (ValidateInputs()) { var pass = tbSPPasssword.Password; var user = tbSPUsername.Text.TrimEnd().TrimStart(); var url = tbSiteURL.Text.TrimEnd().TrimStart(); // encrypt sensitive information. var encryptedPass = PortableCryptography.Encrypt(pass, user); SharePointInformation sharePointInformation = new SharePointInformation { EncryptedPassword = encryptedPass, SiteUrl = url, Username = user, IsSharePointOnline = (bool)chkOnline.IsChecked }; // Store information to memory. ApplicationState.SetValue("SharePointInformation", sharePointInformation); var currDirectory = Environment.CurrentDirectory; var directoryPath = currDirectory + App.Directory; var fileName = directoryPath + App.Filename; if (chkRemember.IsChecked == true) { // In order to remember, we need to store an encrypted configuration file. var json = JsonConvert.SerializeObject(sharePointInformation); var encryptedJson = PortableCryptography.Encrypt(json, "StoredValues"); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } File.WriteAllText(fileName, encryptedJson); ApplicationState.SetValue("RememberMe", true); } else { if (Directory.Exists(directoryPath)) { if (File.Exists(fileName)) { File.Delete(fileName); } } ApplicationState.SetValue("RememberMe", false); } ApplicationState.SetValue("ShowOnlineButton", true); RootWindow.MessageQueue.Enqueue("SharePoint information successfully saved."); } tbSPPasssword.IsEnabled = true; tbSPUsername.IsEnabled = true; tbSiteURL.IsEnabled = true; }