Пример #1
0
        /// <summary>
        /// Tries to connect to the given seafile server using the given ISeafWebConnection implementation and returns an appropriate session object on success
        /// </summary>
        /// <param name="serverUrl">The server url to connect to (including protocol (http or https) and port)</param>
        /// <param name="username">The username to login with</param>
        /// <param name="pwd">The password for the given user (will be overwritten with zeros as soon as the authentication request has been sent)</param>
        public static async Task <SeafileSession> Establish(ISeafileWebConnection seafWebConnection, Uri serverUri, string username, char[] pwd)
        {
            if (seafWebConnection == null)
            {
                throw new ArgumentNullException("seafWebConnection");
            }
            if (serverUri == null)
            {
                throw new ArgumentNullException("serverUri");
            }
            if (username == null)
            {
                throw new ArgumentNullException("username");
            }
            if (pwd == null)
            {
                throw new ArgumentNullException("pwd");
            }

            // authenticate the user
            AuthRequest req      = new AuthRequest(username, pwd);
            var         response = await seafWebConnection.SendRequestAsync(serverUri, req);

            return(new SeafileSession(seafWebConnection, username, serverUri, response.Token));
        }
Пример #2
0
 /// <summary>
 /// Wraps an already existing seafile session
 /// use SeafSession.Establish(...) to establish a new connection and retrieve an authentication token
 /// from the Seafile server
 /// </summary>
 /// <param name="username">The username of the account authToken belongs to</param>
 /// <param name="serverUri">The server url to connect to (including protocol (http or https) and port)</param>
 /// <param name="authToken">The authentication token as received from the Seafile server</param>
 private SeafileSession(ISeafileWebConnection seafWebConnection, string username, Uri serverUri, string authToken)
 {
     webConnection = seafWebConnection;
     Username      = username;
     ServerUri     = serverUri;
     AuthToken     = authToken;
 }
Пример #3
0
        /// <summary>
        /// Create a seafile session for the given authentication token
        /// Will automatically connect to the seafile server and check if the token is valid
        /// and retrieve the username for the given token using the given ISeafWebConnection
        /// </summary>
        public static async Task <SeafileSession> FromToken(ISeafileWebConnection seafWebConnection, Uri serverUri, string authToken)
        {
            if (seafWebConnection == null)
            {
                throw new ArgumentNullException("seafWebConnection");
            }
            if (serverUri == null)
            {
                throw new ArgumentNullException("serverUri");
            }
            if (authToken == null)
            {
                throw new ArgumentNullException("authToken");
            }

            // get the user for the token and check if the token is valid at the same time
            AccountInfoRequest infoReq = new AccountInfoRequest(authToken);
            var accInfo = await seafWebConnection.SendRequestAsync(serverUri, infoReq);

            return(new SeafileSession(seafWebConnection, accInfo.Email, serverUri, authToken));
        }
Пример #4
0
        /// <summary>
        /// Create a seafile session for the given username and authentication token using the given ISeafWebConnection
        /// The validity of the username or token are not checked
        /// (if they are wrong you may not be able to execute requests)
        /// </summary>
        public static SeafileSession FromToken(ISeafileWebConnection seafWebConnection, Uri serverUri, string username, string authToken)
        {
            if (seafWebConnection == null)
            {
                throw new ArgumentNullException("seafWebConnection");
            }
            if (serverUri == null)
            {
                throw new ArgumentNullException("serverUri");
            }
            if (username == null)
            {
                throw new ArgumentNullException("username");
            }
            if (authToken == null)
            {
                throw new ArgumentNullException("authToken");
            }

            return(new SeafileSession(seafWebConnection, username, serverUri, authToken));
        }
Пример #5
0
        /// <summary>
        /// Retrieve some general information about the Seafile server at the given address using
        /// the given ISeafWebConnection
        /// </summary>
        /// <param name="seafWebConnection"></param>
        /// <param name="serverUri"></param>
        /// <returns></returns>
        public static async Task <SeafServerInfo> GetServerInfo(ISeafileWebConnection seafWebConnection, Uri serverUri)
        {
            GetServerInfoRequest r = new GetServerInfoRequest();

            return(await seafWebConnection.SendRequestAsync(serverUri, r));
        }
Пример #6
0
        /// <summary>
        /// Ping the server without authentication using the given ISeafWebConnection
        /// </summary>
        /// <param name="serverUri"></param>
        /// <returns></returns>
        public static async Task <bool> Ping(ISeafileWebConnection seafWebConnection, Uri serverUri)
        {
            PingRequest r = new PingRequest();

            return(await seafWebConnection.SendRequestAsync(serverUri, r));
        }