예제 #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);
        }
예제 #2
0
 private SyncSession(string planName, DataProviderBase provider, PropertyComparerCollection comparers, PropertySetterCollection setters, IList <LogProviderBase> loggers, PropertyMappingCollection mappings)
 {
     this.planName  = planName;
     this.provider  = provider;
     this.comparers = comparers;
     this.setters   = setters;
     this.loggers   = loggers;
     this.mappings  = mappings;
     this.batchSize = 1;
 }