Click here to Skip to main content
15,894,405 members
Articles / Programming Languages / C#

The Razor Framework :: Part 1 :: Plugins/Extensibility

Rate me:
Please Sign up or sign in to vote.
4.93/5 (127 votes)
11 Mar 2005CPOL36 min read 351.8K   1.4K   446  
An extensible dependency based plugin framework for .NET Applications.
using System;
using System.Collections;
using System.Diagnostics;
using System.Text;
using System.IO;

namespace Razor.Networking.Http
{
	/// <summary>
	/// Summary description for HttpChunkList.
	/// </summary>
	internal class HttpChunkList : CollectionBase
	{
		/// <summary>
		/// Initializes a new 
		/// </summary>
		public HttpChunkList()
		{
			
		}

		/// <summary>
		/// Adds a chunk to the list
		/// </summary>
		/// <param name="chunk"></param>
		public void Add(HttpChunk chunk)
		{
			base.InnerList.Add(chunk);
		}

		/// <summary>
		/// Adds an array of chunks to the list
		/// </summary>
		/// <param name="chunks"></param>
		public void AddRange(HttpChunk[] chunks)
		{
			foreach(HttpChunk chunk in chunks)
				this.Add(chunk);
		}

		/// <summary>
		/// Removes a chunk from the list
		/// </summary>
		/// <param name="chunk"></param>
		public void Remove(HttpChunk chunk)
		{

		}		

		/// <summary>
		/// Returns a chunk from the specified index in the list
		/// </summary>
		public HttpChunk this[int index]
		{
			get
			{
				return (HttpChunk)base.InnerList[index];
			}
		}

		/// <summary>
		/// Returns a byte array representation of the chunk list
		/// </summary>
		/// <returns></returns>
		public virtual byte[] ToByteArray()
		{
			byte[] buffer = null;

			// create a stream
			using (MemoryStream stream = new MemoryStream())
			{
				// create a writer
				using (BinaryWriter writer = new BinaryWriter(stream, HttpUtils.Encoding))
				{
					// write each chunk to the stream
					foreach(HttpChunk chunk in base.InnerList)
						writer.Write(chunk.ToByteArray());

					// retrieve the buffer from the stream
					buffer = stream.GetBuffer();

					// close the writer and the underlying stream
					writer.Close();
				}
			}

			return buffer;
		}

		/// <summary>
		/// Returns a string repsentation of the chunk list
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			StringBuilder sb = new StringBuilder();

			// append each chunk
			foreach(HttpChunk chunk in base.InnerList)
				sb.Append(chunk.ToString());
			
			return sb.ToString();
		}

	}
}

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)


Written By
Software Developer (Senior)
United States United States
Senior Application Developer specializing in Windows desktop and network development.

Professional Experience
- B.S. of Computer Science (Graduated 2001 - PSU)
- Senior Application Developer (8+ yrs)
- Microsoft Certified Professional

Primary Interests
- C#, C++, HTML, Javascript
- XML, ASP.NET, Web Services, SOAP, UDDI
- Socket programming and anything network related
- Reflection, Serialization, and Plugin Frameworks
- Owner-drawn controls and GDI+ goodness

Comments and Discussions