using System;
///!!!
using System.Text;
using System.IO;

namespace WS2Client
{
	/// <summary>
	/// Summary description for ServiceObject.
	/// </summary>
	public class ServiceObject
	{
		private string _path;
		private string _class;
		private IRun _client; 

		public ServiceObject(string a_path, string a_class)
		{
			_path = a_path;

			_class = a_class;
		}

		public override string ToString()
		{
			return _path;
		}

		public IRun CreateClientObject()
		{
			// TODO: predelat na reflexi
			_client = null;
            log(String.Concat("CreateClientObject._class=", _class));///!!!
            log(String.Concat("CreateClientObject._path=", _path));///!!!
            switch (_class)
			{
				case "DamasRun":
                    _client = new Damas.DamasRun();
					break;
//				case "ETraceRun":
//					_client = new ETrace.ETraceRun();
//					break;
				default:
					throw new Exception("Client class " + _class + " not implemented.");
			}

			return _client;
		}
		
		public IRun ClientObject
		{
			get
			{
				if (_client==null)
				{
					throw new Exception("IRun client object not created. Call CreateClientObject first.");
				}
				return _client;
			}
		}

        ///!!!
        private void log(string text)
        {
            TextWriter tw = new StreamWriter("log.txt", true);
            tw.WriteLine("[" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + "].ServiceObject: " + text);
            tw.Flush();
            tw.Close();
        }
    }
}
