Click here to Skip to main content
11,496,146 members (1,637 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
Add your own
alternative version

STUN Client

, 20 Apr 2007 CPOL 141.8K 7.9K 65
STUN client C# implementation with sample application
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
Stun.zip
Stun
Net
docs
dns
dns_records.jpg
dns_records.vsd
Net
_junk
_Obsolete
_Stuff
AUTH
bin
Release
LumiSoft.Net.dll
Data
Dns
Client
FTP
Client
Server
HTTP
Server
ICMP
IMAP
Client
Server
IO
Log
LumiSoft.Net
Mime
vCard
Net.csproj.user
Net.suo
NNTP
Client
POP3
Client
Server
SDP
ServersCore
SIP
Client
Message
Proxy
Stack
SMTP
Client
Server
STUN
Client
Message
STUN_Client_app
STUN_Client_app.suo
STUN_Client_app
bin
Debug
LumiSoft.Net.dll
STUN_Client_app.exe
STUN_Client_app.vshost.exe
dep
LumiSoft.Net.dll
Properties
Settings.settings
using System;
using System.Collections;

namespace LumiSoft.Net.Mime
{
	/// <summary>
	/// Header field parameters collection.
	/// </summary>
	public class HeaderFieldParameterCollection : IEnumerable
	{
		private ParametizedHeaderField m_pHeaderField = null;

		/// <summary>
		/// Default constructor.
		/// </summary>
		/// <param name="headerField">Header field.</param>
		internal HeaderFieldParameterCollection(ParametizedHeaderField headerField)
		{
			m_pHeaderField = headerField;
		}

		#region method Add

		/// <summary>
		/// Adds a new header field parameter with specified name and value to the end of the collection.
		/// </summary>
		/// <param name="parameterName">Parameter name.</param>
		/// <param name="parameterValue">Parameter value.</param>
		public void Add(string parameterName,string parameterValue)
		{
			parameterName = parameterName.ToLower();

			Hashtable parameters = m_pHeaderField.ParseParameters();
			if(!parameters.ContainsKey(parameterName)){
				parameters.Add(parameterName,parameterValue);

				m_pHeaderField.StoreParameters(m_pHeaderField.Value,parameters);
			}
			else{
				throw new Exception("Header field '" + m_pHeaderField.Name + "' parameter '" + parameterName + "' already exists !");
			}
		}

		#endregion


		#region method Remove

		/// <summary>
		/// Removes specified header field parameter from the collection.
		/// </summary>
		/// <param name="parameterName">The name of the header field parameter to remove.</param>
		public void Remove(string parameterName)
		{
			parameterName = parameterName.ToLower();

			Hashtable parameters = m_pHeaderField.ParseParameters();
			if(!parameters.ContainsKey(parameterName)){
				parameters.Remove(parameterName);

				m_pHeaderField.StoreParameters(m_pHeaderField.Value,parameters);
			}
		}

		#endregion

		#region method Clear

		/// <summary>
		/// Clears the collection of all header field parameters.
		/// </summary>
		public void Clear()
		{
			Hashtable parameters = m_pHeaderField.ParseParameters();
			parameters.Clear();
			m_pHeaderField.StoreParameters(m_pHeaderField.Value,parameters);
		}

		#endregion


		#region method Contains

		/// <summary>
		/// Gets if collection contains specified parameter.
		/// </summary>
		/// <param name="parameterName">Parameter name.</param>
		/// <returns></returns>
		public bool Contains(string parameterName)
		{
			parameterName = parameterName.ToLower();

			Hashtable parameters = m_pHeaderField.ParseParameters();
			return parameters.ContainsKey(parameterName);
		}

		#endregion


		#region interface IEnumerator

		/// <summary>
		/// Gets enumerator.
		/// </summary>
		/// <returns></returns>
		public IEnumerator GetEnumerator()
		{
			Hashtable parameters = m_pHeaderField.ParseParameters();
			HeaderFieldParameter[] retVal = new HeaderFieldParameter[parameters.Count];
			int i = 0;
			foreach(DictionaryEntry entry in parameters){
				retVal[i] = new HeaderFieldParameter(entry.Key.ToString(),entry.Value.ToString());
				i++;
			}

			return retVal.GetEnumerator();
		}

		#endregion

		#region Properties Implementation

		/// <summary>
		/// Gets or sets specified parameter value.
		/// </summary>
		public string this[string parameterName]
		{
			get{ 
				parameterName = parameterName.ToLower();

				Hashtable parameters = m_pHeaderField.ParseParameters();
				if(!parameters.ContainsKey(parameterName)){
					throw new Exception("Specified parameter '" + parameterName + "' doesn't exist !");
				}
				else{
					return (string)parameters[parameterName];
				}
			}

			set{
				parameterName = parameterName.ToLower();

				Hashtable parameters = m_pHeaderField.ParseParameters();
				if(parameters.ContainsKey(parameterName)){
					parameters[parameterName] = value;

					m_pHeaderField.StoreParameters(m_pHeaderField.Value,parameters);
				}
			}
		}

		/// <summary>
		/// Gets header field parameters count in the collection.
		/// </summary>
		public int Count
		{
			get{ return m_pHeaderField.ParseParameters().Count; }
		}

		#endregion

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ivar Lumi

Estonia Estonia
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 20 Apr 2007
Article Copyright 2007 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid