Пример #1
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));
        }
Пример #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));
        }
Пример #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);
            var metadata = JsonSerializer.Deserialize(s.ToString()).AsDocument;

            fs.SetMetadata(id, metadata);
        }
Пример #4
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            var fs       = new LiteStorage(engine);
            var id       = this.ReadId(s);
            var metadata = JsonSerializer.Deserialize(s.ToString()).AsDocument;

            fs.SetMetadata(id, metadata);
        }
Пример #5
0
 public DBService(string connstr)
 {
     _db         = new LiteDatabase(connstr);
     _entrys     = _db.GetCollection <Entry>(_STR_ENTRY_COLLECTION_NAME);
     _storage    = _db.FileStorage;
     _entryCount = _entrys.Count();
     _rand       = new Random();
 }
        public static byte[] GetFileData(this LiteStorage storage, string fileId)
        {
            MemoryStream stream = new MemoryStream();

            storage.Download(fileId, stream);
            byte[] data = stream.ToArray();
            return(data);
        }
Пример #7
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));
        }
Пример #8
0
 internal SongCollection(LiteDatabase db, ILoggerFactory loggerFactory, Configuration config, IServiceProvider services)
 {
     logger     = loggerFactory.CreateLogger <SongCollection>();
     collection = db.GetCollection <SongData>();
     collection.EnsureIndex(d => d.Id);
     collection.EnsureIndex(d => d.LastAccess);
     fileStorage = db.FileStorage;
     downloader  = new YouTubeDownloader(services.GetRequiredService <IMusicEncoderService>());
     this.config = config;
 }
Пример #9
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"));
                }
        }
Пример #10
0
        public IEnumerable <BsonValue> Execute(StringScanner s, LiteEngine engine)
        {
            var fs       = new LiteStorage(engine);
            var id       = this.ReadId(s);
            var metadata = JsonSerializer.Deserialize(s.ToString()).AsDocument;

            s.ThrowIfNotFinish();

            fs.SetMetadata(id, metadata);

            yield break;
        }
Пример #11
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            var fs = new LiteStorage(engine);
            var id = this.ReadId(s);

            var filename = s.Scan(@"\s*.*").Trim();

            if (!File.Exists(filename)) throw new IOException("File " + filename + " not found");

            var file = fs.Upload(id, filename);

            display.WriteResult(file.AsDocument);
        }
Пример #12
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();
        }
Пример #13
0
        public void LiteStorage_Create_ShouldAddItem()
        {
            StorageManager.DropDatabase();

            LiteStorage <ApplicationUser> usersStorage = new LiteStorage <ApplicationUser>();
            ApplicationUser userToAdd = new ApplicationUser("*****@*****.**", "+77715691115", "12345");

            userToAdd.Id = Guid.NewGuid().ToString();

            usersStorage.Create(userToAdd);

            var allUsers = usersStorage.ReadAll();

            Assert.IsNotNull(allUsers);
        }
Пример #14
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            var fs       = new LiteStorage(engine);
            var id       = this.ReadId(s);
            var filename = s.Scan(@"\s*.*").Trim();

            var file = fs.FindById(id);

            if (file != null)
            {
                file.SaveAs(filename);

                display.WriteResult(file.AsDocument);
            }
        }
Пример #15
0
        public IEnumerable <BsonValue> Execute(StringScanner s, LiteEngine engine)
        {
            var fs       = new LiteStorage(engine);
            var id       = this.ReadId(s);
            var filename = s.Scan(@"\s*.*").Trim();

            var file = fs.FindById(id);

            if (file != null)
            {
                file.SaveAs(filename);

                yield return(file.AsDocument);
            }
        }
Пример #16
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            var fs = new LiteStorage(engine);
            var id = this.ReadId(s);
            var filename = s.Scan(@"\s*.*").Trim();

            var file = fs.FindById(id);

            if (file != null)
            {
                file.SaveAs(filename);

                display.WriteResult(file.AsDocument);
            }
        }
Пример #17
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            var fs = new LiteStorage(engine);
            var id = this.ReadId(s);

            var filename = s.Scan(@"\s*.*").Trim();

            if (!File.Exists(filename))
            {
                throw new IOException("File " + filename + " not found");
            }

            var file = fs.Upload(id, filename);

            display.WriteResult(file.AsDocument);
        }
