private ConnectionTreeModel SetupConnectionTreeModel() { /* * Root * |--- con0 * |--- folder1 * | L--- con1 * L--- folder2 * |--- con2 * L--- folder3 * |--- con3 * L--- con4 */ BuildTreeNodes(); var connectionTreeModel = new ConnectionTreeModel(); var rootNode = new RootNodeInfo(RootNodeType.Connection); rootNode.AddChild(_folder1); rootNode.AddChild(_folder2); rootNode.AddChild(_con0); _folder1.AddChild(_con1); _folder2.AddChild(_con2); _folder2.AddChild(_folder3); _folder3.AddChild(_con3); _folder3.AddChild(_con4); connectionTreeModel.AddRootNode(rootNode); return(connectionTreeModel); }
/// <summary> /// Saves the given <see cref="ConnectionTreeModel"/>. /// If <see cref="useDatabase"/> is true, <see cref="connectionFileName"/> is ignored /// </summary> /// <param name="connectionTreeModel"></param> /// <param name="useDatabase"></param> /// <param name="saveFilter"></param> /// <param name="connectionFileName"></param> /// <param name="forceSave">Bypasses safety checks that prevent saving if a connection file isn't loaded.</param> /// <param name="propertyNameTrigger"> /// Optional. The name of the property that triggered /// this save. /// </param> public void SaveConnections(ConnectionTreeModel connectionTreeModel, bool useDatabase, SaveFilter saveFilter, string connectionFileName, bool forceSave = false, string propertyNameTrigger = "") { if (connectionTreeModel == null) { return; } if (!forceSave && !IsConnectionsFileLoaded) { return; } if (_batchingSaves) { _saveRequested = true; return; } try { Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, "Saving connections..."); RemoteConnectionsSyncronizer?.Disable(); var previouslyUsingDatabase = UsingDatabase; var saver = useDatabase ? (ISaver <ConnectionTreeModel>) new SqlConnectionsSaver(saveFilter, _localConnectionPropertiesSerializer, _localConnectionPropertiesDataProvider) : new XmlConnectionsSaver(connectionFileName, saveFilter); saver.Save(connectionTreeModel, propertyNameTrigger); if (UsingDatabase) { LastSqlUpdate = DateTime.Now; } UsingDatabase = useDatabase; ConnectionFileName = connectionFileName; RaiseConnectionsSavedEvent(connectionTreeModel, previouslyUsingDatabase, UsingDatabase, connectionFileName); Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, "Successfully saved connections"); } catch (Exception ex) { Runtime.MessageCollector?.AddExceptionMessage( string.Format(Language.strConnectionsFileCouldNotSaveAs, connectionFileName), ex, logOnly: false); } finally { RemoteConnectionsSyncronizer?.Enable(); } }
public void ReturnsEmptyDataTableWhenGivenEmptyConnectionTreeModel() { var model = new ConnectionTreeModel(); var dataTable = _dataTableSerializer.Serialize(model); Assert.That(dataTable.Rows.Count, Is.EqualTo(0)); }
public void ExpandingAllItemsUpdatesColumnWidthAppropriately() { var connectionTreeModel = new ConnectionTreeModel(); var root = new RootNodeInfo(RootNodeType.Connection); connectionTreeModel.AddRootNode(root); ContainerInfo parent = root; foreach (var i in Enumerable.Repeat("", 8)) { var newContainer = new ContainerInfo { IsExpanded = false }; parent.AddChild(newContainer); parent = newContainer; } _connectionTree.ConnectionTreeModel = connectionTreeModel; var widthBefore = _connectionTree.Columns[0].Width; _connectionTree.ExpandAll(); var widthAfter = _connectionTree.Columns[0].Width; Assert.That(widthAfter, Is.GreaterThan(widthBefore)); }
public ConnectionsLoadedEventArgs(Optional <ConnectionTreeModel> previousTreeModelModel, ConnectionTreeModel newTreeModelModel, bool previousSourceWasDatabase, bool newSourceIsDatabase, string newSourcePath) { if (previousTreeModelModel == null) { throw new ArgumentNullException(nameof(previousTreeModelModel)); } if (newTreeModelModel == null) { throw new ArgumentNullException(nameof(newTreeModelModel)); } if (newSourcePath == null) { throw new ArgumentNullException(nameof(newSourcePath)); } PreviousConnectionTreeModel = previousTreeModelModel; PreviousSourceWasDatabase = previousSourceWasDatabase; NewConnectionTreeModel = newTreeModelModel; NewSourceIsDatabase = newSourceIsDatabase; NewSourcePath = newSourcePath; }
private ConnectionTreeModel CreateConnectionTreeModel() { var connectionTreeModel = new ConnectionTreeModel(); connectionTreeModel.AddRootNode(new RootNodeInfo(RootNodeType.Connection)); return(connectionTreeModel); }
public void Setup() { var encryptor = new AeadCryptographyProvider(); _serializer = new XmlConnectionsSerializer(encryptor); _connectionTreeModel = SetupConnectionTreeModel(); }
public ConnectionTreeModel Deserialize() { var connectionTreeModel = new ConnectionTreeModel(); var root = new RootNodeInfo(RootNodeType.Connection); connectionTreeModel.AddRootNode(root); var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(_puttycmConnectionsXml); var configurationNode = xmlDocument.SelectSingleNode("/configuration"); var rootNodes = configurationNode?.SelectNodes("./root"); if (rootNodes == null) { return(connectionTreeModel); } foreach (XmlNode rootNode in rootNodes) { ImportRootOrContainer(rootNode, root); } return(connectionTreeModel); }
public void OnetimeSetup() { var connectionFileContents = Resources.test_remotedesktopconnection_rdp; _deserializer = new RemoteDesktopConnectionDeserializer(); _connectionTreeModel = _deserializer.Deserialize(connectionFileContents); }
private ConnectionTreeModel CreateNodeHierarchy(List <ConnectionInfo> connectionList) { var connectionTreeModel = new ConnectionTreeModel(); var rootNode = new RootNodeInfo(RootNodeType.Connection) { ConstantID = "0" }; connectionTreeModel.AddRootNode(rootNode); foreach (DataRow row in _dataTable.Rows) { var id = (string)row["ConstantID"]; var connectionInfo = connectionList.First(node => node.ConstantID == id); var parentId = (string)row["ParentID"]; if (parentId == "0") { rootNode.AddChild(connectionInfo); } else { (connectionList.First(node => node.ConstantID == parentId) as ContainerInfo)?.AddChild(connectionInfo); } } return(connectionTreeModel); }
public ConnectionTreeModel Deserialize() { var connectionTreeModel = new ConnectionTreeModel(); var root = new RootNodeInfo(RootNodeType.Connection); connectionTreeModel.AddRootNode(root); var connectionInfo = new ConnectionInfo(); foreach (var line in _fileContent) { var parts = line.Split(new[] { ':' }, 3); if (parts.Length < 3) { continue; } var key = parts[0]; var value = parts[2]; SetConnectionInfoParameter(connectionInfo, key, value); } root.AddChild(connectionInfo); return(connectionTreeModel); }
/// <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); }
public void Setup() { _connectionTreeModel = CreateConnectionTreeModel(); _connectionTree = new ConnectionTree { PostSetupActions = new IConnectionTreeDelegate[] { new RootNodeExpander() } }; }
private void PopulateTreeView(ConnectionTreeModel newModel) { SetObjects(newModel.RootNodes); RegisterModelUpdateHandlers(newModel); NodeSearcher = new NodeSearcher(newModel); ExecutePostSetupActions(); AutoResizeColumn(Columns[0]); }
public string Serialize(ConnectionTreeModel connectionTreeModel) { connectionTreeModel.ThrowIfNull(nameof(connectionTreeModel)); var rootNode = connectionTreeModel.RootNodes.First(node => node is RootNodeInfo); return(Serialize(rootNode)); }
public void Setup() { _cryptographyProvider = new CryptographyProviderFactory().CreateAeadCryptographyProvider(BlockCipherEngines.AES, BlockCipherModes.GCM); var saveFilter = new SaveFilter(); _documentCompiler = new XmlConnectionsDocumentCompiler(_cryptographyProvider, saveFilter); _connectionTreeModel = SetupConnectionTreeModel(); }
public void Setup(string confCons, string password) { _xmlConnectionsDeserializer = new XmlConnectionsDeserializer(confCons) { AuthenticationRequestor = password.ConvertToSecureString }; _connectionTreeModel = _xmlConnectionsDeserializer.Deserialize(); }
public ConnectionTreeModel Deserialize(bool import) { try { if (!import) { Runtime.IsConnectionsFileLoaded = false; } var rootXmlElement = _xmlDocument.DocumentElement; _rootNodeInfo = InitializeRootNode(rootXmlElement); CreateDecryptor(_rootNodeInfo, rootXmlElement); var connectionTreeModel = new ConnectionTreeModel(); connectionTreeModel.AddRootNode(_rootNodeInfo); if (_confVersion > 1.3) { var protectedString = _xmlDocument.DocumentElement?.Attributes["Protected"].Value; if (!_decryptor.ConnectionsFileIsAuthentic(protectedString, _rootNodeInfo.PasswordString.ConvertToSecureString())) { mRemoteNG.Settings.Default.LoadConsFromCustomLocation = false; mRemoteNG.Settings.Default.CustomConsPath = ""; return(null); } } if (_confVersion >= 2.6) { if (rootXmlElement?.Attributes["FullFileEncryption"].Value == "True") { var decryptedContent = _decryptor.Decrypt(rootXmlElement.InnerText); rootXmlElement.InnerXml = decryptedContent; } } if (import && !IsExportFile(rootXmlElement)) { Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strCannotImportNormalSessionFile); return(null); } AddNodesFromXmlRecursive(_xmlDocument.DocumentElement, _rootNodeInfo); if (!import) { Runtime.IsConnectionsFileLoaded = true; } return(connectionTreeModel); } catch (Exception ex) { Runtime.IsConnectionsFileLoaded = false; Runtime.MessageCollector.AddExceptionStackTrace(Language.strLoadFromXmlFailed, ex); throw; } }
public static void ExportToFile(ConnectionInfo selectedNode, ConnectionTreeModel connectionTreeModel) { try { var saveFilter = new SaveFilter(); using (var exportForm = new ExportForm()) { if (selectedNode?.GetTreeNodeType() == TreeNodeType.Container) { exportForm.SelectedFolder = selectedNode as ContainerInfo; } else if (selectedNode?.GetTreeNodeType() == TreeNodeType.Connection) { if (selectedNode.Parent.GetTreeNodeType() == TreeNodeType.Container) { exportForm.SelectedFolder = selectedNode.Parent; } exportForm.SelectedConnection = selectedNode; } if (exportForm.ShowDialog(FrmMain.Default) != DialogResult.OK) { return; } ConnectionInfo exportTarget; switch (exportForm.Scope) { case ExportForm.ExportScope.SelectedFolder: exportTarget = exportForm.SelectedFolder; break; case ExportForm.ExportScope.SelectedConnection: exportTarget = exportForm.SelectedConnection; break; default: exportTarget = connectionTreeModel.RootNodes.First(node => node is RootNodeInfo); break; } saveFilter.SaveUsername = exportForm.IncludeUsername; saveFilter.SavePassword = exportForm.IncludePassword; saveFilter.SaveDomain = exportForm.IncludeDomain; saveFilter.SaveInheritance = exportForm.IncludeInheritance; saveFilter.SaveCredentialId = exportForm.IncludeAssignedCredential; SaveExportFile(exportForm.FileName, exportForm.SaveFormat, saveFilter, exportTarget); } } catch (Exception ex) { Runtime.MessageCollector.AddExceptionMessage("App.Export.ExportToFile() failed.", ex); } }
private void RaiseConnectionsSavedEvent(ConnectionTreeModel modelThatWasSaved, bool previouslyUsingDatabase, bool usingDatabase, string connectionFileName) { ConnectionsSaved?.Invoke(this, new ConnectionsSavedEventArgs(modelThatWasSaved, previouslyUsingDatabase, usingDatabase, connectionFileName)); }
public void Setup() { _connectionTreeModel = SetupConnectionTreeModel(); _cryptographyProvider = new AeadCryptographyProvider(); var connectionNodeSerializer = new XmlConnectionNodeSerializer27( _cryptographyProvider, _connectionTreeModel.RootNodes.OfType <RootNodeInfo>().First().PasswordString.ConvertToSecureString(), new SaveFilter()); _serializer = new XmlConnectionsSerializer(_cryptographyProvider, connectionNodeSerializer); }
private ConnectionTreeModel SetupConnectionTreeModel() { /* * Tree: * Root * |--- folder1 (description1, hostname1) * | |--- con1 (description2, hostname2) * | L--- con2 (description3, hostname3) * |--- folder2 (description4, hostname4) * | |--- con3 (description5, hostname5) * | L--- con4 (description6, hostname6) * L--- con5 (description7, hostname7) * */ var connectionTreeModel = new ConnectionTreeModel(); var root = new RootNodeInfo(RootNodeType.Connection); _folder1 = new ContainerInfo { Name = "folder1", Description = "description1", Hostname = "hostname1" }; _con1 = new ConnectionInfo { Name = "con1", Description = "description2", Hostname = "hostname2" }; _con2 = new ConnectionInfo { Name = "con2", Description = "description3", Hostname = "hostname3" }; _folder2 = new ContainerInfo { Name = "folder2", Description = "description4", Hostname = "hostname4" }; _con3 = new ConnectionInfo { Name = "con3", Description = "description5", Hostname = "hostname5" }; _con4 = new ConnectionInfo { Name = "con4", Description = "description6", Hostname = "hostname6" }; _con5 = new ConnectionInfo { Name = "con5", Description = "description7", Hostname = "hostname7" }; _folder1.Inheritance.TurnOffInheritanceCompletely(); _con1.Inheritance.TurnOffInheritanceCompletely(); _con2.Inheritance.TurnOffInheritanceCompletely(); _folder2.Inheritance.TurnOffInheritanceCompletely(); _con3.Inheritance.TurnOffInheritanceCompletely(); _con4.Inheritance.TurnOffInheritanceCompletely(); _con5.Inheritance.TurnOffInheritanceCompletely(); connectionTreeModel.AddRootNode(root); root.AddChildRange(new [] { _folder1, _folder2, _con5 }); _folder1.AddChildRange(new [] { _con1, _con2 }); _folder2.AddChildRange(new[] { _con3, _con4 }); return(connectionTreeModel); }
public void Setup() { _connectionTreeModel = SetupConnectionTreeModel(); _cryptographyProvider = new CryptoProviderFactory(BlockCipherEngines.AES, BlockCipherModes.GCM).Build(); var connectionNodeSerializer = new XmlConnectionNodeSerializer27( _cryptographyProvider, _connectionTreeModel.RootNodes.OfType <RootNodeInfo>().First().PasswordString.ConvertToSecureString(), new SaveFilter()); _documentCompiler = new XmlConnectionsDocumentCompiler(_cryptographyProvider, connectionNodeSerializer); }
public ConnectionTreeModel Deserialize() { var connectionTreeModel = new ConnectionTreeModel(); var root = new RootNodeInfo(RootNodeType.Connection); connectionTreeModel.AddRootNode(root); ImportContainers(_ldapPath, root); return(connectionTreeModel); }
public void RenamingNodeWithNothingSelectedDoesNothing() { var connectionTreeModel = new ConnectionTreeModel(); var root = new RootNodeInfo(RootNodeType.Connection); connectionTreeModel.AddRootNode(root); _connectionTree.ConnectionTreeModel = connectionTreeModel; _connectionTree.SelectedObject = null; Assert.DoesNotThrow(() => _connectionTree.RenameSelectedNode()); }
public ConnectionsSavedEventArgs(ConnectionTreeModel modelThatWasSaved, bool previouslyUsingDatabase, bool usingDatabase, string connectionFileName) { if (modelThatWasSaved == null) { throw new ArgumentNullException(nameof(modelThatWasSaved)); } ModelThatWasSaved = modelThatWasSaved; PreviouslyUsingDatabase = previouslyUsingDatabase; UsingDatabase = usingDatabase; ConnectionFileName = connectionFileName; }
public void Setup() { _originalModel = SetupConnectionTreeModel(); var cryptoProvider = _cryptoFactory.Build(); var nodeSerializer = new XmlConnectionNodeSerializer27( cryptoProvider, _originalModel.RootNodes.OfType <RootNodeInfo>().First().PasswordString.ConvertToSecureString(), new SaveFilter()); _serializer = new XmlConnectionsSerializer(cryptoProvider, nodeSerializer); _deserializer = new XmlConnectionsDeserializer(); }
private void UnregisterModelUpdateHandlers(ConnectionTreeModel oldConnectionTreeModel) { _puttySessionsManager.PuttySessionsCollectionChanged -= OnPuttySessionsCollectionChanged; if (oldConnectionTreeModel == null) { return; } oldConnectionTreeModel.CollectionChanged -= HandleCollectionChanged; oldConnectionTreeModel.PropertyChanged -= HandleCollectionPropertyChanged; }
public void CannotDuplicateRootPuttyNode() { var connectionTreeModel = new ConnectionTreeModel(); var puttyRoot = new RootNodeInfo(RootNodeType.PuttySessions); connectionTreeModel.AddRootNode(puttyRoot); _connectionTree.ConnectionTreeModel = connectionTreeModel; _connectionTree.SelectedObject = puttyRoot; _connectionTree.DuplicateSelectedNode(); Assert.That(connectionTreeModel.RootNodes, Has.One.Items); }
public void DuplicatingWithNoNodeSelectedDoesNothing() { var connectionTreeModel = new ConnectionTreeModel(); var puttyRoot = new RootNodeInfo(RootNodeType.PuttySessions); connectionTreeModel.AddRootNode(puttyRoot); _connectionTree.ConnectionTreeModel = connectionTreeModel; _connectionTree.SelectedObject = null; _connectionTree.DuplicateSelectedNode(); Assert.That(connectionTreeModel.RootNodes, Has.One.Items); }