WAProvideProjectFactoryAttribute.cs :  » Development » StyleCop » Microsoft » VisualStudio » Shell » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » StyleCop 
StyleCop » Microsoft » VisualStudio » Shell » WAProvideProjectFactoryAttribute.cs
//***************************************************************************
//
//    Copyright (c) Microsoft Corporation. All rights reserved.
//    This code is licensed under the Visual Studio SDK license terms.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//***************************************************************************

using System;
using System.IO;
using System.ComponentModel;
using System.Globalization;
using Microsoft.Win32;

namespace Microsoft.VisualStudio.Shell{
    /// <summary>
    /// This attribute can be used to register information about a project system that supports
    /// the WAP flavor/sub-type.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
    public class WAProvideProjectFactoryAttribute : RegistrationAttribute
    {
        private Type _factoryType;
        private string _displayProjectFileExtensions = null;
        private string _name;
        private string _displayName = null;
        private string _defaultProjectExtension = null;
        private string _possibleProjectExtensions = null;
        private string _projectTemplatesDirectory;
        private int _sortPriority = 100;
        private Guid _folderGuid = Guid.Empty;
        private string _languageVsTemplate;
        private string _templateGroupIDsVsTemplate;
        private string _templateIDsVsTemplate;
        private string _displayProjectTypeVsTemplate;
        private string _projectSubTypeVsTemplate;
        private bool _newProjectRequireNewFolderVsTemplate = false;
        private bool _showOnlySpecifiedTemplatesVsTemplate = false;

        public WAProvideProjectFactoryAttribute(Type factoryType, string name)
        {
            if (factoryType == null)
            {
                throw new ArgumentNullException("factoryType");
            }

            _factoryType = factoryType;
            _name = name;
        }

        public WAProvideProjectFactoryAttribute(Type factoryType, string name, string languageVsTemplate, bool showOnlySpecifiedTemplatesVsTemplate, string templateGroupIDsVsTemplate, string templateIDsVsTemplate)
        {
            if (factoryType == null)
            {
                throw new ArgumentNullException("factoryType");
            }

            _factoryType = factoryType;
            _name = name;
            _languageVsTemplate = languageVsTemplate;
            _templateGroupIDsVsTemplate = templateGroupIDsVsTemplate;
            _templateIDsVsTemplate = templateIDsVsTemplate;
            _showOnlySpecifiedTemplatesVsTemplate = showOnlySpecifiedTemplatesVsTemplate;
        }

        public string Name
        {
            get { return _name; }
        }

        public string DisplayName
        {
            get { return _displayName; }
        }

        public int SortPriority
        {
            get { return _sortPriority; }
            set { _sortPriority = value; }
        }

        public Type FactoryType
        {
            get
            {
                return _factoryType;
            }
        }

        public string DisplayProjectFileExtensions
        {
            get
            {
                return _displayProjectFileExtensions;
            }
        }

        public string DefaultProjectExtension
        {
            get
            {
                return _defaultProjectExtension;
            }
        }

        public string PossibleProjectExtensions
        {
            get
            {
                return _possibleProjectExtensions;
            }
        }

        public string ProjectTemplatesDirectory
        {
            get
            {
                return _projectTemplatesDirectory;
            }
        }

        public string FolderGuid
        {
            get { return _folderGuid.ToString("B"); }
            set { _folderGuid = new Guid(value); }
        }

        public string LanguageVsTemplate
        {
            get { return _languageVsTemplate; }
            set { _languageVsTemplate = value; }
        }

        public string DisplayProjectTypeVsTemplate
        {
            get { return _displayProjectTypeVsTemplate; }
            set { _displayProjectTypeVsTemplate = value; }
        }

        public string ProjectSubTypeVsTemplate
        {
            get { return _projectSubTypeVsTemplate; }
            set { _projectSubTypeVsTemplate = value; }
        }

        public bool NewProjectRequireNewFolderVsTemplate
        {
            get { return _newProjectRequireNewFolderVsTemplate; }
            set { _newProjectRequireNewFolderVsTemplate = value; }
        }

