using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

namespace edu.jhu.Cas.Procrastinate {
    [RunInstaller(true)]
    public class ProcrasInstaller : System.Configuration.Install.Installer {

        private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
        private System.ServiceProcess.ServiceInstaller serviceInstaller1;
        private System.ComponentModel.Container components = null;

        public ProcrasInstaller() {
            InitializeComponent();
            components = components;//callete compiler
        }
        private void InitializeComponent() {
            this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
            this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
            this.serviceProcessInstaller1.Password = null;
            this.serviceProcessInstaller1.Username = null;

            //this.serviceInstaller1.ServiceName = "CasJobs Jobs";
            this.Installers.AddRange(new System.Configuration.Install.Installer[] {
																					  this.serviceProcessInstaller1,
																				  this.serviceInstaller1});
        }

        public override void Install(IDictionary stateSaver) {
            string name = "";
            while (name == "") {
                PrintIntro();
                name = Console.ReadLine();
                Console.WriteLine("Are you sure you want to call this installation '" + name + "'?");
                string tmp = Console.ReadLine().Trim();
                switch (tmp.ToLower()) {
                    case "yes":
                    case "y":
                        this.serviceInstaller1.ServiceName = name;
                        break;
                    default:
                        name = "";
                        break;
                }
            }
            base.Install(stateSaver);
        }
        
        public override void Uninstall(IDictionary savedState){
            Console.WriteLine(@"

Please enter the name of the CASJobs service you'd like to uninstall:
");
            this.serviceInstaller1.ServiceName = Console.ReadLine();
            base.Uninstall(savedState);
        }

        private void PrintIntro() {
            Console.WriteLine(@"
CASJobs Service Setup

This service consists of two parts:

The 'Jobs' portion of this service processes and executes 'long' 
queries for CASJobs.

The 'Output' portion of this service processes and executes table
extraction jobs, like CSV, FITS, etc.

Whether one portion or both is run is determined by the config file.
To run two portions, copy the executable to a file with a different name, 
and also give it a different name here.

Please enter a name by which you'd like to identify this service:

");

        }
    }
}

