コード例 #1
0
 public YadAuthPasswordRequest(HttpCommonSettings settings, IAuth auth, string csrf, string trackId)
     : base(settings, auth)
 {
     _auth    = auth;
     _csrf    = csrf;
     _trackId = trackId;
 }
コード例 #2
0
 public YadAuthLoginRequest(HttpCommonSettings settings, IAuth auth, string csrf, string uuid)
     : base(settings, auth)
 {
     _auth = auth;
     _csrf = csrf;
     _uuid = uuid;
 }
コード例 #3
0
        public OAuth(HttpCommonSettings settings, IBasicCredentials creds, AuthCodeRequiredDelegate onAuthCodeRequired)
        {
            _settings           = settings;
            _creds              = creds;
            _onAuthCodeRequired = onAuthCodeRequired;
            Cookies             = new CookieContainer();

            _authToken = new Cached <AuthTokenResult>(old =>
            {
                Logger.Debug(null == old ? "OAuth: authorizing." : "OAuth: AuthToken expired, refreshing.");

                var token = null == old || string.IsNullOrEmpty(old.RefreshToken)
                        ? Auth().Result
                        : Refresh(old.RefreshToken).Result;

                return(token);
            },
                                                      value =>
            {
                if (null == value)
                {
                    return(TimeSpan.MaxValue);
                }
                return(value.ExpiresIn.Add(-TimeSpan.FromMinutes(5)));
            });
            //value => TimeSpan.FromSeconds(20));
        }
コード例 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="auth"></param>
 /// <param name="sourceFullPath"></param>
 /// <param name="destinationPath">(without item name)</param>
 /// <param name="conflictResolver"></param>
 public CopyRequest(HttpCommonSettings settings, IAuth auth, string sourceFullPath, string destinationPath, ConflictResolver?conflictResolver = null)
     : base(settings, auth)
 {
     _sourceFullPath   = sourceFullPath;
     _destinationPath  = destinationPath;
     _conflictResolver = conflictResolver ?? ConflictResolver.Rename;
 }
コード例 #5
0
ファイル: WebAuth.cs プロジェクト: riftbit/WebDavMailRuCloud
        public WebAuth(HttpCommonSettings settings, IBasicCredentials creds, AuthCodeRequiredDelegate onAuthCodeRequired)
        {
            _settings = settings;
            _creds    = creds;
            Cookies   = new CookieContainer();

            var logged = MakeLogin(onAuthCodeRequired).Result;

            if (!logged)
            {
                throw new AuthenticationException($"Cannot log in {creds.Login}");
            }


            _authToken = new Cached <AuthTokenResult>(old =>
            {
                Logger.Debug("AuthToken expired, refreshing.");
                if (!creds.IsAnonymous)
                {
                    var token = Auth().Result;
                    return(token);
                }
                return(null);
            },
                                                      value => TimeSpan.FromSeconds(AuthTokenExpiresInSec));

            _cachedDownloadToken = new Cached <string>(old => new DownloadTokenRequest(_settings, this).MakeRequestAsync().Result.ToToken(),
                                                       value => TimeSpan.FromSeconds(DownloadTokenExpiresSec));
        }
コード例 #6
0
 public CreateFileRequest(HttpCommonSettings settings, IAuth auth, string fullPath, string hash, long size, ConflictResolver?conflictResolver)
     : base(settings, auth)
 {
     _fullPath         = fullPath;
     _hash             = hash;
     _size             = size;
     _conflictResolver = conflictResolver ?? ConflictResolver.Rename;
 }
コード例 #7
0
 public ItemInfoRequest(HttpCommonSettings settings, IAuth auth, string path, bool isWebLink = false, int offset = 0, int limit = int.MaxValue)
     : base(settings, auth)
 {
     _path      = path;
     _isWebLink = isWebLink;
     _offset    = offset;
     _limit     = limit;
 }
コード例 #8
0
        public YadWebAuth(HttpCommonSettings settings, IBasicCredentials creds)
        {
            _settings = settings;
            _creds    = creds;
            Cookies   = new CookieContainer();

            var _ = MakeLogin().Result;
        }
コード例 #9
0
 public MobAddFileRequest(HttpCommonSettings settings, IAuth auth, string metaServer, string fullPath, byte[] hash, long size, DateTime?dateTime, ConflictResolver?conflict)
     : base(settings, auth, metaServer)
 {
     _fullPath         = fullPath;
     _hash             = hash ?? new byte[20]; // zero length file
     _size             = size;
     _conflictResolver = conflict ?? ConflictResolver.Rewrite;
     _dateTime         = (dateTime ?? DateTime.Now).ToUniversalTime();
 }
