Beispiel #1
0
        public object CreateType(string typeName, params object[] constructorArgs)
        {
            Trace.Assert(!String.IsNullOrWhiteSpace(typeName));

            Type t = typeLoader.LoadType(typeName);

            if (t == null)
            {
                console.log("Could not find a matching type: " + typeName);
                return(null);
            }
            object[] realArgs = ConvertToActualArgs(constructorArgs, t);
            if (realArgs == null)
            {
                console.log("Could not find a matching constructor.");
                return(null);
            }

            if (t.ContainsGenericParameters)
            {
                t = t.MakeGenericType(t.GetGenericArguments().Select(a => typeof(object)).ToArray());
            }
            TypeILWrapper wrapper  = new TypeILWrapper();
            object        instance = t.GetConstructors().Length == 0
        ? wrapper.CreateWrapperFromType(t)
        : wrapper.CreateWrapperFromInstance(Activator.CreateInstance(t, realArgs));

            console.log("Created instance of " + typeName + ".");
            return(instance);
        }
Beispiel #2
0
        public int process(string command, string arguments = null)
        {
            Trace.Assert(!String.IsNullOrWhiteSpace(command));

            using (var process = new Process
            {
                StartInfo =
                {
                    FileName               = command,
                    Arguments              = arguments,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true
                }
            })
            {
                process.Start();
                string err    = process.StandardError.ReadToEnd();
                string output = process.StandardOutput.ReadToEnd();

                if (!String.IsNullOrWhiteSpace(err))
                {
                    console.error(err);
                }
                if (!String.IsNullOrWhiteSpace(output))
                {
                    console.log(output);
                }

                process.WaitForExit();

                return(process.ExitCode);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Note: This is not supposed to be called manually, it should be called
        /// through the jish.assembly command which is defined in jish.js.  This
        /// is also why the help in this file is misleading (says name = assembly).
        //  This is intentional as jish.js assembly delegates to this.
        /// </summary>
        /// <param name="assemblyFileNameOrAssemblyName"></param>
        /// <returns>Returns a dictionary of all commands added (by namespace.commandName).</returns>
        public IDictionary <string, object> loadAssemblyImpl(string assemblyFileNameOrAssemblyName)
        {
            Trace.Assert(!String.IsNullOrWhiteSpace(assemblyFileNameOrAssemblyName));

            Assembly assembly = File.Exists(assemblyFileNameOrAssemblyName)
        ? Assembly.LoadFrom(assemblyFileNameOrAssemblyName)
        : Assembly.Load(assemblyFileNameOrAssemblyName);

            IDictionary <string, object> namespaceCommands = loader.GetCommandsMapFromAssembly(assembly);

            if (namespaceCommands == null)
            {
                console.log("Assembly '" + assembly.GetName().Name + "' is already loaded. Ignoring.");
                return(null);
            }
            console.log("Assembly '" + assembly.GetName().Name + "' loaded.");
            return(namespaceCommands);
        }
Beispiel #4
0
        public void InterceptSpecialCommands(string input)
        {
            Trace.Assert(!String.IsNullOrWhiteSpace(input));
            Trace.Assert(input.StartsWith("."));

            string commandName = new Regex(@"\.([A-z0-9])+").Match(input).Captures[0].Value.Substring(1).Trim();

            if (commandName.Equals("help"))
            {
                console.log(helpManager.GetHelpString());
                return;
            }
            if (!commands.ContainsKey(commandName))
            {
                console.log("Could not find command: " + input);
                return;
            }
            IConsoleCommand command = (IConsoleCommand)kernel.Get(commands[commandName]);

            command.Execute(ParseSpecialCommandInputs(input));
        }
Beispiel #5
0
        public override void Execute(params string[] args)
        {
            jish.ClearBufferedCommand();
            console.log("Clearing context...");
            jish.ExecuteCommand(
                @"
for (var i in this) {
  if (i === 'console' || i === 'global') continue;
  delete this[i];
}
null;
"
                );
        }
Beispiel #6
0
 public override void Execute(params string[] args)
 {
     console.log("test command executed");
 }
Beispiel #7
0
 private void LoadJavaScriptModule(string file)
 {
     RunFile(file);
     console.log("Successfully Imported JavaScript Module: " + file);
 }