//------------------------------------------------------------------------------
//
// Copyright (c) 2002-2006 CodeSmith Tools, LLC.  All rights reserved.
// 
// The terms of use for this software are contained in the file
// named sourcelicense.txt, which can be found in the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by the
// terms of this license.
// 
// You must not remove this notice, or any other, from this software.
//
//------------------------------------------------------------------------------

using System;
using System.Text;

namespace CodeSmith.BaseTemplates
{
	/// <summary>
	/// The result of a script execution including any errors that may have occured.
	/// </summary>
	public class ScriptResult
	{
		private bool _success = false;
		private ScriptErrorCollection _errors = null;
		
		public ScriptResult(bool success, ScriptErrorCollection errors)
		{
			_success = success;
			_errors = errors;
		}
		
		/// <summary>
		/// Whether the script was executed successfully or not.
		/// </summary>
		public bool Success
		{
			get {return _success;}
		}
		
		/// <summary>
		/// Any errors that occured as the result of executing the script.
		/// </summary>
		public ScriptErrorCollection Errors
		{
			get {return _errors;}
		}
		
		/// <summary>
		/// Returns a string containing the script execution results including errors.
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			if (this.Success)
			{
				return "Script executed successfully.";
			}
			else
			{
				StringBuilder builder = new StringBuilder();
				builder.Append("Script execution failed with the following errors:\r\n\r\n");
				
				for (int i = 0; i < this.Errors.Count; i++)
				{
					builder.Append(this.Errors[i].ToString());
					builder.Append("\r\n");
				}
				
				return builder.ToString();
			}
		}
	}
}
