using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Medivators.Listener;
using Medivators.Common.Logging;
using Medivators.SerialDevices;

namespace TestApp
{
	public partial class VirtualService : Form
	{
		private ListenerServiceHelper _service = new ListenerServiceHelper();
		private ILogProvider _pLog = null;
		private ILogProvider _sLog = null;
		private SerialDeviceCollection _devices = null;

		private enum ServiceState
		{
			Stopped,
			Started,
			Paused
		}

		public VirtualService()
		{
			InitializeComponent();
		}

		private void SetState(ServiceState State)
		{
			this.cmdContinue.Enabled = (State == ServiceState.Paused);
			this.cmdPause.Enabled	 = (State == ServiceState.Started);
			this.cmdShutdown.Enabled = (State == ServiceState.Started);
			this.cmdStart.Enabled	 = (State == ServiceState.Stopped);
			this.cmdStop.Enabled	 = (State == ServiceState.Started);
			this.lblState.Text		 = State.ToString();
		}

		private void VirtualService_Load(object sender, EventArgs e)
		{
			SetState(ServiceState.Stopped);
		}

		private void cmdStart_Click(object sender, EventArgs e)
		{
			_service.Start(ref _pLog, ref _sLog, ref _devices);
			SetState(ServiceState.Started);
		}

		private void cmdStop_Click(object sender, EventArgs e)
		{
			_service.Stop(ref _devices);
			SetState(ServiceState.Stopped);
		}

		private void cmdPause_Click(object sender, EventArgs e)
		{
			_service.Pause();
			SetState(ServiceState.Paused);
		}

		private void cmdContinue_Click(object sender, EventArgs e)
		{
			_service.Continue();
			SetState(ServiceState.Started);
		}

		private void cmdShutdown_Click(object sender, EventArgs e)
		{
			_service.Shutdown(ref _devices);
			SetState(ServiceState.Stopped);
		}
	}
}