Exemplo n.º 1
0
        public void ProjectFinishedGenerating(Project project)
        {
            if (project.DTE.SuppressUI)
            {
                return;
            }

            ProjectItem requirementsTxt = null;

            try {
                requirementsTxt = project.ProjectItems.Item("requirements.txt");
            } catch (ArgumentException) {
            }

            if (requirementsTxt == null)
            {
                return;
            }

            var txt = requirementsTxt.FileNames[0];

            if (!File.Exists(txt))
            {
                return;
            }

            var provider = WizardHelpers.GetProvider(project.DTE);

            if (provider == null)
            {
                return;
            }

            try {
                object inObj = (object)txt, outObj = null;
                project.DTE.Commands.Raise(
                    GuidList.guidPythonToolsCmdSet.ToString("B"),
                    (int)PkgCmdIDList.cmdidInstallProjectRequirements,
                    ref inObj,
                    ref outObj
                    );
            } catch (Exception ex) {
                if (ex.IsCriticalException())
                {
                    throw;
                }
                TaskDialog.ForException(
                    provider,
                    ex,
                    Strings.InstallRequirementsFailed,
                    Strings.IssueTrackerUrl
                    ).ShowModal();
            }
        }
Exemplo n.º 2
0
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            var provider = WizardHelpers.GetProvider(automationObject);

            try {
                if (AreToolsInstalled(provider))
                {
                    // If we fail to find the wizard, we will redirect the user to
                    // install the required packages.
                    var asm  = Assembly.Load("Microsoft.VisualStudio.CloudService.Wizard,Version=1.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a");
                    var type = asm.GetType("Microsoft.VisualStudio.CloudService.Wizard.CloudServiceWizard");
                    _wizard = type.InvokeMember(null, BindingFlags.CreateInstance, null, null, new object[0], CultureInfo.CurrentCulture) as IWizard;
                }
            } catch (ArgumentException) {
            } catch (BadImageFormatException) {
            } catch (IOException) {
            } catch (MemberAccessException) {
            }

            if (_wizard == null)
            {
                try {
                    Directory.Delete(replacementsDictionary["$destinationdirectory$"]);
                    Directory.Delete(replacementsDictionary["$solutiondirectory$"]);
                } catch {
                    // If it fails (doesn't exist/contains files/read-only), let the directory stay.
                }

                var dlg = new TaskDialog(provider)
                {
                    Title             = Strings.ProductTitle,
                    MainInstruction   = Strings.AzureToolsRequired,
                    Content           = Strings.AzureToolsInstallInstructions,
                    AllowCancellation = true
                };
                dlg.Buttons.Add(TaskDialogButton.Cancel);
                var download = new TaskDialogButton(Strings.DownloadAndInstall);
                dlg.Buttons.Insert(0, download);

                if (dlg.ShowModal() == download)
                {
                    InstallTools(provider);
                    throw new WizardCancelledException();
                }

                // User cancelled, so go back to the New Project dialog
                throw new WizardBackoutException();
            }

            // Run the original wizard to get the right replacements
            _wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams);
        }
        public void ProjectFinishedGenerating(Project project)
        {
            if (project.DTE.SuppressUI)
            {
                return;
            }

            ProjectItem requirementsTxt = null;

            try {
                requirementsTxt = project.ProjectItems.Item("requirements.txt");
            } catch (ArgumentException) {
            }

            if (requirementsTxt == null)
            {
                return;
            }

            var txt = requirementsTxt.FileNames[0];

            if (!File.Exists(txt))
            {
                return;
            }

            try {
                InstallProjectRequirements(project, txt);
            } catch (Exception ex) {
                if (ex.IsCriticalException())
                {
                    throw;
                }

                ex.ReportUnhandledException(
                    WizardHelpers.GetProvider(project.DTE), // null here is okay
                    GetType(),
                    allowUI: true
                    );
            }
        }
