Exemplo n.º 1
0
        /// <summary>
        ///     Scans the configured <see cref="Directory"/> and fills the cache.
        /// </summary>
        public void Fill()
        {
            var sw = new Stopwatch();

            sw.Start();

            Console.WriteLine($"[SHARED FILE CACHE]: Refreshing...");

            SyncRoot.EnterWriteLock();

            try
            {
                CreateTable();

                Files = System.IO.Directory.GetFiles(Directory, "*", SearchOption.AllDirectories)
                        .Select(f => new Soulseek.File(1, f, new FileInfo(f).Length, Path.GetExtension(f), 0))
                        .ToDictionary(f => f.Filename, f => f);

                // potentially optimize with multi-valued insert
                // https://stackoverflow.com/questions/16055566/insert-multiple-rows-in-sqlite
                foreach (var file in Files)
                {
                    InsertFilename(file.Key);
                }
            }
            finally
            {
                SyncRoot.ExitWriteLock();
            }

            sw.Stop();

            Console.WriteLine($"[SHARED FILE CACHE]: Refreshed in {sw.ElapsedMilliseconds}ms.  Found {Files.Count()} files.");
            LastFill = DateTime.UtcNow;
        }