Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #100 from VasiliyZhushma/master
Browse files Browse the repository at this point in the history
Fix #86: Add Serialization Constructors for Exceptions
  • Loading branch information
davster authored Feb 27, 2018
2 parents c834cc8 + 1d5f5c3 commit d28aa81
Show file tree
Hide file tree
Showing 21 changed files with 496 additions and 170 deletions.
81 changes: 53 additions & 28 deletions Exceptions/AccountIsLockedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,60 @@
* DEALINGS IN THE SOFTWARE.
*/

namespace Microsoft.Exchange.WebServices.Data
namespace Microsoft.Exchange.WebServices.Data
{
using System;
using System;
using System.Runtime.Serialization;

/// <summary>
/// Represents an error that occurs when the account that is being accessed is locked and requires user interaction to be unlocked.
/// </summary>
[Serializable]
public class AccountIsLockedException : ServiceRemoteException
{
/// <summary>
/// Initializes a new instance of the <see cref="AccountIsLockedException"/> class.
/// </summary>
/// <param name="message">Error message text.</param>
/// <param name="accountUnlockUrl">URL for client to visit to unlock account.</param>
/// <param name="innerException">Inner exception.</param>
public AccountIsLockedException(string message, Uri accountUnlockUrl, Exception innerException)
: base(message, innerException)
{
this.AccountUnlockUrl = accountUnlockUrl;
}
/// <summary>
/// Represents an error that occurs when the account that is being accessed is locked and requires user interaction to be unlocked.
/// </summary>
[Serializable]
public class AccountIsLockedException : ServiceRemoteException
{
/// <summary>
/// Initializes a new instance of the <see cref="AccountIsLockedException"/> class.
/// </summary>
/// <param name="message">Error message text.</param>
/// <param name="accountUnlockUrl">URL for client to visit to unlock account.</param>
/// <param name="innerException">Inner exception.</param>
public AccountIsLockedException(string message, Uri accountUnlockUrl, Exception innerException)
: base(message, innerException)
{
this.AccountUnlockUrl = accountUnlockUrl;
}

/// <summary>
/// Gets the URL of a web page where the user can navigate to unlock his or her account.
/// </summary>
public Uri AccountUnlockUrl
{
get;
private set;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="T:Microsoft.Exchange.WebServices.Data.AccountIsLockedException"/> class with serialized data.
/// </summary>
/// <param name="info">The object that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
protected AccountIsLockedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
this.AccountUnlockUrl = (Uri)info.GetValue("AccountUnlockUrl", typeof(Uri));
}

/// <summary>Sets the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object with the parameter name and additional exception information.</summary>
/// <param name="info">The object that holds the serialized object data. </param>
/// <param name="context">The contextual information about the source or destination. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="info" /> object is a null reference (Nothing in Visual Basic). </exception>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
EwsUtilities.Assert(info != null, "AccountIsLockedException.GetObjectData", "info is null");

base.GetObjectData(info, context);

info.AddValue("AccountUnlockUrl", this.AccountUnlockUrl, typeof(Uri));
}

/// <summary>
/// Gets the URL of a web page where the user can navigate to unlock his or her account.
/// </summary>
public Uri AccountUnlockUrl
{
get;
private set;
}
}
}
17 changes: 13 additions & 4 deletions Exceptions/AutodiscoverLocalException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
namespace Microsoft.Exchange.WebServices.Data
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

/// <summary>
/// Represents an exception that is thrown when the Autodiscover service could not be contacted.
Expand Down Expand Up @@ -60,6 +59,16 @@ public AutodiscoverLocalException(string message)
public AutodiscoverLocalException(string message, Exception innerException)
: base(message, innerException)
{
}
}
}

/// <summary>
/// Initializes a new instance of the <see cref="T:Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException"/> class with serialized data.
/// </summary>
/// <param name="info">The object that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
protected AutodiscoverLocalException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
41 changes: 32 additions & 9 deletions Exceptions/AutodiscoverRemoteException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
namespace Microsoft.Exchange.WebServices.Autodiscover
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using Microsoft.Exchange.WebServices.Data;

/// <summary>
Expand All @@ -36,7 +35,7 @@ namespace Microsoft.Exchange.WebServices.Autodiscover
[Serializable]
public class AutodiscoverRemoteException : ServiceRemoteException
{
private AutodiscoverError error;
private readonly AutodiscoverError error;

/// <summary>
/// Initializes a new instance of the <see cref="AutodiscoverRemoteException"/> class.
Expand Down Expand Up @@ -72,13 +71,37 @@ public AutodiscoverRemoteException(
: base(message, innerException)
{
this.error = error;
}
}

/// <summary>
/// Gets the error.
/// </summary>
/// <value>The error.</value>
public AutodiscoverError Error
/// <summary>
/// Initializes a new instance of the <see cref="T:Microsoft.Exchange.WebServices.Data.AutodiscoverRemoteException"/> class with serialized data.
/// </summary>
/// <param name="info">The object that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
protected AutodiscoverRemoteException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
this.error = (AutodiscoverError)info.GetValue("Error", typeof(AutodiscoverError));
}

/// <summary>Sets the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object with the parameter name and additional exception information.</summary>
/// <param name="info">The object that holds the serialized object data. </param>
/// <param name="context">The contextual information about the source or destination. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="info" /> object is a null reference (Nothing in Visual Basic). </exception>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
EwsUtilities.Assert(info != null, "AutodiscoverRemoteException.GetObjectData", "info is null");

base.GetObjectData(info, context);

info.AddValue("Error", this.error, typeof(Uri));
}

