private static MailRuCloud.Api.MailRuCloud CreateCloud(HttpListenerBasicIdentity identity) { Logger.Info($"Cloud instance created for {identity.Name}"); if (!ConstSettings.AvailDomains.Any(d => identity.Name.Contains($"@{d}."))) { string domains = ConstSettings.AvailDomains.Aggregate((c, n) => c + ", @" + n); Logger.Warn($"Missing domain part ({domains}) in login, file and folder deleting will be denied"); } //2FA authorization ITwoFaHandler twoFaHandler = null; if (!string.IsNullOrEmpty(TwoFactorHandlerName)) { twoFaHandler = TwoFaHandlers.Get(TwoFactorHandlerName); if (null == twoFaHandler) { Logger.Error($"Cannot load two-factor auth handler {TwoFactorHandlerName}"); } } var cloud = new MailRuCloud.Api.MailRuCloud(identity.Name, identity.Password, twoFaHandler); return(cloud); }
private static MailRuCloud.Api.MailRuCloud CreateCloud(HttpListenerBasicIdentity identity) { Logger.Info($"Cloud instance created for {identity.Name}"); if (!ConstSettings.AvailDomains.Any(d => identity.Name.Contains($"@{d}."))) { string domains = ConstSettings.AvailDomains.Aggregate((c, n) => c + ", @" + n); Logger.Warn($"Missing domain part ({domains}) in login, file and folder deleting will be denied"); } var credentials = new Credentials(identity.Name, identity.Password); var cloud = new MailRuCloud.Api.MailRuCloud(Settings, credentials); return(cloud); }
public static Task <bool> Move(this MailRuCloud.Api.MailRuCloud cloud, IStoreItem item, string destinationPath) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (string.IsNullOrEmpty(destinationPath)) { throw new ArgumentNullException(nameof(destinationPath)); } if (!(item is IMailruStoreItem)) { throw new ArgumentException($"{nameof(IMailruStoreItem)} required.", nameof(item)); } return(cloud.Move(((IMailruStoreItem)item).EntryInfo, destinationPath)); }
public static Task <bool> Remove(this MailRuCloud.Api.MailRuCloud cloud, IStoreItem item) { if (null == item) { return(Task.FromResult(false)); } if (item is MailruStoreItem storeItem) { return(cloud.Remove(storeItem.FileInfo)); } if (item is MailruStoreCollection storeCollection) { return(cloud.Remove(storeCollection.DirectoryInfo)); } throw new ArgumentException(string.Empty, nameof(item)); }
private Stream OpenReadStream(MailRuCloud.Api.MailRuCloud cloud, long?start, long?end) { Stream stream = cloud.GetFileDownloadStream(_fileInfo, start, end).Result; return(stream); }
public static int Upload(UploadOptions cmdoptions) { string user = cmdoptions.Login; string password = cmdoptions.Password; string listname = cmdoptions.FileList; string targetpath = cmdoptions.Target; if (targetpath.StartsWith(@"\\\")) { targetpath = Regex.Replace(targetpath, @"\A\\\\\\.*?\\.*?\\", @"\"); } targetpath = WebDavPath.Clean(targetpath); var settings = new CloudSettings { TwoFaHandler = null, Protocol = Protocol.WebM1Bin }; var credentials = new Credentials(user, password); var cloud = new MailRuCloud.Api.MailRuCloud(settings, credentials); using (var file = new StreamReader(listname)) { string line; while ((line = file.ReadLine()) != null) { System.Console.WriteLine($"Source: {line}"); var fileInfo = new FileInfo(line); string targetfile = WebDavPath.Combine(targetpath, fileInfo.Name); System.Console.WriteLine($"Target: {targetfile}"); using (var source = System.IO.File.Open(line, FileMode.Open, FileAccess.Read, FileShare.Read)) { var hasher = new MailRuSha1Hash(); hasher.Append(source); var hash = hasher.HashString; if (cloud.AddFile(hash, targetfile, fileInfo.Length, ConflictResolver.Rename).Result.Success) { System.Console.WriteLine("Added by hash"); } else { source.Seek(0, SeekOrigin.Begin); var buffer = new byte[64000]; long wrote = 0; using (var target = cloud.GetFileUploadStream(WebDavPath.Combine(targetfile, fileInfo.Name), fileInfo.Length).Result) { int read; while ((read = source.Read(buffer, 0, buffer.Length)) > 0) { target.Write(buffer, 0, read); wrote += read; System.Console.Write($"\r{wrote / fileInfo.Length * 100}%"); } } } System.Console.WriteLine(" Done."); //source.CopyTo(target); } } } return(0); }