//===============================================================================
// Microsoft patterns & practices
// Web Service Software Factory
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.RecipeFramework;
using EnvDTE;
using Microsoft.Practices.RecipeFramework.Library;
using Microsoft.Practices.RecipeFramework.Extensions.CommonHelpers;

namespace Howest.Guidance.DataAccess.Actions.VisualStudio
{
    /// <summary/>
    public class AddFolderAction : ConfigurableAction
    {
        #region Input Properties

        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; }
        }

        private string folderName;

        /// <summary>
        /// Gets or sets the name of the folder.
        /// </summary>
        /// <value>The name of the folder.</value>
        [Input(Required = true)]
        public string FolderName
        {
            get { return folderName; }
            set { folderName = value; }
        }

        #endregion

        #region Output Properties

        private ProjectItem folder;

        /// <summary>
        /// Gets or sets the folder.
        /// </summary>
        /// <value>The folder.</value>
        [Output]
        public ProjectItem Folder
        {
            get { return folder; }
            set { folder = value; }
        }
        #endregion

        #region ConfigurableAction Implementation

        /// <summary>
        /// Executes this instance.
        /// </summary>
        public override void Execute()
        {
            folder = DteHelperEx.FindItemByName(project.ProjectItems, folderName, true);
            
            if(folder == null)
            {
                folder = project.ProjectItems.AddFolder(folderName, "");
            }
        }

        /// <summary>
        /// Undoes this instance.
        /// </summary>
        public override void Undo()
        {
            //Not Implemented
        } 

        #endregion
    }
}
