示例#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="seafWebConnection">The seaf web connection</param>
        /// <param name="serverUri">The server uri 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 <SeafSession> Establish(ISeafWebConnection seafWebConnection, Uri serverUri, string username, char[] pwd)
        {
            if (seafWebConnection == null)
            {
                throw new ArgumentNullException(nameof(seafWebConnection));
            }
            if (serverUri == null)
            {
                throw new ArgumentNullException(nameof(serverUri));
            }
            if (username == null)
            {
                throw new ArgumentNullException(nameof(username));
            }
            if (pwd == null)
            {
                throw new ArgumentNullException(nameof(pwd));
            }

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

            return(new SeafSession(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="seafWebConnection">The seaf web connection</param>
 /// <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 SeafSession(ISeafWebConnection 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 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 SeafSession FromToken(ISeafWebConnection seafWebConnection, Uri serverUri, string username, string authToken)
        {
            if (seafWebConnection == null)
            {
                throw new ArgumentNullException(nameof(seafWebConnection));
            }
            if (serverUri == null)
            {
                throw new ArgumentNullException(nameof(serverUri));
            }
            if (username == null)
            {
                throw new ArgumentNullException(nameof(username));
            }
            if (authToken == null)
            {
                throw new ArgumentNullException(nameof(authToken));
            }

            return(new SeafSession(seafWebConnection, username, serverUri, authToken));
        }
示例#4
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 <SeafSession> FromToken(ISeafWebConnection seafWebConnection, Uri serverUri, string authToken)
        {
            if (seafWebConnection == null)
            {
                throw new ArgumentNullException(nameof(seafWebConnection));
            }
            if (serverUri == null)
            {
                throw new ArgumentNullException(nameof(serverUri));
            }
            if (authToken == null)
            {
                throw new ArgumentNullException(nameof(authToken));
            }

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

            return(new SeafSession(seafWebConnection, accInfo.Email, 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">The seaf web connection</param>
        /// <param name="serverUri">The server uri to get the info</param>
        /// <returns></returns>
        public static async Task <SeafServerInfo> GetServerInfo(ISeafWebConnection seafWebConnection, Uri serverUri)
        {
            var request = new GetServerInfoRequest();

            return(await seafWebConnection.SendRequestAsync(serverUri, request));
        }
示例#6
0
        /// <summary>
        ///     Ping the server without authentication using the given ISeafWebConnection
        /// </summary>
        /// <param name="seafWebConnection">The seaf web connection</param>
        /// <param name="serverUri">The server uri to ping</param>
        /// <returns></returns>
        public static async Task <bool> Ping(ISeafWebConnection seafWebConnection, Uri serverUri)
        {
            var request = new PingRequest();

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