コード例 #1
0
ファイル: FileTests.cs プロジェクト: floolean/PCLStorageEx
        public async Task DeleteFileTwice()
        {
            //	Arrange
            IFolder folder   = TestFileSystem.LocalStorage;
            string  fileName = "fileToDeleteTwice.txt";
            IFile   file     = await folder.CreateFileAsync(fileName, CreationCollisionOption.FailIfExists);

            await file.DeleteAsync();

            //	Act & Assert
            await ExceptionAssert.ThrowsAsync <IOException>(async() => { await file.DeleteAsync(); });
        }
コード例 #2
0
 /// <summary>
 /// This will be automatically called when destructor is called, but apps can choose to call it earlier
 /// </summary>
 public async void Dispose()
 {
     try
     {
         if (_disposed)
         {
             return;
         }
         _disposed = true;
         await _file.DeleteAsync();
     }
     catch { }
 }
コード例 #3
0
        async Task FileTest()
        {
            Log("FileTest Begin");

            byte[] data = new byte[128 * 1024 * 1024];
            Random rng  = new Random();

            rng.NextBytes(data);

            Log("FileTest Data Ready To Write");

            try
            {
                var   folder = FileSystem.Current.LocalStorage;
                IFile file   = await folder.CreateFileAsync("data.txt", CreationCollisionOption.ReplaceExisting);

                using (var fileHandler = await file.OpenAsync(FileAccess.ReadAndWrite))
                {
                    await fileHandler.WriteAsync(data, 0, data.Length);
                }
                await file.DeleteAsync();
            }
            catch (Exception e)
            {
                Log("FileTest Error: " + e);
            }

            Log("FileTest Complete");
        }