コード例 #10
0
        public UnpublishRequest(IRequestRepo repo, HttpCommonSettings settings, IAuth auth, string publicLink)
            : base(settings, auth)
        {
            _publicLink = publicLink;

            if (repo.PublicBaseUrlDefault.Length > 0 &&
                _publicLink.StartsWith(repo.PublicBaseUrlDefault, StringComparison.InvariantCultureIgnoreCase))
            {
                _publicLink = _publicLink.Remove(0, repo.PublicBaseUrlDefault.Length);
            }
        }
コード例 #11
0
        private static HttpWebRequest CreateRequest(HttpCommonSettings settings, IAuth authent, File file, long instart, long inend, string downServerUrl, IEnumerable <string> publicBaseUrls) //(IAuth authent, IWebProxy proxy, string url, long instart, long inend,  string userAgent)
        {
            bool isLinked = file.PublicLinks.Any();

            string url;

            if (isLinked)
            {
                var urii    = file.PublicLinks.First().Uri;
                var uriistr = urii.OriginalString;
                var baseura = publicBaseUrls.First(pbu => uriistr.StartsWith(pbu, StringComparison.InvariantCulture));
                if (string.IsNullOrEmpty(baseura))
                {
                    throw new ArgumentException("url does not starts with base url");
                }

                url = $"{downServerUrl}{WebDavPath.EscapeDataString(uriistr.Remove(0, baseura.Length))}";
            }
            else
            {
                url  = $"{downServerUrl}{Uri.EscapeDataString(file.FullPath.TrimStart('/'))}";
                url += $"?client_id={settings.ClientId}&token={authent.AccessToken}";
            }

            var uri = new Uri(url);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.OriginalString);

            request.AllowAutoRedirect = true;

            request.AddRange(instart, inend);
            request.Proxy = settings.Proxy;
            //request.CookieContainer = authent.Cookies;
            request.Method = "GET";
            //request.Accept = "*/*";
            //request.UserAgent = settings.UserAgent;
            //request.Host = uri.Host;
            request.AllowWriteStreamBuffering = false;

            if (isLinked)
            {
                request.Headers.Add("Accept-Ranges", "bytes");
            }

            request.Timeout          = 15 * 1000;
            request.ReadWriteTimeout = 15 * 1000;

            return(request);
        }
コード例 #12
0
        public FolderInfoRequest(HttpCommonSettings settings, IAuth auth, RemotePath path, int offset = 0, int limit = int.MaxValue)
            : base(settings, auth)
        {
            _isWebLink = path.IsLink;

            if (path.IsLink)
            {
                string ustr = path.Link.Href.OriginalString;
                _path = "/" + ustr.Remove(0, ustr.IndexOf("/public/") + "/public/".Length);
            }
            else
            {
                _path = path.Path;
            }

            _offset = offset;
            _limit  = limit;
        }
コード例 #13
0
        public ShardManager(HttpCommonSettings httpsettings, IAuth auth, IRequestRepo repo)
        {
            _metaServer = new Cached <Requests.WebBin.MobMetaServerRequest.Result>(old =>
            {
                Logger.Debug("Requesting new meta server");
                var server = new Requests.WebBin.MobMetaServerRequest(httpsettings).MakeRequestAsync().Result;
                return(server);
            },
                                                                                   value => TimeSpan.FromSeconds(MetaServerExpiresSec));

            BannedShards = new Cached <List <ShardInfo> >(old => new List <ShardInfo>(),
                                                          value => TimeSpan.FromMinutes(2));

            //CachedShards = new Cached<Dictionary<ShardType, ShardInfo>>(old => new ShardInfoRequest(httpsettings, auth).MakeRequestAsync().Result.ToShardInfo(),
            //    value => TimeSpan.FromSeconds(ShardsExpiresInSec));

            CachedShards = new Cached <Dictionary <ShardType, ShardInfo> >(old => repo.GetShardInfo1(),
                                                                           value => TimeSpan.FromSeconds(ShardsExpiresInSec));

            DownloadServersPending = new Pending <Cached <Requests.WebBin.ServerRequest.Result> >(8,
                                                                                                  () => new Cached <Requests.WebBin.ServerRequest.Result>(old =>
            {
                var server = new Requests.WebBin.GetServerRequest(httpsettings).MakeRequestAsync().Result;
                Logger.Debug($"Download server changed to {server.Url}");
                return(server);
            },
                                                                                                                                                          value => TimeSpan.FromSeconds(DownloadServerExpiresSec)
                                                                                                                                                          ));

            WeblinkDownloadServersPending = new Pending <Cached <Requests.WebBin.ServerRequest.Result> >(8,
                                                                                                         () => new Cached <Requests.WebBin.ServerRequest.Result>(old =>
            {
                var server = new Requests.WebBin.WeblinkGetServerRequest(httpsettings).MakeRequestAsync().Result;
                Logger.Debug($"weblink Download server changed to {server.Url}");
                return(server);
            },
                                                                                                                                                                 value => TimeSpan.FromSeconds(DownloadServerExpiresSec)
                                                                                                                                                                 ));
        }
