public SpecialCommand Build(MailRuCloud cloud, string param) { var res = ParceLine(param, cloud.Settings.SpecialCommandPrefix); if (!res.IsValid && !string.IsNullOrEmpty(cloud.Settings.AdditionalSpecialCommandPrefix)) { res = ParceLine(param, cloud.Settings.AdditionalSpecialCommandPrefix); } if (!res.IsValid) { return(null); } var parames = ParseParameters(res.Data); var commandContainer = FindCommandContainer(parames); if (commandContainer == null) { return(null); } parames = parames.Skip(commandContainer.Commands.Length).ToList(); var cmd = commandContainer.CreateFunc(cloud, res.Path, parames); return(cmd); }
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."); }
protected UploadStreamHttpClient(string destinationPath, MailRuCloud cloud, long size) { _cloud = cloud; _file = new File(destinationPath, size, null); Initialize(); }
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 async Task GetPublishDirectLinkTest() { MailRuCloud cloud = new MailRuCloud(); string downloadLink = await cloud.GetPublishDirectLink("https://cloud.mail.ru/public/Euhr/WwtEeZmKH", FileType.SingleFile); Assert.IsNotNull(downloadLink); }
protected SpecialCommand(MailRuCloud cloud, string path, IList <string> parames) { Cloud = cloud; Path = path; Parames = parames; CheckParams(); }
public static void Init(string login, string password, string userAgent = "") { if (!string.IsNullOrEmpty(userAgent)) { ConstSettings.UserAgent = userAgent; } Instance = new MailRuCloud(login, password); }
public static CryptoKeyInfo GetCryptoPublicInfo(MailRuCloud cloud, File file) { var iv = file.EnsurePublicKey(cloud); if (null == iv) { throw new Exception("Cannot get crypto public key"); } return(iv); }
public string GetPublicLink(MailRuCloud cloud) { string pl = PublicLink; if (string.IsNullOrEmpty(pl)) { pl = cloud.GetSharedLink(FullPath); } return(pl); }
public LinkManager(MailRuCloud cloud) { _cloud = cloud; _itemCache = new ItemCache <string, IEntry>(TimeSpan.FromSeconds(60)) { CleanUpPeriod = TimeSpan.FromMinutes(5) }; cloud.FileUploaded += OnFileUploaded; Load(); }
public SplittedUploadStream(string destinationPath, MailRuCloud cloud, long size, bool checkHash = true, CryptInfo cryptInfo = null) { _destinationPath = destinationPath; _cloud = cloud; _size = size; _checkHash = checkHash; _cryptInfo = cryptInfo; _maxFileSize = _cloud.Account.Info.FileSizeLimit > 0 ? _cloud.Account.Info.FileSizeLimit - 1024 : long.MaxValue - 1024; Initialize(); }
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 TestDownloadFileToStream() { var fileName = "UploadTest.txt"; var content = "MyTestContent"; var sourcePath = "/"; var api = new MailRuCloud() { Account = account }; var result = new MemoryStream(api.GetFile(new MailRuCloudApi.File(fileName, sourcePath + fileName), false).Result); using (var streamReader = new StreamReader(result)) Assert.AreEqual(content, streamReader.ReadToEnd()); }
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 TestUploadBinaryFileFromStream() { var fileName = "UploadTestBinary.bin"; var content = Enumerable.Range(0, 256).Select(i => (byte)i).ToArray(); var destinationPath = "/"; var source = new MemoryStream(content); var size = source.Length; var api = new MailRuCloud() { Account = account }; var result = api.UploadFileAsync(fileName, source, destinationPath).Result; Assert.IsInstanceOfType(result, typeof(MailRuCloudApi.File)); Assert.AreEqual(size, result.Size.DefaultValue); }
public void TestUploadFileFromStream() { var fileName = "UploadTest.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 result = api.UploadFileAsync(fileName, source, destinationPath).Result; Assert.IsInstanceOfType(result, typeof(MailRuCloudApi.File)); Assert.AreEqual(size, result.Size.DefaultValue); }
public JoinCommand(MailRuCloud cloud, string path, IList <string> parames) : base(cloud, path, parames) { var m = Regex.Match(Parames[0], @"(?snx-) (https://?cloud.mail.ru/public)?(?<data>/\w*/?\w*)/?\s*"); if (m.Success) //join by shared link { _func = () => ExecuteByLink(Path, m.Groups["data"].Value); } else { var mhash = Regex.Match(Parames[0], @"#(?<data>\w+)"); var msize = Regex.Match(Parames[1], @"(?<data>\w+)"); if (mhash.Success && msize.Success && Parames.Count == 3) //join by hash and size { _func = () => ExecuteByHash(Path, mhash.Groups["data"].Value, long.Parse(Parames[1]), Parames[2]); } } }
public void TestDownloadBinaryFileToStream() { var fileName = "UploadTestBinary.bin"; var content = Enumerable.Range(0, 256).Select(i => (byte)i).ToArray(); var sourcePath = "/"; var api = new MailRuCloud() { Account = account }; var result = new MemoryStream(api.GetFile(new MailRuCloudApi.File(fileName, sourcePath + fileName), false).Result); var output = new byte[result.Length]; result.Read(output, 0, (int)result.Length); CollectionAssert.AreEqual(content, output); }
public void UploadFileTest() { var api = new MailRuCloud(); api.Account = this.account; var percent = 0; api.ChangingProgressEvent += delegate(object sender, ProgressChangedEventArgs e) { percent = e.ProgressPercentage; }; var task = api.UploadFileAsync(new FileInfo(@"C:\Development\MailRuCloudApi\1.txt"), "/"); Assert.IsTrue(task.Result); Assert.IsTrue(percent == 100); Thread.Sleep(5000); }
public void UploadFileTest() { var api = new MailRuCloud(); api.Account = this.account; var percent = 0; api.ChangingProgressEvent += delegate(object sender, ProgressChangedEventArgs e) { percent = e.ProgressPercentage; }; var task = api.UploadFile(new FileInfo(@"..\..\Properties\AssemblyInfo.cs"), "/"); Assert.IsTrue(task.Result); Assert.IsTrue(percent == 100); Thread.Sleep(5000); }
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 static Task <bool> Move(this MailRuCloud cloud, IStoreItem item, string destinationName) { if (null == item) { return(Task.FromResult(false)); } var storeItem = item as MailruStoreItem; if (storeItem != null) { return(cloud.Move(storeItem.FileInfo, destinationName)); } var storeCollection = item as MailruStoreCollection; if (storeCollection != null) { return(cloud.Move(storeCollection.DirectoryInfo, destinationName)); } throw new ArgumentException(string.Empty, nameof(item)); }
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); }
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")); } }
public SpecialCommand Build(MailRuCloud cloud, string param) { if (null == param || !param.Contains("/>>")) { return(null); } int pos = param.LastIndexOf("/>>", StringComparison.Ordinal); string path = WebDavPath.Clean(param.Substring(0, pos + 1)); string data = param.Substring(pos + 3); var parames = ParseParameters(data); var commandContainer = FindCommandContainer(parames); if (commandContainer == null) { return(null); } parames = parames.Skip(commandContainer.Commands.Length).ToList(); var cmd = commandContainer.CreateFunc(cloud, path, parames); return(cmd); }
public MoveCommand(MailRuCloud cloud, string path, IList <string> parames) : base(cloud, path, parames) { }
public UploadStream(string destinationPath, MailRuCloud cloud, long size) : base(destinationPath, cloud, size) { }
public LocalToServerCopyCommand(MailRuCloud cloud, string path, IList <string> parames) : base(cloud, path, parames) { }
public CryptPasswdCommand(MailRuCloud cloud, string path, IList <string> parames) : base(cloud, path, parames) { }
public UploadStreamFabric(MailRuCloud cloud) { _cloud = cloud; }