/// <summary>
        /// Load connections from a source. <see cref="connectionFileName"/> is ignored if
        /// <see cref="useDatabase"/> is true.
        /// </summary>
        /// <param name="useDatabase"></param>
        /// <param name="import"></param>
        /// <param name="connectionFileName"></param>
        public void LoadConnections(bool useDatabase, bool import, string connectionFileName)
        {
            var oldConnectionTreeModel  = ConnectionTreeModel;
            var oldIsUsingDatabaseValue = UsingDatabase;

            var newConnectionTreeModel = useDatabase
                ? new SqlConnectionsLoader().Load()
                : new XmlConnectionsLoader(connectionFileName).Load();

            if (newConnectionTreeModel == null)
            {
                DialogFactory.ShowLoadConnectionsFailedDialog(connectionFileName, "Decrypting connection file failed", IsConnectionsFileLoaded);
                return;
            }

            IsConnectionsFileLoaded = true;
            ConnectionFileName      = connectionFileName;
            UsingDatabase           = useDatabase;

            if (!import)
            {
                _puttySessionsManager.AddSessions();
                newConnectionTreeModel.RootNodes.AddRange(_puttySessionsManager.RootPuttySessionsNodes);
            }

            ConnectionTreeModel = newConnectionTreeModel;
            UpdateCustomConsPathSetting(connectionFileName);
            RaiseConnectionsLoadedEvent(oldConnectionTreeModel, newConnectionTreeModel, oldIsUsingDatabaseValue, useDatabase, connectionFileName);
        }
Exemple #2
0
        /// <summary>
        /// Load connections from a source. <see cref="connectionFileName"/> is ignored if
        /// <see cref="useDatabase"/> is true.
        /// </summary>
        /// <param name="useDatabase"></param>
        /// <param name="import"></param>
        /// <param name="connectionFileName"></param>
        public void LoadConnections(bool useDatabase, bool import, string connectionFileName)
        {
            var oldConnectionTreeModel  = ConnectionTreeModel;
            var oldIsUsingDatabaseValue = UsingDatabase;

            var connectionLoader = useDatabase
                ? (IConnectionsLoader) new SqlConnectionsLoader(_localConnectionPropertiesSerializer,
                                                                _localConnectionPropertiesDataProvider)
                : new XmlConnectionsLoader(connectionFileName);

            var newConnectionTreeModel = connectionLoader.Load();

            if (useDatabase)
            {
                LastSqlUpdate = DateTime.Now;
            }

            if (newConnectionTreeModel == null)
            {
                DialogFactory.ShowLoadConnectionsFailedDialog(connectionFileName, "Decrypting connection file failed",
                                                              IsConnectionsFileLoaded);
                return;
            }

            IsConnectionsFileLoaded = true;
            ConnectionFileName      = connectionFileName;
            UsingDatabase           = useDatabase;

            if (!import)
            {
                _puttySessionsManager.AddSessions();
                newConnectionTreeModel.RootNodes.AddRange(_puttySessionsManager.RootPuttySessionsNodes);
            }

            ConnectionTreeModel = newConnectionTreeModel;
            UpdateCustomConsPathSetting(connectionFileName);
            RaiseConnectionsLoadedEvent(oldConnectionTreeModel, newConnectionTreeModel, oldIsUsingDatabaseValue,
                                        useDatabase, connectionFileName);
            Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg,
                                                $"Connections loaded using {connectionLoader.GetType().Name}");
        }