Beispiel #1
0
        private static Script getSampleScript(ScriptContext context)
        {
            Script script = new Script();

            script.Id = "WAIT";
            script.VersionInfo.Title = "WAIT";
            script.VersionInfo.Value = "(Generated sample script)";
            script.EngineVersion     = context.CoreVersion.ToString();
            script.Parameters.Add(
                new CommandLineParameter {
                Default = "2000", Value = "Number of seconds to wait", Description = "seconds", Switch = "seconds", Count = CommandLineValueCount.Single
            }
                );
            script.Parameters.Add(
                new CommandLineParameter {
                Default = "0", Value = "Display this message", Switch = "help", Synonyms = "?;helpme", Unspecified = "true"
            }
                );


            script.Add(new Code {
                Value = "Context.WriteLine(\"Hello, world!\");"
            });
            script.Add(new Code {
                Value = "Context.WriteLine(\"This script will be waiting for {0} seconds.\",c[\"seconds\"]);"
            });
            Timer timer = new Timer {
                OutTo = "execTime", Format = TimerFormat.TimeSpan
            };

            timer.Add(new Sleep {
                Timeout = "${seconds}"
            });
            script.AddTry(timer);
            script.AddTry(new Print {
                Value = "Execution took ${execTime}"
            });

            script.AddTry(new Throw {
                Value = "Test error"
            });
            script.AddTry(new Print {
                Value = "This will not be printed"
            });
            script.AddCatch(new Print {
                Value = "Catched exception: ${=c.CurrentException.Message}"
            });
            script.AddFinally(new Print {
                Value = "Clean up part"
            });
            return(script);
        }
Beispiel #2
0
        private static Script getSampleScript(ScriptContext context)
        {
            Script script = new Script();
            script.Id = "WAIT";
            script.VersionInfo.Title = "WAIT";
            script.VersionInfo.Value = "(Generated sample script)";
            script.EngineVersion = context.CoreVersion.ToString();
            script.Parameters.Add(
                new CommandLineParameter { Default = "2000", Value = "Number of seconds to wait", Description = "seconds", Switch = "seconds", Count = CommandLineValueCount.Single }
                );
            script.Parameters.Add(
                new CommandLineParameter { Default = "0", Value = "Display this message", Switch = "help", Synonyms = "?;helpme", Unspecified = "true" }
                );

            script.Add(new Code { Value = "Context.WriteLine(\"Hello, world!\");" });
            script.Add(new Code { Value = "Context.WriteLine(\"This script will be waiting for {0} seconds.\",c[\"seconds\"]);" });
            Timer timer = new Timer { OutTo = "execTime", Format = TimerFormat.TimeSpan };
            timer.Add(new Sleep { Timeout = "${seconds}" });
            script.AddTry(timer);
            script.AddTry(new Print { Value="Execution took ${execTime}"});

            script.AddTry(new Throw { Value = "Test error" });
            script.AddTry(new Print { Value = "This will not be printed" });
            script.AddCatch(new Print { Value = "Catched exception: ${=c.CurrentException.Message}" });
            script.AddFinally(new Print { Value = "Clean up part" });
            return script;
        }