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 GetItemsTest() { var api = new MailRuCloud(); api.Account = this.account; var items = api.GetItems("/Camera Uploads/"); Assert.IsNotNull(items); Assert.IsTrue(items.Files.Count == items.NumberOfFiles || items.Folders.Count == items.NumberOfFolders); var percent = 0; api.ChangingProgressEvent += delegate(object sender, ProgressChangedEventArgs e) { percent = e.ProgressPercentage; }; var fileToDownload = items.Files.First(t => t.Size <= 1 * 1024 * 1024); var task = api.GetFileAsync(fileToDownload); Assert.IsNotNull(task.Result); Assert.IsTrue(percent == 100); percent = 0; var task2 = api.GetFileAsync(fileToDownload, @"C:\Development\MailRuCloudApi\"); Assert.IsTrue(task2.Result); Assert.IsTrue(percent == 100); var fileInfo = new FileInfo(@"C:\Development\MailRuCloudApi\" + fileToDownload.Name); Assert.IsTrue(fileInfo.Exists, "File is not created."); Assert.IsTrue(fileInfo.Length > 0, "File size in not retrieved."); }
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 void RenameTest() { var api = new MailRuCloud(); api.Account = this.account; var result = api.UploadFileAsync(new FileInfo(@"D:\1.stl"), "/"); if (result.Result) { var file = api.GetItems("/").Files.First(x => x.Name == "1.stl"); api.Rename(file, "rename stl test.stl"); api.CreateFolder("new test folder", "/"); var folder = api.GetItems("/").Folders.First(x => x.Name == "new test folder"); api.Rename(folder, "rename folder test"); var entry = api.GetItems("/"); Assert.IsNotNull(entry.Folders.FirstOrDefault(x => x.Name == "rename folder test")); Assert.IsNotNull(entry.Files.FirstOrDefault(x => x.Name == "rename stl test.stl")); } }
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; }
public void GetPublishDirectLinkTest() { var api = new MailRuCloud(); api.Account = this.account; var items = api.GetItems("/Camera Uploads"); var fileToDownload = items.Files.First(t => t.Size <= 1 * 1024 * 1024); var publicFileLink = api.GetPublishLink(fileToDownload); Assert.IsTrue(!string.IsNullOrEmpty(publicFileLink)); var directLink = api.GetPublishDirectLink(publicFileLink); Assert.IsTrue(!string.IsNullOrEmpty(directLink)); var unpublishFile = api.UnpublishLink(fileToDownload, publicFileLink); Assert.IsTrue(unpublishFile); }
public void PublicUnpublishLink() { var api = new MailRuCloud(); api.Account = this.account; var items = api.GetItems("/Camera Uploads"); var fileToDownload = items.Files.First(t => t.Size <= 1 * 1024 * 1024); var publicFileLink = api.GetPublishLink(fileToDownload); var folder = new Folder(0, 0, "Camera Uploads", 0, "/Camera Uploads"); var publishFolderLink = api.GetPublishLink(folder); Assert.IsTrue(!string.IsNullOrEmpty(publicFileLink)); Assert.IsTrue(!string.IsNullOrEmpty(publishFolderLink)); var unpublishFile = api.UnpublishLink(fileToDownload, publicFileLink); var unpublishFolder = api.UnpublishLink(folder, publishFolderLink); Assert.IsTrue(unpublishFile); Assert.IsTrue(unpublishFolder); }