Example #1
0
        public void FromIList()
        {
            IList   list = new ArrayList();
            Binding b    = Adapt.From(list);

            Assert.IsNotNull(b);
            Assert.AreEqual(typeof(ListAdapter), b.GetType());
        }
Example #2
0
        public void IEnum()
        {
            int        cnt = 0;
            Properties javaSystemProperties = java.lang.System.getProperties();

            foreach (var prop in Adapt.Enumeration(javaSystemProperties.keys()))
            {
                cnt++;
            }
            Assert.AreEqual(javaSystemProperties.size(), cnt);
        }
Example #3
0
 public override void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     using (var bao = Adapt.Disposable(new ByteArrayOutputStream()))
     {
         using (var oos = Adapt.Disposable(new ObjectOutputStream(bao.Real)))
         {
             oos.Real.writeObject(Bridge.Cast <Object>(this));
             byte[] data = bao.Real.toByteArray();
             info.AddValue("exception", data);
         }
     }
 }
Example #4
0
 protected Throwable(SerializationInfo info, StreamingContext context)
 {
     byte[] data = (byte[])info.GetValue("exception", typeof(byte[]));
     using (var bai = Adapt.Disposable(new ByteArrayInputStream(data)))
     {
         using (var ois = Adapt.Disposable(new ObjectInputStream(bai.Real)))
         {
             Object exception = ois.Real.readObject();
             ((IJvmProxy)this).Copy(JNIEnv.ThreadEnv, exception.jvmHandle);
         }
     }
 }
Example #5
0
        public void BuffAdapt(Adapt adapt, int index)
        {
            int       attack = 0;
            int       health = 0;
            Attribute attr   = Attribute.None;

            Action <TriggerParams> deathRattle = (tp) => { tp.Board.Summon("Plant", tp.Index, Direction.InPlace, 2); };


            switch (adapt)
            {
            case Adapt.DeathRattle:
                attr |= Attribute.DeathRattle;
                break;

            case Adapt.DivineShield:
                attr |= Attribute.DivineShield;
                break;

            case Adapt.OneOne:
                attack++;
                health++;
                break;

            case Adapt.Poison:
                attr |= Attribute.Poison;
                break;

            case Adapt.Windfury:
                attr |= Attribute.WindFury;
                break;

            case Adapt.Taunt:
                attr |= Attribute.Taunt;
                break;

            case Adapt.ThreeAttack:
                attack += 3;
                break;

            case Adapt.ThreeHealth:
                health += 3;
                break;
            }

            BuffAllOfType(MinionType.Murloc, attack, health, attr, deathRattle);
        }
Example #6
0
        private static void Main()
        {
            // create bridge, with default setup
            // it will lookup jni4net.j.jar next to jni4net.n.dll
            Bridge.CreateJVM(new BridgeSetup()
            {
                Verbose = true
            });

            // here you go!
            [email protected]("Hello Java world!");

            // OK, simple hello is boring, let's play with Java properties
            // they are Hashtable realy
            Properties javaSystemProperties = java.lang.System.getProperties();

            // let's enumerate all keys.
            // We use Adapt helper to convert enumeration from java o .NET
            foreach (java.lang.String key in Adapt.Enumeration(javaSystemProperties.keys()))
            {
                [email protected](key);

                // this is automatic conversion of CLR string to java.lang.String
                [email protected](" : ");

                // we use the hashtable
                Object value = javaSystemProperties.get(key);

                // and this is CLR ToString() redirected to Java toString() method
                string valueToString = value.ToString();
                [email protected](valueToString);
            }

            // Java output is really Stream
            PrintStream stream = java.lang.System.@out;

            // it implements java.io.Flushable interface
            Flushable flushable = stream;

            flushable.flush();
        }
Example #7
0
        public static void Register()
        {
            if (config.Verbose)
            {
                Console.WriteLine("clr.version         :" + RuntimeEnvironment.GetSystemVersion());
                Console.WriteLine("clr.arch            :" + ((IntPtr.Size == 8) ? "64bit" : "32bit"));
            }
            LoadClasspath();
            if (config.Verbose)
            {
                Console.WriteLine("java.home           :" + Bridge.Setup.JavaHome);
                Console.WriteLine("java.version        :" + java.lang.System.getProperty("java.version"));
                Console.WriteLine("sun.arch.data.model :" + java.lang.System.getProperty("sun.arch.data.model"));
                Console.WriteLine("");
            }

            LoadAssemblies();

            RegisterAssemblies();

            if (config.JavaClass != null)
            {
                RegisterClasses();
            }
            if (config.ClrType != null)
            {
                RegisterTypes();
            }

            foreach (Assembly assembly in generateAssemblies)
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (type.IsPublic)
                    {
                        TypeRegistration registration = new TypeRegistration();
                        registration.TypeName = type.FullName;
                        GType reg = RegisterType(type, registration);
                        reg.IsJVMGenerate      = true;
                        reg.IsSkipCLRInterface = !registration.SyncInterface;
                        reg.MergeJavaSource    = registration.MergeJavaSource;
                    }
                }
            }

            foreach (string classPath in generateCp)
            {
                if (Directory.Exists(classPath))
                {
                    string path = Path.GetFullPath(classPath);
                    foreach (string classFile in Directory.GetFiles(path, "*.class", SearchOption.AllDirectories))
                    {
                        if (!classFile.Contains("$"))
                        {
                            string name      = classFile.Substring(path.Length + 1);
                            string clazzName = name.Substring(0, name.Length - (".class".Length)).Replace('\\', '/');
                            RegisterClass(clazzName);
                        }
                    }
                }
                else if (File.Exists(classPath) && Path.GetExtension(classPath) == ".jar")
                {
                    using (var fis = Adapt.Disposable(new FileInputStream(classPath)))
                    {
                        using (var zis = Adapt.Disposable(new ZipInputStream(fis.Real)))
                        {
                            ZipEntry entry = zis.Real.getNextEntry();
                            while (entry != null)
                            {
                                string name = entry.getName();
                                if (!entry.isDirectory() && name.EndsWith(".class") && !name.Contains("$"))
                                {
                                    string clazzName = name.Substring(0, name.Length - (".class".Length));
                                    RegisterClass(clazzName);
                                }
                                entry = zis.Real.getNextEntry();
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        /// <summary>
        /// Initializes the <see cref="Adapt"/> static facade with
        /// the specified service.
        /// </summary>
        /// <param name="service">The adapter service to use on the <see cref="Adapt"/> class.</param>
        public static void Initialize(IAdapterService service)
        {
            Guard.NotNull(() => service, service);

            Adapt.Initialize(service);
        }
Example #9
0
 public void FromNull()
 {
     Adapt.From(null);
 }