Пример #1
0
        private void CloseConnectionTab()
        {
            Crownwood.Magic.Controls.TabPage selectedTab = TabController.SelectedTab;
            if (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.All)
            {
                DialogResult result = CTaskDialog.MessageBox(this, GeneralAppInfo.ProdName, string.Format(Language.strConfirmCloseConnectionMainInstruction, selectedTab.Title), "", "", "", Language.strCheckboxDoNotShowThisMessageAgain, ETaskDialogButtons.YesNo, ESysIcons.Question, ESysIcons.Question);
                if (CTaskDialog.VerificationChecked)
                {
                    Settings.Default.ConfirmCloseConnection--;
                }
                if (result == DialogResult.No)
                {
                    return;
                }
            }

            try
            {
                if (selectedTab.Tag != null)
                {
                    InterfaceControl interfaceControl = (InterfaceControl)selectedTab.Tag;
                    interfaceControl.Protocol.Close();
                }
                else
                {
                    CloseTab(selectedTab);
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, "UI.Window.Connection.CloseConnectionTab() failed" + Environment.NewLine + ex.Message, true);
            }

            UpdateSelectedConnection();
        }
Пример #2
0
        private void ValidateConnectionFileVersion()
        {
            if (_xmlDocument.DocumentElement.HasAttribute("ConfVersion"))
            {
                _confVersion = Convert.ToDouble(_xmlDocument.DocumentElement.Attributes["ConfVersion"].Value.Replace(",", "."),
                                                CultureInfo.InvariantCulture);
            }
            else
            {
                Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, Language.strOldConffile);
            }

            const double maxSupportedConfVersion = 2.5;

            if (!(_confVersion > maxSupportedConfVersion))
            {
                return;
            }
            CTaskDialog.ShowTaskDialogBox(
                frmMain.Default,
                Application.ProductName,
                "Incompatible connection file format",
                $"The format of this connection file is not supported. Please upgrade to a newer version of {Application.ProductName}.",
                string.Format("{1}{0}File Format Version: {2}{0}Highest Supported Version: {3}", Environment.NewLine,
                              ConnectionFileName, _confVersion, maxSupportedConfVersion),
                "",
                "",
                "",
                "",
                ETaskDialogButtons.Ok,
                ESysIcons.Error,
                ESysIcons.Error
                );
            throw (new Exception($"Incompatible connection file format (file format version {_confVersion})."));
        }
Пример #3
0
        private void Connection_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!frmMain.Default.IsClosing &&
                ((Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.All & TabController.TabPages.Count > 0) ||
                 (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.Multiple & TabController.TabPages.Count > 1)))
            {
                var result = CTaskDialog.MessageBox(this, GeneralAppInfo.ProductName, string.Format(Language.strConfirmCloseConnectionPanelMainInstruction, Text), "", "", "", Language.strCheckboxDoNotShowThisMessageAgain, ETaskDialogButtons.YesNo, ESysIcons.Question, ESysIcons.Question);
                if (CTaskDialog.VerificationChecked)
                {
                    Settings.Default.ConfirmCloseConnection--;
                }
                if (result == DialogResult.No)
                {
                    e.Cancel = true;
                    return;
                }
            }

            try
            {
                foreach (TabPage tabP in TabController.TabPages)
                {
                    if (tabP.Tag == null)
                    {
                        continue;
                    }
                    var interfaceControl = (InterfaceControl)tabP.Tag;
                    interfaceControl.Protocol.Close();
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, "UI.Window.Connection.Connection_FormClosing() failed" + Environment.NewLine + ex.Message, true);
            }
        }
