public wrapperStatic compile()
        {
            wrapperStatic _wrapperStatic;

            if (!this.compiled)
            {
                // generar un archivo  por cada tipo
                string   name = GetSHA1(this.type.AssemblyQualifiedName).ToUpper();
                string   file = environment.getCompilationFile(name);
                FileInfo f    = new FileInfo(file);

                try
                {
                    if (f.Exists)
                    {
                        string str  = "C" + GetSHA1(type.AssemblyQualifiedName);
                        string str1 = "C" + GetSHA1(type.AssemblyQualifiedName) + "_static";

                        Type            _type        = Assembly.LoadFile(file).GetType(string.Concat("jxshell.dotnet4.", str1));
                        ConstructorInfo _constructor = _type.GetConstructor(new Type[] { typeof(Type), typeof(typeDescriptor) });

                        this.compiledWrapper = (wrapperStatic)_constructor.Invoke(new object[] { this.type, this });
                        this.compiled        = true;
                    }
                    else
                    {
                        StringBuilder stringBuilder = new StringBuilder();
                        string        str           = "";
                        string        str1          = "";
                        typeDescriptor.addUsingsStatements(stringBuilder);
                        this.precompile(stringBuilder, ref str, ref str1);
                        stringBuilder.AppendLine("class program{public static void main(){}}");

                        csharplanguage _csharplanguage = typeDescriptor.language;
                        _csharplanguage.runScriptWithId(stringBuilder.ToString(), name);

                        Type            _type        = _csharplanguage.getCompiledAssembly().GetType(string.Concat("jxshell.dotnet4.", str));
                        ConstructorInfo _constructor = _type.GetConstructor(new Type[] { typeof(Type), typeof(typeDescriptor) });

                        this.compiledWrapper = (wrapperStatic)_constructor.Invoke(new object[] { this.type, this });
                        this.compiled        = true;
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    throw new Exception(string.Concat("No se puede obtener un wrapper para el tipo ", this.type.ToString(), ". ", exception.Message), exception);
                }
                _wrapperStatic = this.compiledWrapper;
            }
            else
            {
                _wrapperStatic = this.compiledWrapper;
            }
            return(_wrapperStatic);
        }
Exemple #2
0
        public void loadManyTypes(string types)
        {
            string[] array = types.Split(new string[]
            {
                "-"
            }, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder stringBuilder = new StringBuilder();

            typeDescriptor.addUsingsStatements(stringBuilder);
            Dictionary <Type, type_1> dictionary = new Dictionary <Type, type_1>();

            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string         typeName          = array2[i];
                Type           typeOrGenericType = this.getTypeOrGenericType(typeName);
                typeDescriptor typeDescriptor    = new typeDescriptor(typeOrGenericType, typeName, false);
                if (!typeDescriptor.isCompiled())
                {
                    string staticClass   = "";
                    string instanceClass = "";
                    typeDescriptor.precompile(stringBuilder, ref staticClass, ref instanceClass);
                    dictionary[typeOrGenericType] = new type_1
                    {
                        td            = typeDescriptor,
                        staticClass   = staticClass,
                        instanceClass = instanceClass,
                        t             = typeOrGenericType
                    };
                }
            }
            stringBuilder.AppendLine("class program{public static void main(){}}");
            csharplanguage csharplanguage = (csharplanguage)language.defaultLanguage.create();

            if (dictionary.Count > 0)
            {
                csharplanguage.runScript(stringBuilder.ToString(), typeDescriptor.generateInMemory);
            }
            foreach (KeyValuePair <Type, type_1> current in dictionary)
            {
                type_1          value       = current.Value;
                Type            type        = csharplanguage.getCompiledAssembly().GetType("jxshell.dotnet4." + value.staticClass);
                ConstructorInfo constructor = type.GetConstructor(new Type[]
                {
                    typeof(Type),
                    typeof(typeDescriptor)
                });
                value.td.setCompiledWrapper((wrapperStatic)constructor.Invoke(new object[]
                {
                    value.t,
                    value.td
                }));
            }
        }
        public wrapperStatic compile()
        {
            wrapperStatic result;

            if (this.compiled)
            {
                result = this.compiledWrapper;
            }
            else
            {
                StringBuilder stringBuilder = new StringBuilder();
                string        str           = "";
                string        text          = "";
                typeDescriptor.addUsingsStatements(stringBuilder);
                this.precompile(stringBuilder, ref str, ref text);
                stringBuilder.AppendLine("class program{public static void main(){}}");
                try
                {
                    csharplanguage csharplanguage = typeDescriptor.language;
                    //Clipboard.SetText(stringBuilder.ToString());
                    csharplanguage.runScript(stringBuilder.ToString(), typeDescriptor.generateInMemory);
                    Type            type            = csharplanguage.getCompiledAssembly().GetType("jxshell.dotnet4." + str);
                    ConstructorInfo constructorInfo = type.GetConstructor(new Type[]
                    {
                        typeof(Type),
                        typeof(typeDescriptor)
                    });
                    this.compiledWrapper = (wrapperStatic)constructorInfo.Invoke(new object[]
                    {
                        this.type,
                        this
                    });
                    this.compiled = true;
                }
                catch (Exception ex)
                {
                    throw new Exception("No se puede obtener un wrapper para el tipo " + this.type.ToString() + ". " + ex.Message, ex);
                }
                result = this.compiledWrapper;
            }
            return(result);
        }
Exemple #4
0
 internal static void _execute(Command cmd)
 {
     try
     {
         //File.WriteAllText("/Users/james/commands.log", Newtonsoft.Json.JsonConvert.SerializeObject(cmd));
         object[] args;
         if (cmd.arguments != null)
         {
             args = new object[cmd.arguments.Count];
             for (int i = 0; i < cmd.arguments.Count; i++)
             {
                 args[i] = cmd.arguments[i].getValue();
             }
         }
         else
         {
             args = new object[0];
         }
         bool emp = false;
         if (cmd.command == "assembly.add")
         {
             for (int i = 0; i < cmd.arguments.Count; i++)
             {
                 Manager.lastManager.loadAssemblyPartialName(cmd.arguments[i].getValue().ToString());
             }
             emp = true;
         }
         else if (cmd.command == "assembly.addfile")
         {
             for (int i = 0; i < cmd.arguments.Count; i++)
             {
                 Manager.lastManager.loadAssemblyFile(cmd.arguments[i].getValue().ToString());
             }
             emp = true;
         }
         else if (cmd.command == "remove")
         {
             if (cmd.objectid > 0)
             {
                 Objects.remove(cmd.objectid);
             }
             emp = true;
         }
         else if (cmd.command == "compile")
         {
             string         code = cmd.arguments[0].getValue().ToString();
             csharplanguage lang = (csharplanguage)language.languages["c#"].create();
             lang.compileString(code, "");
             Assembly a = lang.getCompiledAssembly();
             if (a != null)
             {
                 Manager.lastManager.loadAssembly(a);
             }
             emp = true;
         }
         else if (cmd.command == "loadmembers")
         {
             //string code = cmd.typename;
             Type                    ty = Manager.lastManager.getTypeOrGenericType(cmd.typename);
             typeDescriptor          t2 = typeDescriptor.loadFromType(ty, "", false);
             TypeLoader.TypeResponse tr = TypeLoader.loadMembers(t2);
             cmd.command = "get";
             Response r = new Response(cmd, tr, null);
             CommandLine.write(r);
         }
         else if (cmd.objectid > 0)
         {
             object obj = Objects.getbyid(cmd.objectid);
             if (obj == null)
             {
                 throw new NullReferenceException("El objeto ha sido liberado de memoria o el id no es válido");
             }
             object result = null;
             if (cmd.getproperty)
             {
                 result = TypeLoader.getProperty(cmd, ref args, obj);
             }
             else if (cmd.getfield)
             {
                 result = TypeLoader.getField(cmd, obj);
             }
             else if (cmd.method)
             {
                 result = TypeLoader.invokeMethod(cmd, ref args, obj);
             }
             else if (cmd.setproperty)
             {
                 TypeLoader.setProperty(cmd, ref args, obj, cmd.value.getValue());
             }
             else if (cmd.setfield)
             {
                 TypeLoader.setField(cmd, obj, cmd.value.getValue());
             }
             Response r = new Response(cmd, result, null);
             CommandLine.write(r);
         }
         else
         {
             object result = null;
             if (cmd.getproperty)
             {
                 result = TypeLoader.getProperty(cmd, ref args, null);
             }
             else if (cmd.getfield)
             {
                 result = TypeLoader.getField(cmd, null);
             }
             else if (cmd.method)
             {
                 result = TypeLoader.invokeMethod(cmd, ref args, null);
             }
             else if (cmd.setproperty)
             {
                 TypeLoader.setProperty(cmd, ref args, null, cmd.value.getValue());
             }
             else if (cmd.setfield)
             {
                 TypeLoader.setField(cmd, null, cmd.value.getValue());
             }
             Response r = new Response(cmd, result, null);
             CommandLine.write(r);
         }
         if (emp)
         {
             CommandLine.write(new Response
             {
                 isnull    = true,
                 commandid = cmd.commandid
             });
         }
     }
     catch (Exception e)
     {
         if (e.InnerException != null)
         {
             throw e.InnerException;
         }
         if (e is KeyNotFoundException)
         {
             throw new MissingMemberException("El método o propiedad no existe");
         }
         throw;
     }
 }