public void SetUp()
        {
            _repo1 = new GitModuleTestHelper("repo1");
            _repo2 = new GitModuleTestHelper("repo2");
            _repo3 = new GitModuleTestHelper("repo3");

            _repo2.AddSubmodule(_repo3, "repo3");
            _repo1.AddSubmodule(_repo2, "repo2");
            var submodules = _repo1.GetSubmodulesRecursive();

            _repo1Module = _repo1.Module;
            _repo2Module = submodules.ElementAt(0);
            _repo3Module = submodules.ElementAt(1);

            // Use the singleton provider, which is also used by the left panel, so we can synchronize on updates
            _provider = SubmoduleStatusProvider.Default;

            _commands = new GitUICommands(_repo1Module);

            var composition = TestComposition.Empty
                              .AddParts(typeof(MockWindowsJumpListManager))
                              .AddParts(typeof(MockRepositoryDescriptionProvider))
                              .AddParts(typeof(MockAppTitleGenerator));
            ExportProvider mefExportProvider = composition.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);
        }
        private IBuildServerSettingsUserControl?CreateBuildServerSettingsUserControl()
        {
            Validates.NotNull(Module);

            if (BuildServerType.SelectedIndex == 0 || string.IsNullOrEmpty(Module.WorkingDir))
            {
                return(null);
            }

            var defaultProjectName = Module.WorkingDir.Split(Delimiters.PathSeparators, StringSplitOptions.RemoveEmptyEntries).Last();

            var exports        = ManagedExtensibility.GetExports <IBuildServerSettingsUserControl, IBuildServerTypeMetadata>();
            var selectedExport = exports.SingleOrDefault(export => export.Metadata.BuildServerType == GetSelectedBuildServerType());

            if (selectedExport is not null)
            {
                var buildServerSettingsUserControl = selectedExport.Value;
                Validates.NotNull(_remotesManager);
                var remoteUrls = _remotesManager.LoadRemotes(false).Select(r => string.IsNullOrEmpty(r.PushUrl) ? r.Url : r.PushUrl);

                buildServerSettingsUserControl.Initialize(defaultProjectName, remoteUrls);
                return(buildServerSettingsUserControl);
            }

            return(null);
        }
Esempio n. 3
0
        protected override void Init(ISettingsPageHost aPageHost)
        {
            base.Init(aPageHost);

            _populateBuildServerTypeTask =
                Task.Factory.StartNew(() =>
            {
                var exports          = ManagedExtensibility.GetExports <IBuildServerAdapter, IBuildServerTypeMetadata>();
                var buildServerTypes = exports.Select(export =>
                {
                    var canBeLoaded = export.Metadata.CanBeLoaded;
                    return(export.Metadata.BuildServerType.Combine(" - ", canBeLoaded));
                }).ToArray();

                return(buildServerTypes);
            })
                .ContinueWith(
                    task =>
            {
                checkBoxEnableBuildServerIntegration.Enabled = true;
                checkBoxShowBuildSummary.Enabled             = true;
                BuildServerType.Enabled = true;

                BuildServerType.DataSource = new[] { _noneItem.Text }.Concat(task.Result).ToArray();
                return(BuildServerType.DataSource);
            },
                    TaskScheduler.FromCurrentSynchronizationContext());
        }
Esempio n. 4
0
        /// <summary>
        /// Initialises all available plugins on the background thread.
        /// </summary>
        public static void Initialize()
        {
            lock (Plugins)
            {
                if (Plugins.Count > 0)
                {
                    return;
                }

                try
                {
                    ManagedExtensibility.SetUserPluginsPath(AppSettings.UserPluginsPath);

                    foreach (var plugin in ManagedExtensibility.GetExports <IGitPlugin>().Select(lazy => lazy.Value))
                    {
                        Validates.NotNull(plugin.Name);
                        plugin.SettingsContainer = new GitPluginSettingsContainer(plugin.Name);

                        if (plugin is IRepositoryHostPlugin repositoryHostPlugin)
                        {
                            GitHosters.Add(repositoryHostPlugin);
                        }

                        Plugins.Add(plugin);
                    }
                }
                catch
                {
                    // no-op
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Initialises all available plugins on the background thread.
        /// </summary>
        public static void Initialize()
        {
            lock (Plugins)
            {
                if (Plugins.Count > 0)
                {
                    return;
                }

                try
                {
                    foreach (var plugin in ManagedExtensibility.GetExports <IGitPlugin>().Select(lazy => lazy.Value))
                    {
                        Validates.NotNull(plugin.Description);

                        // Description for old plugin setting processing as key
                        plugin.SettingsContainer = new GitPluginSettingsContainer(plugin.Id, plugin.Description);

                        if (plugin is IRepositoryHostPlugin repositoryHostPlugin)
                        {
                            GitHosters.Add(repositoryHostPlugin);
                        }

                        Plugins.Add(plugin);
                    }
                }
                catch
                {
                    // no-op
                }
            }
        }
        protected override void Init(ISettingsPageHost pageHost)
        {
            base.Init(pageHost);

            _remotesManager = new ConfigFileRemoteSettingsManager(() => Module);
            _populateBuildServerTypeTask = ThreadHelper.JoinableTaskFactory.RunAsync(
                async() =>
            {
                await TaskScheduler.Default.SwitchTo(alwaysYield: true);

                var exports          = ManagedExtensibility.GetExports <IBuildServerAdapter, IBuildServerTypeMetadata>();
                var buildServerTypes = exports.Select(export =>
                {
                    var canBeLoaded = export.Metadata.CanBeLoaded;
                    return(export.Metadata.BuildServerType.Combine(" - ", canBeLoaded));
                }).ToArray();

                await this.SwitchToMainThreadAsync();

                checkBoxEnableBuildServerIntegration.Enabled = true;
                checkBoxShowBuildResultPage.Enabled          = true;
                BuildServerType.Enabled = true;

                BuildServerType.DataSource = new[] { _noneItem.Text }.Concat(buildServerTypes).ToArray();
                return(BuildServerType.DataSource);
            });
        }
        public void SetUp()
        {
            _remoteReferenceRepository ??= new ReferenceRepository();

            // we will be modifying .git/config and need to completely reset each time
            _referenceRepository = new ReferenceRepository();

            _referenceRepository.Module.AddRemote(RemoteName, _remoteReferenceRepository.Module.WorkingDir);
            _referenceRepository.Fetch(RemoteName);

            _commands = new GitUICommands(_referenceRepository.Module);

            _referenceRepository.CreateCommit("Commit1", "Commit1");
            _referenceRepository.CreateBranch("Branch1", _referenceRepository.CommitHash);
            _referenceRepository.CreateTag("Branch1", _referenceRepository.CommitHash);
            _referenceRepository.CreateCommit("Commit2", "Commit2");
            _referenceRepository.CreateBranch("Branch2", _referenceRepository.CommitHash);

            _referenceRepository.CreateCommit("head commit");

            var composition = TestComposition.Empty
                              .AddParts(typeof(MockWindowsJumpListManager))
                              .AddParts(typeof(MockRepositoryDescriptionProvider))
                              .AddParts(typeof(MockAppTitleGenerator));
            ExportProvider mefExportProvider = composition.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);
        }
        private async Task <IBuildServerAdapter> GetBuildServerAdapterAsync()
        {
            await TaskScheduler.Default;

            var buildServerSettings = _module().EffectiveSettings.BuildServer;

            if (!buildServerSettings.EnableIntegration.Value)
            {
                return(null);
            }

            var buildServerType = buildServerSettings.Type.Value;

            if (string.IsNullOrEmpty(buildServerType))
            {
                return(null);
            }

            var exports = ManagedExtensibility.GetExports <IBuildServerAdapter, IBuildServerTypeMetadata>();
            var export  = exports.SingleOrDefault(x => x.Metadata.BuildServerType == buildServerType);

            if (export is not null)
            {
                try
                {
                    var canBeLoaded = export.Metadata.CanBeLoaded;
                    if (!string.IsNullOrEmpty(canBeLoaded))
                    {
                        Debug.Write(export.Metadata.BuildServerType + " adapter could not be loaded: " + canBeLoaded);
                        return(null);
                    }

                    var buildServerAdapter = export.Value;

                    buildServerAdapter.Initialize(this, buildServerSettings.TypeSettings,
                                                  () =>
                    {
                        // To run the `StartSettingsDialog()` in the UI Thread
                        _revisionGrid.Invoke((Action)(() =>
                        {
                            _revisionGrid.UICommands.StartSettingsDialog(typeof(BuildServerIntegrationSettingsPage));
                        }));
                    }, objectId => _revisionGrid.GetRevision(objectId) is not null);
                    return(buildServerAdapter);
                }
                catch (InvalidOperationException ex)
                {
                    Debug.Write(ex);

                    // Invalid arguments, do not return a build server adapter
                }
            }

            return(null);
        }
        private void RunFormTest(Func <FormBrowse, Task> testDriverAsync)
        {
            // Needed for FormBrowse, ScriptOptionsParser
            ManagedExtensibility.Initialise(new[]
            {
                typeof(GitUI.GitExtensionsForm).Assembly,
                typeof(GitCommands.GitModule).Assembly
            });

            UITest.RunForm(
                showForm: () => _uiCommands.StartBrowseDialog(owner: null).Should().BeTrue(),
                testDriverAsync);
        }
Esempio n. 10
0
        public void SetUp()
        {
            if (_referenceRepository is null)
            {
                _referenceRepository = new ReferenceRepository();
            }
            else
            {
                _referenceRepository.Reset();
            }

            ExportProvider mefExportProvider = TestComposition.Empty.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);
        }
Esempio n. 11
0
        private async Task <IBuildServerAdapter> GetBuildServerAdapterAsync()
        {
            await TaskScheduler.Default;

            var buildServerSettings = _module().EffectiveSettings.BuildServer;

            if (!buildServerSettings.EnableIntegration.ValueOrDefault)
            {
                return(null);
            }

            var buildServerType = buildServerSettings.Type.ValueOrDefault;

            if (string.IsNullOrEmpty(buildServerType))
            {
                return(null);
            }

            var exports = ManagedExtensibility.GetExports <IBuildServerAdapter, IBuildServerTypeMetadata>();
            var export  = exports.SingleOrDefault(x => x.Metadata.BuildServerType == buildServerType);

            if (export != null)
            {
                try
                {
                    var canBeLoaded = export.Metadata.CanBeLoaded;
                    if (!canBeLoaded.IsNullOrEmpty())
                    {
                        Debug.Write(export.Metadata.BuildServerType + " adapter could not be loaded: " + canBeLoaded);
                        return(null);
                    }

                    var buildServerAdapter = export.Value;

                    buildServerAdapter.Initialize(this, buildServerSettings.TypeSettings, objectId => _revisionGrid.GetRevision(objectId) != null);
                    return(buildServerAdapter);
                }
                catch (InvalidOperationException ex)
                {
                    Debug.Write(ex);

                    // Invalid arguments, do not return a build server adapter
                }
            }

            return(null);
        }
Esempio n. 12
0
        public void SetUp()
        {
            if (_referenceRepository is null)
            {
                _referenceRepository = new ReferenceRepository();
            }
            else
            {
                _referenceRepository.Reset();
            }

            _commands = new GitUICommands(_referenceRepository.Module);

            ExportProvider mefExportProvider = _composition.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);
        }
        private Task <IBuildServerAdapter> GetBuildServerAdapterAsync()
        {
            return(Task.Run(() =>
            {
                if (!Module.EffectiveSettings.BuildServer.EnableIntegration.ValueOrDefault)
                {
                    return null;
                }

                var buildServerType = Module.EffectiveSettings.BuildServer.Type.ValueOrDefault;
                if (string.IsNullOrEmpty(buildServerType))
                {
                    return null;
                }

                var exports = ManagedExtensibility.GetExports <IBuildServerAdapter, IBuildServerTypeMetadata>();
                var export = exports.SingleOrDefault(x => x.Metadata.BuildServerType == buildServerType);

                if (export != null)
                {
                    try
                    {
                        var canBeLoaded = export.Metadata.CanBeLoaded;
                        if (!canBeLoaded.IsNullOrEmpty())
                        {
                            Debug.Write(export.Metadata.BuildServerType + " adapter could not be loaded: " + canBeLoaded);
                            return null;
                        }

                        var buildServerAdapter = export.Value;

                        buildServerAdapter.Initialize(this, Module.EffectiveSettings.BuildServer.TypeSettings, sha1 => _revisionGrid.GetRevision(sha1) != null);
                        return buildServerAdapter;
                    }
                    catch (InvalidOperationException ex)
                    {
                        Debug.Write(ex);

                        // Invalid arguments, do not return a build server adapter
                    }
                }

                return null;
            }));
        }
Esempio n. 14
0
        public void SetUp()
        {
            if (_referenceRepository is null)
            {
                _referenceRepository = new ReferenceRepository();
            }
            else
            {
                _referenceRepository.Reset();
            }

            var composition = TestComposition.Empty
                              .AddParts(typeof(MockGenericBuildServerAdapter))
                              .AddParts(typeof(MockGenericBuildServerSettingsUserControl));
            ExportProvider mefExportProvider = composition.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);
        }
        private IBuildServerSettingsUserControl CreateBuildServerSettingsUserControl()
        {
            if (BuildServerType.SelectedIndex == 0 || string.IsNullOrEmpty(Module.WorkingDir))
            {
                return(null);
            }
            var defaultProjectName = Module.WorkingDir.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).Last();

            var exports        = ManagedExtensibility.GetExports <IBuildServerSettingsUserControl, IBuildServerTypeMetadata>();
            var selectedExport = exports.SingleOrDefault(export => export.Metadata.BuildServerType == GetSelectedBuildServerType());

            if (selectedExport != null)
            {
                var buildServerSettingsUserControl = selectedExport.Value;
                buildServerSettingsUserControl.Initialize(defaultProjectName);
                return(buildServerSettingsUserControl);
            }

            return(null);
        }
Esempio n. 16
0
        public void SetUp()
        {
            if (_referenceRepository is null)
            {
                _referenceRepository = new ReferenceRepository();
            }
            else
            {
                _referenceRepository.Reset();
            }

            _commands = new GitUICommands(_referenceRepository.Module);

            var composition = TestComposition.Empty
                              .AddParts(typeof(MockWindowsJumpListManager))
                              .AddParts(typeof(MockRepositoryDescriptionProvider))
                              .AddParts(typeof(MockAppTitleGenerator));
            ExportProvider mefExportProvider = composition.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);
        }
