Click here to Skip to main content
15,895,011 members
Articles / Programming Languages / XML

Sedge: An Automated Error Reporting Tool

Rate me:
Please Sign up or sign in to vote.
4.94/5 (11 votes)
14 Jan 2010Ms-PL5 min read 38.4K   923   53  
This article describes Sedge - a highly customizable tool designed to help your customers create better error reports.
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace Sedge.Core.FileSystemWrap
{
	class XmlFileSerializer : IXmlFileSerializer
	{
		public object Load(string path, Type type)
		{
			object result;
			try
			{
				using (FileStream fs = new FileStream(path, FileMode.Open))
				{
					XmlSerializer xs = new XmlSerializer(type);
					result = xs.Deserialize(fs);
				}
			}
			catch
			{
				result = null;
			}
			return result;
		}

		public bool Save<T>(string path, T obj)
		{
			bool result = true;
			try
			{
				using (FileStream fs = new FileStream(path, FileMode.Create))
				{
					XmlSerializer xs = new XmlSerializer(typeof(T));
					using (XmlTextWriter writer = new XmlTextWriter(fs, Encoding.Unicode))
					{
						writer.Formatting = Formatting.Indented;
						xs.Serialize(writer, obj);
					}
				}
			}
			catch
			{
				result = false;
			}

			return result;
		}
	}
}

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 Microsoft Public License (Ms-PL)


Written By
Canada Canada
I am a software developer from Toronto with 15 years of experience in software design and development. My major professional area is the development of highly customized software solutions, including desktop and web applications. Industrial process automation and hardware-related software development are among my favorite projects and I enjoyed developing several applications for semiconductor manufacturing companies.

My blog: http://LunarFrog.com/blog

Comments and Discussions