Ejemplo n.º 1
0
        public void Maitenance(TimeSpan expiredTime, int maxCount)
        {
            DateTime expiredDateTime = DateTime.Now - expiredTime;

            foreach (var fileInfo in _fileStorage.FindAll().Where(x => x.Metadata.TryGetValue("updateAt", out var val) && (DateTime)val < expiredDateTime).ToArray())
            {
                _fileStorage.Delete(fileInfo.Id);
            }

            foreach (var fileInfo in _fileStorage.FindAll().OrderByDescending(x => x.UploadDate).Skip(maxCount).ToArray())
            {
                _fileStorage.Delete(fileInfo.Id);
            }
        }
Ejemplo n.º 2
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            var fs = new LiteStorage(engine);
            var id = this.ReadId(s);

            display.WriteResult(fs.Delete(id));
        }
Ejemplo n.º 3
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            var fs = new LiteStorage(engine);
            var id = this.ReadId(s);

            display.WriteResult(fs.Delete(id));
        }
Ejemplo n.º 4
0
        public IEnumerable <BsonValue> Execute(StringScanner s, LiteEngine engine)
        {
            var fs = new LiteStorage(engine);
            var id = this.ReadId(s);

            s.ThrowIfNotFinish();

            yield return(fs.Delete(id));
        }
Ejemplo n.º 5
0
        public void Storage_ReadWriteStream_Test()
        {
            var HELLO1 = "Hello World LiteDB 1 ".PadRight(300000, '-') + "\nEND";
            var HELLO2 = "Hello World LiteDB 2 - END";

            using (var file = new TempFile())
                using (var db = new LiteEngine(file.Filename))
                {
                    var sto = new LiteStorage(db);

                    // insert HELLO1 file content
                    using (var stream = sto.OpenWrite("f1", "f1.txt"))
                    {
                        using (var sw = new StreamWriter(stream))
                        {
                            sw.Write(HELLO1);
                        }
                    }

                    // test if was updated Length in _files collection
                    var doc = db.Find("_files", Query.EQ("_id", "f1")).Single();

                    Assert.AreEqual(HELLO1.Length, doc["length"].AsInt32);

                    using (var stream = sto.OpenRead("f1"))
                    {
                        var sr    = new StreamReader(stream);
                        var hello = sr.ReadToEnd();

                        Assert.AreEqual(HELLO1, hello);
                    }

                    // updating to HELLO2 content same file id
                    using (var stream = sto.OpenWrite("f1", "f1.txt"))
                    {
                        using (var sw = new StreamWriter(stream))
                        {
                            sw.Write(HELLO2);
                        }
                    }
                    using (var stream = sto.OpenRead("f1"))
                    {
                        var sr    = new StreamReader(stream);
                        var hello = sr.ReadToEnd();

                        Assert.AreEqual(HELLO2, hello);
                    }

                    // now delete all
                    sto.Delete("f1");

                    Assert.IsFalse(sto.Exists("f1"));
                }
        }
Ejemplo n.º 6
0
 public async Task <SongData> GetSong(string songId)
 {
     return(await Task.Run(() =>
     {
         var song = collection.Find(d => d.Id == songId, 0, 1).FirstOrDefault();
         if (song == null)
         {
             return null;
         }
         if ((DateTime.Now - song.LastAccess) > config.Music.MaximumSongAgeTimeSpan)
         {
             collection.Delete(song.Id);
             fileStorage.Delete(song.FileId);
             return null;
         }
         song.LastAccess = DateTime.Now;
         collection.Update(song);
         return song;
     }));
 }
Ejemplo n.º 7
0
        public ThumbnailCacheManager(
            LiteDatabase liteDatabase
            )
        {
            _fileStorage = liteDatabase.FileStorage;
#if DEBUG && true
            foreach (var file in _fileStorage.FindAll().ToArray())
            {
                _fileStorage.Delete(file.Id);
            }
#endif
            _httpClient = new HttpClient();
        }
Ejemplo n.º 8
0
 public bool Remove(String id)
 {
     return(_fileStorage.Delete(id));
 }
Ejemplo n.º 9
0
 public void FileDelete(string key)
 {
     files.Delete(key);
 }