Click here to Skip to main content
15,886,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.3K   923   53  
This article describes Sedge - a highly customizable tool designed to help your customers create better error reports.
using System;
using System.Collections.Generic;
using Sedge.Core.App;
using Sedge.Core.Configuration;
using Sedge.Core.Globalization;
using Sedge.Core.Utils;

namespace Sedge.Core.Execution
{
	public class ScheduleRunner
	{
		private readonly List<IStepController> _stepControllers = new List<IStepController>();
	    private readonly Suite _suite;

		public ScheduleRunner(Suite suite)
		{
		    _suite = suite;
		}

	    public void Run(bool silent)
		{
			PrepareSchedule();

			foreach (Step step in _suite.Steps)
			{
				IStepController controller = CreateStepController(step);
				controller.Initialize(_suite, step.Options);
				_stepControllers.Add(controller);
			}
			
			IMasterController masterController = CreateMasterController();
			masterController.Show(_suite, _stepControllers);
		}

		private void PrepareSchedule()
		{
			_suite.WorkingFolder = GetReportFolder();
			_suite.ImagesFolder = GetSubFolder(_suite.WorkingFolder, Branding.ReportImages);
			_suite.FilesFolder = GetSubFolder(_suite.WorkingFolder, Branding.ReportFiles);
			_suite.UserFilesFolder = GetSubFolder(_suite.WorkingFolder, Branding.ReportUserFiles);
			_suite.HtmlFilesFolder = GetSubFolder(_suite.WorkingFolder, Branding.ReportHtmlFiles);
		}

		protected T CreateUIController<T>(string assemblyName, string className) where T: class 
		{
			if (String.IsNullOrEmpty(assemblyName))
			{
				assemblyName = _suite.UISource;
			}

			assemblyName = ReturnFullPath(assemblyName);
			T result = TypeActivator.Activate<T>(assemblyName, className);
			
			if (result == null)
			{
				ErrorHandler.Error(Locale.Strings.ETypeNotFound, className);
			}

			return result;
		}

		private IStepController CreateStepController(Step step)
		{
			return CreateUIController<IStepController>(step.Assembly, String.Concat(step.Name, "Controller"));
		}

		private IMasterController CreateMasterController()
		{
			return CreateUIController<IMasterController>(String.Empty, "MasterController");
		}

        private static string ReturnFullPath(string testPath)
        {
            if (String.IsNullOrEmpty(testPath))
                testPath = ".";

            string path = Services.FileSystem.Path.GetFullPath(testPath);

            return path;
        }

        private static string GetReportFolder()
        {
            string pattern = String.Format("{0}\\Report{1}{2}{3}", Branding.AppName, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            string tmpPath = Services.FileSystem.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), pattern);
            string path = tmpPath + "_01";

            int i = 1;
            while (Services.FileSystem.Directory.Exists(path))
            {
                path = String.Format("{0}_{1:D2}", tmpPath, i);
                i++;
            }
            Services.FileSystem.Directory.CreateDirectory(path);

            return path;
        }

        private static string GetSubFolder(string folder, string subfolder)
        {
            string path = Services.FileSystem.Path.Combine(folder, subfolder);
            if (!Services.FileSystem.Directory.Exists(path))
            {
                Services.FileSystem.Directory.CreateDirectory(path);
            }

            return path;
        }

	}
}

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