Beispiel #1
0
        private async void installDefaultToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string localPackagesPath = Folders.GetFolder(FolderType.LocalAppDataPackagesFolder);

                if (Directory.Exists(localPackagesPath) && Directory.GetDirectories(localPackagesPath).Length > 0)
                {
                    MessageBox.Show("Close OpenBots and delete all packages first.", "Delete Packages");
                    return;
                }

                //show spinner and disable package manager related buttons
                NotifySync("Installing and loading package assemblies...", Color.White);

                installDefaultToolStripMenuItem.Enabled = false;
                packageManagerToolStripMenuItem.Enabled = false;
                uiBtnPackageManager.Enabled             = false;

                Directory.CreateDirectory(localPackagesPath);

                //require admin access to move/download packages and their dependency .nupkg files to Program Files
                await NugetPackageManager.DownloadCommandDependencyPackages();

                //unpack commands using Program Files as the source repository
                var commandVersion = Regex.Matches(Application.ProductVersion, @"\d+\.\d+\.\d+")[0].ToString();
                Dictionary <string, string> dependencies = Project.DefaultCommandGroups.ToDictionary(x => $"OpenBots.Commands.{x}", x => commandVersion);

                foreach (var dep in dependencies)
                {
                    await NugetPackageManager.InstallPackage(dep.Key, dep.Value, new Dictionary <string, string>(),
                                                             Folders.GetFolder(FolderType.ProgramFilesPackagesFolder));
                }

                //load existing command assemblies
                string configPath   = Path.Combine(ScriptProjectPath, "project.obconfig");
                var    assemblyList = NugetPackageManager.LoadPackageAssemblies(configPath);
                _builder   = AppDomainSetupManager.LoadBuilder(assemblyList, _typeContext.GroupedTypes);
                AContainer = _builder.Build();

                LoadCommands(this);
                ReloadAllFiles();
            }
            catch (Exception ex)
            {
                if (ex is UnauthorizedAccessException)
                {
                    MessageBox.Show("Close Visual Studio and run as Admin to install default packages.", "Unauthorized");
                }
                else
                {
                    Notify("Error: " + ex.Message, Color.Red);
                }
            }

            //hide spinner and enable package manager related buttons
            installDefaultToolStripMenuItem.Enabled = true;
            packageManagerToolStripMenuItem.Enabled = true;
            uiBtnPackageManager.Enabled             = true;
        }
Beispiel #2
0
        private async Task DownloadAndOpenPackage(string packageId, string version)
        {
            try
            {
                tpbLoadingSpinner.Visible = true;
                string packageName = $"{packageId}.{version}";
                Cursor.Current = Cursors.WaitCursor;
                lblError.Text  = $"Installing {packageName}";

                await NugetPackageManager.InstallPackage(packageId, version, _projectDependenciesDict);

                lblError.Text = string.Empty;
            }
            catch (Exception ex)
            {
                tpbLoadingSpinner.Visible = false;
                lblError.Text             = "Error: " + ex.Message;
            }
        }