/// <summary> /// Konstruktor, holt entsprechende Variablen aus der Konfigurationsdatei, /// und initialisiert die Klassen CheckForUSB und Timer. /// </summary> /// <param name="mainW"></param> /// <param name="_DbLevel"></param> public USB_Identification(MainWindow mainW = null, string _DbLevel = "backup") { InitializeComponent(); // Überprüfe CheckForUSB und Timer. Wenn ein Fehler durch die Konfigurationsdatei verursacht wurde, // beende den dezeitigen Zustand. try { this._Cusb = new CheckForUSB(); this._Timer = new Timer(); } catch (Exception ex) { MessageBoxEnhanced.Error(ex.Message); this.Close(); return; } this._MainWindowObj = mainW; // Zuornung aller relevanten Werte aus der Konfiguationsdatei. try { this._USB_FOLDER_NAME = IniParser.GetSetting("USB", "USB_FOLDER_NAME"); this._TIME_FACTOR_TO_ENABLED_BACKUP_CANCEL_BUTTON = Convert.ToInt32(IniParser.GetSetting("USB", "TIME_FACTOR_TO_ENABLED_BACKUP_CANCEL_BUTTON")); this._FILENAME_DB_EXTENSION = IniParser.GetSetting("USB", "FILENAME_DB_EXTENSION").ToLower(); // __FILENAME_DB_EXTENSION darf nicht null sein. if (this._FILENAME_DB_EXTENSION == "") { throw new Exception("FAIL"); } } // Wenn ein Fehler durch die Konfigurationsdatei verursacht wurde, beende den // dezeitigen Zustand catch(Exception){ KöTaf.WPFApplication.Helper.MessageBoxEnhanced.Error(IniParser.GetSetting("ERRORMSG", "configFileError")); this.Close(); return; } this._DbLevel = _DbLevel; this.Topmost = true; // Lese das aktuelle Datum aus XML Datei. Entscheide dann, ob ein Backup notwendig ist. (beim schließen des Programms) liste = _Timer.readXML(Environment.CurrentDirectory + @"\TimeStamp.xml","backup","date","iswrite"); if (liste[0] == DateTime.Now.ToShortDateString().ToString() && liste[1] == "True" && _DbLevel != "restore") { this._DbLevel = "backupExist"; } switch (this._DbLevel) { case "backupExist": this.Close(); break; default: startApplication(); break; } }
/// <summary> /// Die dispatcherTimer Methode; ruft die Backup oder die Restore Klasse auf. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dispatcherTimer_Tick(object sender, EventArgs e) { changeLayout("startDispatcherTimer"); this._Counter += _ADD_COUNT_FACTOR; if (_Counter == _TIME_FACTOR_TO_ENABLED_BACKUP_CANCEL_BUTTON || this._DbLevel == "restore") { btCancelProcess.Visibility = System.Windows.Visibility.Visible; } try { if (_Cusb.checkUSB()) { KöTaf.Utils.BackupRestore.DriveLetter drivelet = _Cusb._DriveL; String dl = drivelet._DriveLetter; switch (this._DbLevel) { case "backupExist": break; case "backup": dispatcherTimer.Stop(); try { br.StartBR("backupDB", dl + _USB_FOLDER_NAME); } catch (Exception ex) { textBlock1.Text = IniParser.GetSetting("ERRORMSG", "backupRuntimeError") + ex.ToString(); } changeLayout("backup"); Timer timer = new Timer(); timer.writeToXML(Environment.CurrentDirectory + @"\TimeStamp.xml", "True", DateTime.Now.ToShortDateString(), "timeStamp/backup/date", "timeStamp/backup/iswrite"); break; case "restore": string[] FileList; dispatcherTimer.Stop(); hList= drivelet.CheckSavedFiles(drivelet._DriveLetter); //Rufe alle Backup Dateien von USB - Datenspeicher ab. var Files = new DirectoryInfo(dl + _USB_FOLDER_NAME).GetFiles() .OrderBy(f => f.CreationTime) .ToArray(); for (int i = Files.Count() -1; i >= 0; i--) { try { FileList = Files[i].ToString().Split(new Char[] { '.' }); if (FileList[2].ToString() == this._FILENAME_DB_EXTENSION.ToString()) listBox1.Items.Add(Files[i]); } catch { throw new Exception(IniParser.GetSetting("ERRORMSG", "falseFilesInFolder")); } } changeLayout("restore"); break; } return; } decide_DbLevel(this._DbLevel); } catch (Exception ex) { isNotCorrectUSB(ex.Message); } }