Beispiel #1
0
        //--- Class Methods ---
        static void Main(string[] args) {

            // check supplied arguments
            if(args.Length == 0) {
                Console.WriteLine("Missing extension path");
                PrintUsage();
                return;
            }
            string extension = args[0];
            string expression = (args.Length > 1) ? args[1] : null;
            try {
                if(!extension.ToLowerInvariant().StartsWith("http")) {
                    if(extension[1] != ':') {
                        extension = Environment.CurrentDirectory + Path.DirectorySeparatorChar + extension;
                    }
                    if(!File.Exists(extension)) {
                        Console.WriteLine("Specified extension not found: {0}", extension);
                        PrintUsage();
                        return;
                    }
                }
            } catch(Exception) {
                Console.WriteLine("Unable to parse extension path: {0}", args[0]);
                PrintUsage();
                return;
            }

            // validate script extension
            ScriptManifestValidator validator = new ScriptManifestValidator();
            ScriptManifestValidationResult validationResult = validator.Validate(extension);
            if(validationResult.IsInvalid) {
                Console.WriteLine("The script has some errors:");
                Console.WriteLine(validationResult.ValidationErrors);
                return;
            }


            // initialize script test service
            ScriptTestHarness harness = new ScriptTestHarness();
            XDoc manifest = null;
            try {
                manifest = harness.LoadExtension(extension);
            } catch(DreamResponseException e) {
                Console.WriteLine("Unable to load script from '{0}': ", extension);
                Console.WriteLine(e.Response.ToText());
                return;
            }

            // list functions
            if(expression == null) {
                Console.WriteLine("Script loaded successfully");
                Console.WriteLine("Available functions:");
                string ns = manifest["namespace"].AsText;
                foreach(XDoc function in manifest["function"]) {
                    string name = function["name"].AsText;
                    Console.WriteLine("  {0}", string.IsNullOrEmpty(ns) ? name : ns + "." + name);
                }
            } else {

                // or execute passed DekiScript
                try {
                    string result = harness.Execute(expression);
                    Console.WriteLine("Script executed successfully:");
                    Console.WriteLine("Script: {0}", expression);
                    Console.WriteLine("Result:");
                    Console.WriteLine(result);
                } catch(DreamResponseException e) {
                    Console.WriteLine("Unable to execute script '{0}': ", expression);
                    Console.WriteLine(e);
                }
            }
        }
Beispiel #2
0
        //--- Class Methods ---
        static void Main(string[] args)
        {
            // check supplied arguments
            if (args.Length == 0)
            {
                Console.WriteLine("Missing extension path");
                PrintUsage();
                return;
            }
            string extension  = args[0];
            string expression = (args.Length > 1) ? args[1] : null;

            try {
                if (!extension.ToLowerInvariant().StartsWith("http"))
                {
                    if (extension[1] != ':')
                    {
                        extension = Environment.CurrentDirectory + Path.DirectorySeparatorChar + extension;
                    }
                    if (!File.Exists(extension))
                    {
                        Console.WriteLine("Specified extension not found: {0}", extension);
                        PrintUsage();
                        return;
                    }
                }
            } catch (Exception) {
                Console.WriteLine("Unable to parse extension path: {0}", args[0]);
                PrintUsage();
                return;
            }

            // validate script extension
            ScriptManifestValidator        validator        = new ScriptManifestValidator();
            ScriptManifestValidationResult validationResult = validator.Validate(extension);

            if (validationResult.IsInvalid)
            {
                Console.WriteLine("The script has some errors:");
                Console.WriteLine(validationResult.ValidationErrors);
                return;
            }


            // initialize script test service
            ScriptTestHarness harness = new ScriptTestHarness();
            XDoc manifest             = null;

            try {
                manifest = harness.LoadExtension(extension);
            } catch (DreamResponseException e) {
                Console.WriteLine("Unable to load script from '{0}': ", extension);
                Console.WriteLine(e.Response.ToText());
                return;
            }

            // list functions
            if (expression == null)
            {
                Console.WriteLine("Script loaded successfully");
                Console.WriteLine("Available functions:");
                string ns = manifest["namespace"].AsText;
                foreach (XDoc function in manifest["function"])
                {
                    string name = function["name"].AsText;
                    Console.WriteLine("  {0}", string.IsNullOrEmpty(ns) ? name : ns + "." + name);
                }
            }
            else
            {
                // or execute passed DekiScript
                try {
                    string result = harness.Execute(expression);
                    Console.WriteLine("Script executed successfully:");
                    Console.WriteLine("Script: {0}", expression);
                    Console.WriteLine("Result:");
                    Console.WriteLine(result);
                } catch (DreamResponseException e) {
                    Console.WriteLine("Unable to execute script '{0}': ", expression);
                    Console.WriteLine(e);
                }
            }
        }