/// <summary>
/// Gets the error.
/// </summary>
/// <value>The error.</value>
public AutodiscoverError Error
{
get { return this.error; }
}
Expand Down
39 changes: 31 additions & 8 deletions Exceptions/AutodiscoverResponseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
namespace Microsoft.Exchange.WebServices.Autodiscover
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using Microsoft.Exchange.WebServices.Data;

/// <summary>
Expand All @@ -39,7 +38,7 @@ public class AutodiscoverResponseException : ServiceRemoteException
/// <summary>
/// Error code when Autodiscover service operation failed remotely.
/// </summary>
private AutodiscoverErrorCode errorCode;
private readonly AutodiscoverErrorCode errorCode;

/// <summary>
/// Initializes a new instance of the <see cref="AutodiscoverResponseException"/> class.
Expand All @@ -50,12 +49,36 @@ internal AutodiscoverResponseException(AutodiscoverErrorCode errorCode, string m
: base(message)
{
this.errorCode = errorCode;
}
}

/// <summary>
/// Gets the ErrorCode for the exception.
/// </summary>
public AutodiscoverErrorCode ErrorCode
/// <summary>
/// Initializes a new instance of the <see cref="T:Microsoft.Exchange.WebServices.Data.AutodiscoverResponseException"/> class with serialized data.
/// </summary>
/// <param name="info">The object that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
protected AutodiscoverResponseException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
this.errorCode = (AutodiscoverErrorCode)info.GetInt32("ErrorCode");
}

/// <summary>Sets the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object with the parameter name and additional exception information.</summary>
/// <param name="info">The object that holds the serialized object data. </param>
/// <param name="context">The contextual information about the source or destination. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="info" /> object is a null reference (Nothing in Visual Basic). </exception>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
EwsUtilities.Assert(info != null, "AutodiscoverResponseException.GetObjectData", "info is null");

base.GetObjectData(info, context);

info.AddValue("ErrorCode", (int)this.errorCode);
}

/// <summary>
/// Gets the ErrorCode for the exception.
/// </summary>
public AutodiscoverErrorCode ErrorCode
{
get { return this.errorCode; }
}
Expand Down
39 changes: 31 additions & 8 deletions Exceptions/BatchServiceResponseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
namespace Microsoft.Exchange.WebServices.Data
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

/// <summary>
/// Represents a remote service exception that can have multiple service responses.
Expand All @@ -40,7 +39,7 @@ public abstract class BatchServiceResponseException<TResponse> : ServiceRemoteEx
/// <summary>
/// The list of responses returned by the web method.
/// </summary>
private ServiceResponseCollection<TResponse> responses;
private readonly ServiceResponseCollection<TResponse> responses;

/// <summary>
/// Initializes a new instance of MultiServiceResponseException.
Expand Down Expand Up @@ -78,12 +77,36 @@ internal BatchServiceResponseException(
"serviceResponses is null");

this.responses = serviceResponses;
}
}

/// <summary>
/// Gets a list of responses returned by the web method.
/// </summary>
public ServiceResponseCollection<TResponse> ServiceResponses
/// <summary>
/// Initializes a new instance of the <see cref="T:Microsoft.Exchange.WebServices.Data.BatchServiceResponseException"/> class with serialized data.
/// </summary>
/// <param name="info">The object that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
protected BatchServiceResponseException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
this.responses = (ServiceResponseCollection<TResponse>)info.GetValue("Responses", typeof(ServiceResponseCollection<TResponse>));
}

/// <summary>Sets the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object with the parameter name and additional exception information.</summary>
/// <param name="info">The object that holds the serialized object data. </param>
/// <param name="context">The contextual information about the source or destination. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="info" /> object is a null reference (Nothing in Visual Basic). </exception>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
EwsUtilities.Assert(info != null, "BatchServiceResponseException.GetObjectData", "info is null");

base.GetObjectData(info, context);

info.AddValue("Responses", this.responses, typeof(ServiceResponseCollection<TResponse>));
}

/// <summary>
/// Gets a list of responses returned by the web method.
/// </summary>
public ServiceResponseCollection<TResponse> ServiceResponses
{
get { return this.responses; }
}
Expand Down
17 changes: 13 additions & 4 deletions Exceptions/CreateAttachmentException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
namespace Microsoft.Exchange.WebServices.Data
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

/// <summary>
/// Represents an error that occurs when a call to the CreateAttachment web method fails.
Expand Down Expand Up @@ -59,6 +58,16 @@ internal CreateAttachmentException(
Exception innerException)
: base(serviceResponses, message, innerException)
{
}
}
}

/// <summary>
/// Initializes a new instance of the <see cref="T:Microsoft.Exchange.WebServices.Data.CreateAttachmentException"/> class with serialized data.
/// </summary>
/// <param name="info">The object that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
private CreateAttachmentException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
25 changes: 17 additions & 8 deletions Exceptions/DeleteAttachmentException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
namespace Microsoft.Exchange.WebServices.Data
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

/// <summary>
/// Represents an error that occurs when a call to the DeleteAttachment web method fails.
/// </summary>
[Serializable]
/// <summary>
/// Represents an error that occurs when a call to the DeleteAttachment web method fails.
/// </summary>
[Serializable]
public sealed class DeleteAttachmentException : BatchServiceResponseException<DeleteAttachmentResponse>
{
/// <summary>
Expand All @@ -59,6 +58,16 @@ internal DeleteAttachmentException(
Exception innerException)
: base(serviceResponses, message, innerException)
{
}
}
}

/// <summary>
/// Initializes a new instance of the <see cref="T:Microsoft.Exchange.WebServices.Data.DeleteAttachmentException"/> class with serialized data.
/// </summary>
/// <param name="info">The object that holds the serialized object data.</param>
/// <param name="context">The contextual information about the source or destination.</param>
private DeleteAttachmentException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Loading

0 comments on commit d28aa81

Please sign in to comment.