Ejemplo n.º 1
0
        /// <summary>
        /// Register holiday
        /// </summary>
        /// <param name="services"></param>
        /// <param name="optionsAction"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static IServiceCollection AddHoliday(this IServiceCollection services, Action <MSDIHolidayOptions> optionsAction = null)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var holidayManager         = HolidayManagerFactory.Create();
            var holidayProviderManager = new HolidayProviderManager();

            InternalSingleInstanceServiceLocator.SetHolidayManager(holidayManager);
            InternalSingleInstanceServiceLocator.SetHolidayProviderManager(holidayProviderManager);

            var options = new MSDIHolidayOptions(holidayProviderManager);

            //todo 读取配置,获取 Holiday 配置信息

            //todo 读取配置,获得运行时节日配置信息
            //扫描并生成到 options.RuntimeFixedHolidayFunc
            //读取并激活

            //To Activate Holiday options
            optionsAction?.Invoke(options);

            //To Activate Weekend options.
            services.RegisterWeekendDefinitions(options);

            services.RegisterManagers(holidayManager, holidayProviderManager);
            services.RegisterGetters();

            return(services);
        }
Ejemplo n.º 2
0
        // ReSharper disable once UnusedMethodReturnValue.Local
        private static IServiceCollection RegisterWeekendDefinitions(this IServiceCollection services, MSDIHolidayOptions options)
        {
            var weekendRegister = WeekendDefinitionRegister.Create();

            if (options.WeekendIncludeExtendDefinitions)
            {
                weekendRegister.IncludeExtendDefinitions();
            }

            if (!string.IsNullOrWhiteSpace(options.WeekendUnlinkedAssembliesPattern))
            {
                weekendRegister.IncludeExtendDefinitions();
                weekendRegister.UnlinkedAssembliesPattern(options.WeekendUnlinkedAssembliesPattern);
            }

            weekendRegister.Scan().Register(options.BizWeekendDefinitions).Done();

            return(services);
        }