//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOAuth.Messages {
using System;
using System.Collections.Generic;
using DotNetOAuth.ChannelElements;
using DotNetOAuth.Messaging;
using DotNetOAuth.Messaging.Bindings;
///
/// A base class for all OAuth messages.
///
internal abstract class MessageBase : IDirectedProtocolMessage {
///
/// A store for extra name/value data pairs that are attached to this message.
///
private Dictionary extraData = new Dictionary();
///
/// Gets a value indicating whether signing this message is required.
///
private MessageProtection protectionRequired;
///
/// Gets a value indicating whether this is a direct or indirect message.
///
private MessageTransport transport;
///
/// The URI to the remote endpoint to send this message to.
///
private Uri recipient;
///
/// Initializes a new instance of the class.
///
/// The level of protection the message requires.
/// A value indicating whether this message requires a direct or indirect transport.
protected MessageBase(MessageProtection protectionRequired, MessageTransport transport) {
this.protectionRequired = protectionRequired;
this.transport = transport;
}
///
/// Initializes a new instance of the class.
///
/// The level of protection the message requires.
/// A value indicating whether this message requires a direct or indirect transport.
/// The URI that a directed message will be delivered to.
protected MessageBase(MessageProtection protectionRequired, MessageTransport transport, Uri recipient) {
if (recipient == null) {
throw new ArgumentNullException("recipient");
}
this.protectionRequired = protectionRequired;
this.transport = transport;
this.recipient = recipient;
}
#region IProtocolMessage Properties
///
/// Gets the version of the protocol this message is prepared to implement.
///
Version IProtocolMessage.ProtocolVersion {
get { return new Version(1, 0); }
}
///
/// Gets the level of protection this message requires.
///
MessageProtection IProtocolMessage.RequiredProtection {
get { return this.protectionRequired; }
}
///
/// Gets a value indicating whether this is a direct or indirect message.
///
MessageTransport IProtocolMessage.Transport {
get { return this.transport; }
}
///
/// Gets the dictionary of additional name/value fields tacked on to this message.
///
IDictionary IProtocolMessage.ExtraData {
get { return this.extraData; }
}
#endregion
#region IDirectedProtocolMessage Members
///
/// Gets the URI to the Service Provider endpoint to send this message to.
///
Uri IDirectedProtocolMessage.Recipient {
get { return this.recipient; }
}
#endregion
#region IProtocolMessage Methods
///
/// Checks the message state for conformity to the protocol specification
/// and throws an exception if the message is invalid.
///
void IProtocolMessage.EnsureValidMessage() {
this.EnsureValidMessage();
}
#endregion
///
/// Checks the message state for conformity to the protocol specification
/// and throws an exception if the message is invalid.
///
protected virtual void EnsureValidMessage() { }
}
}