/// <summary> /// Initializes a new instance of the <see cref="Account" /> class. /// </summary> /// <param name="cloudApi"></param> /// <param name="login">Login name as email.</param> /// <param name="password">Password related with this login</param> /// <param name="twoFaHandler"></param> public Account(CloudApi cloudApi, string login, string password, ITwoFaHandler twoFaHandler) { _cloudApi = cloudApi; LoginName = login; Password = password; WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials; Proxy = WebRequest.DefaultWebProxy; var twoFaHandler1 = twoFaHandler; if (twoFaHandler1 != null) { AuthCodeRequiredEvent += twoFaHandler1.Get; } _bannedShards = new Cached <List <ShardInfo> >(() => new List <ShardInfo>(), TimeSpan.FromMinutes(4)); _cachedShards = new Cached <Dictionary <ShardType, ShardInfo> >(() => new ShardInfoRequest(_cloudApi).MakeRequestAsync().Result.ToShardInfo(), TimeSpan.FromSeconds(ShardsExpiresInSec)); DownloadToken = new Cached <string>(() => new DownloadTokenRequest(_cloudApi).MakeRequestAsync().Result.ToToken(), TimeSpan.FromSeconds(DownloadTokenExpiresSec)); AuthToken = new Cached <string>(() => { Logger.Debug("AuthToken expired, refreshing."); var token = new AuthTokenRequest(_cloudApi).MakeRequestAsync().Result.ToToken(); DownloadToken.Expire(); return(token); }, TimeSpan.FromSeconds(AuthTokenExpiresInSec)); }
public UploadStream(string destinationPath, CloudApi cloud, long size) { _cloud = cloud; _file = new File(destinationPath, size, null); _shard = _cloud.Account.GetShardInfo(ShardType.Upload).Result; Initialize(); }
public SplittedUploadStream(string destinationPath, CloudApi cloud, long size) { _destinationPath = destinationPath; _cloud = cloud; _size = size; _maxFileSize = _cloud.Account.Info.FileSizeLimit > 0 ? _cloud.Account.Info.FileSizeLimit - 1024 : long.MaxValue - 1024; Initialize(); }
public DownloadStream(IList <File> files, CloudApi cloud, long?start = null, long?end = null) { var globalLength = files.Sum(f => f.Size); _cloud = cloud; _files = files; _start = start; _end = end >= globalLength ? globalLength - 1 : end; Length = _start != null && _end != null ? _end.Value - _start.Value + 1 : globalLength; Initialize(); }
public DownloadStream(IList <File> files, CloudApi cloud, long?start = null, long?end = null) { var globalLength = files.Sum(f => f.Size); _cloud = cloud; _shard = files.All(f => string.IsNullOrEmpty(f.PublicLink)) ? _cloud.Account.GetShardInfo(ShardType.Get).Result : _cloud.Account.GetShardInfo(ShardType.WeblinkGet).Result; _files = files; _start = start; _end = end >= globalLength ? globalLength - 1 : end; Length = _start != null && _end != null ? _end.Value - _start.Value + 1 : globalLength; Initialize(); }
public DownloadStream(File file, CloudApi cloud, long?start = null, long?end = null) : this(file.Parts, cloud, start, end) { }