Пример #1
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItem3Callback(object sender, EventArgs e)
        {
            var dte = GetGlobalService(typeof(DTE)) as DTE;

            if (dte == null)
            {
                return;
            }

            ProjectItem selectedProjectItem = dte.SelectedItems.Item(1).ProjectItem;
            Solution2   solution            = (Solution2)dte.Application.Solution;
            Project     project             = (Project)((Array)(dte.ActiveSolutionProjects)).GetValue(0);

            //Get the exsting file names so it won't get duplicated when creating a new item
            List <string> fileNames = new List <string>();

            string projectPath = (selectedProjectItem == null)
                ? Path.GetDirectoryName(project.FullName)
                : Path.GetDirectoryName(selectedProjectItem.FileNames[1]);

            if (projectPath != null)
            {
                foreach (string fullname in Directory.GetFiles(projectPath))
                {
                    string filename = Path.GetFileName(fullname);
                    if (!string.IsNullOrEmpty(filename) && filename.ToUpper().EndsWith(".JS"))
                    {
                        fileNames.Add(filename);
                    }
                }
            }

            //Display the form prompting for the file name
            ClassNamer namer     = new ClassNamer(_projectType, false, false, "JS", fileNames);
            bool?      fileNamed = namer.ShowDialog();

            if (!fileNamed.HasValue || !fileNamed.Value)
            {
                return;
            }
            string templateName = "JavaScript Web.csharp.zip";

            var item = solution.GetProjectItemTemplate(templateName, "CSharp");

            dte.StatusBar.Text = @"Adding file from template...";

            if (selectedProjectItem == null)
            {
                project.ProjectItems.AddFromTemplate(item, namer.FileName);
            }
            else
            {
                selectedProjectItem.ProjectItems.AddFromTemplate(item, namer.FileName);
            }
        }
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItem3Callback(object sender, EventArgs e)
        {
            var dte = GetGlobalService(typeof(DTE)) as DTE;
            if (dte == null) return;

            ProjectItem selectedProjectItem = dte.SelectedItems.Item(1).ProjectItem;
            Solution2 solution = (Solution2)dte.Application.Solution;
            Project project = (Project)((Array)(dte.ActiveSolutionProjects)).GetValue(0);

            //Get the exsting file names so it won't get duplicated when creating a new item
            List<string> fileNames = new List<string>();

            string projectPath = (selectedProjectItem == null)
                ? Path.GetDirectoryName(project.FullName)
                : Path.GetDirectoryName(selectedProjectItem.FileNames[1]);

            if (projectPath != null)
            {
                foreach (string fullname in Directory.GetFiles(projectPath))
                {
                    string filename = Path.GetFileName(fullname);
                    if (!string.IsNullOrEmpty(filename) && filename.ToUpper().EndsWith(".JS"))
                        fileNames.Add(filename);
                }
            }

            //Display the form prompting for the file name
            ClassNamer namer = new ClassNamer(_projectType, false, false, "JS", fileNames);
            bool? fileNamed = namer.ShowDialog();
            if (!fileNamed.HasValue || !fileNamed.Value) return;
            string templateName = "JavaScript Web.csharp.zip";

            var item = solution.GetProjectItemTemplate(templateName, "CSharp");
            dte.StatusBar.Text = @"Adding file from template...";

            if (selectedProjectItem == null)
                project.ProjectItems.AddFromTemplate(item, namer.FileName);
            else
                selectedProjectItem.ProjectItems.AddFromTemplate(item, namer.FileName);
        }
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItem1Callback(object sender, EventArgs e)
        {
            bool isUnit = (_testType == "UNIT" || _testType == "NUNIT");
            bool isNunit = _testType == "NUNIT";

            var dte = GetGlobalService(typeof(DTE)) as DTE;
            if (dte == null) return;

            ProjectItem selectedProjectItem = dte.SelectedItems.Item(1).ProjectItem;
            Solution2 solution = (Solution2)dte.Application.Solution;
            Project project = (Project)((Array)(dte.ActiveSolutionProjects)).GetValue(0);

            //Get the exsting class file names so it won't get duplicated when creating a new item
            List<string> fileNames = new List<string>();
            string projectPath = (selectedProjectItem == null)
                ? Path.GetDirectoryName(project.FullName)
                : Path.GetDirectoryName(selectedProjectItem.FileNames[1]);

            if (projectPath != null)
            {
                foreach (string fullname in Directory.GetFiles(projectPath))
                {
                    string filename = Path.GetFileName(fullname);
                    if (!string.IsNullOrEmpty(filename) && filename.ToUpper().EndsWith(".CS"))
                        fileNames.Add(filename);
                }
            }

            //Display the form prompting for the class file name and unit test type
            ClassNamer namer = new ClassNamer(_projectType, isUnit, isNunit, null, fileNames);
            bool? fileNamed = namer.ShowDialog();
            if (!fileNamed.HasValue || !fileNamed.Value) return;
            string testStyle = namer.TestType;
            string templateName = String.Empty;

            //Based on the results, load the proper template in the project
            if (_projectType == "PLUGIN")
            {
                if (!isUnit)
                    templateName = "Plugin Class.csharp.zip";
                else
                {
                    if (!isNunit)
                    {
                        switch (testStyle)
                        {
                            case "Unit":
                                templateName = "Plugin Unit Test.csharp.zip";
                                break;
                            case "Integration":
                                templateName = "Plugin Int Test.csharp.zip";
                                break;
                            default:
                                return;
                        }
                    }
                    else
                    {
                        switch (testStyle)
                        {
                            case "Unit":
                                templateName = "Plugin NUnit Test.csharp.zip";
                                break;
                            case "Integration":
                                templateName = "Plugin NUnit Int Test.csharp.zip";
                                break;
                            default:
                                return;
                        }
                    }
                }
            }

            if (_projectType == "WORKFLOW")
            {
                if (!isUnit)
                    templateName = "Workflow Class.csharp.zip";
                else
                {
                    if (!isNunit)
                    {
                        switch (testStyle)
                        {
                            case "Unit":
                                templateName = "Workflow Unit Test.csharp.zip";
                                break;
                            case "Integration":
                                templateName = "Workflow Int Test.csharp.zip";
                                break;
                            default:
                                return;
                        }
                    }
                    else
                    {
                        switch (testStyle)
                        {
                            case "Unit":
                                templateName = "Workflow NUnit Test.csharp.zip";
                                break;
                            case "Integration":
                                templateName = "Workflow NUnit Int Test.csharp.zip";
                                break;
                            default:
                                return;
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(templateName)) return;

            var item = solution.GetProjectItemTemplate(templateName, "CSharp");
            dte.StatusBar.Text = @"Adding class from template...";

            if (selectedProjectItem == null)
                project.ProjectItems.AddFromTemplate(item, namer.FileName);
            else
                selectedProjectItem.ProjectItems.AddFromTemplate(item, namer.FileName);
        }
Пример #4
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItem1Callback(object sender, EventArgs e)
        {
            bool isUnit  = (_testType == "UNIT" || _testType == "NUNIT");
            bool isNunit = _testType == "NUNIT";

            var dte = GetGlobalService(typeof(DTE)) as DTE;

            if (dte == null)
            {
                return;
            }

            ProjectItem selectedProjectItem = dte.SelectedItems.Item(1).ProjectItem;
            Solution2   solution            = (Solution2)dte.Application.Solution;
            Project     project             = (Project)((Array)(dte.ActiveSolutionProjects)).GetValue(0);

            //Get the exsting class file names so it won't get duplicated when creating a new item
            List <string> fileNames   = new List <string>();
            string        projectPath = (selectedProjectItem == null)
                ? Path.GetDirectoryName(project.FullName)
                : Path.GetDirectoryName(selectedProjectItem.FileNames[1]);

            if (projectPath != null)
            {
                foreach (string fullname in Directory.GetFiles(projectPath))
                {
                    string filename = Path.GetFileName(fullname);
                    if (!string.IsNullOrEmpty(filename) && filename.ToUpper().EndsWith(".CS"))
                    {
                        fileNames.Add(filename);
                    }
                }
            }

            //Display the form prompting for the class file name and unit test type
            ClassNamer namer     = new ClassNamer(_projectType, isUnit, isNunit, null, fileNames);
            bool?      fileNamed = namer.ShowDialog();

            if (!fileNamed.HasValue || !fileNamed.Value)
            {
                return;
            }
            string testStyle    = namer.TestType;
            string templateName = String.Empty;

            //Based on the results, load the proper template in the project
            if (_projectType == "PLUGIN")
            {
                if (!isUnit)
                {
                    templateName = "Plugin Class.csharp.zip";
                }
                else
                {
                    if (!isNunit)
                    {
                        switch (testStyle)
                        {
                        case "Unit":
                            templateName = "Plugin Unit Test.csharp.zip";
                            break;

                        case "Integration":
                            templateName = "Plugin Int Test.csharp.zip";
                            break;

                        default:
                            return;
                        }
                    }
                    else
                    {
                        switch (testStyle)
                        {
                        case "Unit":
                            templateName = "Plugin NUnit Test.csharp.zip";
                            break;

                        case "Integration":
                            templateName = "Plugin NUnit Int Test.csharp.zip";
                            break;

                        default:
                            return;
                        }
                    }
                }
            }

            if (_projectType == "WORKFLOW")
            {
                if (!isUnit)
                {
                    templateName = "Workflow Class.csharp.zip";
                }
                else
                {
                    if (!isNunit)
                    {
                        switch (testStyle)
                        {
                        case "Unit":
                            templateName = "Workflow Unit Test.csharp.zip";
                            break;

                        case "Integration":
                            templateName = "Workflow Int Test.csharp.zip";
                            break;

                        default:
                            return;
                        }
                    }
                    else
                    {
                        switch (testStyle)
                        {
                        case "Unit":
                            templateName = "Workflow NUnit Test.csharp.zip";
                            break;

                        case "Integration":
                            templateName = "Workflow NUnit Int Test.csharp.zip";
                            break;

                        default:
                            return;
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(templateName))
            {
                return;
            }

            var item = solution.GetProjectItemTemplate(templateName, "CSharp");

            dte.StatusBar.Text = @"Adding class from template...";

            if (selectedProjectItem == null)
            {
                project.ProjectItems.AddFromTemplate(item, namer.FileName);
            }
            else
            {
                selectedProjectItem.ProjectItems.AddFromTemplate(item, namer.FileName);
            }
        }