Exemplo n.º 1
0
        /// <summary>
        /// 對指定計算式策略所需參數的對象實例化
        /// </summary>
        /// <param name="topicIdentifier">題型種類</param>
        /// <param name="topicNumber">參數識別ID</param>
        /// <returns>對象實例</returns>
        public virtual TopicParameterBase CreateTopicParameterInstance(string topicIdentifier, string topicNumber)
        {
            // 參數對象緩存區管理
            string key = $"{topicIdentifier}::{topicNumber}";

            Lazy <TopicParameterBase, ITogicMetaDataView> lazyParameter = ParameterCache.GetOrAdd(key, (o) =>
            {
                // 注入運算符參數對象(題型與參數是一對一關係)
                IEnumerable <Lazy <TopicParameterBase, ITogicMetaDataView> > parameters = _composer.GetExports <TopicParameterBase, ITogicMetaDataView>();
                if (!parameters.Any())
                {
                    // 指定的題型參數對象未找到
                    throw new TopicNotFoundException(MessageUtil.GetMessage(() => MsgResources.E0019L, topicIdentifier));
                }
                LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0004L));

                return(parameters.First());
            });

            // 參數類實例化
            TopicParameterBase paramater = lazyParameter.Value;

            // 通用參數初期化處理(依據Provider配置)
            paramater.InitParameterBase(key);
            // 派生類參數初期化(各子類實現)
            paramater.InitParameter();

            LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0005L, key));

            return(paramater);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 策略作成
        /// </summary>
        /// <param name="param">参数对象</param>
        public virtual void Build(TopicParameterBase param)
        {
            Guard.ArgumentNotNull(param, "param");
            if (!typeof(T).IsAssignableFrom(param.GetType()))
            {
                throw CreateInvalidParameterException(typeof(T));
            }

            var p = (T)param;

            PreMarkFormulaList(p);

            try
            {
                MarkFormulaList(p);
            }
            catch
            {
                throw;
            }
            finally
            {
                PostMarkFormulaList(p);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="topicIdentifier">題型識別ID</param>
        /// <param name="topicNumber">參數編號(如果沒有指定參數編號,則默認返回當前參數序列的第一個參數項目)</param>
        /// <returns></returns>
        public TopicParameterBase Structure(string topicIdentifier, string topicNumber)
        {
            // 題型實例
            ITopic instance = TopicFactory.CreateTopicInstance(topicIdentifier);

            // 計算式所需參數
            TopicParameterBase parameter = TopicFactory.CreateTopicParameterInstance(topicIdentifier, topicNumber);

            LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0006L));

            // 根據參數構建題型
            instance.Build(parameter);

            LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0007L));

            return(parameter);
        }
        /// <summary>
        /// 參數初期化處理
        /// </summary>
        /// <param name="topicArgumentsIdentifier">題型參數識別ID</param>
        internal void InitParameterBase(string topicArgumentsIdentifier)
        {
            // 參數配置json注入parameter
            TopicParameterBase parameter = helper.CreateParameterProvider().Initialize(topicArgumentsIdentifier, out Dictionary <string, string> replenishArgument);

            // 補充參數設定
            SetReplenishArgument(replenishArgument);

            QuestionType       = parameter.QuestionType;
            Signs              = parameter.Signs;
            FourOperationsType = parameter.FourOperationsType;
            MaximumLimit       = parameter.MaximumLimit;
            NumberOfQuestions  = parameter.NumberOfQuestions;
            Reserve            = parameter.Reserve;
            LeftScope          = parameter.LeftScope;
            RightScope         = parameter.RightScope;
        }