Example #1
0
        public void MenuItem3Callback(object sender, EventArgs e)
        {
            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);
            }
        }
        public void MenuItem3Callback(object sender, EventArgs e)
        {
            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);
        }
Example #3
0
        public void MenuItem1Callback(object sender, EventArgs e)
        {
            bool isUnit  = (_testType == "UNIT" || _testType == "NUNIT");
            bool isNunit = _testType == "NUNIT";

            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);
            }
        }
        public void MenuItem1Callback(object sender, EventArgs e)
        {
            bool isUnit = (_testType == "UNIT" || _testType == "NUNIT");
            bool isNunit = _testType == "NUNIT";

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