Beispiel #1
0
        /// <summary>
        /// Syncs the existing database data with new data loaded from the given directory
        /// if an image exists in the directory but not in the database a new entry is created and if an image only exits in the database it will be deleted.
        /// A progress notifier can be supplied as this function my take a long time to execute
        /// </summary>
        /// <param name="dir">directory to sync</param>
        /// <param name="notifyProgress">Function that is periodically called to signify progress don by this method</param>
        /// <returns></returns>
        public async Task SyncPictureDataFromDirectory(string dir, Func <float, Task> notifyProgress)
        {
            Logger.Log(LogLevel.Information, "Requested file sync with files from directory [%s]", new { dir });
            await notifyProgress(0.05f);

            var paths = LoadPaths(dir);

            await notifyProgress(0.2f);

            var newPaths = await _picDb.FilterNewPaths(paths);

            await notifyProgress(0.4f);

            await _picDb.RemoveOldFromDb(paths);

            await notifyProgress(0.6f);

            await _picDb.InsertAll(newPaths.Select(LoadFromFile));

            await notifyProgress(0.8f);
        }