Пример #18
0
        public IEnumerable <BsonValue> Execute(StringScanner s, LiteEngine engine)
        {
            var fs = new LiteStorage(engine);
            var id = this.ReadId(s);

            var filename = s.Scan(@"\s*.*").Trim();

            if (!File.Exists(filename))
            {
                throw new IOException("File " + filename + " not found");
            }

            var file = fs.Upload(id, filename);

            yield return(file.AsDocument);
        }
Пример #19
0
        public GenericRepository(string dbPath)
        {
            var cstr = new ConnectionString()
            {
                Filename  = dbPath,
                CacheSize = 1048576,/// 1mb
                LimitSize = 524288000
            };

            db = new LiteDatabase(cstr);


            var tbName = typeof(T).Name;

            table = db.GetCollection <T>(tbName);

            files = db.FileStorage;
        }
Пример #20
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);
                        }
                    }
                    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);
                    }
                }
        }
Пример #21
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            var fs = new LiteStorage(engine);

            if (s.HasTerminated)
            {
                var files = fs.FindAll().Select(x => x.AsDocument);

                display.WriteResult(new BsonArray(files));
            }
            else
            {
                var id = this.ReadId(s);

                var files = fs.Find(id).Select(x => x.AsDocument);

                display.WriteResult(new BsonArray(files));
            }
        }
Пример #22
0
        public Repository(string databaseName)
        {
            TMDbClient = new TMDbClient("1915ba01826b36e88f574596aa8a7e54", false);

            ImageClient             = new HttpClient();
            ImageClient.BaseAddress = new Uri("http://image.tmdb.org/t/p/");

            YouTubeClient             = new HttpClient();
            YouTubeClient.BaseAddress = new Uri("http://img.youtube.com/vi/");

            DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data"));
            LiteDatabase  database  = new LiteDatabase(Path.Combine(directory.FullName, databaseName));

            FileStorage = database.FileStorage;

            Movies  = new ContainerCollection <MovieContainer>(database, "Movies");
            People  = new ContainerCollection <PersonContainer>(database, "People");
            TvShows = new ContainerCollection <TvShowContainer>(database, "TvShows");
        }
Пример #23
0
        public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
        {
            var fs = new LiteStorage(engine);

            if (s.HasTerminated)
            {
                var files = fs.FindAll().Select(x => x.AsDocument);

                display.WriteResult(new BsonArray(files));
            }
            else
            {
                var id = this.ReadId(s);

                var files = fs.Find(id).Select(x => x.AsDocument);

                display.WriteResult(new BsonArray(files));
            }
        }
Пример #24
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);
                    }
                }
                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);
                }
            }
        }
Пример #25
0
        public IEnumerable <BsonValue> Execute(StringScanner s, LiteEngine engine)
        {
            var fs = new LiteStorage(engine);
            IEnumerable <LiteFileInfo> files;

            if (s.HasTerminated)
            {
                files = fs.FindAll();
            }
            else
            {
                var id = ReadId(s);

                s.ThrowIfNotFinish();

                files = fs.Find(id);
            }

            foreach (var file in files.Select(x => x.AsDocument))
            {
                yield return(file);
            }
        }
Пример #26
0
        private static void UploadFileAndSetMetadata(DateTime absoluteExpiration, MemoryStream imageStream, LiteStorage fileStorage, string id)
        {
            imageStream.Position = 0;
            var fileInfo = fileStorage.Upload(id, null, imageStream);

            fileStorage.SetMetadata(
                fileInfo.Id,
                new BsonDocument(new Dictionary <string, BsonValue> {
                { "Expires", absoluteExpiration }
            }));

            imageStream.Position = 0;
        }
Пример #27
0
        private static void UploadFileAndSetMetadata(DateTime absoluteExpiration, MemoryStream imageStream, LiteStorage fileStorage, string id)
        {
            imageStream.Position = 0;
            var fileInfo = fileStorage.Upload(id, null, imageStream);

            fileInfo.Metadata.Add(new KeyValuePair <string, BsonValue>("Expires", absoluteExpiration));
            imageStream.Position = 0;
        }