Esempio n. 17
0
        public static void Load()
        {
            lock (Plugin.LoadedPlugins.Plugins)
            {
                if (Plugin.LoadedPlugins.Plugins.Count > 0)
                {
                    return;
                }

                foreach (var plugin in ManagedExtensibility.GetExports <IGitPlugin>().Select(lazy => lazy.Value))
                {
                    plugin.SettingsContainer = new GitPluginSettingsContainer(plugin.Name);
                    if (plugin is IRepositoryHostPlugin repositoryHostPlugin)
                    {
                        RepoHosts.GitHosters.Add(repositoryHostPlugin);
                    }

                    Plugin.LoadedPlugins.Plugins.Add(plugin);
                }
            }
        }
Esempio n. 18
0
        public void SetUp()
        {
            // we will be modifying .git/config and need to completely reset each time
            _referenceRepository = new ReferenceRepository();

            foreach (var name in RemoteNames)
            {
                _referenceRepository.Module.AddRemote(name, $"http://localhost/remotes/{name}.git");
            }

            _commands       = new GitUICommands(_referenceRepository.Module);
            _remotesManager = new ConfigFileRemoteSettingsManager(() => _referenceRepository.Module);

            var composition = TestComposition.Empty
                              .AddParts(typeof(MockWindowsJumpListManager))
                              .AddParts(typeof(MockRepositoryDescriptionProvider))
                              .AddParts(typeof(MockAppTitleGenerator));
            ExportProvider mefExportProvider = composition.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);
        }
