Exemplo n.º 1
0
        protected static void ParsePure(IZeusScriptingEngine engine, ZeusCodeSegment segment, StringReader reader, StringBuilder builder)
        {
            string line, nextline;
            string tagSpecial         = segment.Template.TagStartSpecial,
                   tagEnd             = segment.Template.TagEnd,
                   language           = segment.Language;
            ArrayList       extraData = segment.ExtraData;
            bool            isGui     = (segment.SegmentType == ZeusConstants.CodeSegmentTypes.GUI_SEGMENT);
            int             index;
            bool            inBlock    = false;
            IZeusCodeParser codeParser = engine.CodeParser;

            line = reader.ReadLine();
            int i = reader.Peek();

            while (line != null)
            {
                nextline = reader.ReadLine();

                index = line.IndexOf(inBlock ? tagEnd : tagSpecial);
                while (index >= 0)
                {
                    if (inBlock)
                    {
                        inBlock = false;
                        builder.Append(codeParser.ParseCustomTag(segment, line.Substring(0, index)));

                        line = line.Substring(index + tagEnd.Length);
                    }
                    else
                    {
                        inBlock = true;

                        if (index > 0)
                        {
                            builder.Append(line.Substring(0, index));
                        }

                        line = line.Substring(index + tagSpecial.Length);
                    }

                    index = line.IndexOf(inBlock ? tagEnd : tagSpecial);
                }

                // with pure script mode, tags can NOT span more than one line!
                inBlock = false;

                builder.Append(line.Trim() + "\r\n");

                line = nextline;
            }

            builder.Insert(0, codeParser.GetCustomHeaderCode(segment, ZeusFactory.IntrinsicObjectsArray));
            builder.Append(codeParser.GetCustomFooterCode(segment, ZeusFactory.IntrinsicObjectsArray));
        }
Exemplo n.º 2
0
		protected static void ParsePure(IZeusScriptingEngine engine, ZeusCodeSegment segment, StringReader reader, StringBuilder builder) 
		{
			string line, nextline;
			string tagSpecial = segment.Template.TagStartSpecial, 
				tagEnd = segment.Template.TagEnd,
				language = segment.Language;
			ArrayList extraData = segment.ExtraData;
			bool isGui = (segment.SegmentType == ZeusConstants.CodeSegmentTypes.GUI_SEGMENT);
			int index;
			bool inBlock = false;
			IZeusCodeParser codeParser = engine.CodeParser;

			line = reader.ReadLine();
			int i = reader.Peek();
			while (line != null)
			{
				nextline = reader.ReadLine();

				index = line.IndexOf(inBlock ? tagEnd : tagSpecial);
				while (index >= 0) 
				{
					if (inBlock) 
					{
						inBlock = false;
						builder.Append( codeParser.ParseCustomTag(segment, line.Substring(0, index)) );

						line = line.Substring(index + tagEnd.Length);
					}
					else
					{
						inBlock = true;

						if (index > 0)
						{
							builder.Append(line.Substring(0, index));
						}
						
						line = line.Substring(index + tagSpecial.Length);
					}

					index = line.IndexOf(inBlock ? tagEnd : tagSpecial);
				}
				
				// with pure script mode, tags can NOT span more than one line!
				inBlock = false;
				
				builder.Append(line.Trim() + "\r\n");
				
				line = nextline;
			}

			builder.Insert(0, codeParser.GetCustomHeaderCode(segment, ZeusFactory.IntrinsicObjectsArray));
			builder.Append(codeParser.GetCustomFooterCode(segment, ZeusFactory.IntrinsicObjectsArray));
		}
Exemplo n.º 3
0
		protected static void ParseMarkup(IZeusScriptingEngine engine, ZeusCodeSegment segment, StringReader reader, StringBuilder builder) 
		{
			string line, nextline;
			string tagStart =  segment.Template.TagStart, 
				tagSpecial =  segment.Template.TagStartSpecial, 
				tagShortcut =  segment.Template.TagStartShortcut, 
				tagEnd = segment.Template.TagEnd,
				language = segment.Language;
			ArrayList extraData = segment.ExtraData;
			int index;
			bool inBlock = false;
			bool isShortcut = false;
			bool isCustom = false;
			string nextTagToFind = string.Empty;
			IZeusCodeParser codeParser = engine.CodeParser;
            var sb = new StringBuilder();

			int headerInsertIndex = builder.Length;

			line = reader.ReadLine();
			int i = reader.Peek();
			while (line != null)
			{
				nextline = reader.ReadLine();

				index = line.IndexOf(inBlock ? tagEnd : tagStart);
				while (index >= 0) 
				{
					if (inBlock) 
					{
						inBlock = false;

						if (isShortcut) 
						{
                            sb.Append(line.Substring(0, index));

							//TODO: ***If the line in the shortcut has more than one command (a semicolon) throw an exception.
							builder.Append( codeParser.BuildOutputCommand(language, sb.ToString() , false, false) );
                            sb.Clear();

							isShortcut = false;
						}
						else if (isCustom) 
						{
							//TODO: ***If the line in the include has more than one command (a semicolon) throw an exception.
							builder.Append( codeParser.ParseCustomTag(segment, line.Substring(0, index)) );
							
							isCustom = false;
						}
						else
						{
							builder.Append(line.Substring(0, index).Trim() + "\r\n");
						}
						line = line.Substring(index + tagEnd.Length);
					}
					else
					{
						inBlock = true;
						if (index > 0)
						{
                            // Append the code before the open tag
							builder.Append( codeParser.BuildOutputCommand(language, line.Substring(0, index), true, false) );
						}

						if (index == line.IndexOf(tagShortcut)) 
						{
							isCustom = false;
							isShortcut = true;
                            // Set the line to the actual code
							line = line.Substring(index + tagShortcut.Length);
						}
						else if (index == line.IndexOf(tagSpecial)) 
						{
							isCustom = true;
							isShortcut = false;
							line = line.Substring(index + tagSpecial.Length);
						}
						else 
						{
							isCustom = false;
							isShortcut = false;
							line = line.Substring(index + tagStart.Length);
						}
					}

					index = line.IndexOf(inBlock ? tagEnd : tagStart);
				}
				
				// Custom tags have to start and end on the same line!
				isCustom = false;

                if (isShortcut) {
                    sb.Append(line.Trim() + "\r\n");
                }
				else if (inBlock) 
				{
					builder.Append(line.Trim() + "\r\n");
				}
				else 
				{
					if ( !((nextline == null) && (line == string.Empty)) ) 
					{
						builder.Append( codeParser.BuildOutputCommand(language, line, true, true) );
					}
				}

				line = nextline;
			}

            //HuyNH define new template function type:
            //using: <%#FILECOMPILER filename.zeus%>

            if (!segment.Template.Type.Equals(ZeusConstants.Types.INCLUDE_FUNCTION))
            {
                builder.Insert(headerInsertIndex, codeParser.GetCustomHeaderCode(segment, ZeusFactory.IntrinsicObjectsArray));
                builder.Append(codeParser.GetCustomFooterCode(segment, ZeusFactory.IntrinsicObjectsArray));
            }
		}
