Exemple #1
0
        private void SetAgentEnvironment()
        {
            MessageDialog messageDialog = new MessageDialog(
                "Environment Setup",
                "Please wait while the environment is being set up for the Agent.",
                false);

            try
            {
                messageDialog.Topmost = true;
                messageDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                messageDialog.Show();

                // Set Environment Variable Path
                SetEnvironmentVariable();

                // Create Settings File
                CreateSettingsFile();

                // Install Default Packages for the First Time
                NugetPackageManager.SetupFirstTimeUserEnvironment(Environment.UserDomainName, Environment.UserName, SystemForms.Application.ProductVersion);

                messageDialog.CloseManually = true;
                messageDialog.Close();
            }
            catch (Exception ex)
            {
                messageDialog.CloseManually = true;
                messageDialog.Close();

                ShowErrorDialog("An error occurred while setting up environment for the Agent.",
                                "",
                                ex.Message,
                                Application.Current.MainWindow);

                ShutDownApplication();
            }
        }
        private async void frmScriptBuilder_LoadAsync(object sender, EventArgs e)
        {
            if (Debugger.IsAttached)
            {
                //set this value to 'true' to display the 'Install Default' button, and 'false' to hide it
                installDefaultToolStripMenuItem.Visible = true;
            }
            else //if OpenBots Studio is running in release mode
            {
                try
                {
                    //scan whether the current user account has unpacked default commands in their local appdata
                    await NugetPackageManager.SetupFirstTimeUserEnvironment();
                }
                catch (Exception ex)
                {
                    //packages missing from Program Files
                    MessageBox.Show($"{ex.Message}\n\nFirst time user environment setup failed.", "Error");
                }
            }

            var defaultTypesBinding = new BindingSource(_typeContext.DefaultTypes, null);

            VariableType.DataSource    = defaultTypesBinding;
            VariableType.DisplayMember = "Key";
            VariableType.ValueMember   = "Value";

            ArgumentType.DataSource    = defaultTypesBinding;
            ArgumentType.DisplayMember = "Key";
            ArgumentType.ValueMember   = "Value";

            //set controls double buffered
            foreach (Control control in Controls)
            {
                typeof(Control).InvokeMember("DoubleBuffered",
                                             BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                             null, control, new object[] { true });
            }

            //get app settings
            _appSettings = new ApplicationSettings();
            _appSettings = _appSettings.GetOrCreateApplicationSettings();

            _slimBarHeight  = tlpControls.RowStyles[0].Height;
            _thickBarHeight = tlpControls.RowStyles[1].Height;

            LoadActionBarPreference();

            //get scripts folder
            var rpaScriptsFolder = Folders.GetFolder(FolderType.ScriptsFolder);

            if (!Directory.Exists(rpaScriptsFolder))
            {
                frmDialog userDialog = new frmDialog("Would you like to create a folder to save your scripts in now? " +
                                                     "A script folder is required to save scripts generated with this application. " +
                                                     "The new script folder path would be '" + rpaScriptsFolder + "'.", "Unable to locate Script Folder!",
                                                     DialogType.YesNo, 0);

                if (userDialog.ShowDialog() == DialogResult.OK)
                {
                    Directory.CreateDirectory(rpaScriptsFolder);
                }

                userDialog.Dispose();
            }

            //get latest files for recent files list on load
            GenerateRecentProjects();

            //no height for status bar
            HideNotificationRow();

            //set listview column size
            frmScriptBuilder_SizeChanged(null, null);
            Refresh();
        }
        private async void frmScriptBuilder_LoadAsync(object sender, EventArgs e)
        {
            //set controls double buffered
            foreach (Control control in Controls)
            {
                typeof(Control).InvokeMember("DoubleBuffered",
                                             BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                             null, control, new object[] { true });
            }

            //get app settings
            _appSettings    = new ApplicationSettings().GetOrCreateApplicationSettings();
            _slimBarHeight  = tlpControls.RowStyles[0].Height;
            _thickBarHeight = tlpControls.RowStyles[1].Height;

            LoadActionBarPreference();

            //get scripts folder
            var rpaScriptsFolder = Folders.GetFolder(FolderType.ScriptsFolder, false);

            if (!Directory.Exists(rpaScriptsFolder))
            {
                var             rootFolder = Folders.GetFolder(FolderType.RootFolder);
                frmFolderDialog userDialog = new frmFolderDialog("Would you like to create a folder to save your scripts in now? " +
                                                                 "A script folder is required to save scripts generated by this application. " +
                                                                 $"The new script folder path would be '{Path.Combine(rootFolder, "OB Scripts")}'.",
                                                                 "Unable to locate OB Scripts Folder!", rootFolder);

                userDialog.ShowDialog();
                userDialog.Dispose();
            }

            //get latest files for recent files list on load
            GenerateRecentProjects();

            //set listview column size
            frmScriptBuilder_SizeChanged(null, null);
            Refresh();

            if (Debugger.IsAttached)
            {
                //set this value to 'true' to display the 'Install Default' button, and 'false' to hide it
                installDefaultToolStripMenuItem.Visible = true;
            }
            else //if OpenBots Studio is running in release mode
            {
                _isFirstTimeSetupComplete = false;
                try
                {
                    //scan whether the current user account has unpacked default commands in their local appdata
                    await NugetPackageManager.SetupFirstTimeUserEnvironment();
                }
                catch (Exception ex)
                {
                    //packages missing from Program Files
                    MessageBox.Show($"{ex.Message}\n\nFirst time user environment setup failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                _isFirstTimeSetupComplete = true;
            }

            var defaultTypesBinding = new BindingSource(_typeContext.DefaultTypes, null);

            variableType.DataSource    = defaultTypesBinding;
            variableType.DisplayMember = "Key";
            variableType.ValueMember   = "Value";

            argumentType.DataSource    = defaultTypesBinding;
            argumentType.DisplayMember = "Key";
            argumentType.ValueMember   = "Value";

            var importedNameSpacesBinding = new BindingSource(_scriptContext.ImportedNamespaces, null);

            lbxImportedNamespaces.DataSource    = importedNameSpacesBinding;
            lbxImportedNamespaces.DisplayMember = "Key";

            var allNameSpacesBinding = new BindingSource(_allNamespaces, null);

            cbxAllNamespaces.DataSource    = allNameSpacesBinding;
            cbxAllNamespaces.DisplayMember = "Key";

            if (_studioFormShownEarly)
            {
                _studioFormShownEarly = false;
                Show();
                frmScriptBuilder_Shown(null, null);
            }
        }