Пример #4
0
        private static void CheckLenovoAutoScrollUtility()
        {
            Logger.Instance.InfoFormat("Checking Lenovo AutoScroll Utility...");

            if (!Settings.Default.CompatibilityWarnLenovoAutoScrollUtility)
            {
                return;
            }

            var proccesses = new Process[] { };

            try
            {
                proccesses = Process.GetProcessesByName("virtscrl");
            }
            catch (InvalidOperationException ex)
            {
                Runtime.MessageCollector.AddExceptionMessage("Error in CheckLenovoAutoScrollUtility", ex);
            }

            if (proccesses.Length <= 0)
            {
                return;
            }
            CTaskDialog.MessageBox(Application.ProductName, Language.strCompatibilityProblemDetected, string.Format(Language.strCompatibilityLenovoAutoScrollUtilityDetected, Application.ProductName), "", "", Language.strCheckboxDoNotShowThisMessageAgain, ETaskDialogButtons.Ok, ESysIcons.Warning, ESysIcons.Warning);
            if (CTaskDialog.VerificationChecked)
            {
                Settings.Default.CompatibilityWarnLenovoAutoScrollUtility = false;
            }
        }
        private static void CheckFipsPolicy(MessageCollector messageCollector)
        {
            if (Settings.Default.OverrideFIPSCheck)
            {
                messageCollector.AddMessage(MessageClass.InformationMsg, "OverrideFIPSCheck is set. Will skip check...", true);
                return;
            }

            messageCollector.AddMessage(MessageClass.InformationMsg, "Checking FIPS Policy...", true);
            if (!FipsPolicyEnabledForServer2003() && !FipsPolicyEnabledForServer2008AndNewer())
            {
                return;
            }

            var errorText = string.Format(Language.strErrorFipsPolicyIncompatible, GeneralAppInfo.ProductName);

            messageCollector.AddMessage(MessageClass.ErrorMsg, errorText, true);

            var ShouldIStayOrShouldIGo = CTaskDialog.MessageBox(Application.ProductName, Language.strCompatibilityProblemDetected, errorText, "", "", Language.strCheckboxDoNotShowThisMessageAgain, ETaskDialogButtons.OkCancel, ESysIcons.Warning, ESysIcons.Warning);

            if (CTaskDialog.VerificationChecked && ShouldIStayOrShouldIGo == DialogResult.OK)
            {
                messageCollector.AddMessage(MessageClass.ErrorMsg, "User requests that FIPS check be overridden", true);
                Settings.Default.OverrideFIPSCheck = true;
                Settings.Default.Save();
                return;
            }

            if (ShouldIStayOrShouldIGo == DialogResult.Cancel)
            {
                Environment.Exit(1);
            }
        }
Пример #6
0
        private void GetUpdateInfoCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (InvokeRequired)
            {
                AsyncCompletedEventHandler myDelegate = GetUpdateInfoCompleted;
                Invoke(myDelegate, sender, e);
                return;
            }

            try
            {
                _appUpdate.GetUpdateInfoCompletedEvent -= GetUpdateInfoCompleted;

                btnTestProxy.Enabled = true;
                btnTestProxy.Text    = Language.strButtonTestProxy;

                if (e.Cancelled)
                {
                    return;
                }
                if (e.Error != null)
                {
                    throw e.Error;
                }

                CTaskDialog.ShowCommandBox(this, Convert.ToString(Application.ProductName),
                                           Language.strProxyTestSucceeded, "", Language.strButtonOK, false);
            }
            catch (Exception ex)
            {
                CTaskDialog.ShowCommandBox(this, Convert.ToString(Application.ProductName), Language.strProxyTestFailed,
                                           MiscTools.GetExceptionMessageRecursive(ex), "", "", "", Language.strButtonOK, false, ESysIcons.Error,
                                           0);
            }
        }
Пример #7
0
        private void frmMain_Shown(object sender, EventArgs e)
        {
#if !PORTABLE
            if (!Settings.Default.CheckForUpdatesAsked)
            {
                string[] commandButtons =
                {
                    Language.strAskUpdatesCommandRecommended, Language.strAskUpdatesCommandCustom,
                    Language.strAskUpdatesCommandAskLater
                };

                CTaskDialog.ShowTaskDialogBox(this, GeneralAppInfo.ProductName, Language.strAskUpdatesMainInstruction, string.Format(Language.strAskUpdatesContent, GeneralAppInfo.ProductName),
                                              "", "", "", "", string.Join(" | ", commandButtons), ETaskDialogButtons.None, ESysIcons.Question, ESysIcons.Question);

                if (CTaskDialog.CommandButtonResult == 0 | CTaskDialog.CommandButtonResult == 1)
                {
                    Settings.Default.CheckForUpdatesAsked = true;
                }

                if (CTaskDialog.CommandButtonResult != 1)
                {
                    return;
                }

                using (var optionsForm = new frmOptions(Language.strTabUpdates))
                {
                    optionsForm.ShowDialog(this);
                }

                return;
            }

            if (!Settings.Default.CheckForUpdatesOnStartup)
            {
                return;
            }

            DateTime nextUpdateCheck = Convert.ToDateTime(
                Settings.Default.CheckForUpdatesLastCheck.Add(
                    TimeSpan.FromDays(Convert.ToDouble(Settings.Default.CheckForUpdatesFrequencyDays))));

            if (!Settings.Default.UpdatePending && DateTime.UtcNow <= nextUpdateCheck)
            {
                return;
            }
            if (!IsHandleCreated)
            {
                CreateHandle();                   // Make sure the handle is created so that InvokeRequired returns the correct result
            }
            Startup.Instance.CheckForUpdate();
#endif
        }
 private void ShowIncompatibleVersionDialogBox()
 {
     CTaskDialog.ShowTaskDialogBox(
         frmMain.Default,
         Application.ProductName,
         "Incompatible connection file format",
         $"The format of this connection file is not supported. Please upgrade to a newer version of {Application.ProductName}.",
         string.Format("{1}{0}File Format Version: {2}{0}Highest Supported Version: {3}", Environment.NewLine, ConnectionFileName, _confVersion, MaxSupportedConfVersion),
         "",
         "",
         "",
         "",
         ETaskDialogButtons.Ok,
         ESysIcons.Error,
         ESysIcons.Error
         );
 }
