/// <summary>
        /// Saves the given filepath in the configuration file and creates new database.
        /// </summary>
        /// <param name="sender">The caller of this method.</param>
        /// <param name="path">The name of the to-be-created database file.</param>
        public void Create(Form sender, string path, Form newForm)
        {
            this.logger.Log(Logger.Level.Info, "User wants to create new database - filename from userinput: " + path);

            // add .db, if not already done
            if (!path.EndsWith(".db"))
            {
                path += ".db";
                this.logger.Log(Logger.Level.Info, "No extension .db found. Added by application.");
            }

            try
            {
                ConfigFileManager cfm = new ConfigFileManager();
                cfm.SetDatabasePath(path);
                DALFactory.GetDAL().CreateDataBase();
            }
            // probably no write access to config file or syntax error in config file
            catch (System.Configuration.ConfigurationException)
            {
                throw;
            }
            // database could not be created for some reason - see logfile
            catch (SQLiteException)
            {
                throw;
            }

            // database could be created - change to normal startscreen
            this.ChangeToHomeScreen(sender, newForm);
        }
        /// <summary>
        /// Checks if a database exists at the given path and stores it in the config file.
        /// If everything went fine, this method closes the calling Form and opens the main window.
        /// </summary>
        /// <param name="sender">The caller of this method.</param>
        /// <param name="path">The path of the SQLite file</param>
        /// <param name="sendingForm">The form in which the sending element (button) was placed.</param>
        /// <exception cref="InvalidFileException">Thrown if chosen file is invalid.</exception>
        public void Connect(object sender, string path, Form sendingForm, Form newForm)
        {
            ConfigFileManager cfm = new ConfigFileManager();
            bool exists = cfm.CheckDataBaseExistance(path);

            if (exists == false)
            {
                this.logger.Log(Logger.Level.Error, "Tried to open file " + path + " which does not exist or is not a a valid SQLite file!");
                throw new InvalidFileException("Angegebene Datei existiert nicht oder ist kein gültiges SQLite-File!");
            }
            else
            {
                cfm.SetDatabasePath(path);

                // only when sender was DBNotFoundForm, not when sender is HomeForm!
                if (sendingForm != null && sendingForm.Name == "DBNotFoundForm")
                {
                    // set database description values
                    this.ChangeToHomeScreen(sendingForm, newForm);
                }
            }
        }
Exemplo n.º 3
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            /***
             * Implements error logging.
             * Configure all appenders.
             * Get logging level out of App.config.
             */
            Logger logger = Logger.Instance;

            // Create file appender for logging
            FileAppender filelogger = new FileAppender();
            filelogger.Configure();

            // Add all logger appenders to static list
            Logger.Appenders.Add(filelogger);

            // Get logging level out of config file
            AppSettingsReader config = new AppSettingsReader(); // Settings.Default.
            Logger.Loggerlevel = (int)config.GetValue("LoggerLevel", typeof(int));

            // Program startup logging
            logger.Log(Logger.Level.Info, "-----------------------------------------------------------");
            logger.Log(Logger.Level.Info, "Program is started.");
            logger.Log(Logger.Level.Info, "Logging level: " + Logger.Loggerlevel);

            /***
             * Checks data base existance and creates if needed.
             */
            ConfigFileManager cfm = new ConfigFileManager();
            bool exists = false;

            try
            {
                // Check if mock database shall be used. Result is stored in var ConfigFileManager.mockDB
                cfm.UsingMockDatabase();

                // Save info in logfile
                if (ConfigFileManager.MockDB == true)
                {
                    logger.Log(Logger.Level.Info, "Using mock database.");
                }
                else
                {
                    logger.Log(Logger.Level.Info, "Using SQLite database.");

                }

                exists = cfm.CheckDataBaseExistance();
            }
            // probably syntax error in config file - see logfile
            catch (System.Configuration.ConfigurationErrorsException)
            {
                Application.Exit();
            }

            // Open window, which one depends on whether the database has been found or not
            if (!exists)
            {
                Application.Run(new DBNotFoundForm());
            }
            else // database found. Start with home screen.
            {
                Application.Run(new HomeForm());
            }
        }
 public void MyTestCleanup()
 {
     target = null;
 }
 public void MyTestInitialize()
 {
     target = new ConfigFileManager();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Sets win title and label within "Home" subwindow to the currently opened database
 /// </summary>
 public void SetOpenedDbText()
 {
     ConfigFileManager cfm = new ConfigFileManager();
     this.homeCurrentDBLabel.Text = ConfigFileManager.DbName;
 }