1
//-----------------------------------------------------------------------
2 // <copyright file="StoreResponse.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
5 //-----------------------------------------------------------------------
7 namespace DotNetOpenAuth
.OpenId
.Extensions
.AttributeExchange
{
9 using System
.Collections
.Generic
;
11 using System
.Globalization
;
12 using System
.Diagnostics
;
13 using DotNetOpenAuth
.Messaging
;
16 /// The Attribute Exchange Store message, response leg.
18 public sealed class StoreResponse
: ExtensionBase
{
20 /// The value of the mode parameter used to express a successful store operation.
22 private const string SuccessMode
= "store_response_success";
25 /// The value of the mode parameter used to express a store operation failure.
27 private const string FailureMode
= "store_response_failure";
30 /// Initializes a new instance of the <see cref="StoreResponse"/> class.
32 public StoreResponse()
33 : base(new Version(1, 0), Constants
.TypeUri
, null) {
37 /// Gets or sets a value indicating whether the storage request succeeded.
39 public bool Succeeded
{
40 get { return this.mode == SuccessMode; }
41 set { this.mode = value ? SuccessMode : FailureMode; }
45 /// Gets or sets the reason for the failure, if applicable.
47 [MessagePart("error", IsRequired
= false)]
48 public string FailureReason { get; set; }
51 /// Gets or sets the mode argument.
53 /// <value>One of 'store_response_success' or 'store_response_failure'.</value>
54 [MessagePart("mode", IsRequired
= true)]
55 private string mode { get; set; }
58 /// Checks the message state for conformity to the protocol specification
59 /// and throws an exception if the message is invalid.
62 /// <para>Some messages have required fields, or combinations of fields that must relate to each other
63 /// in specialized ways. After deserializing a message, this method checks the state of the
64 /// message to see if it conforms to the protocol.</para>
65 /// <para>Note that this property should <i>not</i> check signatures or perform any state checks
66 /// outside this scope of this particular message.</para>
68 /// <exception cref="ProtocolException">Thrown if the message is invalid.</exception>
69 protected override void EnsureValidMessage() {
70 base.EnsureValidMessage();
72 ErrorUtilities
.VerifyProtocol(
73 this.mode
== SuccessMode
|| this.mode
== FailureMode
,
74 MessagingStrings
.UnexpectedMessagePartValue
, "mode", this.mode
);