Esempio n. 19
0
        private IIssueTrackerAdapter GetIssueTrackerAdapter()
        {
            if (!Module.EffectiveSettings.IssueTracker.EnableIntegration.ValueOrDefault)
            {
                return(null);
            }
            var IssueTrackerType = Module.EffectiveSettings.IssueTracker.Type.Value;

            if (string.IsNullOrEmpty(IssueTrackerType))
            {
                return(null);
            }
            var exports = ManagedExtensibility.GetExports <IIssueTrackerAdapter, IIssueTrackerTypeMetadata>();
            var export  = exports.SingleOrDefault(x => x.Metadata.IssueTrackerType == IssueTrackerType);

            if (export != null)
            {
                try
                {
                    var canBeLoaded = export.Metadata.CanBeLoaded;
                    if (!canBeLoaded.IsNullOrEmpty())
                    {
                        System.Diagnostics.Debug.Write(export.Metadata.IssueTrackerType + " adapter could not be loaded: " + canBeLoaded);
                        return(null);
                    }
                    var IssueTrackerAdapter = export.Value;
                    IssueTrackerAdapter.Initialize(this, Module.EffectiveSettings.IssueTracker.TypeSettings);
                    return(IssueTrackerAdapter);
                }
                catch (InvalidOperationException ex)
                {
                    Debug.Write(ex);
                    // Invalid arguments, do not return a Issue server adapter
                }
            }

            return(null);
        }
Esempio n. 20
0
        public void SetUp()
        {
            _repo1 = new GitModuleTestHelper("repo1");
            _repo2 = new GitModuleTestHelper("repo2");
            _repo3 = new GitModuleTestHelper("repo3");

            _repo2.AddSubmodule(_repo3, "repo3");
            _repo1.AddSubmodule(_repo2, "repo2");
            var submodules = _repo1.GetSubmodulesRecursive();

            _repo1Module = _repo1.Module;
            _repo2Module = submodules.ElementAt(0);
            _repo3Module = submodules.ElementAt(1);

            // Use the singleton provider, which is also used by the left panel, so we can synchronize on updates
            _provider = SubmoduleStatusProvider.Default;

            _commands = new GitUICommands(_repo1Module);

            ExportProvider mefExportProvider = _composition.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);
        }
Esempio n. 21
0
        public void ParseScriptArguments_resolve_RepoName()
        {
            var composition = TestComposition.Empty
                              .AddParts(typeof(MockRepositoryDescriptionProvider));

            ExportProvider mefExportProvider = composition.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);

            var option  = "RepoName";
            var dirName = MockRepositoryDescriptionProvider.ShortName; // chose one which will never contain a repo

            _module.WorkingDir.Returns("C:\\" + dirName);

            var result = ScriptOptionsParser.GetTestAccessor().ParseScriptArguments(
                arguments: "{" + option + "}", option,
                owner: null, scriptHostControl: null, _module, allSelectedRevisions: null, selectedTags: null,
                selectedBranches: null, selectedLocalBranches: null, selectedRemoteBranches: null, selectedRemotes: null, selectedRevision: null,
                currentTags: null,
                currentBranches: null, currentLocalBranches: null, currentRemoteBranches: null, currentRevision: null, currentRemote: null);

            result.Should().Be(dirName);
        }
Esempio n. 22
0
        public void SetUp()
        {
            _remoteReferenceRepository ??= new ReferenceRepository();

            // we will be modifying .git/config and need to completely reset each time
            _referenceRepository = new ReferenceRepository();

            _referenceRepository.Module.AddRemote(RemoteName, _remoteReferenceRepository.Module.WorkingDir);
            _referenceRepository.Fetch(RemoteName);

            _commands = new GitUICommands(_referenceRepository.Module);

            _referenceRepository.CreateCommit("Commit1", "Commit1");
            _referenceRepository.CreateBranch("Branch1", _referenceRepository.CommitHash);
            _referenceRepository.CreateTag("Branch1", _referenceRepository.CommitHash);
            _referenceRepository.CreateCommit("Commit2", "Commit2");
            _referenceRepository.CreateBranch("Branch2", _referenceRepository.CommitHash);

            _referenceRepository.CreateCommit("head commit");

            ExportProvider mefExportProvider = _composition.ExportProviderFactory.CreateExportProvider();

            ManagedExtensibility.SetTestExportProvider(mefExportProvider);
        }