Пример #9
0
        private void Connection_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!FrmMain.Default.IsClosing &&
                (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.All & connDock.Documents.Any() ||
                 Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.Multiple &
                 connDock.Documents.Count() > 1))
            {
                var result = CTaskDialog.MessageBox(this, GeneralAppInfo.ProductName,
                                                    string
                                                    .Format(Language.strConfirmCloseConnectionPanelMainInstruction,
                                                            Text), "", "", "",
                                                    Language.strCheckboxDoNotShowThisMessageAgain,
                                                    ETaskDialogButtons.YesNo, ESysIcons.Question,
                                                    ESysIcons.Question);
                if (CTaskDialog.VerificationChecked)
                {
                    Settings.Default.ConfirmCloseConnection--;
                }

                if (result == DialogResult.No)
                {
                    e.Cancel = true;
                    return;
                }
            }

            try
            {
                foreach (var dockContent in connDock.Documents.ToArray())
                {
                    var tabP = (ConnectionTab)dockContent;
                    if (tabP.Tag == null)
                    {
                        continue;
                    }
                    tabP.silentClose = true;
                    tabP.Close();
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionMessage("UI.Window.Connection.Connection_FormClosing() failed",
                                                             ex);
            }
        }
Пример #10
0
        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!(Runtime.WindowList == null || Runtime.WindowList.Count == 0))
            {
                var openConnections = 0;
                foreach (BaseWindow window in Runtime.WindowList)
                {
                    var connectionWindow = window as ConnectionWindow;
                    if (connectionWindow != null)
                    {
                        openConnections = openConnections + connectionWindow.TabController.TabPages.Count;
                    }
                }

                if (openConnections > 0 && (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.All | (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.Multiple & openConnections > 1) || Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.Exit))
                {
                    var result = CTaskDialog.MessageBox(this, Application.ProductName, Language.strConfirmExitMainInstruction, "", "", "", Language.strCheckboxDoNotShowThisMessageAgain, ETaskDialogButtons.YesNo, ESysIcons.Question, ESysIcons.Question);
                    if (CTaskDialog.VerificationChecked)
                    {
                        Settings.Default.ConfirmCloseConnection--;
                    }
                    if (result == DialogResult.No)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
            }

            Shutdown.Cleanup();

            IsClosing = true;

            if (Runtime.WindowList != null)
            {
                foreach (BaseWindow window in Runtime.WindowList)
                {
                    window.Close();
                }
            }

            Shutdown.StartUpdate();

            Debug.Print("[END] - " + Convert.ToString(DateTime.Now, CultureInfo.InvariantCulture));
        }
Пример #11
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            if (!protocolClose)
            {
                if (!silentClose)
                {
                    if (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.All)
                    {
                        var result = CTaskDialog.MessageBox(this, GeneralAppInfo.ProductName,
                                                            string
                                                            .Format(Language.strConfirmCloseConnectionPanelMainInstruction,
                                                                    TabText), "", "", "",
                                                            Language.strCheckboxDoNotShowThisMessageAgain,
                                                            ETaskDialogButtons.YesNo, ESysIcons.Question,
                                                            ESysIcons.Question);
                        if (CTaskDialog.VerificationChecked)
                        {
                            Settings.Default.ConfirmCloseConnection--;
                        }

                        if (result == DialogResult.No)
                        {
                            e.Cancel = true;
                        }
                        else
                        {
                            ((InterfaceControl)Tag)?.Protocol.Close();
                        }
                    }
                    else
                    {
                        // close without the confirmation prompt...
                        ((InterfaceControl)Tag)?.Protocol.Close();
                    }
                }
                else
                {
                    ((InterfaceControl)Tag)?.Protocol.Close();
                }
            }

            base.OnFormClosing(e);
        }
