//===============================================================================
// 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.
//===============================================================================

#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using System.Runtime.Serialization;
using EnvDTE80;
using Microsoft.Practices.RecipeFramework.Extensions.References.VisualStudio; 
#endregion

namespace Microsoft.Practices.SoftwareFactories.ServiceFactory.References
{
    /// <summary>
    /// UnBoundRecipeReference that allows to be executed only on a Vs Solution Folder
    /// </summary>
    [Serializable]
    public class SolutionFolderReference : CSharpLanguageReference
    {
        /// <summary>
        /// UnBoundRecipeReference that allows to be executed only on a Vs Solution Folder
        /// </summary>
        public SolutionFolderReference(string recipe)
            : base(recipe)
        {
        }

        /// <summary>
        /// Returns a friendly name as Any Solution Folder
        /// </summary>
        public override string AppliesTo
        {
            get { return Properties.Resources.SolutionFolderReference; }
        }

        /// <summary>
        /// Performs the validation of the item passed as target
        /// Returns true if the reference is allowed to be executed in the target
        /// that is if the target is a Solution Folder
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public override bool OnIsEnabledFor(object target)
        {
            Project project = target as Project;

            if(project != null)
            {
                SolutionFolder solutionFolder = project.Object as SolutionFolder;
                return solutionFolder != null;
            }
            else
            {
                return false;
            }
        }

        #region ISerializable Members

        /// <summary>
        /// Required constructor for deserialization.
        /// </summary>
        protected SolutionFolderReference(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        #endregion ISerializable Members
    }

}
