예제 #1
0
        /// <summary>
        /// 分析师直播
        /// </summary>
        /// <param name="tag"></param>
        private void makeModule(Tag tag)
        {
            object             collection = null;
            List <AnalystLive> list;
            string             modudle = ((StringLiteral)tag.AttributeValue("modudle")).Content;
            string             dataId  = ((StringLiteral)tag.AttributeValue("id")).Content;
            int count = int.Parse(((StringLiteral)tag.AttributeValue("count")).Content);

            if (count.ToString() == null)
            {
                count = 1;
            }
            AnalystLiveBLL analystLiveBLL = Factory.BusinessFactory.CreateBll <AnalystLiveBLL>();

            list = analystLiveBLL.GetAnalystLiveListNews(count, modudle);

            if (list == null)
            {
                return;
            }
            else
            {
                collection = list;
            }
            SetValue(dataId, collection);

            Expression expVar = tag.AttributeValue("var");

            if (expVar == null)
            {
                throw new TemplateRuntimeException("foreach 语法缺少 var 属性定义.", tag.Line, tag.Col);
            }

            object varObject = EvalExpression(expVar);

            if (varObject == null)
            {
                varObject = "foreach";
            }
            string     varname   = varObject.ToString();
            Expression expIndex  = tag.AttributeValue("index");
            string     indexname = null;

            if (expIndex != null)
            {
                object obj = EvalExpression(expIndex);
                if (obj != null)
                {
                    indexname = obj.ToString();
                }
            }
            //判断是否循环的最后一条标识
            Expression islastExp = tag.AttributeValue("islast");
            string     islast    = null;

            if (islastExp != null)
            {
                object obj = EvalExpression(islastExp);
                if (obj != null)
                {
                    islast = obj.ToString();
                }
            }
            IEnumerator ienum = ((IEnumerable)collection).GetEnumerator();
            int         index = 0;

            if (islast != null)
            {
                variables[islast] = false;
            }
            while (ienum.MoveNext())
            {
                index++;
                if (index == ((List <AnalystLive>)collection).Count && islast != null)
                {
                    variables[islast] = true;
                }
                object value = ienum.Current;
                variables[varname] = value;
                if (indexname != null)
                {
                    variables[indexname] = index;
                }

                ProcessElements(tag.InnerElements);
            }
        }