Exemplo n.º 1
0
        private void RunDBConfigForAdd()
        {
            _currentAddSettings = _clientLogic.AdminCollectNewContext();
            Debug.Assert(_currentAddSettings != null);

            if (_currentAddSettings != null)
            {
                try
                {
                    Mouse.OverrideCursor = Cursors.Wait;

                    DBConfigSettings.Settings.ResetSettings();
                    DBConfigSettings.Settings.IsNewProfile    = true;
                    DBConfigSettings.Settings.IsUpgrade       = false;
                    DBConfigSettings.Settings.ServiceHost     = ServiceProxy.Services.ServiceHost;
                    DBConfigSettings.Settings.ServicePort     = ServiceProxy.Services.ServicePort;
                    DBConfigSettings.Settings.ServiceUsername = UserSettings.Settings.ServiceUsername;
                    DBConfigSettings.Settings.ServicePassword = UserSettings.Settings.ServicePassword;
                    DBConfigSettings.Settings.ServiceDomain   = UserSettings.Settings.ServiceDomain;

                    if (_clientLogic.ContextCollection != null)
                    {
                        foreach (DisplayContext existingSettings in _clientLogic.ContextCollection)
                        {
                            DBConfigSettings.Settings.ExistingProfileFolders.Add(existingSettings.StackHashContextSettings.ErrorIndexSettings.Folder);
                            DBConfigSettings.Settings.ExistingProfileNames.Add(existingSettings.StackHashContextSettings.ErrorIndexSettings.Name);
                        }
                    }

                    DBConfigSettings.Settings.Save();

                    _dbConfigProcess = Process.Start("StackHashDBConfig.exe");
                    _dbConfigProcess.EnableRaisingEvents = true;
                    _dbConfigProcess.Exited += new EventHandler(_dbConfigProcess_Exited);
                }
                catch (Exception ex)
                {
                    Mouse.OverrideCursor = null;

                    bool           userCancel = false;
                    Win32Exception win32ex    = ex as Win32Exception;
                    if (win32ex != null)
                    {
                        userCancel = (win32ex.NativeErrorCode == 1223);
                    }

                    if (userCancel)
                    {
                        // user cancelled DB config
                        DeleteContextCore(_currentAddSettings.Id);
                        _currentAddSettings = null;
                    }
                    else
                    {
                        DiagnosticsHelper.LogException(DiagSeverity.ComponentFatal,
                                                       "Failed to launch StackHashDBConfig.exe",
                                                       ex);

                        StackHashMessageBox.Show(this,
                                                 Properties.Resources.DBConfigLaunchFailedMBMessage,
                                                 Properties.Resources.DBConfigLaunchFailedMBTitle,
                                                 StackHashMessageBoxType.Ok,
                                                 StackHashMessageBoxIcon.Error,
                                                 ex,
                                                 StackHashMessageBox.ParseServiceErrorFromException(ex));
                    }
                }
            }
        }