Exemplo n.º 4
0
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            var provider = WizardHelpers.GetProvider(automationObject);

            if (_wizard == null)
            {
                try {
                    Directory.Delete(replacementsDictionary["$destinationdirectory$"]);
                    Directory.Delete(replacementsDictionary["$solutiondirectory$"]);
                } catch {
                    // If it fails (doesn't exist/contains files/read-only), let the directory stay.
                }

                var dlg = new TaskDialog(provider)
                {
                    Title             = Strings.ProductTitle,
                    MainInstruction   = Strings.AzureToolsRequired,
                    Content           = Strings.AzureToolsInstallInstructions,
                    AllowCancellation = true
                };
                dlg.Buttons.Add(TaskDialogButton.Cancel);
                var download = new TaskDialogButton(Strings.DownloadAndInstall);
                dlg.Buttons.Insert(0, download);

                if (dlg.ShowModal() == download)
                {
                    StartDownload(provider);
                    throw new WizardCancelledException();
                }

                // User cancelled, so go back to the New Project dialog
                throw new WizardBackoutException();
            }

            OfferUpgrade(provider);

            // Run the original wizard to get the right replacements
            _wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams);
        }
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            var provider = WizardHelpers.GetProvider(automationObject);

            if (_wizard == null)
            {
                try {
                    Directory.Delete(replacementsDictionary["$destinationdirectory$"]);
                    Directory.Delete(replacementsDictionary["$solutiondirectory$"]);
                } catch {
                    // If it fails (doesn't exist/contains files/read-only), let the directory stay.
                }

                var dlg = new TaskDialog(provider)
                {
                    Title             = Resources.PythonToolsForVisualStudio,
                    MainInstruction   = Resources.AzureToolsRequired,
                    Content           = Resources.AzureToolsInstallInstructions,
                    AllowCancellation = true
                };
                var download = new TaskDialogButton(Resources.DownloadAndInstall);
                dlg.Buttons.Add(download);
                dlg.Buttons.Add(TaskDialogButton.Cancel);

                if (dlg.ShowModal() == download)
                {
                    Process.Start(new ProcessStartInfo(AzureToolsDownload));
                    throw new WizardCancelledException();
                }

                // User cancelled, so go back to the New Project dialog
                throw new WizardBackoutException();
            }

            if (_recommendUpgrade)
            {
                var sm    = SettingsManagerCreator.GetSettingsManager(provider);
                var store = sm.GetReadOnlySettingsStore(SettingsScope.UserSettings);

                if (!store.CollectionExists(PythonConstants.DontShowUpgradeDialogAgainCollection) ||
                    !store.GetBoolean(PythonConstants.DontShowUpgradeDialogAgainCollection, DontShowUpgradeDialogAgainProperty, false))
                {
                    var dlg = new TaskDialog(provider)
                    {
                        Title             = Resources.PythonToolsForVisualStudio,
                        MainInstruction   = Resources.AzureToolsUpgradeRecommended,
                        Content           = Resources.AzureToolsUpgradeInstructions,
                        AllowCancellation = true,
                        VerificationText  = Resources.DontShowAgain
                    };
                    var download = new TaskDialogButton(Resources.DownloadAndInstall);
                    dlg.Buttons.Add(download);
                    var cont = new TaskDialogButton(Resources.ContinueWithoutAzureToolsUpgrade);
                    dlg.Buttons.Add(cont);
                    dlg.Buttons.Add(TaskDialogButton.Cancel);

                    var response = dlg.ShowModal();

                    if (response != cont)
                    {
                        try {
                            Directory.Delete(replacementsDictionary["$destinationdirectory$"]);
                            Directory.Delete(replacementsDictionary["$solutiondirectory$"]);
                        } catch {
                            // If it fails (doesn't exist/contains files/read-only), let the directory stay.
                        }
                    }

                    if (dlg.SelectedVerified)
                    {
                        var rwStore = sm.GetWritableSettingsStore(SettingsScope.UserSettings);
                        rwStore.CreateCollection(PythonConstants.DontShowUpgradeDialogAgainCollection);
                        rwStore.SetBoolean(PythonConstants.DontShowUpgradeDialogAgainCollection, DontShowUpgradeDialogAgainProperty, true);
                    }

                    if (response == download)
                    {
                        Process.Start(new ProcessStartInfo(AzureToolsDownload));
                        throw new WizardCancelledException();
                    }
                    else if (response == TaskDialogButton.Cancel)
                    {
                        // User cancelled, so go back to the New Project dialog
                        throw new WizardBackoutException();
                    }
                }
            }

            // Run the original wizard to get the right replacements
            _wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams);
        }
        public void ProjectFinishedGenerating(Project project)
        {
            if (project.DTE.SuppressUI)
            {
                return;
            }

            string description = null;

            try {
                var p = project.Properties.Item("InterpreterDescription");
                if (p != null)
                {
                    description = p.Value as string;
                }
            } catch (ArgumentException) {
            }

            if (string.IsNullOrEmpty(description))
            {
                bool isValid = false;
                try {
                    var p = project.Properties.Item("InterpreterId");
                    isValid = p != null && !string.IsNullOrEmpty(p.Value as string);
                } catch (ArgumentException) {
                }
                if (!isValid)
                {
                    // We don't have a usable interpreter, so there's no point
                    // going ahead.
                    // Fall out - the user will find what they need when they
                    // try and run or edit, but until then there's no reason to
                    // block them or duplicate all of our help messages into yet
                    // another assembly.
                    return;
                }
            }

            ProjectItem requirementsTxt = null;

            try {
                requirementsTxt = project.ProjectItems.Item("requirements.txt");
            } catch (ArgumentException) {
            }

            if (requirementsTxt == null)
            {
                return;
            }

            var txt = requirementsTxt.FileNames[0];

            if (!File.Exists(txt))
            {
                return;
            }

            var provider = WizardHelpers.GetProvider(project.DTE);

            if (provider == null)
            {
                return;
            }

            var td = new TaskDialog(provider)
            {
                Title             = string.Format("{0} - {1}", project.Name, Resources.PythonToolsForVisualStudio),
                MainInstruction   = Resources.InstallRequirementsHeading,
                Content           = Resources.InstallRequirementsMessage,
                EnableHyperlinks  = true,
                AllowCancellation = true,
            };

            var venv = new TaskDialogButton(
                Resources.InstallRequirementsIntoVirtualEnv,
                Resources.InstallRequirementsIntoVirtualEnvTip
                );

            description = description ?? Resources.DefaultInterpreterDescription;
            var install = new TaskDialogButton(
                string.Format(Resources.InstallRequirementsIntoGlobalEnv, description),
                Resources.InstallRequirementsIntoGlobalEnvTip
                );
            var goAway = new TaskDialogButton(Resources.InstallRequirementsNowhere);

            td.Buttons.Add(venv);
            td.Buttons.Add(install);
            td.Buttons.Add(goAway);

            try {
                td.ExpandedInformation  = File.ReadAllText(txt);
                td.CollapsedControlText = Resources.InstallRequirementsShowPackages;
                td.ExpandedControlText  = Resources.InstallRequirementsHidePackages;
            } catch (IOException) {
            } catch (NotSupportedException) {
            } catch (UnauthorizedAccessException) {
            }

            var btn   = td.ShowModal();
            int cmdId = 0;

            if (btn == venv)
            {
                cmdId = (int)PkgCmdIDList.cmdidAddVirtualEnv;
            }
            else if (btn == install)
            {
                cmdId = (int)PkgCmdIDList.cmdidInstallRequirementsTxt;
            }
            if (cmdId != 0)
            {
                object inObj = (object)true, outObj = null;
                try {
                    project.DTE.Commands.Raise(
                        GuidList.guidPythonToolsCmdSet.ToString("B"),
                        cmdId,
                        ref inObj,
                        ref outObj
                        );
                } catch (Exception ex) {
                    if (ex.IsCriticalException())
                    {
                        throw;
                    }
                    TaskDialog.ForException(
                        provider,
                        ex,
                        Resources.InstallRequirementsFailed,
                        PythonConstants.IssueTrackerUrl
                        ).ShowModal();
                }
            }
        }