using System;
using System.Collections.Generic;
using System.Text;
using TeamBuild.Properties;

namespace TeamBuild
{
	class Program
	{

		static void Main(string[] args)
		{
			string teamProject = string.Empty;
			string buildDirectory = string.Empty;
			string buildMachine = string.Empty;
			string teamBuildType = string.Empty;

      Uri serverUri = new Uri(Settings.Default.TeamBuild_BuildServer_BuildController);

			try
			{
				// Set build parameters
				BuildServer.BuildController bc = new BuildServer.BuildController();

				bc.Url = Settings.Default.TeamBuild_BuildServer_BuildController;
				bc.Credentials = System.Net.CredentialCache.DefaultCredentials;

				BuildServer.BuildParameters bp = new BuildServer.BuildParameters();

        bp.TeamFoundationServer = serverUri.Scheme + "://" + serverUri.Host + ":" + serverUri.Port + "/";
        bp.TeamProject = Settings.Default.TeamProject;
        bp.BuildType = Settings.Default.BuildType;
        
        bp.BuildDirectory = Settings.Default.BuildDirectory;
        bp.BuildMachine = serverUri.Host;

        // Execute build
				bc.StartBuild(bp);
			}

			catch (Exception ex)
			{
				Console.WriteLine(ex.ToString());
			}

		}

		private static string GetParameter(string arg)
		{
			try
			{
				return arg.Substring(arg.IndexOf(":") + 1);
			}
			catch
			{
				return string.Empty;
			}
		}

		private static bool FindParameter(string search, string find)
		{

			if (search.StartsWith(find, StringComparison.InvariantCultureIgnoreCase))
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		private static void DisplayHelp()
		{
			Console.WriteLine("");
			Console.WriteLine("Copyright (C) 2005 by Aaron Engel");
			Console.WriteLine("");
			Console.WriteLine("Usage : TeamBuild.exe [options]");
			Console.WriteLine("-TFSServer:<server>\t\t Team Foundation Server");
			Console.WriteLine("-PortfolioProject:<project>\t Team Project Name");
			Console.WriteLine("-BuildDirectory:<directory>\t Build directory on target");
			Console.WriteLine("-BuildMachine:<machine>\t\t Machine where item is to be built");
			Console.WriteLine("-BuildType:<buildtype>\t\t Name of the Build Type to be Executed");
			Console.WriteLine("-Port:<port> (Optional)\t\t Team System Port (8080 default)");
		}
	}
}