コード例 #14
0
 public WeblinkGetServerRequest(HttpCommonSettings settings) : base(settings)
 {
 }
コード例 #15
0
 public OAuthRefreshRequest(HttpCommonSettings settings, string refreshToken) : base(settings, null)
 {
     _refreshToken = refreshToken;
 }
コード例 #16
0
 public RenameRequest(HttpCommonSettings settings, IAuth auth, string fullPath, string newName)
     : base(settings, auth)
 {
     _fullPath = fullPath;
     _newName  = newName;
 }
コード例 #17
0
 public UnpublishRequest(HttpCommonSettings settings, IAuth auth, string publicLink)
     : base(settings, auth)
 {
     _publicLink = publicLink;
 }
コード例 #18
0
 public RemoveRequest(HttpCommonSettings settings, IAuth auth, string fullPath)
     : base(settings, auth)
 {
     _fullPath = fullPath;
 }
コード例 #19
0
 public YadDownloadRequest(HttpCommonSettings settings, IAuth authent, string url, long instart, long inend)
 {
     Request = CreateRequest(authent, settings.Proxy, url, instart, inend, settings.UserAgent);
 }
コード例 #20
0
 public SharedFoldersListRequest(HttpCommonSettings settings, IAuth auth, string metaServer) : base(settings, auth, metaServer)
 {
 }
コード例 #21
0
 public MoveRequest(HttpCommonSettings settings, IAuth auth, string metaServer, string fromPath, string toPath)
     : base(settings, auth, metaServer)
 {
     _fromPath = fromPath;
     _toPath   = toPath;
 }
コード例 #22
0
 public AccountInfoRequest(HttpCommonSettings settings, IAuth auth) : base(settings, auth)
 {
 }
コード例 #23
0
 public SecondStepAuthRequest(HttpCommonSettings settings, string csrf, string authCode) : base(settings, null)
 {
     _csrf     = csrf;
     _authCode = authCode;
 }
コード例 #24
0
 protected BaseRequestMobile(HttpCommonSettings settings, IAuth auth, string metaServer) : base(settings, auth)
 {
     _metaServer = metaServer;
 }
コード例 #25
0
 public UploadRequest(string shardUrl, File file, IAuth authent, HttpCommonSettings settings)
 {
     Request = CreateRequest(shardUrl, authent, settings.Proxy, file, settings.UserAgent);
 }
コード例 #26
0
 public OAuthSecondStepRequest(HttpCommonSettings settings, string login, string tsaToken, string authCode) : base(settings, null)
 {
     _login    = login;
     _tsaToken = tsaToken;
     _authCode = authCode;
 }
コード例 #27
0
 public MobAddFileRequest(HttpCommonSettings settings, IAuth auth, string metaServer, string fullPath, string hash, long size, DateTime?dateTime, ConflictResolver?conflict)
     : this(settings, auth, metaServer, fullPath, hash?.HexStringToByteArray(), size, dateTime, conflict)
 {
 }
コード例 #28
0
 public CloneItemRequest(HttpCommonSettings settings, IAuth auth, string fromUrl, string toPath)
     : base(settings, auth)
 {
     _fromUrl = fromUrl;
     _toPath  = toPath;
 }
コード例 #29
0
 public DownloadRequest(File file, long instart, long inend, IAuth authent, HttpCommonSettings settings, Cached <Dictionary <ShardType, ShardInfo> > shards)
 {
     Request = CreateRequest(authent, settings.Proxy, file, instart, inend, settings.UserAgent, shards);
 }
コード例 #30
0
 public ListRequest(HttpCommonSettings settings, IAuth auth, string metaServer, string fullPath, int depth)
     : base(settings, auth, metaServer)
 {
     _fullPath = fullPath;
     Depth     = depth;
 }