Esempio n. 1
0
        public static async Task <int> CreateOrAttachToBrokerInstanceAsync(ILogger logger = null)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            await StopBrokerInstanceAsync();

            lock (_createOrAttachToBrokerInstanceLock) {
                Process[] processes = Process.GetProcessesByName(RHostBroker);
                if (processes.Length > 0)
                {
                    _brokerProcess = processes[0];
                    _brokerProcess.EnableRaisingEvents = true;
                    _brokerProcess.Exited += async(object sender, EventArgs e) => {
                        await ProcessExitedAsync(logger);
                    };
                    logger?.LogInformation(Resources.Info_BrokerAlreadyRunning, _brokerProcess.Id);
                }
                else
                {
                    string assemblyRoot   = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetAssemblyPath());
                    string rBrokerExePath = Path.Combine(assemblyRoot, RHostBrokerExe);
                    string configFilePath = Path.Combine(assemblyRoot, RHostBrokerConfig);

                    ProcessStartInfo psi = new ProcessStartInfo(rBrokerExePath);
                    psi.Arguments        = $"--config \"{configFilePath}\"";
                    psi.UseShellExecute  = false;
                    psi.CreateNoWindow   = false;
                    psi.WorkingDirectory = assemblyRoot;

                    if (Properties.Settings.Default.UseDifferentBrokerUser)
                    {
                        CredentialManager.SetCredentialsOnProcess(psi, logger);
                    }

                    _brokerProcess = new Process()
                    {
                        StartInfo = psi
                    };
                    _brokerProcess.EnableRaisingEvents = true;
                    _brokerProcess.Exited += async(object sender, EventArgs e) => {
                        await ProcessExitedAsync(logger);
                    };
                    _brokerProcess.Start();
                    logger?.LogInformation(Resources.Info_NewBrokerInstanceStarted, _brokerProcess.Id);
                }

                AutoRestart = true;
                return(_brokerProcess.Id);
            }
        }
Esempio n. 2
0
        private async void AddOrChangeBrokerUserBtn_Click(object sender, RoutedEventArgs e)
        {
            try {
                if (await CredentialManager.IsBrokerUserCredentialSavedAsync(_logger))
                {
                    CredentialManager.RemoveCredentials(_logger);
                }
                var count = await CredentialManager.GetAndSaveCredentialsFromUserAsync(_logger);

                if (count >= CredentialManager.MaxCredUIAttempts)
                {
                    await SetErrorTextAsync(Monitor.Resources.Info_TooManyLoginAttempts);
                }
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                _logger?.LogError(Monitor.Resources.Error_AddOrChangeUserFailed, ex.Message);
                await SetErrorTextAsync(ex.Message);
            }
        }
Esempio n. 3
0
        public async Task StartUpAsync()
        {
            try {
                int id = 0;
                if (Properties.Settings.Default.UseDifferentBrokerUser)
                {
                    if (await CredentialManager.IsBrokerUserCredentialSavedAsync(_logger))
                    {
                        id = await BrokerManager.CreateOrAttachToBrokerInstanceAsync(_logger);
                    }
                    else
                    {
                        await SetErrorTextAsync(Monitor.Resources.Info_DidNotFindSavedCredentails);

                        var count = await CredentialManager.GetAndSaveCredentialsFromUserAsync(_logger);

                        if (count >= CredentialManager.MaxCredUIAttempts)
                        {
                            await SetErrorTextAsync(Monitor.Resources.Info_TooManyLoginAttempts);
                        }
                    }
                }
                else
                {
                    id = await BrokerManager.CreateOrAttachToBrokerInstanceAsync(_logger);
                }

                if (id != 0)
                {
                    await SetStatusTextAsync(Monitor.Resources.Status_BrokerStarted.FormatInvariant(id));
                }
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                _logger?.LogError(Monitor.Resources.Error_StartUpFailed, ex.Message);
                await SetErrorTextAsync(ex.Message);
            }
        }
Esempio n. 4
0
 private void RemoveBrokerUserBtn_Click(object sender, RoutedEventArgs e)
 {
     CredentialManager.RemoveCredentials(_logger);
 }