public async Task <Stream> Create(File file, FileUploadedDelegate onUploaded = null, bool discardEncryption = false) { if (!(await _cloud.GetItemAsync(file.Path, MailRuCloud.ItemType.Folder) is Folder folder)) { throw new DirectoryNotFoundException(file.Path); } Stream stream; bool cryptRequired = _cloud.IsFileExists(CryptFileInfo.FileName, WebDavPath.GetParents(folder.FullPath).ToList()).Any(); if (cryptRequired && !discardEncryption) { if (!_cloud.Account.Credentials.CanCrypt) { throw new Exception($"Cannot upload {file.FullPath} to crypt folder without additional password!"); } // #142 remove crypted file parts if size changed var remoteFile = folder.Files.FirstOrDefault(f => f.FullPath == file.FullPath); if (remoteFile != null) { await _cloud.Remove(remoteFile); } stream = GetCryptoStream(file, onUploaded); } else { stream = GetPlainStream(file, onUploaded); } return(stream); }
public void TestRemoveFileByFullPath() { var fileName = "RemoveTest.txt"; var content = "MyTestContent"; var destinationPath = "/"; var source = new MemoryStream(Encoding.UTF8.GetBytes(content)); var size = source.Length; var api = new MailRuCloud() { Account = account }; var entry = api.GetItems(destinationPath).Result; Assert.IsFalse(entry.Files.Any(i => i.Name == fileName)); var result = api.UploadFileAsync(fileName, source, destinationPath).Result; Assert.IsInstanceOfType(result, typeof(MailRuCloudApi.File)); entry = api.GetItems(destinationPath).Result; Assert.IsTrue(entry.Files.Any(i => i.Name == fileName)); api.Remove(destinationPath + fileName).Wait(); entry = api.GetItems(destinationPath).Result; Assert.IsFalse(entry.Files.Any(i => i.Name == fileName)); }
public void RemoveFileFolderTest() { var api = new MailRuCloud(); api.Account = this.account; var result = api.UploadFileAsync(new FileInfo(@"C:\Development\MailRuCloudApi\1.txt"), "/"); var file = api.GetItems("/").Files.First(x => x.Name == "1.txt"); api.Remove(file); api.CreateFolder("new test folder", "/"); var folder = api.GetItems("/").Folders.First(x => x.Name == "new test folder"); api.Remove(folder); }
public static Task <bool> Remove(this MailRuCloud cloud, IStoreItem item) { if (null == item) { return(Task.FromResult(false)); } var storeItem = item as MailruStoreItem; if (storeItem != null) { return(cloud.Remove(storeItem.FileInfo)); } var storeCollection = item as MailruStoreCollection; if (storeCollection != null) { return(cloud.Remove(storeCollection.DirectoryInfo)); } throw new ArgumentException(string.Empty, nameof(item)); }
static void Main(string[] args) { Console.WriteLine(args.Length.ToString()); if (args.Length != 4) { return; } var fileName = args[0]; var destinationPath = args[1]; var login = args[2]; var password = args[3]; account = new Account(login, password); var api = new MailRuCloud() { Account = account }; //var percent = 0; api.ChangingProgressEvent += delegate(object sender, ProgressChangedEventArgs e) { //percent = e.ProgressPercentage Console.WriteLine("uploading " + e.ProgressPercentage); }; api.UploadFile(new FileInfo(fileName), destinationPath).Wait(); DateTime today = DateTime.Now; DateTime answer = today.AddDays(Convert.ToDouble(-45)); Entry items = api.GetItems(destinationPath).Result; foreach (MailRuCloudApi.File f in items.Files) { if (f.LastModifiedTimeUTC < answer) { api.Remove(f.FulPath).Wait(); } } api = null; }