示例#1
0
        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);
        }
示例#2
0
        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();
        }
示例#4
0
        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));
        }
示例#5
0
        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);
        }
示例#6
0
        protected SpecialCommand(MailRuCloud cloud, string path, IList <string> parames)
        {
            Cloud   = cloud;
            Path    = path;
            Parames = parames;

            CheckParams();
        }
示例#7
0
        public static void Init(string login, string password, string userAgent = "")
        {
            if (!string.IsNullOrEmpty(userAgent))
            {
                ConstSettings.UserAgent = userAgent;
            }

            Instance = new MailRuCloud(login, password);
        }
示例#8
0
        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);
        }
示例#9
0
        public string GetPublicLink(MailRuCloud cloud)
        {
            string pl = PublicLink;

            if (string.IsNullOrEmpty(pl))
            {
                pl = cloud.GetSharedLink(FullPath);
            }

            return(pl);
        }
示例#10
0
        public LinkManager(MailRuCloud cloud)
        {
            _cloud     = cloud;
            _itemCache = new ItemCache <string, IEntry>(TimeSpan.FromSeconds(60))
            {
                CleanUpPeriod = TimeSpan.FromMinutes(5)
            };

            cloud.FileUploaded += OnFileUploaded;

            Load();
        }
示例#11
0
        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();
        }
示例#12
0
        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);
        }
示例#13
0
        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());
        }
示例#14
0
        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;
        }
示例#15
0
        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);
        }
示例#16
0
        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);
        }
示例#17
0
        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]);
                }
            }
        }
示例#18
0
        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);
        }
示例#19
0
        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);
        }
示例#20
0
        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);
        }
示例#21
0
        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);
        }
示例#22
0
        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));
        }
示例#23
0
        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);
        }
示例#24
0
        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);
        }
示例#26
0
 public MoveCommand(MailRuCloud cloud, string path, IList <string> parames) : base(cloud, path, parames)
 {
 }
示例#27
0
 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)
 {
 }
示例#29
0
 public CryptPasswdCommand(MailRuCloud cloud, string path, IList <string> parames) : base(cloud, path, parames)
 {
 }
 public UploadStreamFabric(MailRuCloud cloud)
 {
     _cloud = cloud;
 }