Пример #12
0
        private static TreeNode GetParentTreeNode(TreeNode rootTreeNode, TreeNode selectedTreeNode,
                                                  bool alwaysUseSelectedTreeNode = false)
        {
            TreeNode parentTreeNode;

            selectedTreeNode = GetContainerTreeNode(selectedTreeNode);
            if (selectedTreeNode == null || selectedTreeNode == rootTreeNode)
            {
                parentTreeNode = rootTreeNode;
            }
            else
            {
                if (alwaysUseSelectedTreeNode)
                {
                    parentTreeNode = GetContainerTreeNode(selectedTreeNode);
                }
                else
                {
                    CTaskDialog.ShowCommandBox(Application.ProductName, Language.strImportLocationMainInstruction,
                                               Language.strImportLocationContent, "", "", "",
                                               string.Format(Language.strImportLocationCommandButtons, Environment.NewLine, rootTreeNode.Text,
                                                             selectedTreeNode.Text), true, ESysIcons.Question, 0);
                    switch (CTaskDialog.CommandButtonResult)
                    {
                    case 0:     // Root
                        parentTreeNode = rootTreeNode;
                        break;

                    case 1:     // Selected Folder
                        parentTreeNode = GetContainerTreeNode(selectedTreeNode);
                        break;

                    default:     // Cancel
                        parentTreeNode = null;
                        break;
                    }
                }
            }

            return(parentTreeNode);
        }
Пример #13
0
        private void CloseConnectionTab()
        {
            try
            {
                var selectedTab = TabController.SelectedTab;
                if (selectedTab == null)
                {
                    return;
                }
                if (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.All)
                {
                    var result = CTaskDialog.MessageBox(this, GeneralAppInfo.ProductName, string.Format(Language.strConfirmCloseConnectionMainInstruction, selectedTab.Title), "", "", "", Language.strCheckboxDoNotShowThisMessageAgain, ETaskDialogButtons.YesNo, ESysIcons.Question, ESysIcons.Question);
                    if (CTaskDialog.VerificationChecked)
                    {
                        Settings.Default.ConfirmCloseConnection--;
                    }
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                }

                if (selectedTab.Tag != null)
                {
                    var interfaceControl = (InterfaceControl)selectedTab.Tag;
                    interfaceControl.Protocol.Close();
                }
                else
                {
                    CloseTab(selectedTab);
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionMessage("UI.Window.Connection.CloseConnectionTab() failed", ex);
            }

            UpdateSelectedConnection();
        }
Пример #14
0
        private void CloseOtherTabs()
        {
            var selectedTab = (ConnectionTab)GetInterfaceControl()?.Parent;

            if (selectedTab == null)
            {
                return;
            }
            if (Settings.Default.ConfirmCloseConnection == (int)ConfirmCloseEnum.Multiple)
            {
                var result = CTaskDialog.MessageBox(this, GeneralAppInfo.ProductName,
                                                    string.Format(Language.strConfirmCloseConnectionOthersInstruction,
                                                                  selectedTab.TabText), "", "", "",
                                                    Language.strCheckboxDoNotShowThisMessageAgain,
                                                    ETaskDialogButtons.YesNo, ESysIcons.Question,
                                                    ESysIcons.Question);
                if (CTaskDialog.VerificationChecked)
                {
                    Settings.Default.ConfirmCloseConnection--;
                }

                if (result == DialogResult.No)
                {
                    return;
                }
            }

            foreach (var dockContent in connDock.DocumentsToArray())
            {
                var tab = (ConnectionTab)dockContent;
                if (selectedTab != tab)
                {
                    tab.Close();
                }
            }
        }
Пример #15
0
 private void SetConnectionTreeEventHandlers()
 {
     olvConnections.NodeDeletionConfirmer = new SelectedConnectionDeletionConfirmer(prompt =>
                                                                                    CTaskDialog
                                                                                    .MessageBox(Application.ProductName,
                                                                                                prompt,
                                                                                                "",
                                                                                                ETaskDialogButtons
                                                                                                .YesNo,
                                                                                                ESysIcons
                                                                                                .Question));
     olvConnections.KeyDown  += tvConnections_KeyDown;
     olvConnections.KeyPress += tvConnections_KeyPress;
     SetTreePostSetupActions();
     SetConnectionTreeClickHandlers();
     Runtime.ConnectionsService.ConnectionsLoaded += ConnectionsServiceOnConnectionsLoaded;
 }
Пример #16
0
        public static void LoadConnections(bool withDialog = false, bool update = false)
        {
            var connectionsLoader = new ConnectionsLoader();

            try
            {
                // disable sql update checking while we are loading updates
                RemoteConnectionsSyncronizer?.Disable();

                if (!Settings.Default.UseSQLServer)
                {
                    if (withDialog)
                    {
                        var loadDialog = Controls.ConnectionsLoadDialog();
                        if (loadDialog.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        connectionsLoader.ConnectionFileName = loadDialog.FileName;
                    }
                    else
                    {
                        connectionsLoader.ConnectionFileName = GetStartupConnectionFileName();
                    }

                    CreateBackupFile(Convert.ToString(connectionsLoader.ConnectionFileName));
                }

                connectionsLoader.UseDatabase        = Settings.Default.UseSQLServer;
                ConnectionTreeModel                  = connectionsLoader.LoadConnections(false);
                Windows.TreeForm.ConnectionTreeModel = ConnectionTreeModel;

                if (Settings.Default.UseSQLServer)
                {
                    LastSqlUpdate = DateTime.Now;
                }
                else
                {
                    if (connectionsLoader.ConnectionFileName == GetDefaultStartupConnectionFileName())
                    {
                        Settings.Default.LoadConsFromCustomLocation = false;
                    }
                    else
                    {
                        Settings.Default.LoadConsFromCustomLocation = true;
                        Settings.Default.CustomConsPath             = connectionsLoader.ConnectionFileName;
                    }
                }

                // re-enable sql update checking after updates are loaded
                RemoteConnectionsSyncronizer?.Enable();
            }
            catch (Exception ex)
            {
                if (Settings.Default.UseSQLServer)
                {
                    MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex);
                    var commandButtons = string.Join("|", Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName));
                    CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error);
                    switch (CTaskDialog.CommandButtonResult)
                    {
                    case 0:
                        LoadConnections(withDialog, update);
                        return;

                    case 1:
                        Settings.Default.UseSQLServer = false;
                        LoadConnections(true, update);
                        return;

                    default:
                        Application.Exit();
                        return;
                    }
                }
                if (ex is FileNotFoundException && !withDialog)
                {
                    MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionsLoader.ConnectionFileName), ex, MessageClass.InformationMsg);
                    NewConnections(Convert.ToString(connectionsLoader.ConnectionFileName));
                    return;
                }

                MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionsLoader.ConnectionFileName), ex);
                if (connectionsLoader.ConnectionFileName != GetStartupConnectionFileName())
                {
                    LoadConnections(withDialog, update);
                }
                else
                {
                    MessageBox.Show(frmMain.Default,
                                    string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)),
                                    @"Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
            }
        }
