using System;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Reflection;

namespace PeteNelson.SmartClientWrapper
{
	public class MainApp : System.Windows.Forms.Form
	{
		[STAThread]
		static public void Main()
		{
			// Get our current path
			string exeDir = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
			string url = "http://localhost/SmartClient/";

			// Get assembly info from our web service
			localhost.WebService webService = new PeteNelson.SmartClientWrapper.localhost.WebService();
			webService.Url = url + "WebService.asmx";

			localhost.SmartClientDefinition clientDef = webService.GetSmartClientDefinition();

		
			// Download files
			WebClient client = new WebClient();

			for (int i = 0; i < clientDef.Dependencies.Length; i++)
			{
				client.DownloadFile(url + clientDef.Dependencies[i], exeDir + "\\" + clientDef.Dependencies[i]);
			}


			// Load the assembly
			Assembly assembly = Assembly.LoadFrom(clientDef.EntryPointFileName);

			// Run it
			Application.Run((System.Windows.Forms.Form)assembly.CreateInstance(clientDef.EntryPointInstance));

		}
	
	}
}