/// <summary>
        ///     Returns a clone of the existing Config section
        /// </summary>
        /// <returns>Cloned object</returns>
        public object Clone()
        {
            var section = new SyncConfigurationSection();

            // Clonet TargetDatabases
            foreach (TargetDatabaseConfigElement elem in Databases)
            {
                section.Databases.Add((TargetDatabaseConfigElement)elem.Clone());
            }

            // Clone SyncConfigs
            foreach (SyncScopeConfigElement elem in SyncScopes)
            {
                section.SyncScopes.Add((SyncScopeConfigElement)elem.Clone());
            }
            return(section);
        }
        /// <summary>
        /// Returns a clone of the existing Config section
        /// </summary>
        /// <returns>Cloned object</returns>
        public object Clone()
        {
            SyncConfigurationSection section = new SyncConfigurationSection();

            // Clonet TargetDatabases
            foreach (TargetDatabaseConfigElement elem in Databases)
            {
                section.Databases.Add((TargetDatabaseConfigElement)elem.Clone());
            }

            // Clone SyncConfigs
            foreach (SyncScopeConfigElement elem in SyncScopes)
            {
                section.SyncScopes.Add((SyncScopeConfigElement)elem.Clone());
            }
            return section;
        }
Esempio n. 3
0
        private static SelectedConfigSections FillDefaults(ArgsParser parser, SyncConfigurationSection syncConfig)
        {
            SelectedConfigSections sections = new SelectedConfigSections();

            if (string.IsNullOrEmpty(parser.ScopeName) && syncConfig.SyncScopes.Count == 1)
            {
                sections.SelectedSyncScope = syncConfig.SyncScopes.Cast<SyncScopeConfigElement>().First();
                parser.ScopeName = sections.SelectedSyncScope.Name;
            }
            else
            {
                sections.SelectedSyncScope = syncConfig.SyncScopes.Cast<SyncScopeConfigElement>().Single((e) => e.Name.Equals(parser.ScopeName, StringComparison.InvariantCultureIgnoreCase));
            }

            if (string.IsNullOrEmpty(parser.TargetDatabaseName) && syncConfig.Databases.Count == 1)
            {
                sections.SelectedTargetDatabase = syncConfig.Databases.Cast<TargetDatabaseConfigElement>().First();
                parser.TargetDatabaseName = sections.SelectedTargetDatabase.Name;
            }
            else
            {
                sections.SelectedTargetDatabase = syncConfig.Databases.Cast<TargetDatabaseConfigElement>().Single((e) => e.Name.Equals(parser.TargetDatabaseName, StringComparison.InvariantCultureIgnoreCase));
            }
            
            return sections;
        }
Esempio n. 4
0
        private static void ValidateConfigFile(ArgsParser parser, SyncConfigurationSection syncConfig)
        {
            if (syncConfig == null)
            {
                throw new InvalidOperationException("Unable to parse config file.");
            }

            if (syncConfig.SyncScopes.Count == 0)
            {
                throw new InvalidOperationException("Config file should contain atleast one <SyncScope> definition.");
            }

            if (syncConfig.Databases.Count == 0)
            {
                throw new InvalidOperationException("Config file should contain atleast one <TargetDatabase> definition.");
            }

            if (syncConfig.SyncScopes.Count > 1 && string.IsNullOrEmpty(parser.ScopeName))
            {
                throw new InvalidOperationException("More than one <SyncScope> definitions found. Specify /scopename parameter.");
            }

            if (syncConfig.Databases.Count > 1 && string.IsNullOrEmpty(parser.TargetDatabaseName))
            {
                throw new InvalidOperationException("More than one <TargetDatabase> definitions found. Specify /database parameter.");
            }

            if (!string.IsNullOrEmpty(parser.ScopeName) &&
                syncConfig.SyncScopes.Cast<SyncScopeConfigElement>().FirstOrDefault((e) => e.Name.Equals(parser.ScopeName, StringComparison.InvariantCultureIgnoreCase)) == null)
            {
                throw new ArgumentException("Scopename not found in SyncConfiguration/SyncScope definition.", parser.ScopeName);
            }

            if (!string.IsNullOrEmpty(parser.TargetDatabaseName) &&
                syncConfig.Databases.Cast<TargetDatabaseConfigElement>().FirstOrDefault((e) => e.Name.Equals(parser.TargetDatabaseName, StringComparison.InvariantCultureIgnoreCase)) == null)
            {
                throw new ArgumentException("TargetDatabase not found in SyncConfiguration/Databases definition.", parser.ScopeName);
            }
        }