Exemplo n.º 1
0
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            try
            {
                _dte = (DTE)automationObject;

                if (replacementsDictionary.ContainsKey("$destinationdirectory$"))
                {
                    _destDirectory = replacementsDictionary["$destinationdirectory$"];
                }

                if (replacementsDictionary.ContainsKey("$wizarddata$"))
                {
                    string wizardData = replacementsDictionary["$wizarddata$"];
                    ReadWizardData(wizardData);
                }

                //Find default SDK version
                var    props             = _dte.Properties["CRM Developer Extensions", "General"];
                string defaultSdkVersion = props.Item("DefaultCrmSdkVersion").Value;

                //TypeScript projects
                if (_crmProjectType == "TypeScript")
                {
                    Version version = Version.Parse(_dte.Version);
                    if (version.Major < 12)
                    {
                        throw new WizardBackoutException("TypeScript projects require Visual Studio 2013 or later");
                    }

                    TypeScriptPicker tsPicker = new TypeScriptPicker(defaultSdkVersion);
                    tsPicker.ShowDialog();

                    _sdkVersion = tsPicker.Version;

                    return;
                }

                //If UnitTest Item - load the assembly & class names from the referenced project into the picker
                if (_isUnitTestItem == "True")
                {
                    List <string> referencedProjects     = new List <string>();
                    Array         activeSolutionProjects = (Array)_dte.ActiveSolutionProjects;
                    if (activeSolutionProjects != null && activeSolutionProjects.Length > 0)
                    {
                        VSProject vsproject = ((Project)activeSolutionProjects.GetValue(0)).Object;
                        referencedProjects.AddRange(from Reference reference in vsproject.References
                                                    where reference.SourceProject != null
                                                    select reference.Name);

                        List <ComboBoxItem> classItems = GetSourceProjectItems(referencedProjects);
                        var testClassPickerform        = new TestClassPicker(classItems);
                        testClassPickerform.ShowDialog();

                        replacementsDictionary.Add("$fullclassname$", testClassPickerform.FullClassname);
                        replacementsDictionary.Add("$assemblyname$", testClassPickerform.AssemblyName);
                    }

                    return;
                }

                //If UnitTest Project - load the projects into the picker
                List <ComboBoxItem> projectItems = new List <ComboBoxItem>();
                if (_isUnitTest == "True")
                {
                    projectItems = GetSourceProjects();
                }

                //Display the form prompting for the SDK version and/or project to unit test against
                if (_crmProjectType == "Plug-in" || _crmProjectType == "Workflow")
                {
                    var form = new SdkProjectPicker((_isUnitTest == "True"), projectItems, defaultSdkVersion);
                    form.ShowDialog();

                    _sdkVersion = form.Version;
                    _project    = form.Project;
                    _isNunit    = form.Nunit;
                }

                //If UnitTest Project - set the reference to the project being tested
                if (_isUnitTest == "True")
                {
                    if (string.IsNullOrEmpty(_project))
                    {
                        replacementsDictionary.Add("$referenceproject$", "False");
                        return;
                    }

                    Projects projects = _dte.Solution.Projects;
                    Solution solution = _dte.Solution;
                    foreach (Project project in projects)
                    {
                        if (project.Name != _project)
                        {
                            continue;
                        }

                        string path         = string.Empty;
                        string projectPath  = Path.GetDirectoryName(project.FullName);
                        string solutionPath = Path.GetDirectoryName(solution.FullName);
                        if (!string.IsNullOrEmpty(projectPath) && !string.IsNullOrEmpty(solutionPath))
                        {
                            if (projectPath.StartsWith(solutionPath))
                            {
                                path = "..\\" + project.UniqueName;
                            }
                            else
                            {
                                path = project.FullName;
                            }
                        }

                        replacementsDictionary.Add("$referenceproject$", "True");
                        replacementsDictionary.Add("$projectPath$", path);
                        replacementsDictionary.Add("$projectId$", project.Kind);
                        replacementsDictionary.Add("$projectName$", project.Name);
                        break;
                    }
                }
                else
                {
                    replacementsDictionary.Add("$referenceproject$", "False");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Processing Template: " + ex.Message);
            }
        }
        public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            _dte = (DTE)automationObject;

            if (replacementsDictionary.ContainsKey("$destinationdirectory$"))
                _destDirectory = replacementsDictionary["$destinationdirectory$"];

            if (replacementsDictionary.ContainsKey("$wizarddata$"))
            {
                string wizardData = replacementsDictionary["$wizarddata$"];
                ReadWizardData(wizardData);
            }

            //If UnitTest Item - load the assembly & class names from the referenced project into the picker
            if (_isUnitTestItem == "True")
            {
                List<string> referencedProjects = new List<string>();
                Array activeSolutionProjects = (Array)_dte.ActiveSolutionProjects;
                if (activeSolutionProjects != null && activeSolutionProjects.Length > 0)
                {
                    VSProject vsproject = ((Project)activeSolutionProjects.GetValue(0)).Object;
                    referencedProjects.AddRange(from Reference reference in vsproject.References where reference.SourceProject != null select reference.Name);

                    List<ComboBoxItem> classItems = GetSourceProjectItems(referencedProjects);
                    var testClassPickerform = new TestClassPicker(classItems);
                    testClassPickerform.ShowDialog();

                    replacementsDictionary.Add("$fullclassname$", testClassPickerform.FullClassname);
                    replacementsDictionary.Add("$assemblyname$", testClassPickerform.AssemblyName);
                }

                return;
            }

            //If UnitTest Project - load the projects into the picker
            List<ComboBoxItem> projectItems = new List<ComboBoxItem>();
            if (_isUnitTest == "True")
                projectItems = GetSourceProjects();

            var props = _dte.Properties["CRM Developer Extensions", "Settings"];
            string defaultSdkVersion = props.Item("DefaultCrmSdkVersion").Value;

            //Display the form prompting for the SDK version and/or project to unit test against
            var form = new SdkProjectPicker((_isUnitTest == "True"), projectItems, defaultSdkVersion);
            form.ShowDialog();

            _sdkVersion = form.Version;
            _project = form.Project;
            _isNunit = form.Nunit;

            //If UnitTest Project - set the reference to the project being tested
            if (_isUnitTest == "True")
            {
                if (string.IsNullOrEmpty(_project))
                {
                    replacementsDictionary.Add("$referenceproject$", "False");
                    return;
                }

                Projects projects = _dte.Solution.Projects;
                Solution solution = _dte.Solution;
                foreach (Project project in projects)
                {
                    if (project.Name != _project) continue;

                    string path = string.Empty;
                    string projectPath = Path.GetDirectoryName(project.FullName);
                    string solutionPath = Path.GetDirectoryName(solution.FullName);
                    if (!string.IsNullOrEmpty(projectPath) && !string.IsNullOrEmpty(solutionPath))
                    {
                        if (projectPath.StartsWith(solutionPath))
                            path = "..\\" + project.UniqueName;
                        else
                            path = project.FullName;
                    }

                    replacementsDictionary.Add("$referenceproject$", "True");
                    replacementsDictionary.Add("$projectPath$", path);
                    replacementsDictionary.Add("$projectId$", project.Kind);
                    replacementsDictionary.Add("$projectName$", project.Name);
                    break;
                }
            }
            else
                replacementsDictionary.Add("$referenceproject$", "False");
        }