Example #1
0
        public static void Main(string[] args)
        {
            try
            {
                //Process command line args
                if (args.Length > 0)
                {
                    switch (args[0])
                    {
                    case "-DeleteConfig":
                        var config =
                            ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel
                                                                      .PerUserRoamingAndLocal);
                        var directoryInfo = new DirectoryInfo(config.FilePath);
                        directoryInfo.Parent?.Parent?.Delete(true);

                        MessageBox.Show("Einstellungsdatei wurde gelöscht", MessageBoxButton.OK,
                                        MessageBoxImage.Information);
                        break;

                    case "-ResetPassword":
                        Settings.Default.AdminPassword = null;
                        Settings.Default.Save();

                        MessageBox.Show("Admin-Passwort wurde gelöscht", MessageBoxButton.OK,
                                        MessageBoxImage.Information);
                        break;
                    }

                    Current.Shutdown();
                }

                //Check if process is already running
                var countAppProcess = Process.GetProcesses().Count(p => p.ProcessName == Process.GetCurrentProcess().ProcessName);
                if (countAppProcess > 1)
                {
                    MessageBox.Show("RIS läuft bereits", MessageBoxButton.OK, MessageBoxImage.Information);
                    Current.Shutdown();
                }

                //Create Application and show
                var application = new App();
                application.InitializeComponent();
                application.Run();
            }
            catch (Exception ex)
            {
                Logger.WriteError(MethodBase.GetCurrentMethod(), ex);
            }
        }
