We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- using System;
- using System.Collections;
- using System.Globalization;
- using System.Net;
- namespace System.Runtime.Remoting.Channels
- {
-
- [Serializable()]
- internal class BaseTransportHeaders : ITransportHeaders
- {
-
-
-
-
- internal const int WellknownHeaderCount = 4;
-
- private object _connectionId;
-
- private object _ipAddress;
-
- private string _requestUri;
-
- private string _contentType;
-
-
-
- private ITransportHeaders _otherHeaders;
-
-
- public BaseTransportHeaders()
- {
- _otherHeaders = null;
- }
-
-
- public string RequestUri {
- get { return _requestUri; }
- set { _requestUri = value; }
- }
-
-
- public string ContentType {
- get { return _contentType; }
- set { _contentType = value; }
- }
-
-
- public object ConnectionId {
- set { _connectionId = value; }
- }
-
- public IPAddress IPAddress {
- set { _ipAddress = value; }
- }
-
-
-
-
-
-
- public object this[object key]
- {
- get {
- string strKey = key as string;
- if (strKey != null) {
- int index = MapHeaderNameToIndex(strKey);
- if (index != -1)
- return GetValueFromHeaderIndex(index);
- }
-
- if (_otherHeaders != null)
- return _otherHeaders[key];
-
- return null;
- }
-
- set {
- bool bSet = false;
-
- string strKey = key as string;
- if (strKey != null) {
- int index = MapHeaderNameToIndex(strKey);
- if (index != -1) {
- SetValueFromHeaderIndex(index, value);
- bSet = true;
- }
- }
-
- if (!bSet) {
- if (_otherHeaders == null)
- _otherHeaders = new TransportHeaders();
- _otherHeaders[key] = value;
- }
- }
- }
-
-
-
- public IEnumerator GetEnumerator()
- {
- return new BaseTransportHeadersEnumerator(this);
- }
-
-
- internal IEnumerator GetOtherHeadersEnumerator()
- {
- if (_otherHeaders == null)
- return null;
-
- return _otherHeaders.GetEnumerator();
- }
-
-
-
- internal int MapHeaderNameToIndex(string headerName)
- {
-
-
-
-
-
- if (String.Compare(headerName, CommonTransportKeys.ConnectionId, StringComparison.OrdinalIgnoreCase) == 0)
- return 0;
- else if (String.Compare(headerName, CommonTransportKeys.IPAddress, StringComparison.OrdinalIgnoreCase) == 0)
- return 1;
- else if (String.Compare(headerName, CommonTransportKeys.RequestUri, StringComparison.OrdinalIgnoreCase) == 0)
- return 2;
- else if (String.Compare(headerName, "Content-Type", StringComparison.OrdinalIgnoreCase) == 0)
- return 3;
-
- return -1;
- }
-
-
- internal string MapHeaderIndexToName(int index)
- {
-
-
-
-
-
- switch (index) {
- case 0:
- return CommonTransportKeys.ConnectionId;
- case 1:
- return CommonTransportKeys.IPAddress;
- case 2:
- return CommonTransportKeys.RequestUri;
- case 3:
- return "Content-Type";
- default:
-
- return null;
- }
-
- }
-
-
- internal object GetValueFromHeaderIndex(int index)
- {
-
-
-
-
-
-
-
-
-
- switch (index) {
- case 0:
- return _connectionId;
- case 1:
- return _ipAddress;
- case 2:
- return _requestUri;
- case 3:
- return _contentType;
- default:
-
- return null;
- }
-
- }
-
-
- internal void SetValueFromHeaderIndex(int index, object value)
- {
-
-
-
-
-
-
-
-
-
- switch (index) {
- case 0:
- _connectionId = value;
- break;
- case 1:
- _ipAddress = value;
- break;
- case 2:
- _requestUri = (string)value;
- break;
- case 3:
- _contentType = (string)value;
- break;
- default:
-
-
- {
- InternalRemotingServices.RemotingAssert(false, "someone forgot to update this method");
- break;
- }
- break;
-
- }
-
- }
-
-
-
- }
-
-
-
- internal class BaseTransportHeadersEnumerator : IEnumerator
- {
- private BaseTransportHeaders _headers;
- private bool _bStarted;
- private int _currentIndex;
- private IEnumerator _otherHeadersEnumerator;
-
- public BaseTransportHeadersEnumerator(BaseTransportHeaders headers)
- {
- _headers = headers;
- Reset();
- }
-
-
- public bool MoveNext()
- {
- if (_currentIndex != -1) {
- if (_bStarted)
- _currentIndex++;
- else
- _bStarted = true;
-
- while (_currentIndex != -1) {
- if (_currentIndex >= BaseTransportHeaders.WellknownHeaderCount) {
- _otherHeadersEnumerator = _headers.GetOtherHeadersEnumerator();
- _currentIndex = -1;
- }
- else {
- if (_headers.GetValueFromHeaderIndex(_currentIndex) != null)
- return true;
-
- _currentIndex++;
- }
- }
- }
-
- if (_otherHeadersEnumerator != null) {
- if (!_otherHeadersEnumerator.MoveNext()) {
- _otherHeadersEnumerator = null;
- return false;
- }
- else
- return true;
- }
-
- return false;
- }
-
- public void Reset()
- {
- _bStarted = false;
- _currentIndex = 0;
- _otherHeadersEnumerator = null;
- }
-
- public object Current {
- get {
- if (!_bStarted)
- return null;
-
- if (_currentIndex != -1) {
- return new DictionaryEntry(_headers.MapHeaderIndexToName(_currentIndex), _headers.GetValueFromHeaderIndex(_currentIndex));
- }
-
- if (_otherHeadersEnumerator != null) {
- return _otherHeadersEnumerator.Current;
- }
-
- return null;
- }
- }
-
- }
-
-
-
-
- }