Example #1
0
        private void LoadSettings(string DestinationDbConn)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(_xml);

            // Retrieve source DB setting
            var sourceDBNode = doc.SelectSingleNode("settings/source-db");

            if (sourceDBNode == null)
            {
                throw new Exception("Cannot find source DB setting.");
            }
            _sourceDb = LoadDbInfo(sourceDBNode);

            // Retrieve destination setting
            var destinationDBNode = doc.SelectSingleNode("settings/destination-db");

            if (destinationDBNode == null)
            {
                throw new Exception("Cannot find destination DB setting.");
            }
            _destinationDb = LoadDbInfo(destinationDBNode);
            if (DestinationDbConn != string.Empty)
            {
                this._destinationDb.Conn = DestinationDbConn;                                   //read from outside
            }
            // Retrieve sql command timeout setting
            var sqlCommandTimeoutNode = doc.SelectSingleNode("settings/sql-command-timeout");

            if (sqlCommandTimeoutNode != null)
            {
                int timeout = 0;
                if (int.TryParse(sqlCommandTimeoutNode.InnerText, out timeout))
                {
                    _sqlCommandTimeout = timeout;
                }
            }

            var tableMappingNodes = doc.SelectNodes("settings/mappings/table-mapping");

            if (tableMappingNodes != null)
            {
                foreach (XmlNode tableMappingNode in tableMappingNodes)
                {
                    _tableMappings.Add(GetTableMapping(tableMappingNode));//获取所有的表名称
                }
            }
            var postSyncTaskNodes = doc.SelectNodes("settings/post-sync-tasks/task");
            if (postSyncTaskNodes != null)
            {
                foreach (XmlNode postSyncTaskNode in postSyncTaskNodes)
                {
                    _postSyncTasks.Add(GetTask(postSyncTaskNode));
                }
            }

            var assetIdNodes = doc.SelectNodes("settings/custom-bonds/asset-id");
            if (assetIdNodes != null)
            {
                foreach (XmlNode assetIdNode in assetIdNodes)
                {
                    _customBonds.Add(assetIdNode.InnerText);
                }
            }

            var dateKeyNode = doc.SelectSingleNode("settings/date-key");
            if (dateKeyNode != null)
            {
                var tableNode = dateKeyNode.SelectSingleNode("table");
                if (tableNode != null)
                {
                    _dateKeyTable = tableNode.InnerText;
                }
                var columnNode = dateKeyNode.SelectSingleNode("column");
                if (columnNode != null)
                {
                    _dateKeyColumn = columnNode.InnerText;
                }
            }
            var deltaHourNode = doc.SelectSingleNode("settings/delta-hours");
            if (deltaHourNode != null)
            {
                try
                {
                    _deltaHours = int.Parse(deltaHourNode.InnerText);
                }
                catch (Exception e)
                {
                    _deltaHours = 0;
                    Console.WriteLine("delta-hours invalid.");
                }
            }
        }
Example #2
0
        private void LoadSettings()
        {
            var doc = new XmlDocument();

            doc.LoadXml(_xml);

            // Retrieve source DB setting
            var sourceDbNode = doc.SelectSingleNode("settings/source-db");

            if (sourceDbNode == null)
            {
                throw new Exception("Cannot find source DB setting.");
            }
            _sourceDb = LoadDbInfo(sourceDbNode);


            // Retrieve sql command timeout setting
            var sqlCommandTimeoutNode = doc.SelectSingleNode("settings/sql-command-timeout");

            if (sqlCommandTimeoutNode != null)
            {
                int timeout;
                if (int.TryParse(sqlCommandTimeoutNode.InnerText, out timeout))
                {
                    _sqlCommandTimeout = timeout;
                }
            }

            var fileSavePath = doc.SelectSingleNode("settings/fileSavePath");

            if (fileSavePath != null)
            {
                _fileSavePath = fileSavePath.InnerText;
            }

            var hostName = doc.SelectSingleNode("settings/hostname");

            if (hostName != null)
            {
                _hostname = hostName.InnerText;
            }

            var userName = doc.SelectSingleNode("settings/username");

            if (userName != null)
            {
                _username = userName.InnerText;
            }

            var password = doc.SelectSingleNode("settings/password");

            if (password != null)
            {
                _password = password.InnerText;
            }

            var targetDir = doc.SelectSingleNode("settings/targetDir");

            if (targetDir != null)
            {
                _targetDir = targetDir.InnerText;
            }

            var fileName = doc.SelectSingleNode("settings/fileName");

            if (fileName != null)
            {
                _fileName = fileName.InnerText;
            }

            var tableMappingNodes = doc.SelectNodes("settings/mappings/table-mapping");

            if (tableMappingNodes != null)
            {
                foreach (XmlNode tableMappingNode in tableMappingNodes)
                {
                    _tableMappings.Add(GetTableMapping(tableMappingNode));//获取所有的表名称
                }
            }
        }