Exemplo n.º 4
0
        protected static void ParseMarkup(IZeusScriptingEngine engine, ZeusCodeSegment segment, StringReader reader, StringBuilder builder)
        {
            string line, nextline;
            string tagStart           = segment.Template.TagStart,
                   tagSpecial         = segment.Template.TagStartSpecial,
                   tagShortcut        = segment.Template.TagStartShortcut,
                   tagEnd             = segment.Template.TagEnd,
                   language           = segment.Language;
            ArrayList       extraData = segment.ExtraData;
            int             index;
            bool            inBlock       = false;
            bool            isShortcut    = false;
            bool            isCustom      = false;
            string          nextTagToFind = string.Empty;
            IZeusCodeParser codeParser    = engine.CodeParser;
            var             sb            = new StringBuilder();

            int headerInsertIndex = builder.Length;

            line = reader.ReadLine();
            int i = reader.Peek();

            while (line != null)
            {
                nextline = reader.ReadLine();

                index = line.IndexOf(inBlock ? tagEnd : tagStart);
                while (index >= 0)
                {
                    if (inBlock)
                    {
                        inBlock = false;

                        if (isShortcut)
                        {
                            sb.Append(line.Substring(0, index));

                            //TODO: ***If the line in the shortcut has more than one command (a semicolon) throw an exception.
                            builder.Append(codeParser.BuildOutputCommand(language, sb.ToString(), false, false));
                            sb.Clear();

                            isShortcut = false;
                        }
                        else if (isCustom)
                        {
                            //TODO: ***If the line in the include has more than one command (a semicolon) throw an exception.
                            builder.Append(codeParser.ParseCustomTag(segment, line.Substring(0, index)));

                            isCustom = false;
                        }
                        else
                        {
                            builder.Append(line.Substring(0, index).Trim() + "\r\n");
                        }
                        line = line.Substring(index + tagEnd.Length);
                    }
                    else
                    {
                        inBlock = true;
                        if (index > 0)
                        {
                            // Append the code before the open tag
                            builder.Append(codeParser.BuildOutputCommand(language, line.Substring(0, index), true, false));
                        }

                        if (index == line.IndexOf(tagShortcut))
                        {
                            isCustom   = false;
                            isShortcut = true;
                            // Set the line to the actual code
                            line = line.Substring(index + tagShortcut.Length);
                        }
                        else if (index == line.IndexOf(tagSpecial))
                        {
                            isCustom   = true;
                            isShortcut = false;
                            line       = line.Substring(index + tagSpecial.Length);
                        }
                        else
                        {
                            isCustom   = false;
                            isShortcut = false;
                            line       = line.Substring(index + tagStart.Length);
                        }
                    }

                    index = line.IndexOf(inBlock ? tagEnd : tagStart);
                }

                // Custom tags have to start and end on the same line!
                isCustom = false;

                if (isShortcut)
                {
                    sb.Append(line.Trim() + "\r\n");
                }
                else if (inBlock)
                {
                    builder.Append(line.Trim() + "\r\n");
                }
                else
                {
                    if (!((nextline == null) && (line == string.Empty)))
                    {
                        builder.Append(codeParser.BuildOutputCommand(language, line, true, true));
                    }
                }

                line = nextline;
            }

            //HuyNH define new template function type:
            //using: <%#FILECOMPILER filename.zeus%>

            if (!segment.Template.Type.Equals(ZeusConstants.Types.INCLUDE_FUNCTION))
            {
                builder.Insert(headerInsertIndex, codeParser.GetCustomHeaderCode(segment, ZeusFactory.IntrinsicObjectsArray));
                builder.Append(codeParser.GetCustomFooterCode(segment, ZeusFactory.IntrinsicObjectsArray));
            }
        }
Exemplo n.º 5
0
        static protected void ExecuteCode(IZeusExecutionHelper helper, IZeusTemplate template, IZeusContext context, ArrayList templateGroupIds)
        {
            if (!template.BodySegment.IsEmpty)
            {
                try
                {
                    // Execute Template Body
                    helper.EngineExecuteCode(template.BodySegment, context);

                    if (helper.HasErrors)
                    {
                        IZeusExecutionError[] errors = helper.Errors;
                        helper.ClearErrors();
                        throw new ZeusExecutionException(template, errors, true);
                    }
                }
                catch (Exception ex)
                {
                    throw new ZeusRuntimeException(template, ex, true);
                }
            }

            if (template.Type == ZeusConstants.Types.GROUP)
            {
                if (template.IncludedTemplates.Count > 0)
                {
                    // Execute Template Body
                    if (templateGroupIds.Contains(template.UniqueID))
                    {
                        return;
                    }

                    templateGroupIds.Add(template.UniqueID);

                    foreach (ZeusTemplate childTemplate in template.IncludedTemplates)
                    {
                        if (childTemplate.UniqueID != template.UniqueID)
                        {
                            //clear the output buffer before executing the next template!
                            context.Output.clear();

                            //Push the current template onto the Execution stack
                            if (context is ZeusContext)
                            {
                                ((ZeusContext)context).TemplateStack.Push(childTemplate);
                            }

                            try
                            {
                                IZeusScriptingEngine engine = ZeusFactory.GetEngine(childTemplate.BodySegment.Engine);
                                ExecuteCode(engine.ExecutionHelper, childTemplate, context, templateGroupIds);
                            }
                            finally
                            {
                                //Pop the current template off of the Execution stack
                                if (context is ZeusContext)
                                {
                                    ((ZeusContext)context).TemplateStack.Pop();
                                }
                            }
                        }
                    }
                }
            }
        }