Esempio n. 1
0
        /// <summary>
        /// Set up of db file and checking workspace files.
        /// </summary>
        public async Task SetUp()
        {
            string dbFile;

            do
            {
                // ask for database filename and see if it's valid
                Console.Write("Enter the name of the exported database file " +
                              "(it must be placed on the same place as this .exe file, " +
                              "leave as empty if the exported db filename is Backup_pages.db): ");

                dbFile = Console.ReadLine();
                DbFile = string.IsNullOrWhiteSpace(dbFile) ? DbFile : dbFile;

                // check if database schema contains the images table and expected columns
                // see DbLayout.cs for how it layouts a database schema
                // see Database.cs line 39 for expected column names and data-types
                Console.Write($"Checking if {DbFile} is a valid database... ");
                if (!await new Database.Database(DbFile).IsDatabaseValid())
                {
                    continue;
                }
            } while (!File.Exists(DbFile) || !DbFile.EndsWith(".db"));

            Console.WriteLine("Ok.");
            var database = new Database.Database(DbFile);

            // setup workspace files. Adds an 'images' folder, and a 'log.txt' text file
            // Grabs all images from the db for preparation with other methods
            Console.Write("Checking workspace files... ");
            Directory.CreateDirectory("images");

            using (var sw = File.AppendText("log.txt"))
            {
                await sw.WriteLineAsync($"Log started at: {DateTime.Now.ToString()}" + sw.NewLine +
                                        "----------------------------------------------------------------------" + sw.NewLine);
            }

            DbImages = await database.GetDbImagesFromDb();

            Console.WriteLine($"Workspace files has been created. You have {DbImages.Count} images.\n");
        }