Пример #17
0
        /// <summary>
        /// Creates and shows a dialog to either create a new connections file, load a different one,
        /// exit, or optionally cancel the operation.
        /// </summary>
        /// <param name="connectionFileName"></param>
        /// <param name="messageText"></param>
        /// <param name="showCancelButton"></param>
        public static void ShowLoadConnectionsFailedDialog(string connectionFileName,
                                                           string messageText,
                                                           bool showCancelButton)
        {
            var commandButtons = new List <string>
            {
                Language.ConfigurationCreateNew,
                Language.strOpenADifferentFile,
                Language.strMenuExit
            };

            if (showCancelButton)
            {
                commandButtons.Add(Language.strButtonCancel);
            }

            var answered = false;

            while (!answered)
            {
                try
                {
                    CTaskDialog.ShowTaskDialogBox(
                        GeneralAppInfo.ProductName,
                        messageText,
                        "", "", "", "", "",
                        string.Join(" | ", commandButtons),
                        ETaskDialogButtons.None,
                        ESysIcons.Question,
                        ESysIcons.Question);

                    switch (CTaskDialog.CommandButtonResult)
                    {
                    case 0:     // New
                        var saveAsDialog = ConnectionsSaveAsDialog();
                        saveAsDialog.ShowDialog();
                        Runtime.ConnectionsService.NewConnectionsFile(saveAsDialog.FileName);
                        answered = true;
                        break;

                    case 1:     // Load
                        Runtime.LoadConnections(true);
                        answered = true;
                        break;

                    case 2:     // Exit
                        Application.Exit();
                        answered = true;
                        break;

                    case 3:     // Cancel
                        answered = true;
                        break;
                    }
                }
                catch (Exception exception)
                {
                    Runtime.MessageCollector.AddExceptionMessage(
                        string
                        .Format(Language.strConnectionsFileCouldNotBeLoadedNew,
                                connectionFileName),
                        exception,
                        MessageClass.WarningMsg);
                }
            }
        }
