Skip to content

Commit 7848c89

Browse files
committed
Merge pull request #27 from sharwell/SerializableExceptions
Serializable exceptions
2 parents 42e1705 + dfc5c62 commit 7848c89

22 files changed

Lines changed: 253 additions & 52 deletions
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
2+
using System.Runtime.Serialization;
53

64
namespace net.openstack.Core.Exceptions
75
{
6+
[Serializable]
87
public class CDNNotEnabledException : Exception
98
{
109
public CDNNotEnabledException() { }
10+
1111
public CDNNotEnabledException(string message) : base(message) { }
12+
13+
protected CDNNotEnabledException(SerializationInfo info, StreamingContext context)
14+
: base(info, context)
15+
{
16+
}
1217
}
1318
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace net.openstack.Core.Exceptions
45
{
6+
[Serializable]
57
public class CidrFormatException : Exception
68
{
79
public CidrFormatException() { }
10+
811
public CidrFormatException(string message) : base(message) { }
12+
13+
protected CidrFormatException(SerializationInfo info, StreamingContext context)
14+
: base(info, context)
15+
{
16+
}
917
}
1018
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
2+
using System.Runtime.Serialization;
53

64
namespace net.openstack.Core.Exceptions
75
{
6+
[Serializable]
87
public class ContainerNameException : Exception
98
{
109
public ContainerNameException() { }
10+
1111
public ContainerNameException(string message) : base(message) { }
12+
13+
protected ContainerNameException(SerializationInfo info, StreamingContext context)
14+
: base(info, context)
15+
{
16+
}
1217
}
1318
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace net.openstack.Core.Exceptions
45
{
6+
[Serializable]
57
internal class InvalidCloudIdentityException : Exception
68
{
79
public InvalidCloudIdentityException(string message) : base(message) {}
10+
11+
protected InvalidCloudIdentityException(SerializationInfo info, StreamingContext context)
12+
: base(info, context)
13+
{
14+
}
815
}
9-
}
16+
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
using System;
2+
using System.Runtime.Serialization;
23

34
namespace net.openstack.Core.Exceptions
45
{
6+
[Serializable]
57
public class NoDefaultRegionSetException : Exception
68
{
79
public NoDefaultRegionSetException(string message) : base(message)
810
{
911
}
12+
13+
protected NoDefaultRegionSetException(SerializationInfo info, StreamingContext context)
14+
: base(info, context)
15+
{
16+
}
1017
}
11-
}
18+
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
2+
using System.Runtime.Serialization;
53

64
namespace net.openstack.Core.Exceptions
75
{
6+
[Serializable]
87
public class ObjectNameException : Exception
98
{
109
public ObjectNameException() { }
10+
1111
public ObjectNameException(string message) : base(message) { }
12+
13+
protected ObjectNameException(SerializationInfo info, StreamingContext context)
14+
: base(info, context)
15+
{
16+
}
1217
}
1318
}
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using RestResponse = JSIStudios.SimpleRESTServices.Client.Response;
4+
15
namespace net.openstack.Core.Exceptions.Response
26
{
7+
[Serializable]
38
public class BadServiceRequestException : ResponseException
49
{
5-
public BadServiceRequestException(JSIStudios.SimpleRESTServices.Client.Response response) : base("Unable to process the service request. Please try again later.", response) { }
10+
public BadServiceRequestException(RestResponse response) : base("Unable to process the service request. Please try again later.", response) { }
11+
12+
public BadServiceRequestException(string message, RestResponse response) : base(message, response) { }
613

7-
public BadServiceRequestException(string message, JSIStudios.SimpleRESTServices.Client.Response response) : base(message, response) { }
14+
protected BadServiceRequestException(SerializationInfo info, StreamingContext context)
15+
: base(info, context)
16+
{
17+
}
818
}
9-
}
19+
}
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using RestResponse = JSIStudios.SimpleRESTServices.Client.Response;
4+
15
namespace net.openstack.Core.Exceptions.Response
26
{
7+
[Serializable]
38
public class ItemNotFoundException : ResponseException
49
{
5-
public ItemNotFoundException(JSIStudios.SimpleRESTServices.Client.Response response) : base("The item was not found or does not exist.", response) { }
10+
public ItemNotFoundException(RestResponse response) : base("The item was not found or does not exist.", response) { }
11+
12+
public ItemNotFoundException(string message, RestResponse response) : base(message, response) { }
613

7-
public ItemNotFoundException(string message, JSIStudios.SimpleRESTServices.Client.Response response) : base(message, response) { }
14+
protected ItemNotFoundException(SerializationInfo info, StreamingContext context)
15+
: base(info, context)
16+
{
17+
}
818
}
9-
}
19+
}
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
2+
using System.Runtime.Serialization;
3+
using RestResponse = JSIStudios.SimpleRESTServices.Client.Response;
54

65
namespace net.openstack.Core.Exceptions.Response
76
{
8-
class MethodNotImplementedException : ResponseException
7+
[Serializable]
8+
public class MethodNotImplementedException : ResponseException
99
{
10-
public MethodNotImplementedException(JSIStudios.SimpleRESTServices.Client.Response response) : base("The requested method is not implemented at the service.", response) { }
10+
public MethodNotImplementedException(RestResponse response) : base("The requested method is not implemented at the service.", response) { }
1111

12-
public MethodNotImplementedException(string message, JSIStudios.SimpleRESTServices.Client.Response response) : base(message, response) { }
12+
public MethodNotImplementedException(string message, RestResponse response) : base(message, response) { }
13+
14+
protected MethodNotImplementedException(SerializationInfo info, StreamingContext context)
15+
: base(info, context)
16+
{
17+
}
1318
}
1419
}

src/corelib/Core/Exceptions/Response/ResponseException.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
using System;
2-
using System.Net;
32
using System.Runtime.Serialization;
4-
using JSIStudios.SimpleRESTServices.Client.Json;
3+
using System.Security;
54
using Newtonsoft.Json;
5+
using RestResponse = JSIStudios.SimpleRESTServices.Client.Response;
66

77
namespace net.openstack.Core.Exceptions.Response
88
{
99
[Serializable]
1010
public class ResponseException : Exception
1111
{
12-
public JSIStudios.SimpleRESTServices.Client.Response Response { get; private set; }
13-
public ResponseException(string message, JSIStudios.SimpleRESTServices.Client.Response response)
12+
public RestResponse Response { get; private set; }
13+
14+
public ResponseException(string message, RestResponse response)
1415
: base(message)
1516
{
1617
Response = response;
@@ -89,6 +90,7 @@ public string Details
8990
}
9091
}
9192

93+
[SecurityCritical]
9294
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
9395
{
9496
throw new NotImplementedException();
@@ -107,5 +109,21 @@ private sealed class ErrorDetails
107109
[DataMember(Name = "details")]
108110
public string Details;
109111
}
112+
113+
protected ResponseException(SerializationInfo info, StreamingContext context)
114+
: base(info, context)
115+
{
116+
Response = (RestResponse)info.GetValue("Response", typeof(RestResponse));
117+
}
118+
119+
[SecurityCritical]
120+
public override void GetObjectData(SerializationInfo info, StreamingContext context)
121+
{
122+
if (info == null)
123+
throw new ArgumentNullException("info");
124+
125+
base.GetObjectData(info, context);
126+
info.AddValue("Response", Response);
127+
}
110128
}
111-
}
129+
}

0 commit comments

Comments
 (0)