Esempio n. 23
0
        public static void Initialize()
        {
            lock (Plugins)
            {
                if (Plugins.Count > 0)
                {
                    return;
                }

                ManagedExtensibility.SetApplicationDataFolder(AppSettings.ApplicationDataPath.Value);

                foreach (var plugin in ManagedExtensibility.GetExports <IGitPlugin>().Select(lazy => lazy.Value))
                {
                    plugin.SettingsContainer = new GitPluginSettingsContainer(plugin.Name);

                    if (plugin is IRepositoryHostPlugin repositoryHostPlugin)
                    {
                        GitHosters.Add(repositoryHostPlugin);
                    }

                    Plugins.Add(plugin);
                }
            }
        }
 public void ThrowWhenUserPluginsPathAlreadyInitialized()
 {
     ManagedExtensibility.SetUserPluginsPath("A");
     Assert.Throws <InvalidOperationException>(() => ManagedExtensibility.SetUserPluginsPath("B"));
 }
Esempio n. 25
0
        private static void RunApplication()
        {
            string[] args = Environment.GetCommandLineArgs();

            // This form created to obtain UI synchronization context only
            using (new Form())
            {
                // Store the shared JoinableTaskContext
                ThreadHelper.JoinableTaskContext = new JoinableTaskContext();
            }

            ManagedExtensibility.Initialise(new[]
            {
                typeof(GitUI.GitExtensionsForm).Assembly,
                typeof(GitCommands.GitModule).Assembly
            });

            AppSettings.LoadSettings();

            if (EnvUtils.RunningOnWindows())
            {
                WebBrowserEmulationMode.SetBrowserFeatureControl();
                FormFixHome.CheckHomePath();
            }

            if (string.IsNullOrEmpty(AppSettings.Translation))
            {
                using FormChooseTranslation formChoose = new();
                formChoose.ShowDialog();
            }

            AppSettings.TelemetryEnabled ??= MessageBox.Show(
                null,
                ResourceManager.TranslatedStrings.TelemetryPermissionMessage,
                ResourceManager.TranslatedStrings.TelemetryPermissionCaption,
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question) == DialogResult.Yes;

            try
            {
                // Ensure we can find the git command to execute,
                // unless we are being instructed to uninstall,
                // or AppSettings.CheckSettings is set to false.
                if (!(args.Length >= 2 && args[1] == "uninstall"))
                {
                    if (!CheckSettingsLogic.SolveGitCommand())
                    {
                        if (!LocateMissingGit())
                        {
                            Environment.Exit(-1);
                            return;
                        }
                    }

                    if (AppSettings.CheckSettings)
                    {
                        GitUICommands        uiCommands         = new("");
                        CommonLogic          commonLogic        = new(uiCommands.Module);
                        CheckSettingsLogic   checkSettingsLogic = new(commonLogic);
                        SettingsPageHostMock fakePageHost       = new(checkSettingsLogic);
                        using var checklistSettingsPage = SettingsPageBase.Create <ChecklistSettingsPage>(fakePageHost);
                        if (!checklistSettingsPage.CheckSettings())
                        {
                            if (!checkSettingsLogic.AutoSolveAllSettings() || !checklistSettingsPage.CheckSettings())
                            {
                                uiCommands.StartSettingsDialog();
                            }
                        }
                    }
                }
            }
            catch
            {
                // TODO: remove catch-all
            }

            if (EnvUtils.RunningOnWindows())
            {
                MouseWheelRedirector.Active = true;
            }

            GitUICommands commands = new(GetWorkingDir(args));

            if (args.Length <= 1)
            {
                commands.StartBrowseDialog(owner: null);
            }
            else
            {
                // if we are here args.Length > 1

                // Avoid replacing the ExitCode eventually set while parsing arguments,
                // i.e. assume -1 and afterwards, only set it to 0 if no error is indicated.
                Environment.ExitCode = -1;
                if (commands.RunCommand(args))
                {
                    Environment.ExitCode = 0;
                }
            }

            AppSettings.SaveSettings();
        }