Exemple #1
0
        public ConnectionTreeModel Deserialize(bool import)
        {
            try
            {
                if (!import)
                {
                    Runtime.IsConnectionsFileLoaded = false;
                }

                var rootXmlElement = _xmlDocument.DocumentElement;
                CreateDecryptor(rootXmlElement);
                var rootInfo            = InitializeRootNode(rootXmlElement);
                var connectionTreeModel = new ConnectionTreeModel();
                connectionTreeModel.AddRootNode(rootInfo);


                if (_confVersion > 1.3)
                {
                    var protectedString = _xmlDocument.DocumentElement?.Attributes["Protected"].Value;
                    if (!_decryptor.ConnectionsFileIsAuthentic(protectedString, Runtime.EncryptionKey, rootInfo))
                    {
                        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, rootInfo);

                if (!import)
                {
                    Runtime.IsConnectionsFileLoaded = true;
                }

                return(connectionTreeModel);
            }
            catch (Exception ex)
            {
                Runtime.IsConnectionsFileLoaded = false;
                Runtime.MessageCollector.AddExceptionStackTrace(Language.strLoadFromXmlFailed, ex);
                throw;
            }
        }
        public ConnectionTreeModel Deserialize(bool import)
        {
            try
            {
                if (!import)
                {
                    Runtime.IsConnectionsFileLoaded = false;
                }

                var rootInfo            = InitializeRootNode();
                var connectionTreeModel = new ConnectionTreeModel();
                connectionTreeModel.AddRootNode(rootInfo);

                if (_confVersion > 1.3)
                {
                    var protectedString = _xmlDocument.DocumentElement?.Attributes["Protected"].Value;
                    if (!_decryptor.ConnectionsFileIsAuthentic(protectedString, rootInfo))
                    {
                        mRemoteNG.Settings.Default.LoadConsFromCustomLocation = false;
                        mRemoteNG.Settings.Default.CustomConsPath             = "";
                        return(null);
                    }
                }

                if (import && !IsExportFile())
                {
                    Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strCannotImportNormalSessionFile);
                    return(null);
                }

                AddNodesFromXmlRecursive(_xmlDocument.DocumentElement, rootInfo);
                //Windows.treeForm.InitialRefresh();
                //SetSelectedNode(RootTreeNode);

                if (!import)
                {
                    Runtime.IsConnectionsFileLoaded = true;
                }

                return(connectionTreeModel);
            }
            catch (Exception ex)
            {
                Runtime.IsConnectionsFileLoaded = false;
                Runtime.MessageCollector.AddExceptionStackTrace(Language.strLoadFromXmlFailed, ex);
                throw;
            }
        }