Пример #18
0
        //Refernce: https://bitbucket.org/geckofx/geckofx-33.0/issues/90/invalid-security-certificate-error-on
        internal static void GeckoBrowser_NSSError(object sender, GeckoNSSErrorEventArgs e)
        {
            /* some messages say "Certificate", some say "certificate"
             * I'm guessing that this is going to be a localization issue...
             * Log a message so we can try to find a better solution if problems are reported in the future...
             */
            if (!e.Message.ToLower().Contains("certificate"))
            {
                Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, $"Unhandled NSSError: {e.Message}");
                e.Handled = false;
                return;
            }

            string[] commandButtons =
            {
                Language.strHttpsInsecureAllowOnce,     // 0
                Language.strHttpsInsecureAllowAlways,   // 1
                Language.strHttpsInsecureDontAllow      // 2
            };

            CTaskDialog.ShowTaskDialogBox(null, GeneralAppInfo.ProductName, Language.strHttpsInsecurePromptTitle,
                                          string.Format(Language.strHttpsInsecurePrompt, e.Uri.AbsoluteUri), "", "", "", "",
                                          string.Join(" | ", commandButtons), ETaskDialogButtons.None, ESysIcons.Question, ESysIcons.Question);

            var allow     = false;
            var temporary = true;

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (CTaskDialog.CommandButtonResult)
            {
            case 0:
                allow     = true;
                temporary = true;
                break;

            case 1:
                allow     = true;
                temporary = false;
                break;

            case 2:
                allow     = false;
                temporary = true;     // just to be safe
                break;
            }

            if (!allow)
            {
                Runtime.MessageCollector.AddMessage(MessageClass.WarningMsg, $"User did not allow navigation to {e.Uri.AbsoluteUri} with an insecure certificate: {e.Message}");
                return;
            }

            /* "temporary == false" (aka always) might not work:
             * https://bitbucket.org/geckofx/geckofx-45.0/issues/152/remembervalidityoverride-doesnt-save-in
             * However, my testing was successful in Gecko 45.0.22
             */
            CertOverrideService.GetService().RememberValidityOverride(e.Uri, e.Certificate,
                                                                      CertOverride.Mismatch | CertOverride.Time | CertOverride.Untrusted, temporary);

            e.Handled = true;
            ((GeckoWebBrowser)sender).Navigate(e.Uri.AbsoluteUri);
        }
Пример #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="withDialog">
        /// Should we show the file selection dialog to allow the user to select
        /// a connection file
        /// </param>
        public static void LoadConnections(bool withDialog = false)
        {
            var connectionFileName = "";

            try
            {
                // disable sql update checking while we are loading updates
                ConnectionsService.RemoteConnectionsSyncronizer?.Disable();

                if (withDialog)
                {
                    var loadDialog = DialogFactory.BuildLoadConnectionsDialog();
                    if (loadDialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    connectionFileName            = loadDialog.FileName;
                    Settings.Default.UseSQLServer = false;
                    Settings.Default.Save();
                }
                else if (!Settings.Default.UseSQLServer)
                {
                    connectionFileName = ConnectionsService.GetStartupConnectionFileName();
                }

                ConnectionsService.LoadConnections(Settings.Default.UseSQLServer, false, connectionFileName);

                if (Settings.Default.UseSQLServer)
                {
                    ConnectionsService.LastSqlUpdate = DateTime.Now;
                }

                // re-enable sql update checking after updates are loaded
                ConnectionsService.RemoteConnectionsSyncronizer?.Enable();
            }
            catch (Exception ex)
            {
                if (Settings.Default.UseSQLServer)
                {
                    MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex);
                    var commandButtons = string.Join("|", Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName));
                    CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error);
                    switch (CTaskDialog.CommandButtonResult)
                    {
                    case 0:
                        LoadConnections(withDialog);
                        return;

                    case 1:
                        Settings.Default.UseSQLServer = false;
                        LoadConnections(true);
                        return;

                    default:
                        Application.Exit();
                        return;
                    }
                }
                if (ex is FileNotFoundException && !withDialog)
                {
                    MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionFileName), ex, MessageClass.InformationMsg);

                    string[] commandButtons =
                    {
                        Language.ConfigurationCreateNew,
                        Language.ConfigurationCustomPath,
                        Language.ConfigurationImportFile,
                        Language.strMenuExit
                    };

                    var answered = false;
                    while (!answered)
                    {
                        try
                        {
                            CTaskDialog.ShowTaskDialogBox(
                                GeneralAppInfo.ProductName,
                                Language.ConnectionFileNotFound,
                                "", "", "", "", "",
                                string.Join(" | ", commandButtons),
                                ETaskDialogButtons.None,
                                ESysIcons.Question,
                                ESysIcons.Question);

                            switch (CTaskDialog.CommandButtonResult)
                            {
                            case 0:
                                ConnectionsService.NewConnectionsFile(connectionFileName);
                                answered = true;
                                break;

                            case 1:
                                LoadConnections(true);
                                answered = true;
                                break;

                            case 2:
                                ConnectionsService.NewConnectionsFile(connectionFileName);
                                Import.ImportFromFile(ConnectionsService.ConnectionTreeModel.RootNodes[0]);
                                answered = true;
                                break;

                            case 3:
                                Application.Exit();
                                answered = true;
                                break;
                            }
                        }
                        catch (Exception exc)
                        {
                            MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionFileName), exc, MessageClass.InformationMsg);
                        }
                    }
                    return;
                }

                MessageCollector.AddExceptionStackTrace(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionFileName), ex);
                if (connectionFileName != ConnectionsService.GetStartupConnectionFileName())
                {
                    LoadConnections(withDialog);
                }
                else
                {
                    MessageBox.Show(FrmMain.Default,
                                    string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, ConnectionsService.GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)),
                                    @"Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
            }
        }