コード例 #4
0
        async Task NetworkTest()
        {
            Log("NetworkTest Begin");

            var   folder = FileSystem.Current.LocalStorage;
            IFile file   = await folder.CreateFileAsync("network.txt", CreationCollisionOption.ReplaceExisting);

            try
            {
                string random = Guid.NewGuid().ToString();
                Uri    url    = new Uri("https://dl.dropboxusercontent.com/u/4053974/teamviewer_linux_x64.deb?foo=" + random);
                var    client = new HttpClient();

                using (var fileHandler = await file.OpenAsync(FileAccess.ReadAndWrite))
                {
                    var httpResponse = await client.GetAsync(url);

                    byte[] dataBuffer = await httpResponse.Content.ReadAsByteArrayAsync();

                    await fileHandler.WriteAsync(dataBuffer, 0, dataBuffer.Length);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                await file.DeleteAsync();
            }

            Log("NetworkTest Complete");
        }
コード例 #5
0
        public async static void deleteMediaAsync(AbMediaContent media)
        {
            //Asynchronously remove media from other cards
            var removeCardMediaTask = Task.Run(() => FSManager.removeMediaFromCards(media));

            //Make sure media wasn't imported.  If not delete its file
            if (media.filePath.Contains(FilePaths.rootPath))
            {
                IFile mediaFile = await FileSystem.Current.GetFileFromPathAsync(media.filePath);

                await mediaFile.DeleteAsync();
            }

            //Remove from relevant MediaManager data structures
            allMedia.Remove(media);

            DayMediaObservableCollection dayCollection;

            allMediaDict.TryGetValue(media.creationTime.Date, out dayCollection);
            if (dayCollection != null)
            {
                dayCollection.removeMedia(media);
            }

            //Remove empty days
            if (dayCollection.Count == 0)
            {
                allMediaDict.Remove(media.creationTime.Date);
                allMediaCollection.Remove(dayCollection);
            }

            //Wait for card media removal task to complete
            await removeCardMediaTask;
        }
コード例 #6
0
        public async void OnClose()
        {
            counting = false;
            Debug.WriteLine("disappear");
            if (userClocks.Count > 0)
            {
                Debug.WriteLine("saving");
                IFolder folder = FileSystem.Current.LocalStorage;
                folder = await folder.CreateFolderAsync(IntClockStorage.FolderName,
                                                        CreationCollisionOption.OpenIfExists);

                IFile file = await folder.CreateFileAsync(IntClockStorage.UserClocksFileName,
                                                          CreationCollisionOption.ReplaceExisting);

                string clocksJson = JsonConvert.SerializeObject(userClocks, Formatting.Indented);
                await file.WriteAllTextAsync(clocksJson);
            }
            else
            {
                IFolder folder = FileSystem.Current.LocalStorage;
                folder = await folder.CreateFolderAsync(IntClockStorage.FolderName,
                                                        CreationCollisionOption.OpenIfExists);

                ExistenceCheckResult fileExists = await folder.CheckExistsAsync(IntClockStorage.UserClocksFileName);

                //Check if clocks file exists
                if (fileExists == ExistenceCheckResult.FileExists)
                {
                    Debug.WriteLine("deleting");
                    IFile file = await folder.GetFileAsync(IntClockStorage.UserClocksFileName);

                    await file.DeleteAsync();
                }
            }
        }
コード例 #7
0
        public async Task LoadGame()
        {
            IFolder folder = FileSystem.Current.LocalStorage;
            ExistenceCheckResult gameExists = await folder.CheckExistsAsync(GAME_STATE_FILENAME);

            if (gameExists == ExistenceCheckResult.FileExists)
            {
                IFile file = await folder.GetFileAsync(GAME_STATE_FILENAME);

                var serializedGame = await file.ReadAllTextAsync();

                if (serializedGame != null)
                {
                    try
                    {
                        var gameState = JsonConvert.DeserializeObject <GameModel>(serializedGame);
                        _gameState.SetGame(gameState);
                        _gameService.PushGame();
                    }
                    catch (Exception e)
                    {
                        await file.DeleteAsync();
                    }
                }
            }
        }
コード例 #8
0
        private static async Task <bool> download(string url, string fileName)
        {
            IFile file = null;

            try
            {
                var client = new HttpClient();
                var data   = await client.GetByteArrayAsync(url);

                var fileNamePaths = fileName.Split('\\');
                fileName = fileNamePaths[fileNamePaths.Length - 1];
                file     = await FileSystem.Current.LocalStorage.CreateFileAsync(fileName,
                                                                                 CreationCollisionOption.ReplaceExisting);

                using (var fileStream = await file.OpenAsync(PCLStorage.FileAccess.ReadAndWrite))
                {
                    fileStream.Write(data, 0, data.Length);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            if (file != null)
            {
                await file.DeleteAsync();
            }
            return(false);
        }
コード例 #9
0
        private void OnDelete(object sender, EventArgs e)
        {
            var selected     = (MenuItem)sender;
            var selectedFile = selected.CommandParameter as IFile;

            Device.BeginInvokeOnMainThread(async() =>
            {
                bool answer = await DisplayAlert("Delete File", "Do you want to delete " + selectedFile.Name + " ?", "Yes", "No");
                if (answer)
                {
                    IFolder folder             = FileSystem.Current.LocalStorage;
                    String folderName          = "receipt";
                    ExistenceCheckResult exist = await folder.CheckExistsAsync(folderName);

                    if (exist == ExistenceCheckResult.FolderExists)
                    {
                        IFile file = await folder.GetFileAsync(selectedFile.Name);

                        //	Act
                        await file.DeleteAsync();

                        IList <IFile> files     = await folder.GetFilesAsync();
                        pdfListView.ItemsSource = files;
                    }
                }
            });
        }
コード例 #10
0
        public async Task <bool> RemoveFromFileAsync()
        {
            try
            {
                IFolder rootFolder = FileSystem.Current.LocalStorage;
                IFolder folder     = await rootFolder.CreateFolderAsync("Lists", CreationCollisionOption.OpenIfExists);

                string validName = Name;
                foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                {
                    validName = validName.Replace(c, '_');
                }

                IFile file = await folder.CreateFileAsync(validName, CreationCollisionOption.OpenIfExists);

                await file.DeleteAsync();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
                // TODO notify to MatnaPage (DisplayAlert?)
                return(false);
            }
            return(true);
        }
コード例 #11
0
        public async Task UploadResponsedSurveys()
        {
            folder = FileSystem.Current.LocalStorage;
            if (!CheckNetwork.Check_Connectivity())
            {
                return;
            }
            List <Survey>        surveys = new List <Survey>();
            ExistenceCheckResult result  = await folder.CheckExistsAsync("ShareResponsedSurveys");

            if (result == ExistenceCheckResult.FolderExists)
            {
                folder = await folder.CreateFolderAsync("ShareResponsedSurveys", CreationCollisionOption.OpenIfExists);

                file = await folder.CreateFileAsync("ShareResponsedSurveys", CreationCollisionOption.OpenIfExists);

                string Content = await file.ReadAllTextAsync();

                if (String.IsNullOrEmpty(Content) || String.IsNullOrWhiteSpace(Content))
                {
                    return;
                }
                surveys = Serializable_Survey.deserialize(Content).ToList();
                foreach (Survey S in surveys)
                {
                    SurveysServices S_S = new SurveysServices();
                    S_S.Set_UrlApi("ShareResponsedSurveys/");
                    await S_S.PostSurveysAsync(S);
                }
                file = await folder.GetFileAsync("ShareResponsedSurveys");

                await file.DeleteAsync();
            }
        }
コード例 #12
0
        public async void ClearStorage()
        {
            var folder = await CreateFolder();

            if (folder == null)
            {
                return;
            }

            ExistenceCheckResult isFileExisting = await folder.CheckExistsAsync(FileName);

            if (isFileExisting != ExistenceCheckResult.NotFound)
            {
                try
                {
                    IFile file = await folder.CreateFileAsync(FileName, CreationCollisionOption.OpenIfExists);

                    await file.DeleteAsync();
                }
                catch (Exception ex)
                {
                    return;
                }
            }
        }
コード例 #13
0
        public static async Task DeleteFileIfExistsAsync(string fileName)
        {
            try
            {
#if UWP
                var folder = ApplicationData.Current.LocalFolder;
                var file   = await folder.TryGetFileAsync(fileName);

                if (file != null)
                {
                    await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
                }
#else
                IFolder folder = FileSystem.Current.LocalStorage;
                IFile   file   = await folder.GetFileAsync(fileName);

                if (file != null)
                {
                    await file.DeleteAsync();
                }
#endif
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
コード例 #14
0
        public async Task DeleteTextFile()
        {
            // arrange
            CloudBlobClient client        = _azureStorageResource.CreateBlobClient();
            string          containerName = Guid.NewGuid().ToString("N");
            await client.GetContainerReference(containerName).CreateIfNotExistsAsync();

            var            storage   = new FileStorage(client, containerName);
            IFileContainer container = await storage.CreateContainerAsync("abc");

            await container.CreateTextFileAsync("def", "ghi");

            IListBlobItem item = client.GetContainerReference(containerName)
                                 .GetDirectoryReference("abc")
                                 .ListBlobs()
                                 .SingleOrDefault();

            Assert.NotNull(item);

            // act
            IFile file = await container.GetFileAsync("def");

            await file.DeleteAsync();

            // assert
            Assert.False(client.GetContainerReference(containerName)
                         .GetDirectoryReference("abc")
                         .ListBlobs()
                         .Any());
        }
コード例 #15
0
        public async Task MoveFile_GenerateUniqueName()
        {
            //	Arrange
            IFolder folder    = TestFileSystem.LocalStorage;
            string  fileName1 = "file1.txt";
            string  fileName2 = "file2.txt";
            IFile   file1     = await folder.CreateFileAsync(fileName1, CreationCollisionOption.FailIfExists);

            IFile file2 = await folder.CreateFileAsync(fileName2, CreationCollisionOption.FailIfExists);

            //	Act
            await file1.MoveAsync(Path.Combine(folder.Path, fileName2), NameCollisionOption.GenerateUniqueName);

            // Assert
            string file1NameWithoutExtension = file1.Name.Substring(0, file1.Name.IndexOf('.'));
            string fileName2WithoutExtension = fileName2.Substring(0, fileName2.IndexOf('.'));

            Assert.IsTrue(file1NameWithoutExtension.StartsWith(fileName2WithoutExtension, StringComparison.CurrentCulture));
            Assert.IsFalse(file1NameWithoutExtension.Equals(fileName2WithoutExtension));
            IList <IFile> files = await folder.GetFilesAsync();

            Assert.IsFalse(files.Any(f => f.Name == fileName1));
            Assert.IsTrue(files.Any(f => f.Name == fileName2));
            Assert.IsTrue(files.Any(f => f.Name == file1.Name));

            // Cleanup
            await file1.DeleteAsync();

            await file2.DeleteAsync();
        }
コード例 #16
0
        public async Task RenameFile_GenerateUniqueName()
        {
            //	Arrange
            IFolder folder            = TestFileSystem.LocalStorage;
            string  fileName1         = "file1.txt";
            string  fileName2         = "file2.txt";
            string  fileName1_renamed = "file2 (2).txt";
            IFile   file1             = await folder.CreateFileAsync(fileName1, CreationCollisionOption.FailIfExists);

            IFile file2 = await folder.CreateFileAsync(fileName2, CreationCollisionOption.FailIfExists);

            //	Act
            await file1.RenameAsync(fileName2, NameCollisionOption.GenerateUniqueName);

            // Assert
            Assert.AreEqual(fileName1_renamed, file1.Name);
            IList <IFile> files = await folder.GetFilesAsync();

            Assert.IsFalse(files.Any(f => f.Name == fileName1));
            Assert.IsTrue(files.Any(f => f.Name == fileName2));
            Assert.IsTrue(files.Any(f => f.Name == fileName1_renamed));

            // Cleanup
            await file1.DeleteAsync();

            await file2.DeleteAsync();
        }
コード例 #17
0
        public async Task MoveFile_FailIfExists()
        {
            //	Arrange
            IFolder folder           = TestFileSystem.LocalStorage;
            string  originalFileName = "fileToMove.txt";
            string  movedFile        = "movedFile.txt";
            IFile   file             = await folder.CreateFileAsync(originalFileName, CreationCollisionOption.FailIfExists);

            IFile existingFile = await folder.CreateFileAsync(movedFile, CreationCollisionOption.FailIfExists);

            //	Act & Assert
            await Assert.ThrowsExceptionAsync <IOException>(async() => await file.MoveAsync(Path.Combine(folder.Path, movedFile), NameCollisionOption.FailIfExists));

            Assert.AreEqual(originalFileName, file.Name);

            IList <IFile> files = await folder.GetFilesAsync();

            Assert.IsTrue(files.Any(f => f.Name == movedFile));
            Assert.IsTrue(files.Any(f => f.Name == originalFileName));

            // Cleanup
            await file.DeleteAsync();

            await existingFile.DeleteAsync();
        }
コード例 #18
0
        public async Task <string> GetGameId()
        {
            IFolder folder = FileSystem.Current.LocalStorage;
            ExistenceCheckResult fileExists = await folder.CheckExistsAsync(GAME_STATE_FILENAME);

            if (fileExists == ExistenceCheckResult.FileExists)
            {
                IFile file = await folder.GetFileAsync(GAME_STATE_FILENAME);

                var serializedGame = await file.ReadAllTextAsync();

                if (serializedGame != null)
                {
                    try
                    {
                        var gameState = JsonConvert.DeserializeObject <GameModel>(serializedGame);
                        if (gameState != null)
                        {
                            return(gameState.GameId);
                        }
                    }
                    catch (Exception e)
                    {
                        await file.DeleteAsync();
                    }
                }
            }

            return(null);
        }
コード例 #19
0
ファイル: Runner.cs プロジェクト: cfe84/exp-k8s-iospeed
 private async Task DeleteFilesAsync(string[] files)
 {
     foreach (string file in files)
     {
         await fileDriver.DeleteAsync(file);
     }
 }
コード例 #20
0
ファイル: FileHelper.cs プロジェクト: smiechuskce/WordMemo
        public async void DeleteFile(string filename)
        {
            IFolder rootFolder = FileSystem.Current.LocalStorage;
            IFile   file       = await rootFolder.GetFileAsync(filename);

            await file.DeleteAsync();
        }
コード例 #21
0
ファイル: FileTests.cs プロジェクト: floolean/PCLStorageEx
        public async Task WriteFileStats()
        {
            IFolder folder        = TestFileSystem.LocalStorage;
            var     dateTime      = DateTime.Parse("1.1.2000");
            string  fileName      = "redfilestats";
            string  fileExtension = ".txt";
            IFile   file          = await folder.CreateFileAsync(fileName + fileExtension, CreationCollisionOption.ReplaceExisting);

            await file.SetCreationTime(dateTime);

            await file.SetLastWriteTime(dateTime);

            await file.SetLastAccessTime(dateTime);

            var stats = await file.GetFileStats();

            Assert.AreEqual(0, stats.Length);
            Assert.AreEqual(fileName + fileExtension, stats.Name);
            Assert.AreEqual(fileExtension, stats.Extension);
            Assert.AreEqual(dateTime, stats.CreationTime);
            Assert.AreEqual(dateTime, stats.LastWriteTime);
            Assert.AreEqual(dateTime, stats.LastAccessTime);

            await file.DeleteAsync();
        }
コード例 #22
0
ファイル: FileTests.cs プロジェクト: floolean/PCLStorageEx
        public async Task RenameFile_FailIfExists()
        {
            //	Arrange
            IFolder folder           = TestFileSystem.LocalStorage;
            string  originalFileName = "fileToRename.txt";
            string  renamedFile      = "renamedFile.txt";
            IFile   file             = await folder.CreateFileAsync(originalFileName, CreationCollisionOption.FailIfExists);

            IFile existingFile = await folder.CreateFileAsync(renamedFile, CreationCollisionOption.FailIfExists);

            //	Act & Assert
            await ExceptionAssert.ThrowsAsync <IOException>(async() => await file.RenameAsync(renamedFile, NameCollisionOption.FailIfExists));

            Assert.AreEqual(originalFileName, file.Name);

            var files = await folder.GetFilesAsync();

            Assert.IsTrue(files.Any(f => f.Name == renamedFile));
            Assert.IsTrue(files.Any(f => f.Name == originalFileName));

            // Cleanup
            await file.DeleteAsync();

            await existingFile.DeleteAsync();
        }
コード例 #23
0
        //Delete File
        async void DeleteFile(object sender, EventArgs e)
        {
            var Entry = EntDeleteFile;

            // Alert, if no File Name
            if (Entry.Text == null)
            {
                await DisplayAlert("Delete File", "Input File Name!", "OK");

                return;
            }

            // Delete File entered in EntDeleteSubFolder
            var fileExists = await rootFolder.CheckExistsAsync(Entry.Text);

            if (fileExists != ExistenceCheckResult.FileExists)
            {
                await DisplayAlert("Delete File", Entry.Text + " doesn't exist", "OK");

                return;
            }
            IFile file = await rootFolder.GetFileAsync(Entry.Text);

            await file.DeleteAsync();

            await DisplayAlert("Delete File", Entry.Text + " has been deleted!", "OK");
        }
コード例 #24
0
        static async Task <bool> download(string url, string fileName)
        {
            IFile file = null;

            try{
                var client = new HttpClient();
                var data   = await client.GetByteArrayAsync(url);

                file = await folder.CreateFileAsync(fileName,
                                                    CreationCollisionOption.ReplaceExisting);

                using (var fileStream = await file.OpenAsync(FileAccess.ReadAndWrite)){
                    fileStream.Write(data, 0, data.Length);
                }
                return(true);
            }
            catch (Exception ex) {
                Debug.WriteLine(ex);
            }
            if (file != null)
            {
                await file.DeleteAsync();
            }
            return(false);
        }
コード例 #25
0
        public async Task DeleteFile(string id)
        {
            var client = await EnsureClientCreated();

            IFile file = await client.Files.GetById(id).ToFile().ExecuteAsync();

            await file.DeleteAsync();
        }
コード例 #26
0
 public void Disconnect()
 {
     try
     {
         _file.DeleteAsync().Wait();
     }
     catch {}
 }
コード例 #27
0
ファイル: Authentication.cs プロジェクト: itainteasy/WTalk
 public void Disconnect()
 {
     try
     {
         _file.DeleteAsync().Wait();
         FileCache.Current.Reset();
     }
     catch {}
 }
コード例 #28
0
        /// <summary>
        /// Deletes Favorited File if exists.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public async Task DeleteFavoritesFile(string fileName)
        {
            if ((await folder.CheckExistsAsync(fileName)) == ExistenceCheckResult.FileExists)
            {
                IFile file = await folder.GetFileAsync(fileName);

                await file.DeleteAsync();
            }
        }
コード例 #29
0
        public async void DeleteImg(string imgName)
        {
            IFolder rootFolder = FileSystem.Current.LocalStorage;
            IFolder scanned    = await rootFolder.GetFolderAsync("Scanned");

            IFile imgToDelete = await scanned.GetFileAsync(imgName);

            await imgToDelete.DeleteAsync();
        }
コード例 #30
0
ファイル: VideoHelper.cs プロジェクト: nour7/Ta7meel
        public async Task RemoveVideoFile(string filename)
        {
            IFolder rootFolder = FileSystem.Current.LocalStorage;
            IFolder folder     = await rootFolder.CreateFolderAsync(AppFolder, CreationCollisionOption.OpenIfExists);

            IFile file = await folder.GetFileAsync(filename);

            await file.DeleteAsync();
        }