Beispiel #1
0
        public Assembly CreateScript(ParsingResult Code, bool Debug, string AssembliesPath)
        {
            string code = this.Namespaces + @"
namespace " + AssemblyNamespace + @"
{

    public class CompiledGusScript : GusScript
    {

        " + Code.SharedCode + @"

        public override void Execute(GusServerRequest Request)
        {
            " + Code.ExecutionCode + @"
        }

    }
}";

            return(CompileAssembly(code, Debug, AssembliesPath));
        }
Beispiel #2
0
        public ParsingResult ParseScript(string ScriptCode)
        {
            if (ScriptCode == null)
            {
                return(null);
            }

            StringBuilder Builder       = new StringBuilder();
            StringBuilder sharedBuilder = new StringBuilder();

            int Last         = 0;
            int NextLocation = 0;

            int Location = ScriptCode.IndexOf("<&", 0);

            if (Location == -1)
            {
                return new ParsingResult {
                           ExecutionCode = "Request.ResponseStream.WriteText(@\"" + ScriptCode.Replace("\"", "\"\"") + "\" );\r\n\r\n", SharedCode = ""
                }
            }
            ;

            while (Location > -1)
            {
                if (Location > -1)
                {
                    string value = ScriptCode.Substring(Last, Location - Last).Replace("\"", "\"\"");

                    if (!string.IsNullOrEmpty(value) && value != "\r\n")
                    {
                        Builder.Append("Request.ResponseStream.WriteText(@\"" + ScriptCode.Substring(Last, Location - Last).Replace("\"", "\"\"") + "\" );\r\n\r\n");
                    }
                }

                NextLocation = ScriptCode.IndexOf("&>", Location);

                if (NextLocation < 0)
                {
                    break;
                }

                string Snippet = ScriptCode.Substring(Location, NextLocation - Location + 2);

                if (Snippet.Substring(2, 1) == "@")
                {
                    string Attribute = "";

                    Attribute = Utils.StrExtract(Snippet, "assembly", "=");

                    if (Attribute.Length > 0)
                    {
                        Attribute = Utils.StrExtract(Snippet, "\"", "\"");

                        if (Attribute.Length > 0)
                        {
                            this.Compiler.AddAssembly(Attribute);
                        }
                    }
                    else
                    {
                        Attribute = Utils.StrExtract(Snippet, "import", "=");

                        if (Attribute.Length > 0)
                        {
                            Attribute = Utils.StrExtract(Snippet, "\"", "\"");

                            if (Attribute.Length > 0)
                            {
                                this.Compiler.AddNamespace(Attribute);
                            }
                        }
                    }
                }
                else if (Snippet.Substring(2, 1) == "&" && Snippet.Substring(Snippet.Length - 3, 1) == "&")
                {
                    sharedBuilder.Append(Snippet.Substring(3, Snippet.Length - 6) + "\r\n");
                }
                else
                {
                    for (int buc = 0; buc < CustomKeywords.GetLength(0); buc++)
                    {
                        Snippet = Regex.Replace(Snippet, CustomKeywords[buc, 0], CustomKeywords[buc, 1]);
                    }

                    Builder.Append(Snippet.Substring(2, Snippet.Length - 4) + "\r\n");
                }

                Last     = NextLocation + 2;
                Location = ScriptCode.IndexOf("<&", Last);

                if (Location < 0)
                {
                    Builder.Append("Request.ResponseStream.WriteText(@\"" + ScriptCode.Substring(Last, ScriptCode.Length - Last).Replace("\"", "\"\"") + "\" );\r\n\r\n");
                }
            }

            ParsingResult result = new ParsingResult {
                ExecutionCode = Builder.ToString(), SharedCode = sharedBuilder.ToString()
            };

            return(result);
        }