Пример #20
0
        public void LoadFromSql()
        {
            if (Windows.treeForm == null || Windows.treeForm.tvConnections == null)
            {
                return;
            }
            if (Windows.treeForm.tvConnections.InvokeRequired)
            {
                Windows.treeForm.tvConnections.Invoke(new LoadFromSqlDelegate(LoadFromSql));
                return;
            }

            try
            {
                Runtime.IsConnectionsFileLoaded = false;
                _sqlConnection = !string.IsNullOrEmpty(DatabaseUsername) ? new SqlConnection("Data Source=" + DatabaseHost + ";Initial Catalog=" + DatabaseName + ";User Id=" + DatabaseUsername + ";Password="******"Data Source=" + DatabaseHost + ";Initial Catalog=" + DatabaseName + ";Integrated Security=True");

                _sqlConnection.Open();
                _sqlQuery      = new SqlCommand("SELECT * FROM tblRoot", _sqlConnection);
                _sqlDataReader = _sqlQuery.ExecuteReader(CommandBehavior.CloseConnection);
                _sqlDataReader.Read();

                if (_sqlDataReader.HasRows == false)
                {
                    Runtime.SaveConnections();
                    _sqlQuery      = new SqlCommand("SELECT * FROM tblRoot", _sqlConnection);
                    _sqlDataReader = _sqlQuery.ExecuteReader(CommandBehavior.CloseConnection);
                    _sqlDataReader.Read();
                }

                _confVersion = Convert.ToDouble(_sqlDataReader["confVersion"], CultureInfo.InvariantCulture);
                const double maxSupportedSchemaVersion = 2.5;
                if (_confVersion > maxSupportedSchemaVersion)
                {
                    CTaskDialog.ShowTaskDialogBox(
                        frmMain.Default,
                        Application.ProductName,
                        "Incompatible database schema",
                        $"The database schema on the server is not supported. Please upgrade to a newer version of {Application.ProductName}.",
                        string.Format("Schema Version: {1}{0}Highest Supported Version: {2}", Environment.NewLine, _confVersion, maxSupportedSchemaVersion),
                        "",
                        "",
                        "",
                        "",
                        ETaskDialogButtons.Ok,
                        ESysIcons.Error,
                        ESysIcons.Error
                        );
                    throw (new Exception($"Incompatible database schema (schema version {_confVersion})."));
                }

                RootTreeNode.Name = Convert.ToString(_sqlDataReader["Name"]);

                var rootInfo = new RootNodeInfo(RootNodeType.Connection)
                {
                    Name     = RootTreeNode.Name,
                    TreeNode = RootTreeNode
                };

                RootTreeNode.Tag                = rootInfo;
                RootTreeNode.ImageIndex         = (int)TreeImageType.Root;
                RootTreeNode.SelectedImageIndex = (int)TreeImageType.Root;

                var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                if (cryptographyProvider.Decrypt(Convert.ToString(_sqlDataReader["Protected"]), _pW) != "ThisIsNotProtected")
                {
                    if (Authenticate(Convert.ToString(_sqlDataReader["Protected"]), false, rootInfo) == false)
                    {
                        mRemoteNG.Settings.Default.LoadConsFromCustomLocation = false;
                        mRemoteNG.Settings.Default.CustomConsPath             = "";
                        RootTreeNode.Remove();
                        return;
                    }
                }

                _sqlDataReader.Close();
                Windows.treeForm.tvConnections.BeginUpdate();

                // SECTION 3. Populate the TreeView with the DOM nodes.
                AddNodesFromSql(RootTreeNode);
                RootTreeNode.Expand();

                //expand containers
                foreach (ContainerInfo contI in ContainerList)
                {
                    if (contI.IsExpanded)
                    {
                        contI.TreeNode.Expand();
                    }
                }

                Windows.treeForm.tvConnections.EndUpdate();

                //open connections from last mremote session
                if (mRemoteNG.Settings.Default.OpenConsFromLastSession && !mRemoteNG.Settings.Default.NoReconnect)
                {
                    foreach (ConnectionInfo conI in ConnectionList)
                    {
                        if (conI.PleaseConnect)
                        {
                            Runtime.OpenConnection(conI);
                        }
                    }
                }

                Runtime.IsConnectionsFileLoaded = true;
                Windows.treeForm.InitialRefresh();
                SetSelectedNode(_selectedTreeNode);
            }
            finally
            {
                _sqlConnection?.Close();
            }
        }