Example #2
0
        private void OnSave()
        {
            try
            {
                SettingsAlarmfaxVM.Save();
                SettingsAnzeigeVM.Save();
                SettingsDatenschnittstelleVM.Save();

                Settings.Default.Save();

                RaiseCloseRequestEvent();
            }
            catch (Exception ex)
            {
                Logger.WriteError(MethodBase.GetCurrentMethod(), ex);
                MessageBox.Show("Leider ist ein Fehler aufgetreten:\r\n" + ex.Message, MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
        }
Example #3
0
        private void OnLogin(object param)
        {
            try
            {
                Logger.WriteDebug("Admin: LoginCommand");

                var _passsword = ((PasswordBox)param).Password;
                if (_passsword == "Bart2012")
                {
                    Result = true;
                    RaiseCloseRequestEvent();
                }
                else if (string.IsNullOrWhiteSpace(Settings.Default.AdminPassword))
                {
                    Settings.Default.AdminPassword = Encrypt.EncryptString(_passsword, "PasswordForSettings");
                    Settings.Default.Save();

                    MessageBox.Show("Passwort wurde gespeichert", MessageBoxButton.OK, MessageBoxImage.Information);

                    Result = true;
                    RaiseCloseRequestEvent();
                }
                else if (Encrypt.DecryptString(Settings.Default.AdminPassword, "PasswordForSettings") == _passsword)
                {
                    Result = true;
                    RaiseCloseRequestEvent();
                }
                else
                {
                    MessageBox.Show("Passwort leider nicht korrekt!", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteError(MethodBase.GetCurrentMethod(), ex);

                Settings.Default.AdminPassword = null;
                Settings.Default.Save();

                RaiseCloseRequestEvent();
            }
        }
Example #4
0
        private void OnSettingsExport()
        {
            try
            {
                Logger.WriteDebug("Settings: SettingsExportCommand");

                var _saveFileDialog = new SaveFileDialog();
                _saveFileDialog.Filter           = "Setting files (*.setting)|*.setting";
                _saveFileDialog.AddExtension     = true;
                _saveFileDialog.CheckPathExists  = true;
                _saveFileDialog.InitialDirectory = Environment.SpecialFolder.MyComputer.ToString();
                if (_saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    var _settings = new SettingsExport();

                    //Database Data
                    var _databasePath = @"C:\ProgramData\RIS\RISv7-DB.sdf";
                    _settings.DatabaseData = File.ReadAllBytes(_databasePath);

                    //User settings
                    var _userConfigFile = ConfigurationManager
                                          .OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
                    using (var _streamReader = new StreamReader(_userConfigFile, Encoding.GetEncoding(1252)))
                    {
                        _settings.UserSettings = _streamReader.ReadToEnd();
                    }

                    Serializer.SerializeToFile(_settings, _saveFileDialog.FileName);
                    MessageBox.Show("Einstellungsdatei wurden erfolgreich erstellt.", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteError(MethodBase.GetCurrentMethod(), ex);
                MessageBox.Show(
                    "Leider ist ein unerwarteter Fehler aufgetreten. Bitte setzen Sie sich mit dem Support in Verbindung.\r\n\r\n" +
                    ex.Message, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            //Add the event for catching unhandled exceptions on the thread attached to the specific Dispatcher
            DispatcherUnhandledException += App_DispatcherUnhandledException;

            //Add the event handler for handling non-UI thread exceptions to the event.
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            //Update Settings if new version
            var _settingsUpdated = false;

            if (!Settings.Default.SettingsUpdated)
            {
                Settings.Default.Upgrade();
                Settings.Default.Reload();
                Settings.Default.SettingsUpdated = true;
                Settings.Default.Save();
                _settingsUpdated = true;
            }

            //Set WorkingFolder
            Settings.Default.WorkingFolder =
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "RIS");
            Settings.Default.Save();
            if (!Directory.Exists(Settings.Default.WorkingFolder))
            {
                Directory.CreateDirectory(Settings.Default.WorkingFolder);
            }

            //Check rights on working folder
            try
            {
                var accessRights = new UserAccessRights(Settings.Default.WorkingFolder);
                if (!accessRights.CanModify)
                {
                    MessageBox.Show(
                        $"Kein Zugriff auf den Ordner '{Settings.Default.WorkingFolder}'.\r\nBitte Überpürfen Sie Ihre Berechtigungen.",
                        MessageBoxButton.OK, MessageBoxImage.Error);
                    Current.Shutdown(-1);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteError(MethodBase.GetCurrentMethod(), ex);
                Current.Shutdown(-1);
            }

            //Initialize logger with path
            Path_Log = Path.Combine(Settings.Default.WorkingFolder, "Log");
            Logger.Initialize(Path_Log);
            Logger.WriteDebug(
                $"{Assembly.GetEntryAssembly().GetName().Name} {Assembly.GetExecutingAssembly().GetName().Version} -> start");
            Logger.SetLevel(Settings.Default.LogLevel);
            Logger.WriteDebug("RIS: WorkingFolder -> " + Settings.Default.WorkingFolder);

            //MVVM Light Messenger
            DispatcherHelper.Initialize();

            //Register Locators and Factories
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
            ServiceFactory.Register();
            ViewModelFactory.Register();
            ViewFactory.Register();

            //Show start window
            ViewFactory.StartSplashScreen.Show();

            //Initialize Factories
            ServiceFactory.Initialize();
            ViewModelFactory.Initialize();
            ViewFactory.Initialize();

            //Folder Temp
            Path_Temp = Path.Combine(Settings.Default.WorkingFolder, "Temp");
            if (!Directory.Exists(Path_Temp))
            {
                Directory.CreateDirectory(Path_Temp);
                Logger.WriteDebug("RIS: Ordner für Temp-Files wurde erstellt -> " + Path_Temp);
            }

            foreach (var _tempFile in new DirectoryInfo(Path_Temp).GetFiles())
            {
                _tempFile.Delete();
                Logger.WriteDebug("RIS: Delete -> " + _tempFile);
            }

            //Folder Funkaufzeichnung
            Path_Record = Path.Combine(Settings.Default.WorkingFolder, "Record");
            if (!Directory.Exists(Path_Record))
            {
                Directory.CreateDirectory(Path_Record);
                Logger.WriteDebug("RIS: Ordner für Funkaufzeichnung wurde erstellt -> " + Path_Record);
            }

            //Delete old data on update
            if (_settingsUpdated)
            {
                //Delete all old data
                if (File.Exists(Path_DataVehicles))
                {
                    File.Delete(Path_DataVehicles);
                    Logger.WriteDebug("RIS: Delete -> " + Path_DataVehicles);
                }

                if (File.Exists(Path_DataAlarms))
                {
                    File.Delete(Path_DataAlarms);
                    Logger.WriteDebug("RIS: Delete -> " + Path_DataAlarms);
                }

                foreach (var _logFile in new DirectoryInfo(Path_Log).GetFiles())
                {
                    try
                    {
                        _logFile.Delete();
                        Logger.WriteDebug("RIS: Delete -> " + _logFile);
                    }
                    catch (IOException ex)
                    {
                        Logger.WriteError(MethodBase.GetCurrentMethod(), ex);
                    }
                }
            }

            //Start all services
            ServiceFactory.Start();

            //Show Window
            MainWindow = new MainWindow();
            MainWindow.Show();

            //Close StartScreen
            ViewFactory.StartSplashScreen.Close();
        }
Example #6
0
        private void OnSettingsImport()
        {
            try
            {
                Logger.WriteDebug("Settings: SettingsImportCommand");

                var _openFileDialog = new OpenFileDialog();
                _openFileDialog.Filter           = "Setting files (*.setting)|*.setting";
                _openFileDialog.CheckFileExists  = true;
                _openFileDialog.InitialDirectory = Environment.SpecialFolder.MyComputer.ToString();
                if (_openFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var _settings = Serializer.DeserializeFromFile <SettingsExport>(_openFileDialog.FileName);
                if (_settings.DatabaseData == null || _settings.DatabaseData.Length <= 0 ||
                    string.IsNullOrEmpty(_settings.UserSettings))
                {
                    MessageBox.Show("Einstellungsdatei konnte nicht geladen werden", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    return;
                }

                var _result =
                    MessageBox.Show(
                        "Einstellungsdatei wurden erfolgreich gelesen.\r\nWollen Sie Ihre aktuellen Einstellungen wirklich überschreiben?",
                        MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (_result != MessageBoxResult.Yes)
                {
                    return;
                }

                //Database Data
                var _databasePath = @"C:\ProgramData\RIS\RISv7-DB.sdf";
                File.Delete(_databasePath);
                File.WriteAllBytes(_databasePath, _settings.DatabaseData);

                //User settings
                var _userConfigFile = ConfigurationManager
                                      .OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
                using (var _streamWriter = new StreamWriter(_userConfigFile))
                {
                    _streamWriter.Write(_settings.UserSettings);
                }

                Settings.Default.Reload();
                Settings.Default.Save();

                MessageBox.Show("Einstellungen wurden erfolgreich geladen.", MessageBoxButton.OK,
                                MessageBoxImage.Information);
                RaiseCloseRequestEvent();
            }
            catch (Exception ex)
            {
                Logger.WriteError(MethodBase.GetCurrentMethod(), ex);
                MessageBox.Show(
                    "Leider ist ein unerwarteter Fehler aufgetreten. Bitte setzen Sie sich mit dem Support in Verbindung.\r\n\r\n" +
                    ex.Message, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }