protected override void PlotVertex(ScopeData data)
            {
                float r = data.FractionalI * 2 * (float) Math.PI;

                float v = Math.Abs(data.Value) * 0.75f;

                data.X = (float) Math.Sin(r) * v;
                data.Y = (float) Math.Cos(r) * v;

                data.Red = 1;
                data.Green = Math.Min(Math.Abs(data.Value), 0.5f);
                data.Blue = 0;
            }
        public void Visit(TableVariableRowGetter variable)
        {
            Visit((TableVariableReference)variable);
            ScopeData<TableDescriptor> scope = new ScopeData<TableDescriptor> { Type = new TableDescriptor(null), CodeDomReference = new CodeTypeReference("Table", new CodeTypeReference(variable.Id)) };
            if (Scope.Current.IsTableRegistered(variable.Id))
            {
                scope = Scope.Current.GetTableDescriptor(variable.Id);
                if (scope.CodeDomReference.TypeArguments.Count > 0)
                    scope = new ScopeData<TableDescriptor> { Type = scope.Type, CodeDomReference = scope.CodeDomReference.TypeArguments[0] };
            }

            _codeStack.Peek().Scope = scope;
        }
            protected override void PlotVertex(ScopeData data)
            {
                int dr = rand.Next(2) == 0 ? -1 : 1;

                if (rand.Next(2) == 0) {
                    this.dx += data.Value / 4 * dr;
                } else {
                    this.dy += data.Value / 4 * dr;
                }

                data.X = this.dx;
                data.Y = this.dy;

                data.Alpha = Math.Abs(data.Value) * 0.8f;
                data.Red = this.da;
                data.Green = data.Alpha;
                data.Blue = 1 - this.da;
            }
        public void Visit(VariableReferance variable)
        {
            IScopeData codeType;
            Scope scope = Scope.Current;

            if (!Scope.Current.IsRegistered(variable.Id)) //If variable doesn't exist we need to register Sematic error
            {
                Errors.Add(new UnknownVariableReferenceException(new Semantic.LineInfo(variable.Line.Line, variable.Line.CharacterPosition), variable.Id));
                codeType = new ScopeData<TableDescriptor> { Type = new TableDescriptor(null), CodeDomReference = new CodeTypeReference("Table", new CodeTypeReference("3ab508bc-31b8-486f-a10a-4f5714f80a3b")) };
            }
            else
            {
                scope = Scope.FindScope(variable.Id);
                codeType = scope.GetScope(variable.Id);
            }

            _codeStack.Peek().Scope = codeType;
            _codeStack.Peek().CodeExpression = scope.CreateExpression(variable.Id);
        }
        public void Visit(TableVariableReference variable)
        {
            IScopeData codeType;
            Scope scope = Scope.Current;

            if (!Scope.Current.IsRegistered(variable.Id)) //If variable doesn't exist we need to register Sematic error
            {
                Errors.Add(new UnknownVariableReferenceException(new Semantic.LineInfo(variable.Line.Line, variable.Line.CharacterPosition), variable.Id));
                codeType = new ScopeData<TableDescriptor> { Type = new TableDescriptor(null), CodeDomReference = new CodeTypeReference("Table", new CodeTypeReference(variable.Id)) };
            }
            else if (!Scope.Current.IsTableRegistered(variable.Id)) //has to be a table
            {
                Errors.Add(new NotTableVariableException(new Semantic.LineInfo(variable.Line.Line, variable.Line.CharacterPosition), variable.Id));
                codeType = new ScopeData<TableDescriptor> { Type = new TableDescriptor(null), CodeDomReference = new CodeTypeReference("Table", new CodeTypeReference(variable.Id)) };
            }
            else
            {
                scope = Scope.FindScope(variable.Id);
                codeType = scope.GetScope(variable.Id);
            }

            _codeStack.Peek().Scope = codeType;
            _codeStack.Peek().CodeExpression = new CodeVariableReferenceExpression("_" + scope.ScopeIdentifier + "." + variable.Id);
        }
Example #6
0
		private void GenerateAspxCode(TemplateElement element, ScopeData scopeData)
		{
			foreach (TemplateElement node in element.ChildNodes)
			{
				switch (node.Type)
				{
					case TemplateElementTypes.Tag:
						GenerateTagAspxCode(node, scopeData);
						break;

					case TemplateElementTypes.Literal:
						GenerateLiteralAspxCode(node);
						break;

					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(node, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(node, scopeData);
						break;

					case TemplateElementTypes.CodeBlock:
						GenerateCodeBlockAspxCode(node, scopeData);
						break;

					case TemplateElementTypes.IfExpression:
					case TemplateElementTypes.ElseExpression:
					case TemplateElementTypes.ElseIfExpression:
						GenerateIfElseEpxressionAspxCode(node, scopeData);
						break;

					case TemplateElementTypes.LoadExpression:
						GenerateIncludeExpressionAspxCode(node, scopeData);
						break;

					//case TemplateElementTypes.PreIncludeExpression:
					//	GenerateAspxCode(node.ChildNodes[1], scopeData);
					//	break;

					case TemplateElementTypes.LoopExpression:
						GenerateLoopExpressionAspxCode(node, scopeData);
						break;

					case TemplateElementTypes.AjaxPanel:
						GenerateAjaxPanelAspxCode(node, scopeData);
						break;
				}
			}
		}
Example #7
0
		private void GenerateVariableAspxCode(StringBuffer codeBody, TemplateElement variable, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			Type varType = null;
			string varName = null;
			string paramName = null;
			string name = (string)variable.Items[TemplateElement.KEY_NAME];

            if (scopeData.SearchScopeVariable(name, out varType, out varName))
			{
				StringBuffer newCodeBody = new StringBuffer();

				newCodeBody += varName;

				if (variable.ChildNodes.Count > 0)
					GenerateMemberInvokeAspxCode(newCodeBody, variable.ChildNodes[0], varType, out returnType, scopeData);

				if (returnType == null)
					returnType = varType;

				codeBody += newCodeBody.ToString();
			}
			else if (scopeData.SearchThisVariableProperty(name, out varType, out varName, out paramName))
			{
				StringBuffer newCodeBody = new StringBuffer();

				newCodeBody += varName + "." + paramName;

				if (variable.ChildNodes.Count > 0)
					GenerateMemberInvokeAspxCode(newCodeBody, variable.ChildNodes[0], varType, out returnType, scopeData);

				if (returnType == null)
					returnType = varType;

				codeBody += newCodeBody.ToString();
			}
			else
			{
				MemberInfo member = SearchMemberForVariable(name);

                if (member != null)
                {
                    string instanceName = DeclaringVariable(member.DeclaringType);

                    StringBuffer newCodeBody = new StringBuffer();

                    newCodeBody += instanceName + "." + member.Name;

                    Type memberType;

                    if (member.MemberType == MemberTypes.Property)
                        memberType = ((PropertyInfo)member).PropertyType;
                    else
                        memberType = ((FieldInfo)member).FieldType;

                    if (variable.ChildNodes.Count > 0)
                        GenerateMemberInvokeAspxCode(newCodeBody, variable.ChildNodes[0], memberType, out returnType, scopeData);

                    if (returnType == null)
                        returnType = memberType;

                    codeBody += newCodeBody.ToString();
                }
                else
                {

                    throw new TemplateVariableNotExistsException(name, variable.TemplateFile.FilePath, variable.SourceTemplate, variable.Index);
                    //codeBody += name;
                    //LogHelper.CreateErrorLog(new TemplateVariableNotExistsException(name, variable.TemplateFile.FilePath, variable.SourceTemplate, variable.Index));

                    //if (returnType == null)
                    //    returnType = typeof(string);
                }
			}
		}
            protected override void PlotVertex(ScopeData data)
            {
                data.X = 2 * data.FractionalI - 1;
                data.Y = data.Value;

                data.Red = 0;
                data.Green = green;
                data.Blue = 1;
            }
Example #9
0
		private void GenerateLoopExpressionAspxCode(TemplateElement node, ScopeData scopeData)
		{
			switch(node.ChildNodes[0].Type)
			{
				case TemplateElementTypes.LoopExpressionParam:
					GenerateLoopExpressionParamAspxCode(node.ChildNodes[0], scopeData);
					break;

				case TemplateElementTypes.LoopExpressionParam2:
					GenerateLoopExpressionParam2AspxCode(node.ChildNodes[0], scopeData);
					break;
			}
		}
Example #10
0
		private void GenerateLoopExpressionParam2AspxCode(TemplateElement node, ScopeData scopeData)
		{
			if (node.ChildNodes.Count == 2)
			{
				TemplateElement from = node.ChildNodes[0];
				TemplateElement to = node.ChildNodes[1];

				StringBuffer fromCode = new StringBuffer();

				Type fromType = null;

				switch (from.Type)
				{
					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(fromCode, from, out fromType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(fromCode, from, out fromType, scopeData);
						break;

					case TemplateElementTypes.Literal:
						string fromValue = from.SourceTemplate.Substring(from.Index, from.Length);
						
						int temp = -1;

						if (int.TryParse(fromValue, out temp))
						{
							fromCode += fromValue;
							fromType = typeof(int);
						}
						break;
				}

				StringBuffer toCode = new StringBuffer();

				Type toType = null;

				switch (to.Type)
				{
					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(toCode, to, out toType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(toCode, to, out toType, scopeData);
						break;

					case TemplateElementTypes.Literal:
						string toValue = to.SourceTemplate.Substring(to.Index, to.Length);

						int temp = -1;

						if (int.TryParse(toValue, out temp))
						{
							toCode += toValue;
							toType = typeof(int);
						}
						break;
				}

				if (fromType == typeof(int) && toType == typeof(int))
				{
					string i = node.Items["i"] as string;
					string step = node.Items["step"] as string;

					uint temp = 0;

					if (i != null && (step == null || (uint.TryParse(step, out temp) && temp > 0)))
					{
						if (step == null)
							step = "1";

						ScopeData scope = new ScopeData(scopeData);

						string iVarName = scope.DeclaringScopeVariable(i, typeof(int));

						//example: for (int i = a; a > b ? i >= b : i <= b; i += a > b ? -c : c)

                        m_CodeBody += "<%\r\nfor(int " + iVarName + "=" + fromCode + ";" + fromCode + " > " + toCode + " ? " + iVarName + " >= " + toCode + " : " + iVarName + " <= " + toCode + ";" + iVarName + " += " + fromCode + " > " + toCode + " ? -" + step + " : " + step + "){%>";

						GenerateAspxCode(node.Parent, scope);

                        m_CodeBody += "<%\r\n}%>";
					}
				}
			}
		}
Example #11
0
		private void GenerateCodeBlockAspxCode(StringBuffer codeBody, TemplateElement codeBlock, ScopeData scopeData)
		{
			foreach (TemplateElement element in codeBlock.ChildNodes)
			{
				Type returnType = null;

				switch (element.Type)
				{
					case TemplateElementTypes.Literal:
						GenerateLiteralAspxCode(codeBody, element);
						break;

					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(codeBody, element, out returnType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(codeBody, element, out returnType, scopeData);
						break;
				}
			}
		}
Example #12
0
		private void GenerateIfElseEpxressionAspxCode(TemplateElement expression, ScopeData scopeData)
		{
			if (expression.Type == TemplateElementTypes.IfExpression)
			{
                m_CodeBody += "<%\r\n if (";

				GenerateAspxCode(m_CodeBody, expression.ChildNodes[0], scopeData);

				m_CodeBody += ") { %>";

				GenerateAspxCode(expression, scopeData);

                m_CodeBody += "<%\r\n } %>";
			}
			else if (expression.Type == TemplateElementTypes.ElseExpression)
			{
                m_CodeBody += "<%\r\n } else { %>";
			}
			else if (expression.Type == TemplateElementTypes.ElseIfExpression)
			{
                m_CodeBody += "<%\r\n } else if(";

				GenerateAspxCode(m_CodeBody, expression.ChildNodes[0], scopeData);

				m_CodeBody += ") { %>";
			}
		}
Example #13
0
		private void GenerateOutFunctionAspxCode(StringBuffer codeBody, TemplateElement function, ScopeData scopeData)
		{
			if (function.ChildNodes[0].ChildNodes.Count > 0)
			{
				int defaultValueStartIndex = -1;

				TemplateElement param1 = null;

				if (function.ChildNodes[0].ChildNodes[0].Type == TemplateElementTypes.Variable || function.ChildNodes[0].ChildNodes[0].Type == TemplateElementTypes.Function)
				{
					param1 = function.ChildNodes[0].ChildNodes[0];

					if (function.ChildNodes[0].ChildNodes.Count >= 2)
						defaultValueStartIndex = 1;
				}
				else if (function.ChildNodes[0].ChildNodes.Count >= 2)
				{
					param1 = function.ChildNodes[0].ChildNodes[1];

					if (function.ChildNodes[0].ChildNodes.Count >= 3)
						defaultValueStartIndex = 2;
				}

				if (param1 != null && (param1.Type == TemplateElementTypes.Variable || param1.Type == TemplateElementTypes.Function))
				{
					codeBody += "TryToString(";

					Type returnType = null;

					if (param1.Type == TemplateElementTypes.Variable)
					{
						TemplateElement param0 = new TemplateElement(TemplateElementTypes.Variable, param1.Items);

						GenerateVariableAspxCode(codeBody, param0, out returnType, scopeData);
					}
					else
					{
						TemplateElement param0 = new TemplateElement(TemplateElementTypes.Function, param1.Items);

						param0.ChildNodes.Add(param1.ChildNodes[0]);

						GenerateFunctionAspxCode(codeBody, param0, out returnType, scopeData);
					}

					codeBody += ", delegate(){ return ";

					if (param1.Type == TemplateElementTypes.Variable)
						GenerateVariableAspxCode(codeBody, param1, out returnType, scopeData);
					else
						GenerateFunctionAspxCode(codeBody, param1, out returnType, scopeData);

					codeBody += "; }";

					if (defaultValueStartIndex > 0)
					{
						for (int i = defaultValueStartIndex; i < function.ChildNodes[0].ChildNodes.Count; i++)
						{
							TemplateElement node = function.ChildNodes[0].ChildNodes[i];

							switch (node.Type)
							{
								case TemplateElementTypes.Literal:
									GenerateLiteralAspxCode(codeBody, node);
									break;

								case TemplateElementTypes.Variable:
									GenerateVariableAspxCode(codeBody, node, out returnType, scopeData);
									break;

								case TemplateElementTypes.Function:
									GenerateFunctionAspxCode(codeBody, node, out returnType, scopeData);
									break;

								case TemplateElementTypes.CodeBlock:
									GenerateCodeBlockAspxCode(codeBody, node, scopeData);
									break;

								case TemplateElementTypes.SingleQuteString:
									GenerateSingleQuteStringAspxCode(codeBody, node, scopeData);
									break;

								case TemplateElementTypes.DoubleQuteString:
									GenerateDoubleQuteStringAspxCode(codeBody, node, scopeData);
									break;
							}
						}
					}

					codeBody += ")";
				}
			}
		}
Example #14
0
		private void GenerateCodeBlockAspxCode(TemplateElement codeBlock, ScopeData scopeData)
		{
			bool isOutput = (bool)codeBlock.Items[TemplateElement.KEY_OUTPUT];

            m_CodeBody += isOutput ? "<%=" : "<%\r\n";

			GenerateCodeBlockAspxCode(m_CodeBody, codeBlock, scopeData);
			
			m_CodeBody += isOutput ? "%>" : ";%>";
		}
Example #15
0
		private void GenerateFunctionAspxCode(StringBuffer codeBody, TemplateElement function, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			Type funcReturnType = null;

			string thisVarName = null;
			string thisFuncName = null;

			string name = (string)function.Items[TemplateElement.KEY_NAME];

			if (StringUtil.EqualsIgnoreCase(name, "url"))
			{
				GenerateUrlFunctionAspxCode(codeBody, function, scopeData);
				returnType = typeof(string);
			}
			else if (StringUtil.EqualsIgnoreCase(name, "parent"))
			{
				bool onlyOneParam = true;
				TemplateElement funcParam = null;

				foreach (TemplateElement param in function.ChildNodes[0].ChildNodes)
				{
					if (param.Type == TemplateElementTypes.Literal)
						continue;

                    if (funcParam != null)
					{
						onlyOneParam = false;
						break;
					}

					funcParam = param;
				}

				if (onlyOneParam)
				{
					if (funcParam.Type == TemplateElementTypes.Variable)
						GenerateVariableAspxCode(codeBody, funcParam, out returnType, scopeData.Previous);
					else if (funcParam.Type == TemplateElementTypes.Function)
                        GenerateFunctionAspxCode(codeBody, funcParam, out returnType, scopeData.Previous);
				}
			}
            else if (StringUtil.EqualsIgnoreCase(name, "this"))
            {
                bool onlyOneParam = true;
                TemplateElement funcParam = null;

                foreach (TemplateElement param in function.ChildNodes[0].ChildNodes)
                {
                    if (param.Type == TemplateElementTypes.Literal)
                        continue;

                    if (funcParam != null)
                    {
                        onlyOneParam = false;
                        break;
                    }

                    funcParam = param;
                }

                if (onlyOneParam)
                {
                    if (funcParam.Type == TemplateElementTypes.Variable)
                        GenerateVariableAspxCode(codeBody, funcParam, out returnType, scopeData.Last);
                    else if (funcParam.Type == TemplateElementTypes.Function)
                        GenerateFunctionAspxCode(codeBody, funcParam, out returnType, scopeData.Last);
                }
            }
            else if (StringUtil.EqualsIgnoreCase(name, "out"))
            {
                funcReturnType = typeof(string);

                StringBuffer newCodeBody = new StringBuffer();

                GenerateOutFunctionAspxCode(newCodeBody, function, scopeData);

                if (function.ChildNodes.Count > 1)
                    GenerateMemberInvokeAspxCode(newCodeBody, function.ChildNodes[1], funcReturnType, out returnType, scopeData);

                if (returnType == null)
                    returnType = funcReturnType;

                codeBody += newCodeBody.ToString();
            }
            else if (scopeData.SearchThisVariableMethod(name, out funcReturnType, out thisVarName, out thisFuncName))
            {
                StringBuffer newCodeBody = new StringBuffer();

                newCodeBody += thisVarName + "." + thisFuncName + "(";

                GenerateAspxCode(newCodeBody, function.ChildNodes[0], scopeData);

                newCodeBody += ")";

                if (function.ChildNodes.Count > 1)
                    GenerateMemberInvokeAspxCode(newCodeBody, function.ChildNodes[1], funcReturnType, out returnType, scopeData);

                if (returnType == null)
                    returnType = funcReturnType;

                codeBody += newCodeBody.ToString();
            }
            else
            {
                MethodInfo method = SearchMethodForFunction(name);

                if (method != null)
                {
                    StringBuffer newCodeBody = new StringBuffer();

                    string instanceName = DeclaringVariable(method.DeclaringType);

                    newCodeBody += instanceName + "." + method.Name + "(";

                    GenerateAspxCode(newCodeBody, function.ChildNodes[0], scopeData);

                    newCodeBody += ")";

                    if (function.ChildNodes.Count > 1)
                        GenerateMemberInvokeAspxCode(newCodeBody, function.ChildNodes[1], method.ReturnType, out returnType, scopeData);

                    if (returnType == null)
                        returnType = method.ReturnType;

                    codeBody += newCodeBody.ToString();
                }
            }
		}
Example #16
0
        private void GenerateUrlFunctionAspxCode(StringBuffer codeBody, TemplateElement function, ScopeData scopeData)
        {
            codeBody += "string.Concat(_Url_Before, ";

            for (int i = 0; i < function.ChildNodes[0].ChildNodes.Count; i++)
            {
                TemplateElement node = function.ChildNodes[0].ChildNodes[i];

                Type returnType;

                switch (node.Type)
                {
                    case TemplateElementTypes.Literal:
                        codeBody += "\"" + node.Text + "\"";
                        break;

                    case TemplateElementTypes.Variable:
                        GenerateVariableAspxCode(codeBody, node, out returnType, scopeData);
                        break;

                    case TemplateElementTypes.Function:
                        GenerateFunctionAspxCode(codeBody, node, out returnType, scopeData);
                        break;

                    case TemplateElementTypes.CodeBlock:
                        GenerateCodeBlockAspxCode(codeBody, node, scopeData);
                        break;

                    case TemplateElementTypes.DoubleQuteString:
                        GenerateDoubleQuteStringAspxCode(codeBody, node, scopeData);
                        break;

                    case TemplateElementTypes.SingleQuteString:
                        GenerateSingleQuteStringAspxCode(codeBody, node, scopeData);
                        break;
                }

                if (i < function.ChildNodes[0].ChildNodes.Count - 1)
                    codeBody += " + ";
            }

            codeBody += ", _Url_After)";
            //}
        }
Example #17
0
		private void GenerateFunctionAspxCode(TemplateElement function, ScopeData scopeData)
		{
            string name = (string)function.Items[TemplateElement.KEY_NAME];
			
            //if (StringUtil.EqualsIgnoreCase(name, "url"))
            //{
            //    GenerateUrlFunctionAspxCode(null, function, scopeData);
            //    return;
            //}

			StringBuffer funcBody = new StringBuffer();

			Type returnType = null;

			GenerateFunctionAspxCode(funcBody, function, out returnType, scopeData);

			if (returnType != null && returnType != typeof(void))
				m_CodeBody += "<%=";
			else
                m_CodeBody += "<%\r\n";

			m_CodeBody += funcBody;

			m_CodeBody += "%>";
		}
Example #18
0
		private void GenerateAspxCode(StringBuffer codeBody, TemplateElement element, ScopeData scopeData)
		{
			foreach (TemplateElement node in element.ChildNodes)
			{
				Type returnType = null;

				switch (node.Type)
				{
					case TemplateElementTypes.Literal:
						GenerateLiteralAspxCode(codeBody, node);
						break;

					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(codeBody, node, out returnType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(codeBody, node, out returnType, scopeData);
						break;

					case TemplateElementTypes.CodeBlock:
						GenerateCodeBlockAspxCode(codeBody, node, scopeData);
						break;

					case TemplateElementTypes.DoubleQuteString:
						GenerateDoubleQuteStringAspxCode(codeBody, node, scopeData);
						break;

					case TemplateElementTypes.SingleQuteString:
						GenerateSingleQuteStringAspxCode(codeBody, node, scopeData);
						break;
				}
			}
		}
Example #19
0
		private void GenerateMemberInvokeAspxCode(StringBuffer codeBody, TemplateElement memberInvoke, Type type, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			switch (memberInvoke.Type)
			{

				case TemplateElementTypes.IndexInvoke:
					GenerateIndexInvokeAspxCode(codeBody, memberInvoke, type, out returnType, scopeData);
					break;

				case TemplateElementTypes.PropertyInvoke:
					GeneratePropertyInvokeAspxCode(codeBody, memberInvoke, type, out returnType, scopeData);
					break;

				case TemplateElementTypes.FunctionInvoke:
					GenerateFunctionInvokeAspxCode(codeBody, memberInvoke, type, out returnType, scopeData);
					break;
			}
		}
Example #20
0
		private void GenerateTagAspxCode(TemplateElement tag, ScopeData scopeData)
		{
            string name = ((string)tag.Items[TemplateElement.KEY_NAME]);

            if (string.Compare(name, "page", true) == 0)
                return;
            else if (string.Compare(name, "break", true) == 0)
            {
                m_CodeBody += "<% break; %>";
                return;
            }
            else if (string.Compare(name, "continue", true) == 0)
            {
                m_CodeBody += "<% continue; %>";
                return;
            }

			MethodInfo method = SearchMethodForTag(tag);

			if (method != null)
			{
				string instanceName = DeclaringVariable(method.DeclaringType);

                m_CodeBody += "<%\r\n" + instanceName + "." + method.Name + "(";

				int templateIndex = -1;		//模板委托类型参数的起始索引
				int templateCount = 0;		//模板委托类型参数的个数

				bool needRemoveDot = false;

				ParameterInfo[] parameters = method.GetParameters();

				#region 将模板标签属性输出为方法参数

				for (int i = 0; i < parameters.Length; i++)
				{
					if (parameters[i].ParameterType.IsSubclassOf(typeof(Delegate)) == false)
					{
						TemplateElement attributeListItem = GetAttributeListItem(parameters[i], tag.ChildNodes[0]);

						if (attributeListItem != null)
						{
							GenerateAttributeListItemAspxCode(parameters[i], attributeListItem, scopeData);
						}

						m_CodeBody += ",";

						needRemoveDot = true;
					}
					else
					{
						if (templateIndex == -1)
							templateIndex = i;

						templateCount++;
					}
				}

				if (needRemoveDot == true)
					m_CodeBody.InnerBuilder.Remove(m_CodeBody.InnerBuilder.Length - 1, 1);

				#endregion

				#region 将模板标签的模板内容输出为匿名委托

				for (int i = templateIndex; i - templateIndex < templateCount; i++)
				{
					ScopeData scope = new ScopeData(scopeData);

					if (needRemoveDot == true)
					{
						m_CodeBody += ",";
					}
					else
					{
						needRemoveDot = true;
					}

					m_CodeBody += "delegate(";

					ParameterInfo[] args = parameters[i].ParameterType.GetMethod("Invoke").GetParameters();

					for (int j = 0; j < args.Length; j++)
					{
						m_CodeBody += ReflectionUtil.GetCSharpTypeName(args[j].ParameterType) + " " + scope.DeclaringScopeVariable(args[j]);

						if (j < args.Length - 1)
							m_CodeBody += ",";
					}

					m_CodeBody += "){\r\n%>";

					if (templateCount == 1)
					{
						GenerateAspxCode(tag, scope);
					}
					else
					{
						for (int j = 1; j < tag.ChildNodes.Count; j++)
						{
							TemplateElement element = tag.ChildNodes[j];

							if (element.Type == TemplateElementTypes.Tag)
							{
								string tagName = (string)element.Items[TemplateElement.KEY_NAME];

								if (StringUtil.EqualsIgnoreCase(parameters[i].Name, tagName))
								{
									GenerateAspxCode(element, scope);
									break;
								}
							}
						}
					}

					m_CodeBody += "<%\r\n}";

					//for (int j = 0; j < args.Length; j++)
					//{
					//    UndeclaringScopeVariable(args[j]);
					//}
				}

				#endregion

				m_CodeBody += ");%>";
			}
			else
			{
                //未能找到合适的注册标签,直接输出
                //if (tag.Index != tag.Length)
                //    m_CodeBody += tag.SourceTemplate.Substring(tag.Index, tag.Length);

                //string name = tag.Items[TemplateElement.KEY_NAME] as string;

                //if (StringUtil.EqualsIgnoreCase(name, "ajaxpanel"))
                //{

                //}
			}
		}
Example #21
0
		private void GenerateIndexInvokeAspxCode(StringBuffer codeBody, TemplateElement indexInvoke, Type type, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			Type indexType = null;

			string name = indexInvoke.Items[TemplateElement.KEY_NAME] as string;

			if (type.IsArray)
			{
				indexType = type.GetElementType();
			}
			else
			{
				PropertyInfo property = type.GetProperty("Item", BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);

				if (property != null)
					indexType = property.PropertyType;
			}

			if (indexType != null)
			{
				codeBody += "[";

				GenerateAspxCode(codeBody, indexInvoke.ChildNodes[0], scopeData);

				codeBody += "]";

				if (indexInvoke.ChildNodes.Count > 1)
					GenerateMemberInvokeAspxCode(codeBody, indexInvoke.ChildNodes[1], indexType, out returnType, scopeData);

				if (returnType == null)
					returnType = indexType;
			}
		}
Example #22
0
		private void GenerateIncludeExpressionAspxCode(TemplateElement node, ScopeData scopeData)
		{
            m_CodeBody += "<%\r\n Include(__w, ";

			for (int i = 0; i < node.ChildNodes[0].ChildNodes.Count; i++)
			{
				TemplateElement element = node.ChildNodes[0].ChildNodes[i];

				m_CodeBody += "\"" + element.Items[TemplateElement.KEY_NAME] + "\",";

				for (int j = 0; j < element.ChildNodes.Count; j++)
				{
					TemplateElement element2 = element.ChildNodes[j];

					Type returnType = null;

					switch (element2.Type)
					{
						case TemplateElementTypes.Literal:
							m_CodeBody += "\"";
							GenerateLiteralAspxCode(element2);
							m_CodeBody += "\"";
							break;

						case TemplateElementTypes.Variable:
							GenerateVariableAspxCode(m_CodeBody, element2, out returnType, scopeData);
							break;

						case TemplateElementTypes.Function:
							GenerateFunctionAspxCode(m_CodeBody, element2, out returnType, scopeData);
							break;

						case TemplateElementTypes.CodeBlock:
							GenerateCodeBlockAspxCode(m_CodeBody, element2, scopeData);
							break;
					}

					if (j < element.ChildNodes.Count - 1)
						m_CodeBody += "+";
				}

				if (i < node.ChildNodes[0].ChildNodes.Count - 1)
					m_CodeBody += ",";
			}
			
			m_CodeBody += "); %>";
		}
Example #23
0
		private void GeneratePropertyInvokeAspxCode(StringBuffer codeBody, TemplateElement propertyInvoke, Type type, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			string name = propertyInvoke.Items[TemplateElement.KEY_NAME] as string;

			MethodInfo extensionProperty = SearchExtensionProperty(name, type);

			if (extensionProperty != null)
			{
				StringBuffer sb = new StringBuffer(ReflectionUtil.GetCSharpTypeName(extensionProperty.DeclaringType));

				sb += "." + extensionProperty.Name + "((";

				codeBody.InnerBuilder.Insert(0, sb);

				codeBody += "),\"" + name + "\")";

				if (propertyInvoke.ChildNodes.Count > 0)
					GenerateMemberInvokeAspxCode(codeBody, propertyInvoke.ChildNodes[0], extensionProperty.ReturnType, out returnType, scopeData);
				
				if(returnType == null)
					returnType = extensionProperty.ReturnType;
			}
			else
			{
				MemberInfo member = SearchPropertyAndField(name, type);

				Type magicPropertyType = null;

				if (member != null)
				{
					codeBody += "." + member.Name;

                    Type memberType;

                    if (member.MemberType == MemberTypes.Property)
                        memberType = ((PropertyInfo)member).PropertyType;

                    else
                        memberType = ((FieldInfo)member).FieldType;

					if (propertyInvoke.ChildNodes.Count > 0)
                        GenerateMemberInvokeAspxCode(codeBody, propertyInvoke.ChildNodes[0], memberType, out returnType, scopeData);

					if(returnType == null)
                        returnType = memberType;
				}
				else if (HasMagicProperty(type, out magicPropertyType))
				{
					codeBody += "[\"" + name + "\"]";

					if (propertyInvoke.ChildNodes.Count > 0)
						GenerateMemberInvokeAspxCode(codeBody, propertyInvoke.ChildNodes[0], magicPropertyType, out returnType, scopeData);
				
					if(returnType == null)
						returnType = magicPropertyType;
				}
			}
		}
Example #24
0
		private void GenerateLoopExpressionParamAspxCode(TemplateElement node, ScopeData scopeData)
		{
			if (node.ChildNodes.Count == 2)
			{
				if (node.ChildNodes[0].Type == TemplateElementTypes.Variable)
				{
					TemplateElement variable = node.ChildNodes[0];
					TemplateElement target = node.ChildNodes[1];

					StringBuffer codeBody = new StringBuffer();

					Type returnType = null;

					switch (target.Type)
					{
						case TemplateElementTypes.Variable:
							GenerateVariableAspxCode(codeBody, target, out returnType, scopeData);
							break;

						case TemplateElementTypes.Function:
							GenerateFunctionAspxCode(codeBody, target, out returnType, scopeData);
							break;
					}

					if (returnType != null)
					{
						Type enumerType = returnType.GetInterface("IEnumerable`1");

                        if (enumerType == null)
                            enumerType = returnType.GetInterface("IEnumerator`1");

                        Type varType = null;

                        if (enumerType != null)
                            varType = enumerType.GetGenericArguments()[0];
                        else
                        {
                            if (returnType == s_TypeOfStringCollection || returnType.IsSubclassOf(s_TypeOfStringCollection))
                                varType = typeof(string);
                        }

						if (varType != null)
						{
							string varName = variable.Items[TemplateElement.KEY_NAME] as string;

							string i = node.Items["i"] as string;

							if (varName != null)
							{
								ScopeData scope = new ScopeData(scopeData);

								string iVarName = null;
								
								if(i != null)
									iVarName = scope.DeclaringScopeVariable(i, typeof(int));

                                m_CodeBody += "<%\r\nif(" + codeBody + " != null)\r\n{%>";

								if (iVarName != null)
                                    m_CodeBody += "<%\r\nint " + iVarName + "=0;\r\n%>";

                                m_CodeBody += "<%\r\nforeach(" + ReflectionUtil.GetCSharpTypeName(varType) + " " + scope.DeclaringScopeVariable(varName, varType) + " in " + codeBody + "){%>";

								GenerateAspxCode(node.Parent, scope);

                                m_CodeBody += "<%";

								if (iVarName != null)
                                    m_CodeBody += "\r\n" + iVarName + "+=1;";

                                m_CodeBody += "\r\n}\r\n}";

                                m_CodeBody += "%>";
							}
						}
					}
				}
			}
		}
Example #25
0
		private void GenerateAttributeListItemAspxCode(ParameterInfo parameterInfo, TemplateElement attributeListItem, ScopeData scopeData)
		{
			TemplateDefaultValueAttribute defaultValue = TemplateDefaultValueAttribute.GetFromParameter(parameterInfo);

			if (attributeListItem.ChildNodes.Count == 0)
			{
				if (defaultValue != null)
					m_CodeBody += defaultValue.DefaultValue;
				else
					m_CodeBody += "default(" + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType) + ")";
			}
			else if (attributeListItem.ChildNodes.Count == 1)
			{
				StringBuffer newCodeBody = new StringBuffer();

				TemplateElement element = attributeListItem.ChildNodes[0];

				Type returnType = null;

				switch (element.Type)
				{
					case TemplateElementTypes.Literal:
						if (parameterInfo.ParameterType == typeof(string))
						{
							m_CodeBody += "\"";

							GenerateLiteralAspxCode(attributeListItem.ChildNodes[0]);

							m_CodeBody += "\"";
						}
						else if (parameterInfo.ParameterType.IsEnum)
						{
							m_CodeBody += "TryParse<" + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType) + ">(\"";

							GenerateLiteralAspxCode(attributeListItem.ChildNodes[0]);

							m_CodeBody += "\")";
						}
						else if (parameterInfo.ParameterType == typeof(char))
						{
							m_CodeBody += "\'";

							GenerateLiteralAspxCode(attributeListItem.ChildNodes[0]);

							m_CodeBody += "\'";
						}
						else
						{
							GenerateLiteralAspxCode(element);
						}
						break;

					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(newCodeBody, element, out returnType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(newCodeBody, element, out returnType, scopeData);
						break;

					case TemplateElementTypes.CodeBlock:
						GenerateCodeBlockAspxCode(newCodeBody, element, scopeData);
						break;
				}

				if (returnType != null && returnType != parameterInfo.ParameterType)
				{
					if (returnType == typeof(string))
					{
						m_CodeBody += "TryParse<" + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType) + ">(" + newCodeBody + ")";
					}
                    else if (parameterInfo.ParameterType.IsClass)
                    {
                        m_CodeBody += newCodeBody + " as " + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType);
                    }
                    else
                    {
                        m_CodeBody += "(" + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType) + ")" + newCodeBody;
                    }
				}
				else
				{
					m_CodeBody += newCodeBody;
				}
			}
			else if(attributeListItem.ChildNodes.Count > 1)
			{
				StringBuffer newCodeBody = new StringBuffer();

				GenerateDoubleQuteStringAspxCode(newCodeBody, attributeListItem, scopeData);

				if (parameterInfo.ParameterType != typeof(string))
				{
					m_CodeBody += "TryParse<" + ReflectionUtil.GetCSharpTypeName(parameterInfo.ParameterType) + ">(" + newCodeBody + ")";
				}
				else
				{
					m_CodeBody += newCodeBody;
				}
			}
		}
Example #26
0
		private void GenerateAjaxPanelAspxCode(TemplateElement node, ScopeData scopeData)
		{
			TemplateElement attributeList = node.ChildNodes[0];

			string autoID = NewAjaxPanelID();

			string id = null;
			string tag = null;
			string onUpdate = null;
			string idOnly = "false";
			string ajaxOnly = "false";
			Hashtable others = new Hashtable(2);

			foreach (TemplateElement item in attributeList.ChildNodes)
			{
				string name = item.Items[TemplateElement.KEY_NAME] as string;

				name = name.ToLower();

				switch (name)
				{
					case "id":
                        StringBuffer sb = new StringBuffer();

						GenerateDoubleQuteStringAspxCode(sb, item, scopeData);

                        id = sb.ToString();
						break;

					case "tag":
						tag = item.SourceTemplate.Substring(item.Index, item.Length);
						break;

					case "idonly":
						idOnly = "true";
						break;

					case "ajaxonly":
						ajaxOnly = "true";
						break;

					case "onupdate":
						StringBuffer jscode = new StringBuffer();

						GenerateAspxCode(jscode, item, scopeData);

						onUpdate = jscode.ToString();
						break;

					default:
						StringBuffer code = new StringBuffer();

						GenerateAspxCode(code, item, scopeData);

						others.Add(name, code.ToString());
						break;
				}
			}

			if (id == null)
				id = "\"" + autoID + "\"";

			if (tag == null)
				tag = "div";

			m_CodeBody += "<" + tag + " id=\"<%=" + id + "%>\"";

			if (others.Count > 0)
			{
				foreach (DictionaryEntry item in others)
				{
					m_CodeBody += " " + item.Key + "=\"" + item.Value + "\"";
				}
			}

			m_CodeBody += ">";

            m_CodeBody += "<%\r\nusing(MaxLabs.WebEngine.AjaxPanel " + autoID + " = new MaxLabs.WebEngine.AjaxPanel(" + id + ", " + idOnly + ", " + ajaxOnly + ", this.AjaxPanelContext, this.HtmlTextWriter)){%>";

            m_CodeBody += "<%\r\nHtmlTextWriter " + autoID + "__w = __w; if(__w.InnerWriter is AjaxPanelWriter == false) __w = " + autoID + ".Writer; %>";
			
			GenerateAspxCode(node, scopeData);

            m_CodeBody += "<%\r\n__w = " + autoID + "__w; }%>";

			m_CodeBody += "</" + tag + ">";

			if (onUpdate != null)
			{
                m_CodeBody += "<script type=\"text/javascript\">var __<%=" + id + "%>__ = document.getElementById('<%=" + id + "%>'); __<%=" + id + "%>__.onUpdate = function(panel){ " + onUpdate + " }</script>";
			}
		}
Example #27
0
        public static LanguageExpression FormatCrossScopeResourceId(ExpressionConverter expressionConverter, ScopeData scopeData, string fullyQualifiedType, IEnumerable <LanguageExpression> nameSegments)
        {
            var arguments = new List <LanguageExpression>();

            switch (scopeData.RequestedScope)
            {
            case ResourceScope.Tenant:
                arguments.Add(new JTokenExpression(fullyQualifiedType));
                arguments.AddRange(nameSegments);

                return(new FunctionExpression("tenantResourceId", arguments.ToArray(), Array.Empty <LanguageExpression>()));

            case ResourceScope.Subscription:
                if (scopeData.SubscriptionIdProperty != null)
                {
                    arguments.Add(expressionConverter.ConvertExpression(scopeData.SubscriptionIdProperty));
                }
                arguments.Add(new JTokenExpression(fullyQualifiedType));
                arguments.AddRange(nameSegments);

                return(new FunctionExpression("subscriptionResourceId", arguments.ToArray(), Array.Empty <LanguageExpression>()));

            case ResourceScope.ResourceGroup:
                // We avoid using the 'resourceId' function at all here, because its behavior differs depending on the scope that it is called FROM.
                LanguageExpression scope;
                if (scopeData.SubscriptionIdProperty == null)
                {
                    if (scopeData.ResourceGroupProperty == null)
                    {
                        scope = new FunctionExpression("resourceGroup", Array.Empty <LanguageExpression>(), new LanguageExpression[] { new JTokenExpression("id") });
                    }
                    else
                    {
                        var subscriptionId = new FunctionExpression("subscription", Array.Empty <LanguageExpression>(), new LanguageExpression[] { new JTokenExpression("subscriptionId") });
                        var resourceGroup  = expressionConverter.ConvertExpression(scopeData.ResourceGroupProperty);
                        scope = ExpressionConverter.GenerateResourceGroupScope(subscriptionId, resourceGroup);
                    }
                }
                else
                {
                    if (scopeData.ResourceGroupProperty == null)
                    {
                        throw new NotImplementedException($"Cannot format resourceId with non-null subscription and null resourceGroup");
                    }

                    var subscriptionId = expressionConverter.ConvertExpression(scopeData.SubscriptionIdProperty);
                    var resourceGroup  = expressionConverter.ConvertExpression(scopeData.ResourceGroupProperty);
                    scope = ExpressionConverter.GenerateResourceGroupScope(subscriptionId, resourceGroup);
                }

                // We've got to DIY it, unfortunately. The resourceId() function behaves differently when used at different scopes, so is unsuitable here.
                return(ExpressionConverter.GenerateScopedResourceId(scope, fullyQualifiedType, nameSegments));

            case ResourceScope.ManagementGroup:
                if (scopeData.ManagementGroupNameProperty != null)
                {
                    var managementGroupScope = expressionConverter.GenerateManagementGroupResourceId(scopeData.ManagementGroupNameProperty, true);

                    return(ExpressionConverter.GenerateScopedResourceId(managementGroupScope, fullyQualifiedType, nameSegments));
                }

                // We need to do things slightly differently for Management Groups, because there is no IL to output for "Give me a fully-qualified resource id at the current scope",
                // and we don't even have a mechanism for reliably getting the current scope (e.g. something like 'deployment().scope'). There are plans to add a managementGroupResourceId function,
                // but until we have it, we should generate unqualified resource Ids. There should not be a risk of collision, because we do not allow mixing of resource scopes in a single bicep file.
                return(ExpressionConverter.GenerateUnqualifiedResourceId(fullyQualifiedType, nameSegments));

            default:
                throw new NotImplementedException($"Cannot format resourceId for scope {scopeData.RequestedScope}");
            }
        }
            /// <inheritdoc />
            public override async ItemExecutionPromise Render(IByteCounterStream outputStream, ContextObject context, ScopeData scopeData)
            {
                return(await _action(outputStream, context, scopeData, Value, Children));

                //return Array.Empty<DocumentItemExecution>();
            }
Example #29
0
			public ScopeData(ScopeData previous)
			{
				Previous = previous;
                if (previous != null)
                    Previous.Next = this;
			}
Example #30
0
		private void GenerateFunctionInvokeAspxCode(StringBuffer codeBody, TemplateElement functionInvoke, Type type, out Type returnType, ScopeData scopeData)
		{
			returnType = null;

			string name = functionInvoke.Items[TemplateElement.KEY_NAME] as string;

			if (name == null)
			{
				#region 委托数组的调用
				if (type.IsSubclassOf(typeof(Delegate)) == false)
				{
					codeBody.InnerBuilder.Append(functionInvoke.SourceTemplate, functionInvoke.Index, functionInvoke.Length);
				}
				else
				{
					codeBody += "(";

					GenerateAspxCode(codeBody, functionInvoke.ChildNodes[0], scopeData);

					codeBody += ")";

					if (functionInvoke.ChildNodes.Count > 1)
						GenerateMemberInvokeAspxCode(codeBody, functionInvoke.ChildNodes[1], type.GetMethod("Invoke").ReturnType, out returnType, scopeData);
					
					if(returnType == null)
						returnType = type.GetMethod("Invoke").ReturnType;
				}
				#endregion
			}
			else
			{
				MethodInfo extensionFunction = SearchExtensionFunction(name, type);

				if (extensionFunction != null)
				{
					#region 扩展函数的调用

                    StringBuffer sb = new StringBuffer(ReflectionUtil.GetCSharpTypeName(extensionFunction.DeclaringType));

					sb += "." + extensionFunction.Name + "(";

					codeBody.InnerBuilder.Insert(0, sb);

					codeBody += ",\"" + name + "\"";

					if (extensionFunction.GetParameters().Length > 2)
					{
						codeBody += ",";

						GenerateAspxCode(codeBody, functionInvoke.ChildNodes[0], scopeData);
					}

					codeBody += ")";

					if (functionInvoke.ChildNodes.Count > 1)
						GenerateMemberInvokeAspxCode(codeBody, functionInvoke.ChildNodes[1], extensionFunction.ReturnType, out returnType, scopeData);
					
					if(returnType == null)
						returnType = extensionFunction.ReturnType;

					#endregion
				}
				else
				{
					#region 普通函数调用

					MethodInfo method = SearchMethod(name, type);

					if (method != null)
					{
						codeBody += "." + method.Name + "(";

						GenerateAspxCode(codeBody, functionInvoke.ChildNodes[0], scopeData);

						codeBody += ")";

						if (functionInvoke.ChildNodes.Count > 1)
							GenerateMemberInvokeAspxCode(codeBody, functionInvoke.ChildNodes[1], method.ReturnType, out returnType, scopeData);
						
						if(returnType == null)
							returnType = method.ReturnType;
					}

					#endregion
				}
			}
		}
Example #31
0
		private void GenerateVariableAspxCode(TemplateElement variable, ScopeData scopeData)
		{
			StringBuffer varBody = new StringBuffer();

			Type returnType = null;

			GenerateVariableAspxCode(varBody, variable, out returnType, scopeData);

			if(returnType != null && returnType != typeof(void))
				m_CodeBody += "<%=";
			else
                m_CodeBody += "<%\r\n";

			m_CodeBody += varBody;

			m_CodeBody += "%>";
		}
Example #32
0
		private void GenerateDoubleQuteStringAspxCode(StringBuffer codeBody, TemplateElement node, ScopeData scopeData)
		{
			if (node.ChildNodes.Count == 0)
			{
				codeBody += "\"\"";
				return;
			}

			for (int j = 0; j < node.ChildNodes.Count; j++)
			{
				TemplateElement element2 = node.ChildNodes[j];

				Type returnType = null;

				switch (element2.Type)
				{
					case TemplateElementTypes.Literal:
						codeBody += "\"";
						GenerateLiteralAspxCode(codeBody, element2);
						codeBody += "\"";
						break;

					case TemplateElementTypes.Variable:
						GenerateVariableAspxCode(codeBody, element2, out returnType, scopeData);
						break;

					case TemplateElementTypes.Function:
						GenerateFunctionAspxCode(codeBody, element2, out returnType, scopeData);
						break;

					case TemplateElementTypes.CodeBlock:
						GenerateCodeBlockAspxCode(codeBody, element2, scopeData);
						break;
				}

				if (j < node.ChildNodes.Count - 1)
					codeBody += " + ";
			}
		}
        /// <inheritdoc />
        public override async ItemExecutionPromise Render(IByteCounterStream outputStream, ContextObject context, ScopeData scopeData)
        {
            context = await MorestachioExpression.GetValue(context, scopeData);

            scopeData.AddVariable(Value, context, IdVariableScope);
            return(Enumerable.Empty <DocumentItemExecution>());
        }