Beispiel #1
0
        /// <summary>
        /// 根据配置和指定的数据源初始化<see cref="SyncSession"/>。
        /// </summary>
        /// <param name="planName">配置文件中的计划名称</param>
        /// <param name="dataProvider"><see cref="DataProviderBase"/>的派生类型的对象,提供源数据。</param>
        /// <returns></returns>
        public static SyncSession CreateSession(string planName, DataProviderBase dataProvider)
        {
            Configuration.PermissionCenterIncomeSyncSettings config = Configuration.PermissionCenterIncomeSyncSettings.GetConfig();

            var planConfig = config.SyncPlans[planName];

            if (planConfig == null)
            {
                throw new ArgumentException("未找到同步方案 " + planName, "providerName");
            }

            HashSet <string>          comparerNames = new HashSet <string>();
            HashSet <string>          setterNames   = new HashSet <string>();
            PropertyMappingCollection mappings      = new PropertyMappingCollection();

            mappings.SourceKeyProperty = planConfig.SourceKeyProperty;

            foreach (PropertyMappingConfigurationElement item in planConfig.PropertyMappings)
            {
                comparerNames.Add(item.ComparerName);
                setterNames.Add(item.SetterName); //需要哪些比较器和设置器
                mappings.Add(item.SourceProperty, new PropertyMapping(item.SourceProperty, item.TargetProperty, item.ComparerName, item.SetterName, new WrappedNameValueCollection(item.Parameters)));
            }

            var comparers = CreateComparers(comparerNames, config.Comparers);
            var setters   = CreateSetters(setterNames, config.PropertySetters);

            IList <LogProviderBase> loggers = CreateLoggers(planConfig);

            SyncSession task = new SyncSession(planName, dataProvider, comparers, setters, loggers, mappings);

            task.batchSize = planConfig.BatchSize;

            return(task);
        }
Beispiel #2
0
        /// <summary>
        /// 根据配置初始化一个<see cref="SyncSession"/>
        /// </summary>
        /// <param name="planName">配置文件中的计划名称</param>
        /// <returns></returns>
        public static SyncSession CreateSession(string planName)
        {
            Configuration.PermissionCenterIncomeSyncSettings config = Configuration.PermissionCenterIncomeSyncSettings.GetConfig();
            var planConfig = config.SyncPlans[planName];

            if (planConfig == null)
            {
                throw new ArgumentException("未找到同步方案 " + planName, "providerName");
            }

            if (planConfig.DataProvider == null)
            {
                throw new System.Configuration.ConfigurationErrorsException("配置文件中,未配置dataProvider");
            }

            DataProviderBase provider = (DataProviderBase)CreateDataProvider(planConfig.DataProvider);

            return(CreateSession(planName, provider));
        }