/// <summary> /// Event Handler for onFileChanged for our FileWatcher which is watching our app config /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnFileChange(object sender, FileSystemEventArgs e) { string usrname = AppConfig.readFromAppConfig("username"); string appConfLogin = AppConfig.readFromAppConfig("login"); if (((!usrname.Equals("") || !usrname.Equals(" ")) && appConfLogin.Equals("success"))) { this.dataContext.Login.UserName = usrname; // update username to display it in the ui this.btnLogin.Visibility = System.Windows.Visibility.Hidden; //hidde login button this.btnLogout.Visibility = System.Windows.Visibility.Visible; //show logout button this.txbSuccessfullSaved.Text = Properties.Resources.successFullLoggedIn; // notify user that all is nice // set login key in app.conig to null // reasone for that: if something in the app conf changs, this check obove will not be enabled again // AppConfig.writeToAppConfig("login", ""); } if (appConfLogin.Equals("error")) { // Inform user about problem // MessageBox.Show("L10N", "L10N", MessageBoxButton.OK, MessageBoxImage.Error); // set login key in app.conig to null // reasone for that: if something in the app conf changs, this check obove will not be enabled again // AppConfig.writeToAppConfig("login", ""); } }
public Settings() { InitializeComponent(); tbxEmergencyPath.Text = AppConfig.readFromAppConfig("emergencyInstallationPath"); this.oldEmergencyPath = tbxEmergencyPath.Text; #if DEBUG tbxEmergencyPath.Text = @"D:\Program Files (x86)\Emergency 5"; this.oldEmergencyPath = @"D:\Program Files (x86)\Emergency 5"; #endif #region ZipOrBrotliMode switch (AppConfig.readFromAppConfig("compressionAlgorithm")) { case "zip": rbZip.IsChecked = true; rbBrotli.IsChecked = false; break; case "brotli": rbBrotli.IsChecked = true; rbZip.IsChecked = false; break; default: rbZip.IsChecked = true; rbBrotli.IsChecked = false; break; } #endregion }
/// <summary> /// Handels the Click on the "Cancel" button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCancelSettingsClick(object sender, RoutedEventArgs e) { EmergencyInstallation emergency = new EmergencyInstallation(); emergency.setEmergencyInstallationPath(AppConfig.readFromAppConfig("emergencyInstallationPath")); Close(); }
//Constructor public EmergencyInstallation() { this.setEmergencyInstallationPath(AppConfig.readFromAppConfig("emergencyInstallationPath")); #if DEBUG setEmergencyInstallationPath(@"D:\Program Files (x86)\Emergency 5"); #endif EmergencyInstallation.setIsEmergencyInstalled(this.getEmergencyInstallationPath()); }
/// <summary> /// Logs the user asyncrouns in. No parmaeter needed because the needed data is stored in app.config /// </summary> public async void TokenLogin() { // SSL Crt (should been placed in Solution Dir with Build Option Copy always) // SslCredentials cred = new SslCredentials(File.ReadAllText("server.crt")); // new Channel and then a new client based on that Channel // var connectionChannel = new Channel("beta.emergencyx.de:50051", cred); var emx = EmergencyExplorerService.NewClient(connectionChannel); LoginWithTokenRequest request = new LoginWithTokenRequest { UserId = Convert.ToUInt32(AppConfig.readFromAppConfig("userId")), Token = AppConfig.readFromAppConfig("token") }; LoginResponse response = await emx.LoginWithTokenAsync(request); connectionChannel.ShutdownAsync().Wait(); if (response.Success != true) { throw new NotSuccessFullLoggedInException(); } }
//constructor // public MainWindow() { // default Initialization Stuff // InitializeComponent(); DataContext = new DataPool(); // start datacontext // dataContext.ModTools = new ModTools(dataContext.AppDataModificationsJsonFile); dataContext.EmergencyInstallation = new EmergencyInstallation(); dataContext.Login = new Login(); dataContext.InstalledMods = dataContext.ModTools.getInstalledModifications(); dataContext.Watcher = new FileSystemWatcher(); dataContext.MainWindow = this; //initial value for username // if (AppConfig.readFromAppConfig("username") != "") { dataContext.Login.UserName = AppConfig.readFromAppConfig("username"); } else { dataContext.Login.UserName = Properties.Resources.notLoggedIn; } //hidde success textbox // txbSuccessfullSaved.Visibility = Visibility.Hidden; // check if emergency is installed, if not disable the mod-box (well... because of this datacontext it looks not that nice... // if (EmergencyInstallation.getIsEmergencyInstalled() && dataContext.EmergencyInstallation.verifyEmergencyInstallation(dataContext.EmergencyInstallation.getEmergencyInstallationPath())) { lblEmergencyNotInstalled.Visibility = Visibility.Hidden; } else { liModificationList.Visibility = Visibility.Hidden; } // FileWatcher for App.config stuff // dataContext.Watcher.Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // Pretty long... dataContext.Watcher.Filter = "EmergencyX Client.exe.config"; dataContext.Watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; dataContext.Watcher.EnableRaisingEvents = true; dataContext.Watcher.Changed += this.OnFileChange; //check weather user is logged in or not // if (AppConfig.readFromAppConfig("rememberMe").Equals("True")) { try { dataContext.Login.TokenLogin(); txbSuccessfullSaved.Text = Properties.Resources.successFullLoggedIn; txbSuccessfullSaved.Visibility = Visibility.Visible; btnLogin.Visibility = Visibility.Hidden; btnLogout.Visibility = Visibility.Visible; } catch (NotSuccessFullLoggedInException noe) { MessageBox.Show(Properties.Resources.loginFailed, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }