Browse Source

ConnectionInfo.cs - Added 1 exception documentation.
PrivateKeyFile.cs - Added 4 exception documentation, and added parameter checks for null to DecryptKey.
SftpFile.cs - Added 1 exception documentation.
SftpFileStream.cs - Added 3 exception documentation.
SftpClient.cs - Added 8 exception documentation, and added a an attribute to SetLastAccessTime, SetLastAccessTimeUtc, SetLastWriteTime, SetLastWriteTimeUtc to give warning about not being implemented.
Shell.cs - Added 2 exception documentation.
SshCommand.cs - Added 3 exception documentation, and added 2 notes in BeginExecute as to how to better explain the exception, and question what happens if callback is null.

Kenneth_aa_cp 14 years ago
parent
commit
eb8a5086ad

+ 1 - 0
Renci.SshClient/Renci.SshNet/ConnectionInfo.cs

@@ -251,6 +251,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="session">The session to be authenticated.</param>
         /// <returns>true if authenticated; otherwise false.</returns>
+        /// <exception cref="ArgumentNullException"><paramref name="session"/> is null.</exception>
         public bool Authenticate(Session session)
         {
             if (session == null)

+ 12 - 0
Renci.SshClient/Renci.SshNet/PrivateKeyFile.cs

@@ -77,6 +77,8 @@ namespace Renci.SshNet
         /// Initializes a new instance of the <see cref="PrivateKeyFile"/> class.
         /// </summary>
         /// <param name="fileName">Name of the file.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="fileName"/> is null or empty.</exception>
+        /// <remarks>This method calls <see cref="System.IO.File.Open(string, System.IO.FileMode)"/> internally, this method does not catch exceptions from <see cref="System.IO.File.Open(string, System.IO.FileMode)"/>.</remarks>
         public PrivateKeyFile(string fileName)
         {
             if (string.IsNullOrEmpty(fileName))
@@ -93,6 +95,8 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="fileName">Name of the file.</param>
         /// <param name="passPhrase">The pass phrase.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="fileName"/> is null or empty, or <paramref name="passPhrase"/> is null.</exception>
+        /// <remarks>This method calls <see cref="System.IO.File.Open(string, System.IO.FileMode)"/> internally, this method does not catch exceptions from <see cref="System.IO.File.Open(string, System.IO.FileMode)"/>.</remarks>
         public PrivateKeyFile(string fileName, string passPhrase)
         {
             if (string.IsNullOrEmpty(fileName))
@@ -109,6 +113,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="privateKey">The private key.</param>
         /// <param name="passPhrase">The pass phrase.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="privateKey"/> or <paramref name="passPhrase"/> is null.</exception>
         public PrivateKeyFile(Stream privateKey, string passPhrase)
         {
             this.Open(privateKey, passPhrase);
@@ -214,8 +219,15 @@ namespace Renci.SshNet
         /// <param name="passPhrase">Decryption pass phrase.</param>
         /// <param name="binarySalt">Decryption binary salt.</param>
         /// <returns></returns>
+        /// <exception cref="ArgumentNullException"><paramref name="cipherInfo"/>, <paramref name="cipherData"/>, <paramref name="passPhrase"/> or <paramref name="binarySalt"/> is null.</exception>
         public static IEnumerable<byte> DecryptKey(CipherInfo cipherInfo, byte[] cipherData, string passPhrase, byte[] binarySalt)
         {
+            if (cipherInfo == null)
+                throw new ArgumentNullException("cipherInfo");
+            
+            if (cipherData == null)
+                throw new ArgumentNullException("cipherData");
+
             List<byte> cipherKey = new List<byte>();
 
             using (var md5 = new MD5Hash())

+ 1 - 0
Renci.SshClient/Renci.SshNet/Sftp/SftpFile.cs

@@ -24,6 +24,7 @@ namespace Renci.SshNet.Sftp
         /// <param name="sftpSession">The SFTP session.</param>
         /// <param name="fullName">Full path of the directory or file.</param>
         /// <param name="attributes">Attributes of the directory or file.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="sftpSession"/> or <paramref name="fullName"/> is null.</exception>
         internal SftpFile(SftpSession sftpSession, string fullName, SftpFileAttributes attributes)
         {
             if (attributes == null)

+ 3 - 0
Renci.SshClient/Renci.SshNet/Sftp/SftpFileStream.cs

@@ -457,6 +457,7 @@ namespace Renci.SshNet.Sftp
         /// Clears all buffers for this stream and causes any buffered data to be written to the file.
         /// </summary>
         /// <exception cref="T:System.IO.IOException">An I/O error occurs. </exception>
+        /// <exception cref="ObjectDisposedException">Stream is closed.</exception>
         public override void Flush()
         {
             lock (this._lock)
@@ -591,6 +592,7 @@ namespace Renci.SshNet.Sftp
         /// <exception cref="T:System.NotSupportedException">The stream does not support reading. </exception>
         ///   
         /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
+        /// <exception cref="System.IO.IOException">Read operation failed.</exception>
         public override int ReadByte()
         {
             // Lock down the file stream while we do this.
@@ -767,6 +769,7 @@ namespace Renci.SshNet.Sftp
         /// <exception cref="T:System.NotSupportedException">The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output. </exception>
         ///   
         /// <exception cref="T:System.ObjectDisposedException">Methods were called after the stream was closed. </exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="value"/> must be greater than zero.</exception>
         public override void SetLength(long value)
         {
             // Validate the parameters and setup the object for writing.

+ 11 - 0
Renci.SshClient/Renci.SshNet/SftpClient.cs

@@ -326,6 +326,7 @@ namespace Renci.SshNet
         /// <returns>
         /// List of files
         /// </returns>
+        /// <exception cref="ArgumentException">Either the IAsyncResult object (<paramref name="asyncResult"/>) did not come from the corresponding async method on this type, or EndExecute was called multiple times with the same IAsyncResult.</exception>
         public IEnumerable<SftpFile> EndListDirectory(IAsyncResult asyncResult)
         {
             var ar = asyncResult as SftpListDirectoryAsyncResult;
@@ -555,6 +556,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="path">The file to append the lines to. The file is created if it does not already exist.</param>
         /// <param name="contents">The lines to append to the file.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="path"/> or <paramref name="contents"/> is null.</exception>
         public void AppendAllLines(string path, IEnumerable<string> contents)
         {
             if (contents == null)
@@ -575,6 +577,7 @@ namespace Renci.SshNet
         /// <param name="path">The file to append the lines to. The file is created if it does not already exist.</param>
         /// <param name="contents">The lines to append to the file.</param>
         /// <param name="encoding">The character encoding to use.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="path"/>, <paramref name="contents"/> or <paramref name="encoding"/> is null.</exception>
         public void AppendAllLines(string path, IEnumerable<string> contents, Encoding encoding)
         {
             if (contents == null)
@@ -595,6 +598,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="path">The file to append the specified string to.</param>
         /// <param name="contents">The string to append to the file.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="path"/> or <paramref name="contents"/> is null.</exception>
         public void AppendAllText(string path, string contents)
         {
             using (var stream = this.AppendText(path))
@@ -610,6 +614,7 @@ namespace Renci.SshNet
         /// <param name="path">The file to append the specified string to.</param>
         /// <param name="contents">The string to append to the file.</param>
         /// <param name="encoding">The character encoding to use.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="path"/>, <paramref name="contents"/> or <paramref name="encoding"/> is null.</exception>
         public void AppendAllText(string path, string contents, Encoding encoding)
         {
             using (var stream = this.AppendText(path, encoding))
@@ -623,6 +628,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="path">The path to the file to append to.</param>
         /// <returns>A StreamWriter that appends UTF-8 encoded text to an existing file.</returns>
+        /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
         public StreamWriter AppendText(string path)
         {
             return this.AppendText(path, Encoding.UTF8);
@@ -636,6 +642,7 @@ namespace Renci.SshNet
         /// <returns>
         /// A StreamWriter that appends UTF-8 encoded text to an existing file.
         /// </returns>
+        /// <exception cref="ArgumentNullException"><paramref name="path"/> or <paramref name="encoding"/> is null.</exception>
         public StreamWriter AppendText(string path, Encoding encoding)
         {
             if (encoding == null)
@@ -893,6 +900,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="path">The file for which to set the access date and time information.</param>
         /// <param name="lastAccessTime">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of path. This value is expressed in local time.</param>
+        [Obsolete("Note: This method currently throws NotImplementedException because it has not yet been implemented.")]
         public void SetLastAccessTime(string path, DateTime lastAccessTime)
         {
             throw new NotImplementedException();
@@ -903,6 +911,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="path">The file for which to set the access date and time information.</param>
         /// <param name="lastAccessTimeUtc">A <see cref="System.DateTime"/> containing the value to set for the last access date and time of path. This value is expressed in UTC time.</param>
+        [Obsolete("Note: This method currently throws NotImplementedException because it has not yet been implemented.")]
         public void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)
         {
             throw new NotImplementedException();
@@ -913,6 +922,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="path">The file for which to set the date and time information.</param>
         /// <param name="lastWriteTime">A System.DateTime containing the value to set for the last write date and time of path. This value is expressed in local time.</param>
+        [Obsolete("Note: This method currently throws NotImplementedException because it has not yet been implemented.")]
         public void SetLastWriteTime(string path, DateTime lastWriteTime)
         {
             throw new NotImplementedException();
@@ -923,6 +933,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="path">The file for which to set the date and time information.</param>
         /// <param name="lastWriteTimeUtc">A System.DateTime containing the value to set for the last write date and time of path. This value is expressed in UTC time.</param>
+        [Obsolete("Note: This method currently throws NotImplementedException because it has not yet been implemented.")]
         public void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
         {
             throw new NotImplementedException();

+ 2 - 0
Renci.SshClient/Renci.SshNet/Shell.cs

@@ -108,6 +108,7 @@ namespace Renci.SshNet
         /// <summary>
         /// Starts this shell.
         /// </summary>
+        /// <exception cref="SshException">Shell is started.</exception>
         public void Start()
         {
             if (this.IsStarted)
@@ -186,6 +187,7 @@ namespace Renci.SshNet
         /// <summary>
         /// Stops this shell.
         /// </summary>
+        /// <exception cref="SshException">Shell is not started.</exception>
         public void Stop()
         {
             if (!this.IsStarted)

+ 8 - 2
Renci.SshClient/Renci.SshNet/SshCommand.cs

@@ -146,6 +146,9 @@ namespace Renci.SshNet
         /// <returns>An <see cref="System.IAsyncResult"/> that represents the asynchronous command execution, which could still be pending.</returns>
         /// <exception cref="Renci.SshNet.Common.SshConnectionException">Client is not connected.</exception>
         /// <exception cref="Renci.SshNet.Common.SshOperationTimeoutException">Operation has timed out.</exception>
+        /// <exception cref="InvalidOperationException">Asynchronous operation is already in progress.</exception>
+        /// <exception cref="SshException">Invalid operation.</exception>
+        /// <exception cref="ArgumentException">CommandText property is empty.</exception>
         public IAsyncResult BeginExecute(AsyncCallback callback, object state)
         {
             //  Prevent from executing BeginExecute before calling EndExecute
@@ -163,7 +166,7 @@ namespace Renci.SshNet
             };
 
             
-
+            // TODO: kenneth_aa (2011-08-16) - Need better explanation for this, to make a good exception documentation.
             //  When command re-executed again, create a new channel
             if (this._channel != null)
             {
@@ -174,7 +177,7 @@ namespace Renci.SshNet
 
             if (string.IsNullOrEmpty(this.CommandText))
                 throw new ArgumentException("CommandText property is empty.");
-
+            // TODO: What happens if callback is null?
             this._callback = callback;
 
             this._channel.Open();
@@ -205,6 +208,7 @@ namespace Renci.SshNet
         /// </summary>
         /// <param name="asyncResult">The reference to the pending asynchronous request to finish.</param>
         /// <returns></returns>
+        /// <exception cref="ArgumentException">Either the IAsyncResult object did not come from the corresponding async method on this type, or EndExecute was called multiple times with the same IAsyncResult.</exception>
         public string EndExecute(IAsyncResult asyncResult)
         {
             if (this._asyncResult == asyncResult && this._asyncResult != null)
@@ -396,6 +400,8 @@ namespace Renci.SshNet
             }
         }
 
+        /// <exception cref="SshOperationTimeoutException">Command '{0}' has timed out.</exception>
+        /// <remarks>The actual command will be included in the exception message.</remarks>
         private void WaitHandle(WaitHandle waitHandle)
         {
             var waitHandles = new WaitHandle[]