Beispiel #1
0
        public override string ToLC()
        {
            /*
             *   INTERPRETER:Jint
             *   INPUT x,y
             *   BEGIN SCRIPT
             *   var result = x + y;
             *   END SCRIPT
             *   OUTPUT Int result
             */

            using var writer = new LoliCodeWriter(base.ToLC());
            writer.WriteLine($"INTERPRETER:{Interpreter}");
            writer.WriteLine($"INPUT {InputVariables}");
            writer.WriteLine("BEGIN SCRIPT");
            writer.WriteLine(Regex.Replace(Script, $"(\r\n)*$", ""));
            writer.WriteLine("END SCRIPT");

            foreach (var output in OutputVariables)
            {
                writer.WriteLine($"OUTPUT {output.Type} @{output.Name}");
            }

            return(writer.ToString());
        }
        public virtual string ToLC()
        {
            /*
             * BLOCK:BlockId
             * DISABLED
             * LABEL:My Label
             */

            using var writer = new LoliCodeWriter();

            if (Disabled)
            {
                writer.WriteLine("DISABLED");
            }

            if (Label != ReadableName)
            {
                writer.WriteLine($"LABEL:{Label}");
            }

            // Write all the settings
            foreach (var setting in Settings.Values)
            {
                if (!Descriptor.Parameters.ContainsKey(setting.Name))
                {
                    throw new Exception($"This setting is not a valid input parameter: {setting.Name}");
                }

                writer.AppendSetting(setting, Descriptor.Parameters[setting.Name]);
            }

            return(writer.ToString());
        }
        public override string ToLC(bool printDefaultParams = false)
        {
            /*
             *   KEYCHAIN SUCCESS OR
             *     STRINGKEY @myVariable Contains "abc"
             *     DICTKEY @data.COOKIES HasKey "my-cookie"
             *   KEYCHAIN FAIL AND
             *     LISTKEY @myList Contains "item"
             *     FLOATKEY 1 GreaterThan 2
             */

            using var writer = new LoliCodeWriter(base.ToLC(printDefaultParams));

            // Write all the keychains
            foreach (var keychain in Keychains)
            {
                writer
                .AppendToken("KEYCHAIN", 2)
                .AppendToken(keychain.ResultStatus)
                .AppendLine(keychain.Mode.ToString());

                foreach (var key in keychain.Keys)
                {
                    (string keyName, string comparison) = key switch
                    {
                        BoolKey x => ("BOOLKEY", x.Comparison.ToString()),
                        StringKey x => ("STRINGKEY", x.Comparison.ToString()),
                        IntKey x => ("INTKEY", x.Comparison.ToString()),
                        FloatKey x => ("FLOATKEY", x.Comparison.ToString()),
                        DictionaryKey x => ("DICTKEY", x.Comparison.ToString()),
                        ListKey x => ("LISTKEY", x.Comparison.ToString()),
                        _ => throw new Exception("Unknown key type")
                    };

                    writer
                    .AppendToken(keyName, 4)
                    .AppendToken(LoliCodeWriter.GetSettingValue(key.Left))
                    .AppendToken(comparison)
                    .AppendLine(LoliCodeWriter.GetSettingValue(key.Right));
                }
            }

            return(writer.ToString());
        }
        public override string ToLC()
        {
            /*
             *   TYPE:STANDARD
             *   "name=hello&value=hi"
             *   "application/x-www-form-urlencoded"
             *
             *   TYPE:RAW
             *   BASE64_DATA
             *   "application/octet-stream"
             *
             *   TYPE:BASICAUTH
             *   "myUser"
             *   "myPass"
             *
             *   TYPE:MULTIPART
             *   "myBoundary"
             *   CONTENT:STRING "name" "content" "content-type"
             *   CONTENT:RAW "name" BASE64_DATA "content-type"
             *   CONTENT:FILE "name" "fileName" "content-type"
             *
             */

            using var writer = new LoliCodeWriter(base.ToLC());

            switch (RequestParams)
            {
            case StandardRequestParams x:
                writer
                .AppendLine("TYPE:STANDARD", 2)
                .AppendLine(LoliCodeWriter.GetSettingValue(x.Content), 2)
                .AppendLine(LoliCodeWriter.GetSettingValue(x.ContentType), 2);
                break;

            case RawRequestParams x:
                writer
                .AppendLine("TYPE:RAW", 2)
                .AppendLine(LoliCodeWriter.GetSettingValue(x.Content), 2)
                .AppendLine(LoliCodeWriter.GetSettingValue(x.ContentType), 2);
                break;

            case BasicAuthRequestParams x:
                writer
                .AppendLine("TYPE:BASICAUTH", 2)
                .AppendLine(LoliCodeWriter.GetSettingValue(x.Username), 2)
                .AppendLine(LoliCodeWriter.GetSettingValue(x.Password), 2);
                break;

            case MultipartRequestParams x:
                writer
                .AppendLine("TYPE:MULTIPART", 2)
                .AppendLine(LoliCodeWriter.GetSettingValue(x.Boundary), 2);

                foreach (var content in x.Contents)
                {
                    switch (content)
                    {
                    case StringHttpContentSettingsGroup y:
                        writer
                        .AppendToken("CONTENT:STRING", 2)
                        .AppendToken(LoliCodeWriter.GetSettingValue(y.Name))
                        .AppendToken(LoliCodeWriter.GetSettingValue(y.Data))
                        .AppendLine(LoliCodeWriter.GetSettingValue(y.ContentType));
                        break;

                    case RawHttpContentSettingsGroup y:
                        writer
                        .AppendToken("CONTENT:RAW", 2)
                        .AppendToken(LoliCodeWriter.GetSettingValue(y.Name))
                        .AppendToken(LoliCodeWriter.GetSettingValue(y.Data))
                        .AppendLine(LoliCodeWriter.GetSettingValue(y.ContentType));
                        break;

                    case FileHttpContentSettingsGroup y:
                        writer
                        .AppendToken("CONTENT:FILE", 2)
                        .AppendToken(LoliCodeWriter.GetSettingValue(y.Name))
                        .AppendToken(LoliCodeWriter.GetSettingValue(y.FileName))
                        .AppendLine(LoliCodeWriter.GetSettingValue(y.ContentType));
                        break;
                    }
                }

                break;
            }

            return(writer.ToString());
        }