Beispiel #1
0
        public Site(Uri uri, bool incidx = false, bool scplnks = false, bool scpimgs = false, PipelineOutput outputtype = PipelineOutput.Plaintext)
        {
            URL = uri;

            IncludeIndex = incidx;
            ScrapeLinks  = scplnks;
            ScrapeImages = scplnks;
            OutputType   = outputtype;

            logStream = new LogStream();
        }
Beispiel #2
0
        protected override void Execute(CodeActivityContext context)
        {
            string currentdir = System.IO.Directory.GetCurrentDirectory();

            try
            {
                System.IO.Directory.SetCurrentDirectory(Interfaces.Extensions.ProjectsDirectory);


                var code           = Code.Get(context);
                var language       = Language.Get(context);
                var variables      = new Dictionary <string, Type>();
                var variablevalues = new Dictionary <string, object>();
                var vars           = context.DataContext.GetProperties();
                foreach (dynamic v in vars)
                {
                    Type rtype = v.PropertyType as Type;
                    var  value = v.GetValue(context.DataContext);

                    if (rtype == null && value != null)
                    {
                        rtype = value.GetType();
                    }
                    if (rtype == null)
                    {
                        continue;
                    }
                    variables.Add(v.DisplayName, rtype);
                    variablevalues.Add(v.DisplayName, value);
                }
                string WorkflowInstanceId = context.WorkflowInstanceId.ToString();

                var instance = Plugin.client.GetWorkflowInstanceByInstanceId(WorkflowInstanceId);
                variables.Add("instance", typeof(IWorkflowInstance));
                variablevalues.Add("instance", instance);

                string sourcecode = code;
                if (namespaces == null)
                {
                    throw new Exception("InvokeCode is missing namespaces, please open workflow in designer and save changes");
                }
                if (language == "VB")
                {
                    var header = GetVBHeaderText(variables, "Expression", namespaces);
                    sourcecode = header + code + GetVBFooterText();
                    int numLines = header.Split('\n').Length;
                    Log.Debug("Header (add to line numbers): " + numLines);
                }
                if (language == "C#")
                {
                    var header = GetCSharpHeaderText(variables, "Expression", namespaces);
                    sourcecode = header + code + GetCSharpFooterText();
                    int numLines = header.Split('\n').Length;
                    Log.Debug("Header (add to line numbers): " + numLines);
                }
                if (language == "PowerShell")
                {
                    if (runspace == null)
                    {
                        runspace = RunspaceFactory.CreateRunspace();
                        runspace.Open();
                    }

                    using (var pipeline = runspace.CreatePipeline())
                    {
                        Command cmd = new Command(sourcecode, true);
                        foreach (var parameter in variablevalues)
                        {
                            // cmd.Parameters.Add(parameter.Key, parameter.Value);
                            runspace.SessionStateProxy.SetVariable(parameter.Key, parameter.Value);
                        }
                        pipeline.Commands.Add(cmd);
                        var res = pipeline.Invoke();
                        foreach (var o in res)
                        {
                            if (o != null)
                            {
                                Log.Output(o.ToString());
                            }
                        }
                        foreach (dynamic v in vars)
                        {
                            var value = runspace.SessionStateProxy.GetVariable(v.DisplayName);
                            var myVar = context.DataContext.GetProperties().Find(v.DisplayName, true);
                            try
                            {
                                if (myVar != null && value != null)
                                {
                                    //var myValue = myVar.GetValue(context.DataContext);
                                    myVar.SetValue(context.DataContext, value);
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Error(ex.ToString());
                            }
                        }
                        PipelineOutput.Set(context, res);
                    }

                    return;
                }
                if (language == "AutoHotkey")
                {
                    AppDomain Temporary = null;
                    try
                    {
                        AppDomainSetup domaininfo = new AppDomainSetup();
                        domaininfo.ApplicationBase = global.CurrentDirectory;
                        System.Security.Policy.Evidence adevidence = AppDomain.CurrentDomain.Evidence;
                        Temporary = AppDomain.CreateDomain("Temporary", adevidence, domaininfo);
                        Temporary.AssemblyResolve += AHKProxy.CurrentDomain_AssemblyResolve;

                        //var ahk = (AutoHotkey.Interop.AutoHotkeyEngine)Temporary.CreateInstanceAndUnwrap("sharpAHK, Version=1.0.0.5, Culture=neutral, PublicKeyToken=null", "AutoHotkey.Interop.AutoHotkeyEngine");

                        Type type = typeof(AHKProxy);
                        var  ahk  = (AHKProxy)Temporary.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);

                        foreach (var parameter in variablevalues)
                        {
                            if (parameter.Value == null)
                            {
                                continue;
                            }
                            ahk.SetVar(parameter.Key, parameter.Value.ToString());
                        }
                        ahk.ExecRaw(code);
                        foreach (dynamic v in vars)
                        {
                            var value = ahk.GetVar(v.DisplayName);
                            PropertyDescriptor myVar = context.DataContext.GetProperties().Find(v.DisplayName, true);
                            if (myVar != null && value != null)
                            {
                                if (myVar.PropertyType == typeof(string))
                                {
                                    myVar.SetValue(context.DataContext, value);
                                }
                                else if (myVar.PropertyType == typeof(int))
                                {
                                    myVar.SetValue(context.DataContext, int.Parse(value.ToString()));
                                }
                                else if (myVar.PropertyType == typeof(bool))
                                {
                                    myVar.SetValue(context.DataContext, bool.Parse(value.ToString()));
                                }
                                else
                                {
                                    Log.Information("Ignorering variable " + v.DisplayName + " of type " + myVar.PropertyType.FullName);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.ToString());
                        throw;
                    }
                    finally
                    {
                        if (Temporary != null)
                        {
                            AppDomain.Unload(Temporary);
                        }
                    }
                    return;
                }
                if (language == "Python")
                {
                    Exception ex = null;
                    GenericTools.RunUI(() =>
                    {
                        if (PluginConfig.use_embedded_python)
                        {
                            System.IO.Directory.SetCurrentDirectory(Python.Included.Installer.EmbeddedPythonHome);
                        }
                        else
                        {
                            var path = OpenRPA.Script.PythonUtil.Setup.GetExePath("python");
                            System.IO.Directory.SetCurrentDirectory(path);
                        }

                        bool doRelease = false;
                        IntPtr lck     = IntPtr.Zero;
                        try
                        {
                            if (python_doinit)
                            {
                                Python.Runtime.PythonEngine.Initialize();
                                _             = Python.Runtime.PythonEngine.BeginAllowThreads();
                                python_doinit = false;
                            }
                            lck       = PythonEngine.AcquireLock();
                            doRelease = true;
                            using (var scope = Py.CreateScope())
                            {
                                foreach (var parameter in variablevalues)
                                {
                                    PyObject pyobj = parameter.Value.ToPython();
                                    scope.Set(parameter.Key, pyobj);
                                }
                                try
                                {
                                    PythonOutput output = new PythonOutput();
                                    dynamic sys         = Py.Import("sys");
                                    sys.stdout          = output;
                                    sys.stderr          = output;

                                    //                                    PythonEngine.RunSimpleString(@"
                                    //import sys
                                    //from System import Console
                                    //class output(object):
                                    //    def write(self, msg):
                                    //        Console.Out.Write(msg)
                                    //    def writelines(self, msgs):
                                    //        for msg in msgs:
                                    //            Console.Out.Write(msg)
                                    //    def flush(self):
                                    //        pass
                                    //    def close(self):
                                    //        pass
                                    //sys.stdout = sys.stderr = output()
                                    //");
                                }
                                catch (Exception _ex)
                                {
                                    Log.Debug(_ex.ToString());
                                }
                                scope.Exec(code);
                                foreach (var parameter in variablevalues)
                                {
                                    PyObject pyobj = scope.Get(parameter.Key);
                                    if (pyobj == null)
                                    {
                                        continue;
                                    }
                                    PropertyDescriptor myVar = context.DataContext.GetProperties().Find(parameter.Key, true);
                                    if (myVar == null)
                                    {
                                        continue;
                                    }
                                    if (myVar.PropertyType == typeof(string))
                                    {
                                        myVar.SetValue(context.DataContext, pyobj.ToString());
                                    }
                                    else if (myVar.PropertyType == typeof(int))
                                    {
                                        myVar.SetValue(context.DataContext, int.Parse(pyobj.ToString()));
                                    }
                                    else if (myVar.PropertyType == typeof(bool))
                                    {
                                        myVar.SetValue(context.DataContext, bool.Parse(pyobj.ToString()));
                                    }
                                    else
                                    {
                                        try
                                        {
                                            var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(pyobj.ToString(), myVar.PropertyType);
                                            myVar.SetValue(context.DataContext, obj);
                                        }
                                        catch (Exception _ex)
                                        {
                                            Log.Information("Failed variable " + parameter.Key + " of type " + myVar.PropertyType.FullName + " " + _ex.Message);
                                        }
                                    }
                                }
                            }
                            //lck = PythonEngine.AcquireLock();
                            //PythonEngine.Exec(code);
                        }
                        catch (Exception _ex)
                        {
                            ex = _ex;
                        }
                        finally
                        {
                            if (doRelease)
                            {
                                PythonEngine.ReleaseLock(lck);
                            }
                        }
                    });
                    //using (Python.Runtime.Py.GIL())
                    //{
                    //    IntPtr lck = Python.Runtime.PythonEngine.AcquireLock();
                    //    Python.Runtime.PythonEngine.Exec(code);
                    //    Python.Runtime.PythonEngine.ReleaseLock(lck);
                    //    //// create a Python scope
                    //    //using (var scope = Python.Runtime.Py.CreateScope())
                    //    //{
                    //    //    //// convert the Person object to a PyObject
                    //    //    //PyObject pyPerson = person.ToPython();

                    //    //    // create a Python variable "person"
                    //    //    // scope.Set("person", pyPerson);

                    //    //    // the person object may now be used in Python
                    //    //    // string code = "fullName = person.FirstName + ' ' + person.LastName";
                    //    //    scope.Exec(code);
                    //    //}
                    //}

                    if (ex != null)
                    {
                        throw ex;
                    }

                    // Python.Runtime.PythonEngine.Shutdown();
                    return;
                }
                var assemblyLocations = GetAssemblyLocations();
                CompileAndRun(language, sourcecode, assemblyLocations.ToArray(), variablevalues, context);
            }
            finally
            {
                System.IO.Directory.SetCurrentDirectory(currentdir);
            }
        }
Beispiel #3
0
        protected override void Execute(CodeActivityContext context)
        {
            var code           = Code.Get(context);
            var language       = Language.Get(context);
            var variables      = new Dictionary <string, Type>();
            var variablevalues = new Dictionary <string, object>();
            var vars           = context.DataContext.GetProperties();

            foreach (dynamic v in vars)
            {
                Type rtype = v.PropertyType as Type;
                //var rtype = v.PropertyType.UnderlyingSystemType;
                var value = v.GetValue(context.DataContext);

                if (rtype == null && value != null)
                {
                    rtype = value.GetType();
                }
                if (rtype == null)
                {
                    continue;
                }
                variables.Add(v.DisplayName, rtype);
                variablevalues.Add(v.DisplayName, value);
            }
            string sourcecode = code;

            if (language == "VB")
            {
                sourcecode = GetVBHeaderText(variables, "Expression") + code + GetVBFooterText();
            }
            if (language == "C#")
            {
                sourcecode = GetCSharpHeaderText(variables, "Expression") + code + GetCSharpFooterText();
            }

            if (language == "PowerShell")
            {
                if (runspace == null)
                {
                    runspace = RunspaceFactory.CreateRunspace();
                    runspace.Open();
                }

                using (var pipeline = runspace.CreatePipeline())
                {
                    Command cmd = new Command(sourcecode, true);
                    foreach (var parameter in variablevalues)
                    {
                        // cmd.Parameters.Add(parameter.Key, parameter.Value);
                        runspace.SessionStateProxy.SetVariable(parameter.Key, parameter.Value);
                    }
                    pipeline.Commands.Add(cmd);
                    var res = pipeline.Invoke();
                    foreach (var o in res)
                    {
                        if (o != null)
                        {
                            Log.Output(o.ToString());
                        }
                    }
                    foreach (dynamic v in vars)
                    {
                        var value = runspace.SessionStateProxy.GetVariable(v.DisplayName);
                        var myVar = context.DataContext.GetProperties().Find(v.DisplayName, true);
                        if (myVar != null && value != null && value != "")
                        {
                            //var myValue = myVar.GetValue(context.DataContext);
                            myVar.SetValue(context.DataContext, value);
                        }
                    }
                    PipelineOutput.Set(context, res);
                }

                return;
            }

            if (language == "AutoHotkey")
            {
                if (sharpAHK.ahkGlobal.ahkdll == null)
                {
                    New_AHKSession(true);
                }
                foreach (var parameter in variablevalues)
                {
                    if (parameter.Value == null)
                    {
                        continue;
                    }
                    sharpAHK.ahkGlobal.ahkdll.SetVar(parameter.Key, parameter.Value.ToString());
                }
                sharpAHK.ahkGlobal.ahkdll.ExecRaw(code);
                foreach (dynamic v in vars)
                {
                    var value = sharpAHK.ahkGlobal.ahkdll.GetVar(v.DisplayName);
                    PropertyDescriptor myVar = context.DataContext.GetProperties().Find(v.DisplayName, true);
                    if (myVar != null && value != null && value != "")
                    {
                        if (myVar.PropertyType == typeof(string))
                        {
                            myVar.SetValue(context.DataContext, value);
                        }
                        else if (myVar.PropertyType == typeof(int))
                        {
                            myVar.SetValue(context.DataContext, int.Parse(value.ToString()));
                        }
                        else if (myVar.PropertyType == typeof(bool))
                        {
                            myVar.SetValue(context.DataContext, bool.Parse(value.ToString()));
                        }
                        else
                        {
                            Log.Information("Ignorering variable " + v.DisplayName + " of type " + myVar.PropertyType.FullName);
                        }
                        //var myValue = myVar.GetValue(context.DataContext);
                    }
                }
                sharpAHK.ahkGlobal.ahkdll.Terminate();
                return;
            }
            if (language == "Python")
            {
                try
                {
                    GenericTools.RunUI(() =>
                    {
                        IntPtr lck = IntPtr.Zero;
                        try
                        {
                            lck = PythonEngine.AcquireLock();
                            using (var scope = Py.CreateScope())
                            {
                                foreach (var parameter in variablevalues)
                                {
                                    PyObject pyobj = parameter.Value.ToPython();
                                    scope.Set(parameter.Key, pyobj);
                                }
                                try
                                {
                                    PythonEngine.RunSimpleString(@"
import sys
from System import Console
class output(object):
    def write(self, msg):
        Console.Out.Write(msg)
    def writelines(self, msgs):
        for msg in msgs:
            Console.Out.Write(msg)
    def flush(self):
        pass
    def close(self):
        pass
sys.stdout = sys.stderr = output()
");
                                }
                                catch (Exception ex)
                                {
                                    Log.Debug(ex.ToString());
                                }
                                scope.Exec(code);
                                foreach (var parameter in variablevalues)
                                {
                                    PyObject pyobj = scope.Get(parameter.Key);
                                    if (pyobj == null)
                                    {
                                        continue;
                                    }
                                    PropertyDescriptor myVar = context.DataContext.GetProperties().Find(parameter.Key, true);
                                    if (myVar.PropertyType == typeof(string))
                                    {
                                        myVar.SetValue(context.DataContext, pyobj.ToString());
                                    }
                                    else if (myVar.PropertyType == typeof(int))
                                    {
                                        myVar.SetValue(context.DataContext, int.Parse(pyobj.ToString()));
                                    }
                                    else if (myVar.PropertyType == typeof(bool))
                                    {
                                        myVar.SetValue(context.DataContext, bool.Parse(pyobj.ToString()));
                                    }
                                    else
                                    {
                                        Log.Information("Ignorering variable " + parameter.Key + " of type " + myVar.PropertyType.FullName);
                                    }
                                }
                            }

                            //lck = PythonEngine.AcquireLock();
                            //PythonEngine.Exec(code);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                        finally
                        {
                            PythonEngine.ReleaseLock(lck);
                        }
                    });
                    //using (Python.Runtime.Py.GIL())
                    //{
                    //    IntPtr lck = Python.Runtime.PythonEngine.AcquireLock();
                    //    Python.Runtime.PythonEngine.Exec(code);
                    //    Python.Runtime.PythonEngine.ReleaseLock(lck);
                    //    //// create a Python scope
                    //    //using (var scope = Python.Runtime.Py.CreateScope())
                    //    //{
                    //    //    //// convert the Person object to a PyObject
                    //    //    //PyObject pyPerson = person.ToPython();

                    //    //    // create a Python variable "person"
                    //    //    // scope.Set("person", pyPerson);

                    //    //    // the person object may now be used in Python
                    //    //    // string code = "fullName = person.FirstName + ' ' + person.LastName";
                    //    //    scope.Exec(code);
                    //    //}
                    //}
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    try
                    {
                        // Python.Runtime.PythonEngine.Shutdown();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.ToString());
                    }
                }
                return;
            }
            if (language == "Python2")
            {
                // http://putridparrot.com/blog/hosting-ironpython-in-a-c-application/
                // http://jonsblogat.blogspot.com/2011/06/adding-scripting-support-to-wpf.html
                //var ipy = IronPython.Hosting.Python.CreateRuntime();
                var engine = IronPython.Hosting.Python.CreateEngine();
                var paths  = Environment.GetEnvironmentVariable("path").Split(';');
                var libs   = new List <string>();
                foreach (var p in paths.Where(x => x.ToLower().Contains("python")))
                {
                    if (System.IO.Directory.Exists(p) && p.ToLower().Contains("ironpython"))
                    {
                        libs.Add(p);
                        if (System.IO.Directory.Exists(System.IO.Path.Combine(p, "Lib")))
                        {
                            libs.Add(System.IO.Path.Combine(p, "Lib"));
                        }
                        if (System.IO.Directory.Exists(System.IO.Path.Combine(p, "lib\\site-packages")))
                        {
                            libs.Add(System.IO.Path.Combine(p, "lib\\site-packages"));
                        }
                        if (System.IO.Directory.Exists(System.IO.Path.Combine(p, "DLLs")))
                        {
                            libs.Add(System.IO.Path.Combine(p, "DLLs"));
                        }
                    }
                }
                engine.SetSearchPaths(libs);
                var scope = engine.CreateScope();
                foreach (var parameter in variablevalues)
                {
                    // if (parameter.Value == null) continue;
                    scope.SetVariable(parameter.Key, parameter.Value);
                }
                var source  = engine.CreateScriptSourceFromString(code, Microsoft.Scripting.SourceCodeKind.Statements);
                var errors  = new ErrorListener();
                var command = source.Compile(errors);
                if (command == null)
                {
                    foreach (var e in errors.errors)
                    {
                        Console.WriteLine(e.source.ToString() + "(" + e.span.Start + "): " + e.message);
                    }
                }
                var result = source.Execute(scope);
                foreach (string name in scope.GetVariableNames())
                {
                    try
                    {
                        var myVar = context.DataContext.GetProperties().Find(name, true);
                        if (myVar != null)
                        {
                            myVar.SetValue(context.DataContext, scope.GetVariable(name));
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.ToString());
                    }
                }
                return;
            }

            var assemblyLocations = GetAssemblyLocations();

            CompileAndRun(language, sourcecode, assemblyLocations.ToArray(), variablevalues, context);
        }
Beispiel #4
0
        protected override void Execute(CodeActivityContext context)
        {
            var code           = Code.Get(context);
            var language       = Language.Get(context);
            var variables      = new Dictionary <string, Type>();
            var variablevalues = new Dictionary <string, object>();
            var vars           = context.DataContext.GetProperties();

            foreach (dynamic v in vars)
            {
                Type rtype = v.PropertyType as Type;
                //var rtype = v.PropertyType.UnderlyingSystemType;
                var value = v.GetValue(context.DataContext);

                if (rtype == null && value != null)
                {
                    rtype = value.GetType();
                }
                if (rtype == null)
                {
                    continue;
                }
                variables.Add(v.DisplayName, rtype);
                variablevalues.Add(v.DisplayName, value);
            }
            string sourcecode = code;

            if (language == "VB")
            {
                sourcecode = GetVBHeaderText(variables, "Expression") + code + GetVBFooterText();
            }
            if (language == "C#")
            {
                sourcecode = GetCSharpHeaderText(variables, "Expression") + code + GetCSharpFooterText();
            }

            if (language == "PowerShell")
            {
                if (runspace == null)
                {
                    runspace = RunspaceFactory.CreateRunspace();
                    runspace.Open();
                }

                using (var pipeline = runspace.CreatePipeline())
                {
                    Command cmd = new Command(sourcecode, true);
                    foreach (var parameter in variablevalues)
                    {
                        // cmd.Parameters.Add(parameter.Key, parameter.Value);
                        runspace.SessionStateProxy.SetVariable(parameter.Key, parameter.Value);
                    }
                    pipeline.Commands.Add(cmd);
                    var res = pipeline.Invoke();
                    foreach (var o in res)
                    {
                        Log.Output(o.ToString());
                    }
                    foreach (dynamic v in vars)
                    {
                        var value = runspace.SessionStateProxy.GetVariable(v.DisplayName);
                        var myVar = context.DataContext.GetProperties().Find(v.DisplayName, true);
                        if (myVar != null)
                        {
                            //var myValue = myVar.GetValue(context.DataContext);
                            myVar.SetValue(context.DataContext, value);
                        }
                    }
                    PipelineOutput.Set(context, res);
                }

                return;
            }


            var names             = new List <string>();
            var assemblies        = AppDomain.CurrentDomain.GetAssemblies().ToList();
            var assemblyLocations = new List <string>();

            foreach (var asm in assemblies)
            {
                try
                {
                    //var a = Assembly.ReflectionOnlyLoad(asm.FullName);
                    //var a = Assembly.Load(asm.FullName);
                    //if(!assemblyLocations.Contains(a.Location)) assemblyLocations.Add(a.Location);
                    if (!asm.IsDynamic)
                    {
                        if (asm.Location.Contains("Microsoft.Office.Interop"))
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(asm.Location))
                        {
                            continue;
                        }
                        if (asm.Location.Contains("System.Numerics.Vectors"))
                        {
                            continue;
                        }
                        if (!assemblyLocations.Contains(asm.Location) && !names.Contains(asm.FullName))
                        {
                            names.Add(asm.FullName);
                            assemblyLocations.Add(asm.Location);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            CompileAndRun(language, sourcecode, assemblyLocations.ToArray(), variablevalues, context);
        }
Beispiel #5
0
        protected override void Execute(CodeActivityContext context)
        {
            var code           = Code.Get(context);
            var language       = Language.Get(context);
            var variables      = new Dictionary <string, Type>();
            var variablevalues = new Dictionary <string, object>();
            var vars           = context.DataContext.GetProperties();

            foreach (dynamic v in vars)
            {
                Type rtype = v.PropertyType as Type;
                var  value = v.GetValue(context.DataContext);

                if (rtype == null && value != null)
                {
                    rtype = value.GetType();
                }
                if (rtype == null)
                {
                    continue;
                }
                variables.Add(v.DisplayName, rtype);
                variablevalues.Add(v.DisplayName, value);
            }
            string sourcecode = code;

            if (namespaces == null)
            {
                throw new Exception("InvokeCode is missing namespaces, please open workflow in designer and save changes");
            }
            if (language == "VB")
            {
                sourcecode = GetVBHeaderText(variables, "Expression", namespaces) + code + GetVBFooterText();
            }
            if (language == "C#")
            {
                sourcecode = GetCSharpHeaderText(variables, "Expression", namespaces) + code + GetCSharpFooterText();
            }
            if (language == "PowerShell")
            {
                if (runspace == null)
                {
                    runspace = RunspaceFactory.CreateRunspace();
                    runspace.Open();
                }

                using (var pipeline = runspace.CreatePipeline())
                {
                    Command cmd = new Command(sourcecode, true);
                    foreach (var parameter in variablevalues)
                    {
                        // cmd.Parameters.Add(parameter.Key, parameter.Value);
                        runspace.SessionStateProxy.SetVariable(parameter.Key, parameter.Value);
                    }
                    pipeline.Commands.Add(cmd);
                    var res = pipeline.Invoke();
                    foreach (var o in res)
                    {
                        if (o != null)
                        {
                            Log.Output(o.ToString());
                        }
                    }
                    foreach (dynamic v in vars)
                    {
                        var value = runspace.SessionStateProxy.GetVariable(v.DisplayName);
                        var myVar = context.DataContext.GetProperties().Find(v.DisplayName, true);
                        if (myVar != null && value != null && value != "")
                        {
                            //var myValue = myVar.GetValue(context.DataContext);
                            myVar.SetValue(context.DataContext, value);
                        }
                    }
                    PipelineOutput.Set(context, res);
                }

                return;
            }
            if (language == "AutoHotkey")
            {
                AppDomain Temporary = null;
                try
                {
                    AppDomainSetup domaininfo = new AppDomainSetup();
                    domaininfo.ApplicationBase = System.Environment.CurrentDirectory;
                    System.Security.Policy.Evidence adevidence = AppDomain.CurrentDomain.Evidence;
                    Temporary = AppDomain.CreateDomain("Temporary", adevidence, domaininfo);
                    Temporary.AssemblyResolve += AHKProxy.CurrentDomain_AssemblyResolve;

                    //var ahk = (AutoHotkey.Interop.AutoHotkeyEngine)Temporary.CreateInstanceAndUnwrap("sharpAHK, Version=1.0.0.5, Culture=neutral, PublicKeyToken=null", "AutoHotkey.Interop.AutoHotkeyEngine");

                    Type type = typeof(AHKProxy);
                    var  ahk  = (AHKProxy)Temporary.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);

                    foreach (var parameter in variablevalues)
                    {
                        if (parameter.Value == null)
                        {
                            continue;
                        }
                        ahk.SetVar(parameter.Key, parameter.Value.ToString());
                    }
                    ahk.ExecRaw(code);
                    foreach (dynamic v in vars)
                    {
                        var value = ahk.GetVar(v.DisplayName);
                        PropertyDescriptor myVar = context.DataContext.GetProperties().Find(v.DisplayName, true);
                        if (myVar != null && value != null && value != "")
                        {
                            if (myVar.PropertyType == typeof(string))
                            {
                                myVar.SetValue(context.DataContext, value);
                            }
                            else if (myVar.PropertyType == typeof(int))
                            {
                                myVar.SetValue(context.DataContext, int.Parse(value.ToString()));
                            }
                            else if (myVar.PropertyType == typeof(bool))
                            {
                                myVar.SetValue(context.DataContext, bool.Parse(value.ToString()));
                            }
                            else
                            {
                                Log.Information("Ignorering variable " + v.DisplayName + " of type " + myVar.PropertyType.FullName);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                    throw;
                }
                finally
                {
                    if (Temporary != null)
                    {
                        AppDomain.Unload(Temporary);
                    }
                }
                return;
            }
            if (language == "Python")
            {
                try
                {
                    GenericTools.RunUI(() =>
                    {
                        IntPtr lck = IntPtr.Zero;
                        try
                        {
                            lck = PythonEngine.AcquireLock();
                            using (var scope = Py.CreateScope())
                            {
                                foreach (var parameter in variablevalues)
                                {
                                    PyObject pyobj = parameter.Value.ToPython();
                                    scope.Set(parameter.Key, pyobj);
                                }
                                try
                                {
                                    PythonEngine.RunSimpleString(@"
import sys
from System import Console
class output(object):
    def write(self, msg):
        Console.Out.Write(msg)
    def writelines(self, msgs):
        for msg in msgs:
            Console.Out.Write(msg)
    def flush(self):
        pass
    def close(self):
        pass
sys.stdout = sys.stderr = output()
");
                                }
                                catch (Exception ex)
                                {
                                    Log.Debug(ex.ToString());
                                }
                                scope.Exec(code);
                                foreach (var parameter in variablevalues)
                                {
                                    PyObject pyobj = scope.Get(parameter.Key);
                                    if (pyobj == null)
                                    {
                                        continue;
                                    }
                                    PropertyDescriptor myVar = context.DataContext.GetProperties().Find(parameter.Key, true);
                                    if (myVar.PropertyType == typeof(string))
                                    {
                                        myVar.SetValue(context.DataContext, pyobj.ToString());
                                    }
                                    else if (myVar.PropertyType == typeof(int))
                                    {
                                        myVar.SetValue(context.DataContext, int.Parse(pyobj.ToString()));
                                    }
                                    else if (myVar.PropertyType == typeof(bool))
                                    {
                                        myVar.SetValue(context.DataContext, bool.Parse(pyobj.ToString()));
                                    }
                                    else
                                    {
                                        Log.Information("Ignorering variable " + parameter.Key + " of type " + myVar.PropertyType.FullName);
                                    }
                                }
                            }
                            //lck = PythonEngine.AcquireLock();
                            //PythonEngine.Exec(code);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                        finally
                        {
                            PythonEngine.ReleaseLock(lck);
                        }
                    });
                    //using (Python.Runtime.Py.GIL())
                    //{
                    //    IntPtr lck = Python.Runtime.PythonEngine.AcquireLock();
                    //    Python.Runtime.PythonEngine.Exec(code);
                    //    Python.Runtime.PythonEngine.ReleaseLock(lck);
                    //    //// create a Python scope
                    //    //using (var scope = Python.Runtime.Py.CreateScope())
                    //    //{
                    //    //    //// convert the Person object to a PyObject
                    //    //    //PyObject pyPerson = person.ToPython();

                    //    //    // create a Python variable "person"
                    //    //    // scope.Set("person", pyPerson);

                    //    //    // the person object may now be used in Python
                    //    //    // string code = "fullName = person.FirstName + ' ' + person.LastName";
                    //    //    scope.Exec(code);
                    //    //}
                    //}
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    try
                    {
                        // Python.Runtime.PythonEngine.Shutdown();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.ToString());
                    }
                }
                return;
            }
            var assemblyLocations = GetAssemblyLocations();

            CompileAndRun(language, sourcecode, assemblyLocations.ToArray(), variablevalues, context);
        }