Пример #21
0
        public static void LoadConnections(bool withDialog = false, bool update = false)
        {
            var connectionsLoader = new ConnectionsLoader();

            try
            {
                // disable sql update checking while we are loading updates
                SQLConnProvider?.Disable();

                if (ConnectionList != null && ContainerList != null)
                {
                    PreviousConnectionList = ConnectionList.Copy();
                    PreviousContainerList  = ContainerList.Copy();
                }

                ConnectionList = new ConnectionList();
                ContainerList  = new ContainerList();

                if (!Settings.Default.UseSQLServer)
                {
                    if (withDialog)
                    {
                        var loadDialog = Tools.Controls.ConnectionsLoadDialog();
                        if (loadDialog.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }
                        connectionsLoader.ConnectionFileName = loadDialog.FileName;
                    }
                    else
                    {
                        connectionsLoader.ConnectionFileName = GetStartupConnectionFileName();
                    }

                    CreateBackupFile(Convert.ToString(connectionsLoader.ConnectionFileName));
                }

                connectionsLoader.ConnectionList = ConnectionList;
                connectionsLoader.ContainerList  = ContainerList;

                if (PreviousConnectionList != null && PreviousContainerList != null)
                {
                    connectionsLoader.PreviousConnectionList = PreviousConnectionList;
                    connectionsLoader.PreviousContainerList  = PreviousContainerList;
                }

                if (update)
                {
                    connectionsLoader.PreviousSelected = LastSelected;
                }

                ConnectionTree.ResetTree();

                connectionsLoader.RootTreeNode     = Windows.treeForm.tvConnections.Nodes[0];
                connectionsLoader.UseDatabase      = Settings.Default.UseSQLServer;
                connectionsLoader.DatabaseHost     = Settings.Default.SQLHost;
                connectionsLoader.DatabaseName     = Settings.Default.SQLDatabaseName;
                connectionsLoader.DatabaseUsername = Settings.Default.SQLUser;
                var cryptographyProvider = new LegacyRijndaelCryptographyProvider();
                connectionsLoader.DatabasePassword = cryptographyProvider.Decrypt(Convert.ToString(Settings.Default.SQLPass), GeneralAppInfo.EncryptionKey);
                connectionsLoader.DatabaseUpdate   = update;
                connectionsLoader.LoadConnections(false);

                if (Settings.Default.UseSQLServer)
                {
                    LastSqlUpdate = DateTime.Now;
                }
                else
                {
                    if (connectionsLoader.ConnectionFileName == GetDefaultStartupConnectionFileName())
                    {
                        Settings.Default.LoadConsFromCustomLocation = false;
                    }
                    else
                    {
                        Settings.Default.LoadConsFromCustomLocation = true;
                        Settings.Default.CustomConsPath             = connectionsLoader.ConnectionFileName;
                    }
                }

                // re-enable sql update checking after updates are loaded
                SQLConnProvider?.Enable();
            }
            catch (Exception ex)
            {
                if (Settings.Default.UseSQLServer)
                {
                    MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex);
                    var commandButtons = string.Join("|", Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName));
                    CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error);
                    switch (CTaskDialog.CommandButtonResult)
                    {
                    case 0:
                        LoadConnections(withDialog, update);
                        return;

                    case 1:
                        Settings.Default.UseSQLServer = false;
                        LoadConnections(true, update);
                        return;

                    default:
                        Application.Exit();
                        return;
                    }
                }
                if (ex is FileNotFoundException && !withDialog)
                {
                    MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionsLoader.ConnectionFileName), ex, MessageClass.InformationMsg);
                    NewConnections(Convert.ToString(connectionsLoader.ConnectionFileName));
                    return;
                }

                MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionsLoader.ConnectionFileName), ex);
                if (connectionsLoader.ConnectionFileName != GetStartupConnectionFileName())
                {
                    LoadConnections(withDialog, update);
                }
                else
                {
                    MessageBox.Show(frmMain.Default,
                                    string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)),
                                    "Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
            }
        }