        public bool ShowOnlySpecifiedTemplatesVsTemplate
        {
            get { return _showOnlySpecifiedTemplatesVsTemplate; }
            set { _showOnlySpecifiedTemplatesVsTemplate = value; }
        }

        public string TemplateGroupIDsVsTemplate
        {
            get { return _templateGroupIDsVsTemplate; }
            set { _templateGroupIDsVsTemplate = value; }
        }

        public string TemplateIDsVsTemplate
        {
            get { return _templateIDsVsTemplate; }
            set { _templateIDsVsTemplate = value; }
        }

        private string ProjectRegKey
        {
            get { return string.Format(CultureInfo.InvariantCulture, "Projects\\{0}", FactoryType.GUID.ToString("B")); }
        }

        private string NewPrjTemplateRegKey(RegistrationContext context)
        {
            return string.Format(CultureInfo.InvariantCulture, "NewProjectTemplates\\TemplateDirs\\{0}\\/1", context.ComponentType.GUID.ToString("B"));
        }

        public override void Register(RegistrationContext context)
        {
            //context.Log.WriteLine(SR.GetString(SR.Reg_NotifyProjectFactory, FactoryType.Name));

            using (Key projectKey = context.CreateKey(ProjectRegKey))
            {
                projectKey.SetValue(string.Empty, Name);
                if (_displayName != null)
                    projectKey.SetValue("DisplayName", _displayName);
                if (_displayProjectFileExtensions != null)
                    projectKey.SetValue("DisplayProjectFileExtensions", _displayProjectFileExtensions);
                projectKey.SetValue("Package", context.ComponentType.GUID.ToString("B"));
                if (_defaultProjectExtension != null)
                    projectKey.SetValue("DefaultProjectExtension", _defaultProjectExtension);
                if (_possibleProjectExtensions != null)
                    projectKey.SetValue("PossibleProjectExtensions", _possibleProjectExtensions);
                if (_projectTemplatesDirectory != null)
                {
                    if (!System.IO.Path.IsPathRooted(_projectTemplatesDirectory))
                    {
                        // If path is not rooted, make it relative to package path
                        _projectTemplatesDirectory = System.IO.Path.Combine(context.ComponentPath, _projectTemplatesDirectory);
                    }
                    projectKey.SetValue("ProjectTemplatesDir", context.EscapePath(_projectTemplatesDirectory));
                }

                // VsTemplate Specific Keys
                //
                if (_languageVsTemplate != null)
                    projectKey.SetValue("Language(VsTemplate)", _languageVsTemplate);

                if (_showOnlySpecifiedTemplatesVsTemplate || _templateGroupIDsVsTemplate != null || _templateIDsVsTemplate != null)
                {
                    int showOnlySpecifiedTemplatesVsTemplate = _showOnlySpecifiedTemplatesVsTemplate ? 1 : 0;
                    projectKey.SetValue("ShowOnlySpecifiedTemplates(VsTemplate)", showOnlySpecifiedTemplatesVsTemplate);
                }

                if (_templateGroupIDsVsTemplate != null)
                    projectKey.SetValue("TemplateGroupIDs(VsTemplate)", _templateGroupIDsVsTemplate);

                if (_templateIDsVsTemplate != null)
                    projectKey.SetValue("TemplateIDs(VsTemplate)", _templateIDsVsTemplate);

                if (_displayProjectTypeVsTemplate != null)
                    projectKey.SetValue("DisplayProjectType(VsTemplate)", _displayProjectTypeVsTemplate);

                if (_projectSubTypeVsTemplate != null)
                    projectKey.SetValue("ProjectSubType(VsTemplate)", _projectSubTypeVsTemplate);

                if (_newProjectRequireNewFolderVsTemplate)
                    projectKey.SetValue("NewProjectRequireNewFolder(VsTemplate)", (int)1);
            }
        }

        public override void Unregister(RegistrationContext context)
        {
            context.RemoveKey(ProjectRegKey);
            context.RemoveKey(NewPrjTemplateRegKey(context));
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.