#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.RecipeFramework;
using EnvDTE; 
#endregion

namespace Microsoft.Practices.RecipeFramework.Extensions.Actions.VisualStudio
{
    /// <summary>
    /// Action that runs a web project
    /// </summary>
    public class RunWebProjectAction : ConfigurableAction
    {
        #region Input Properties
        private string startPage;

        /// <summary>
        /// Gets or sets the start page.
        /// </summary>
        /// <value>The start page.</value>
        [Input(Required = true)]
        public string StartPage
        {
            get { return startPage; }
            set { startPage = value; }
        }
        private Project project;

        /// <summary>
        /// Gets or sets the project.
        /// </summary>
        /// <value>The project.</value>
        [Input(Required = true)]
        public Project Project
        {
            get { return project; }
            set { project = value; }
        }
        #endregion

        #region ConfigurableAction Implementation
        /// <summary>
        /// See <see cref="M:Microsoft.Practices.RecipeFramework.IAction.Execute"/>.
        /// </summary>
        public override void Execute()
        {
            DTE vs = (DTE)GetService(typeof(DTE));
            if(!String.IsNullOrEmpty(this.startPage))
            {
                this.project.Properties.Item("StartAction").Value = 1; //Specific Page
                this.project.Properties.Item("StartPage").Value = this.startPage;
                this.project.Save(this.project.Name);
            }

            //This assumes that the project to debug is selected
            vs.ExecuteCommand("Project.SetasStartUpProject", "");

            this.project.DTE.Solution.SolutionBuild.Run();
        }

        /// <summary>
        /// See <see cref="M:Microsoft.Practices.RecipeFramework.IAction.Undo"/>.
        /// </summary>
        public override void Undo()
        {
            //Not Implemented
        }
        #endregion
    }
}
