Added a half-port of the AX extension from DotNetOpenId.
[dotnetoauth.git] / src / DotNetOpenAuth / OpenId / Extensions / AttributeExchange / StoreResponse.cs
blob084b41d2356ded8041b64a1e87470a77775107ff
1 //-----------------------------------------------------------------------
2 // <copyright file="StoreResponse.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
4 // </copyright>
5 //-----------------------------------------------------------------------
7 namespace DotNetOpenAuth.OpenId.Extensions.AttributeExchange {
8 using System;
9 using System.Collections.Generic;
10 using System.Text;
11 using System.Globalization;
12 using System.Diagnostics;
13 using DotNetOpenAuth.Messaging;
15 /// <summary>
16 /// The Attribute Exchange Store message, response leg.
17 /// </summary>
18 public sealed class StoreResponse : ExtensionBase {
19 /// <summary>
20 /// The value of the mode parameter used to express a successful store operation.
21 /// </summary>
22 private const string SuccessMode = "store_response_success";
24 /// <summary>
25 /// The value of the mode parameter used to express a store operation failure.
26 /// </summary>
27 private const string FailureMode = "store_response_failure";
29 /// <summary>
30 /// Initializes a new instance of the <see cref="StoreResponse"/> class.
31 /// </summary>
32 public StoreResponse()
33 : base(new Version(1, 0), Constants.TypeUri, null) {
36 /// <summary>
37 /// Gets or sets a value indicating whether the storage request succeeded.
38 /// </summary>
39 public bool Succeeded {
40 get { return this.mode == SuccessMode; }
41 set { this.mode = value ? SuccessMode : FailureMode; }
44 /// <summary>
45 /// Gets or sets the reason for the failure, if applicable.
46 /// </summary>
47 [MessagePart("error", IsRequired = false)]
48 public string FailureReason { get; set; }
50 /// <summary>
51 /// Gets or sets the mode argument.
52 /// </summary>
53 /// <value>One of 'store_response_success' or 'store_response_failure'.</value>
54 [MessagePart("mode", IsRequired = true)]
55 private string mode { get; set; }
57 /// <summary>
58 /// Checks the message state for conformity to the protocol specification
59 /// and throws an exception if the message is invalid.
60 /// </summary>
61 /// <remarks>
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>
67 /// </remarks>
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);