Exemplo n.º 1
0
        public async Task DeleteFolderTest()
        {
            var provider  = new FileSystemProvider(BaseDir);
            var filename1 = "testfolder\\" + Path.GetRandomFileName();
            var filename2 = "testfolder\\" + Path.GetRandomFileName();
            await provider.AddFile(RandomFileGenerator.RandomFileByteArray(1000), filename1);

            await provider.AddFile(RandomFileGenerator.RandomFileByteArray(2000), filename2);

            var result = await provider.DeleteFolder("testfolder");

            Assert.IsTrue(result);
            Assert.IsFalse(await provider.FileExists(filename1));
            Assert.IsFalse(await provider.FileExists(filename2));
        }
Exemplo n.º 2
0
        void SyncSharedCallback()
        {
            var             local  = new FileSystemProvider(_context.LocalStorage, Provider.SharedDirectory);
            IRemoteProvider remote = CreateRemote(Provider.SharedDirectory);

            // download
            var remoteItems = new List <Item>(remote.Items);

            foreach (Item r in remoteItems)
            {
                if (!local.FileExists(r.RelativePath) || local.FindFile(r.RelativePath).Time < r.Time)
                {
                    Item item = r;
                    remote.LoadFile(r.RelativePath, stream => local.SaveFile(item.RelativePath, stream));
                }
            }

            // remove deleted
            var localItems = new List <Item>(local.Items);

            foreach (Item l in localItems)
            {
                if (!remote.Items.Exists(val => val.RelativePath == l.RelativePath))
                {
                    local.DeleteFile(l.RelativePath);
                }
            }
        }
Exemplo n.º 3
0
        public async Task GetBytesTest()
        {
            var provider = new FileSystemProvider(BaseDir);
            var filename = Path.GetRandomFileName();
            var add      = await provider.AddFile(RandomFileGenerator.RandomFileByteArray(1000), filename);

            Assert.IsTrue(await provider.FileExists(filename));
        }
Exemplo n.º 4
0
        public static bool FileExists(string fileName)
        {
            if (IsDevNull(fileName) || IsStdErr(fileName))
            {
                return(true);
            }

            return(FileSystemProvider.FileExists(fileName));
        }
Exemplo n.º 5
0
        public async Task AddStreamTest()
        {
            var provider = new FileSystemProvider(BaseDir); var filename = Path.GetRandomFileName();

            using (var stream = new MemoryStream(RandomFileGenerator.RandomFileByteArray(1000)))
            {
                var add = await provider.AddFile(stream, filename);

                Assert.IsTrue(add);
                Assert.IsTrue(await provider.FileExists(filename));
            }
        }
Exemplo n.º 6
0
        public async Task GetFileTest()
        {
            var provider       = new FileSystemProvider(BaseDir);
            var filename       = Path.GetRandomFileName();
            var outputFileName = Path.GetTempFileName();
            var add            = await provider.AddFile(RandomFileGenerator.RandomFileByteArray(1000), filename);

            await provider.DownloadToFile(filename, outputFileName, true);//overdie if exists since gettempfileme creates the file

            var file = File.ReadAllBytes(outputFileName);

            Assert.IsTrue(await provider.FileExists(filename));
            File.Delete(outputFileName);
        }
Exemplo n.º 7
0
        public async Task AddFileTest()
        {
            var provider = new FileSystemProvider(BaseDir);
            var filename = Path.GetRandomFileName();
            var tempFile = Path.GetTempFileName();

            using (var file = File.OpenWrite(tempFile))
            {
                await file.WriteAsync(RandomFileGenerator.RandomFileByteArray(1000), 0, 1000);
            }

            var add = await provider.AddFile(tempFile, filename);

            Assert.IsTrue(add);
            Assert.IsTrue(await provider.FileExists(filename));
        }
Exemplo n.º 8
0
 /// <summary>
 /// boolean wether a file exists by its virtual path
 /// </summary>
 /// <param name="VirtualPath">the virtual path</param>
 /// <returns>boolean</returns>
 public static bool FileExists(string VirtualPath)
 {
     return(FileSystemProvider.FileExists(VirtualPath));
 }