public FreedomEffect(Type clazz, int count_0, int limit, int x_1, int y_2, int w, int h) { this.visible = true; this.tex2ds = new List <LTexture>(10); this.SetLocation(x_1, y_2); this.width = w; this.height = h; this.count = count_0; this.timer = new LTimer(80); this.kernels = (IKernel[])Arrays.NewInstance(clazz, count_0); try { System.Reflection.ConstructorInfo constructor = JavaRuntime.GetConstructor(clazz, new Type[] { typeof(int), typeof(int), typeof(int) }); for (int i = 0; i < count_0; i++) { int no = MathUtils.Random(0, limit); kernels[i] = (IKernel)JavaRuntime.Invoke(constructor, new object[] { ((int)(no)), ((int)(w)), ((int)(h)) }); } } catch (Exception e) { Console.Error.WriteLine(e.StackTrace); } }
private void Initialize() { var port = PortUtility.GetFreeTcpPort(); // TODO : Need to move Execute logic to J2NET var classPaths = string.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ";" : ":", jarPath, DriverPath); _process = JavaRuntime.Execute($"-XX:G1PeriodicGCInterval=5000 -cp \"{classPaths}\" com.chequer.jdbcnet.bridge.Main -p {port}"); PortUtility.WaitForOpen(port); _channel = new Channel($"{host}:{port}", ChannelCredentials.Insecure); Driver = new DriverService.DriverServiceClient(_channel); Reader = new ReaderService.ReaderServiceClient(_channel); Statement = new StatementService.StatementServiceClient(_channel); Database = new DatabaseService.DatabaseServiceClient(_channel); var loadDriverResponse = Driver.loadDriver(new LoadDriverRequest { ClassName = DriverClass }); DriverMajorVersion = loadDriverResponse.MajorVersion; DriverMinorVersion = loadDriverResponse.MinorVersion; }
/// <summary> /// 加载并显示Screen到设备屏幕 /// </summary> public void ShowScreen() { if (setupSensors) { Type accelerometer = null; if (accelerometer == null) { try { accelerometer = JavaRuntime.ClassforName("Loon.Core.Input.Sensors.AccelerometerExecute"); supportSensors = true; } catch (Exception) { supportSensors = false; } } if (supportSensors) { try { object o = JavaRuntime.NewInstance(accelerometer); System.Reflection.MethodInfo initialize = JavaRuntime.GetMethod(accelerometer, "Initialize"); initialize.Invoke(o, null); System.Reflection.MethodInfo isActive = JavaRuntime.GetMethod(accelerometer, "IsActive"); supportSensors = (bool)isActive.Invoke(o, null); } catch (Exception) { supportSensors = false; } } } }
public string Set(int index, string value) { string name = "session_name_" + JavaRuntime.CurrentTimeMillis(); Set(name, index, value); return(name); }
/// <summary> /// 以反射方式,尝试通过Application读取数据 /// </summary> /// <param name="pathUri"></param> /// <returns></returns> public static System.IO.Stream ApplicationResourceStream(Uri pathUri) { if (!supportApplication) { return(null); } try { if (appType == null) { try { appType = JavaRuntime.ClassforName("System.Windows.Application"); supportApplication = true; } catch { supportApplication = false; } } object o = JavaRuntime.NewInstance(appType); System.Reflection.MethodInfo method = JavaRuntime.GetMethod(appType, "GetResourceStream", pathUri.GetType()); object res = JavaRuntime.Invoke(method, o, pathUri); if (res != null) { System.Reflection.MethodInfo info = res.GetType().GetMethod("get_Stream"); object open = JavaRuntime.Invoke(info, res); return(open as System.IO.Stream); } } catch { } return(null); }
public virtual Stream GetInputStream() { try { if (ins0 != null) { return(ins0); } if (classLoader == null) { return(ins0 = Resources.OpenStream(path)); } else { try { return(ins0 = JavaRuntime.GetResourceAsStream(classLoader, path)); } catch { return(ins0 = Resources.ApplicationResourceStream(new Uri(path))); } } } catch (Exception e) { Log.Exception(e); } return(null); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); JavaRuntime.VerifyExists(); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariableFiles, sensitiveVariablesPassword); var commandOutput = new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables)); var commandLineRunner = new CommandLineRunner(commandOutput); var embeddedResources = new AssemblyEmbeddedResources(); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new JavaStepConvention(actionType, new JavaRunner(commandLineRunner, variables)), new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources) }; var deployment = new RunningDeployment(null, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); return(0); }
public void CallPos(float x, float y) { switch (type) { case 0: try { if (isBindPos) { if (methods != null) { if (methods[1] != null) { JavaRuntime.Invoke(methods[0], obj, x); JavaRuntime.Invoke(methods[1], obj, y); } else { JavaRuntime.Invoke(methods[0], obj, x, y); } } } } catch (Exception ex) { Log.Exception(ex); } break; case 1: if (actorObject != null) { actorObject.SetLocation((int)x, (int)y); } break; case 2: if (shapeObject != null) { shapeObject.SetLocation(x, y); } break; case 3: if (compObject != null) { compObject.SetLocation(x, y); } break; case 4: if (lObject != null) { lObject.SetLocation(x, y); } break; } }
public static System.IO.Stream OpenStream(string resName) { if (resName.IndexOf("/") == -1 && FileUtils.GetExtension(resName).Length == 0) { resName = "Assets/" + resName; } Stream resource = StrRes(resName); if (resource != null) { return(resource); } System.IO.Stream stream = null; try { stream = File.OpenRead(resName); } catch { try { if (stream == null) { // stream = XNAConfig.LoadStream(resName); } } catch (Exception) { if (stream == null) { Uri pathUri = new Uri("/" + JavaRuntime.GetAssemblyName() + ";component/" + resName, UriKind.RelativeOrAbsolute); // stream = ApplicationResourceStream(pathUri); } } } if (stream == null) { try { stream = new System.IO.FileStream(resName, System.IO.FileMode.Open); } catch { try { // System.IO.IsolatedStorage.IsolatedStorageFile store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); // stream = store.OpenFile(resName, System.IO.FileMode.Open); } catch (Exception ex) { Loon.Utils.Debug.Log.Exception(ex); Loon.Utils.Debug.Log.DebugWrite("\n" + resName + " file not found !"); } } } return(stream); }
public float GetRotation() { switch (type) { case 0: try { if (isBindGetRotation) { if (methods != null) { if (methods[6] != null) { Object o = JavaRuntime.Invoke(methods[6], obj); if (o is Single) { return((Single)o); } else if (o is Int32) { return((Int32)o); } } } } } catch (Exception ex) { Log.Exception(ex); } break; case 1: if (actorObject != null) { return(actorObject.GetRotation()); } break; case 2: if (shapeObject != null) { return(shapeObject.GetRotation()); } break; case 4: if (lObject != null) { return(lObject.GetRotation()); } break; } return(0); }
internal static NativeValue[] ToNativeValueArray(this object[] source, JavaRuntime runtime) { List <NativeValue> values = new List <NativeValue>(); foreach (object obj in source) { values.Add(obj.ToNativeValue(runtime)); } return(values.ToArray()); }
internal static NativeValue ToNativeValue(this object source, JavaRuntime runtime) { JavaType jt = source.GetType().ToJniSignature(); if (jt != null) { return(jt.ToNativeValue(runtime, source)); } return(new NativeValue()); }
static void Main(string[] args) { // Create Java Runtime using (JavaRuntime jre = new JavaRuntime()) { // Load Java Virtual Machine jre.Load(); // Get the "System" type, than get the static field "out" and than invoke method "println" with parameter. jre.GetClass("java.lang.System").GetStaticFieldValue <JObject>("out", "java.io.PrintStream").Invoke <object>("println", "Hello from Java World !!!"); } }
static void Main(string[] args) { // Create Java Runtime Environment using (JavaRuntime jre = new JavaRuntime()) { var options = new Dictionary <string, string>(); options.Add("-Djava.class.path", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); // Load Java Virtual Machine jre.Load(options); // Call sample Java static method. jre.GetClass("JOptionPane").InvokeStaticMethod <object>("showMessageDialog", null, "Hello C# from Java <3"); } }
public virtual Uri GetURI() { try { if (uri != null) { return(uri); } return(uri = JavaRuntime.GetResource(classLoader, path)); } catch (Exception ex) { throw new Exception(ex.Message, ex); } }
/// <summary> /// 尝试读取数据流 /// </summary> /// <param name="resName"></param> /// <returns></returns> public static System.IO.Stream OpenStream(string @resName) { Stream resource = StrRes(resName); if (resource != null) { return(resource); } //尝试读取XAP中文件(Content类型) System.IO.Stream stream = null; try { stream = TitleContainer.OpenStream(resName); } catch { if (stream == null) { //尝试读取DLL中文件(Resource类型) Uri pathUri = new Uri("/" + JavaRuntime.GetAssemblyName() + ";component/" + resName, UriKind.RelativeOrAbsolute); stream = ApplicationResourceStream(pathUri); } } if (stream == null) { //尝试读取标准路径数据 try { stream = new System.IO.FileStream(resName, System.IO.FileMode.Open); } catch { //尝试读取封闭空间中数据 try { System.IO.IsolatedStorage.IsolatedStorageFile store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); stream = store.OpenFile(resName, System.IO.FileMode.Open); } catch (Exception ex) { Log.Exception(ex); Log.DebugWrite("\n" + resName + " file not found !"); } } } return(stream); }
static void Main(string[] args) { // Create Java Runtime using (JavaRuntime jre = new JavaRuntime()) { // Load Java Virtual Machine jre.Load(); // This is equal with -> String myValue = System.getProperty("java.version") // Splitted if for easier debugging. JClass javaType = jre.GetClass("java.lang.System"); // Invokes static method "getProperty" with parameter "java.version" which returns "java.lang.String" and casts it to generic parameter "string". string javaVersion = javaType.InvokeStaticMethod<string>("getProperty", "java.lang.String", "java.version"); Console.WriteLine($"Currently used Java version: { javaVersion }"); } }
private void OnSensor(float[] values) { lock (this) { long curTime = JavaRuntime.CurrentTimeMillis(); if (LSystem.SCREEN_LANDSCAPE) { currentX = -values[0]; currentY = -values[1]; currentZ = -values[2]; } else { currentX = values[0]; currentY = values[1]; currentZ = values[2]; } OnOrientation(currentX, currentY, currentZ); if ((curTime - lastUpdate) > 30) { long diffTime = (curTime - lastUpdate); lastUpdate = curTime; currenForce = MathUtils.Abs(currentX + currentY + currentZ - lastX - lastY - lastZ) / diffTime * 10000; if (currenForce > 500 && eve != null) { eve.OnShakeChanged(currenForce); } } lastX = currentX; lastY = currentY; lastZ = currentZ; if (eve != null) { eve.OnDirection(_direction, currentX, currentY, currentZ); } } }
public void CallRotation(float r) { switch (type) { case 0: try { if (isBindRotation) { if (methods != null) { if (methods[2] != null) { JavaRuntime.Invoke(methods[2], obj, r); } } } } catch (Exception ex) { Log.Exception(ex); } break; case 1: if (actorObject != null) { actorObject.SetRotation(r); } break; case 2: if (shapeObject != null) { shapeObject.SetRotation(r); } break; case 4: if (lObject != null) { lObject.SetRotation(r); } break; } }
public void CallUpdate(long elapsedTime) { switch (type) { case 0: try { if (isBindUpdate) { if (methods != null) { if (methods[3] != null) { JavaRuntime.Invoke(methods[3], obj, elapsedTime); } } } } catch (Exception ex) { Log.Exception(ex); } break; case 1: if (actorObject != null) { actorObject.Action(elapsedTime); } break; case 3: if (compObject != null) { compObject.Update(elapsedTime); } break; case 4: if (lObject != null) { lObject.Update(elapsedTime); } break; } }
static void Main(string[] args) { Console.WriteLine("Starting Java Runtime..."); using (JavaRuntime jre = new JavaRuntime()) { Console.WriteLine("Loading library..."); Console.WriteLine("Adding custom options to Java Runtime..."); var options = new Dictionary <string, string>(); options.Add("-Djava.class.path", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); jre.Load(options); Console.WriteLine($"Java Runtime initialized."); Console.WriteLine($"Java version: { jre.GetJavaVersion() }"); } }
public void CallScale(float scaleX, float scaleY) { switch (type) { case 0: try { if (isBindScale) { if (methods != null) { if (methods[5] != null) { JavaRuntime.Invoke(methods[4], obj, scaleX); JavaRuntime.Invoke(methods[5], obj, scaleY); } else { JavaRuntime.Invoke(methods[4], obj, scaleX, scaleY); } } } } catch (Exception ex) { Log.Exception(ex); } break; case 1: if (actorObject != null) { actorObject.SetScale(scaleX, scaleY); } break; case 2: if (shapeObject != null) { shapeObject.SetScale(scaleX, scaleY); } break; } }
public void Register(LSetting setting, Type clazz, params object[] args) { MaxScreen(setting.width, setting.height); Initialization(setting.landscape, setting.mode); SetShowFPS(setting.showFPS); SetShowMemory(setting.showMemory); SetShowLogo(setting.showLogo); SetFPS(setting.fps); if (GamePage != null) { GamePage.Title = setting.title; } if (clazz != null) { if (args != null) { try { int funs = args.Length; if (funs == 0) { SetScreen((Screen)JavaRuntime.NewInstance(clazz)); ShowScreen(); } else { Type[] functions = new Type[funs]; for (int i = 0; i < funs; i++) { functions[i] = GetType(args[i]); } System.Reflection.ConstructorInfo constructor = JavaRuntime.GetConstructor(clazz, functions); Object o = JavaRuntime.Invoke(constructor, args); } } catch (Exception ex) { Log.Exception(ex); } } } }
private void StartElement(string name) { Type clazz = (Type)CollectionUtils.Get(change, name.ToLower()); if (clazz != null) { DefinitionObject childObject = null; try { childObject = (DefinitionObject)JavaRuntime.NewInstance(clazz); if (_source != null) { childObject.fileName = _source; } } catch (Exception e) { Loon.Utils.Debug.Log.Exception(e); } if (this.isCurrentElementDefined) { childObject.InitWithParentObject(this.currentDefinitionObject); } childObject.DefinitionObjectDidInit(); if (childObject.parentDefinitionObject != null) { childObject.parentDefinitionObject.ChildDefinitionObjectDidInit(childObject); } this.curClass = clazz; this.currentDefinitionObject = childObject; this.isCurrentElementDefined = true; } else { this.isCurrentElementDefined = false; if (this.currentDefinitionObject != null) { this.currentDefinitionObject.UndefinedElementDidStart(name); } } }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); JavaRuntime.VerifyExists(); var embeddedResources = new AssemblyEmbeddedResources(); var conventions = new List <IConvention> { new JavaStepConvention(actionType, new JavaRunner(commandLineRunner, variables)), new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources) }; var deployment = new RunningDeployment(null, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); conventionRunner.RunConventions(); return(0); }
public void Register(LSetting setting, Type clazz, params object[] args) { XNAConfig.Load(); SetShowFPS(setting.showFPS); SetShowMemory(setting.showMemory); SetShowLogo(setting.showLogo); SetFPS(setting.fps); if (clazz != null) { if (args != null) { try { int funs = args.Length; if (funs == 0) { SetScreen((Screen)JavaRuntime.NewInstance(clazz)); ShowScreen(); } else { Type[] functions = new Type[funs]; for (int i = 0; i < funs; i++) { functions[i] = GetType(args[i]); } System.Reflection.ConstructorInfo constructor = JavaRuntime.GetConstructor(clazz, functions); object o = JavaRuntime.Invoke(constructor, args); } } catch (Exception ex) { Loon.Utils.Debug.Log.Exception(ex); } } } }
public NativeValue ToNativeValue(JavaRuntime runtime, object value) { NativeValue val = new NativeValue(); if (value is string) { string str = value.ToString(); val.l = runtime.JavaEnvironment.JNIEnv.NewString(str, str.Length); return(val); } Type type = val.GetType(); foreach (FieldInfo fieldInfo in type.GetFields()) { if (fieldInfo.FieldType == value.GetType()) { fieldInfo.SetValue(val, value); } } return(val); }
public static LTexture LoadTexture(LTexture texture) { return(LoadTexture(JavaRuntime.CurrentTimeMillis(), texture)); }
/// <summary> /// 尝试读取数据流 /// </summary> /// <param name="resName"></param> /// <returns></returns> public static System.IO.Stream OpenStream(string resName) { if (resName.IndexOf("/") == -1 && FileUtils.GetExtension(resName).Length == 0) { resName = "Content/" + resName; } Stream resource = StrRes(resName); if (resource != null) { return(resource); } //尝试读取XAP中文件(Content类型) System.IO.Stream stream = null; try { stream = TitleContainer.OpenStream(resName); } catch { try { if (stream == null) { stream = XNAConfig.LoadStream(resName); } } catch (Exception) { if (stream == null) { //尝试读取DLL中文件(Resource类型) Uri pathUri = new Uri("/" + JavaRuntime.GetAssemblyName() + ";component/" + resName, UriKind.RelativeOrAbsolute); stream = ApplicationResourceStream(pathUri); } } } if (stream == null) { //尝试读取标准路径数据 try { stream = new System.IO.FileStream(resName, System.IO.FileMode.Open); } catch { //尝试读取封闭空间中数据 try { System.IO.IsolatedStorage.IsolatedStorageFile store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); stream = store.OpenFile(resName, System.IO.FileMode.Open); } catch (Exception ex) { Loon.Utils.Debugging.Log.Exception(ex); Loon.Utils.Debugging.Log.DebugWrite('\n' + resName + " file not found !"); } } } return(stream); }
public override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(archiveFile, "No archive file was specified. Please pass --archive YourPackage.jar"); JavaRuntime.VerifyExists(); if (!File.Exists(archiveFile)) { throw new CommandException("Could not find archive file: " + archiveFile); } Log.Info("Deploying: " + archiveFile); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariablesFile, sensitiveVariablesPassword); var semaphore = SemaphoreFactory.Get(); var journal = new DeploymentJournal(fileSystem, semaphore, variables); var substituter = new FileSubstituter(fileSystem); var commandOutput = new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables)); var commandLineRunner = new CommandLineRunner(commandOutput); var jsonReplacer = new JsonConfigurationVariableReplacer(); var jarTools = new JarTool(commandLineRunner, commandOutput, variables); var packageExtractor = new JavaPackageExtractor(jarTools); var embeddedResources = new AssemblyEmbeddedResources(); var javaRunner = new JavaRunner(commandLineRunner, variables); var featureClasses = new List <IFeature> { new TomcatFeature(javaRunner), new WildflyFeature(javaRunner) }; var deployExploded = variables.GetFlag(SpecialVariables.Action.Java.DeployExploded); var conventions = new List <IConvention> { new ContributeEnvironmentVariablesConvention(), new ContributePreviousInstallationConvention(journal), new ContributePreviousSuccessfulInstallationConvention(journal), new LogVariablesConvention(), new AlreadyInstalledConvention(journal), // If we are deploying the package exploded then extract directly to the application directory. // Else, if we are going to re-pack, then we extract initially to a temporary directory deployExploded ? (IInstallConvention) new ExtractPackageToApplicationDirectoryConvention(packageExtractor, fileSystem) : new ExtractPackageToStagingDirectoryConvention(packageExtractor, fileSystem), new FeatureConvention(DeploymentStages.BeforePreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner), new FeatureConvention(DeploymentStages.AfterPreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new SubstituteInFilesConvention(fileSystem, substituter), new JsonConfigurationVariablesConvention(jsonReplacer, fileSystem), new RePackArchiveConvention(fileSystem, jarTools), new CopyPackageToCustomInstallationDirectoryConvention(fileSystem), new FeatureConvention(DeploymentStages.BeforeDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner), new FeatureConvention(DeploymentStages.AfterDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new FeatureConvention(DeploymentStages.BeforePostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new ConfiguredScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner), new FeatureConvention(DeploymentStages.AfterPostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources), new RollbackScriptConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner), new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources) }; var deployment = new RunningDeployment(archiveFile, variables); var conventionRunner = new ConventionProcessor(deployment, conventions); try { conventionRunner.RunConventions(); if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, true)); } } catch (Exception) { if (!deployment.SkipJournal) { journal.AddJournalEntry(new JournalEntry(deployment, false)); } throw; } return(0); }