Exemplo n.º 1
0
 private static bool CheckAlreadyLoaded(BridgeSetup newSetup, JNIEnv env)
 {
     if (clrLoaded)
     {
         return(true);
     }
     if (newSetup.BindNative)
     {
         JniLocalHandle br = env.FindClassPtrNoThrow("net/sf/jni4net/Bridge");
         if (JniLocalHandle.IsNull(br))
         {
             throw new JNIException("Can't find class net.sf.jni4net.Bridge on classpath");
         }
         IntPtr ir           = env.GetStaticFieldIDPtr(br, "isRegistered", "Z");
         bool   isRegistered = env.GetStaticBooleanField(br, ir);
         if (isRegistered)
         {
             // rather neat. When called like Clr->Java->Clr this dll gets loaded twice.
             // which means two separate sets CLR of classes and static members
             if (newSetup.Verbose)
             {
                 Console.WriteLine("Already initialized jni4net core before");
             }
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            try
            {
                var bridgeSetup = new BridgeSetup();
                bridgeSetup.AddAllJarsClassPath(".");
                bridgeSetup.IgnoreJavaHome = true;
                //bridgeSetup.Verbose = true;
                Bridge.CreateJVM(bridgeSetup);
                Bridge.RegisterAssembly(typeof(Date).Assembly);
                Bridge.RegisterAssembly(typeof(KnowledgeBaseFactory).Assembly);
                Bridge.RegisterAssembly(typeof(TypedCashflow_).Assembly);

                Example1();
                Example2();
                Example3();
                Example4();
                Example5();
                Example6();
            }
            catch(System.Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                var bridgeSetup = new BridgeSetup();
                bridgeSetup.AddAllJarsClassPath(".");
                Bridge.CreateJVM(bridgeSetup);
                Bridge.RegisterAssembly(typeof(SimpleMySQLDriver).Assembly);

                ISimpleMySQLDriver driver = new SimpleMySQLDriver();

                String query = "";
                String driver_name = "com.mysql.jdbc.Driver";
                String url = "jdbc:mysql://localhost:5510/sakila";
                String username = "******";
                String password = "******";

                query = "SELECT * FROM sakila.actor WHERE last_name LIKE 'B%'";
                String results = driver.QueryResultSetAsString(driver_name, url, username, password, query);

                //Console.Write(results);
                Debug.WriteLine(results);

                //String last_name = String.Format("Smith{0}", DateTime.Now.Ticks.ToString());
                //query = String.Format("INSERT INTO sakila.actor (first_name, last_name) VALUES ('John', '{0}')", last_name);
                //driver.RunStaticQuery(query);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("***Error in Main(): " + ex.Message);
            }
        }
Exemplo n.º 4
0
        internal static int initDotNetImpl(IntPtr envi, IntPtr clazz)
        {
            JNIEnv env = null;

            try
            {
                try
                {
                    env = JNIEnv.Wrap(envi);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Can't bind env:\n" + ex.Message);
                    Console.Error.WriteLine("Can't bind env:\n" + ex);
                    return(-3);
                }
                JniLocalHandle br = env.FindClassPtrNoThrow("net/sf/jni4net/Bridge");
                if (JniLocalHandle.IsNull(br))
                {
                    Console.Error.WriteLine("Can't find net/sf/jni4net/Bridge class");
                    return(-2);
                }
                IntPtr vb = env.GetStaticFieldIDPtr(br, "verbose", "Z");
                IntPtr db = env.GetStaticFieldIDPtr(br, "debug", "Z");
                if (IntPtr.Zero == vb || IntPtr.Zero == db)
                {
                    Console.Error.WriteLine("Can't find verbose or debug fields");
                    return(-6);
                }
                var newSetup = new BridgeSetup(false)
                {
                    Verbose    = env.GetStaticBooleanField(br, vb),
                    Debug      = env.GetStaticBooleanField(br, db),
                    BindStatic = true,
                    BindNative = true
                };
                BindCore(env, newSetup);
                if (Setup.JavaHome == null)
                {
                    Setup.JavaHome = java.lang.System.getProperty("java.home");
                }
                DumpRuntimeVersions();
            }
            catch (Exception ex)
            {
                try
                {
                    Console.Error.WriteLine("Can't bind bridge:" + ex.Message);
                    Console.Error.WriteLine("Can't bind bridge:" + ex);
                    Class exClazz = env.FindClass("net/sf/jni4net/inj/INJException");
                    env.ThrowNew(exClazz, ex.Message);
                    return(-4);
                }
                catch (Exception)
                {
                    return(-5);
                }
            }
            return(0);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Start this from directory \samples\samples\fop\
        /// with \samples\lib populated with jni4net.j.jar and jni4net.n.dll
        /// and with \samples\samples\fop\lib populated with FOP jar files.
        /// </summary>
        private static void Main()
        {
            FixStartupDirectory();

            // automaticaly setup Java classpath to find jni4net.j
            var setup = new BridgeSetup(true);

            // setup Java classpath to find FOP libraries
            setup.AddAllJarsClassPath("lib");

            // we don't need to call back from Java
            setup.BindStatic = false;

            // now we create JVM and bind jni4net core
            Bridge.CreateJVM(setup);

            // now we bind all proxies of FOP objects
            // which are compiled in this assembly
            Bridge.RegisterAssembly(typeof (Program).Assembly);

            const string inFileName = "data/jni4net.fo";
            const string outFileName = "data/jni4net.pdf";

            //Below is just plain Copy&Paste of FOP basic sample java code
            OutputStream output = null;
            try
            {
                // Step 1: Construct a FopFactory
                // (reuse if you plan to render multiple documents!)
                FopFactory fopFactory = FopFactory.newInstance();

                // Step 2: Set up output stream.
                output = new BufferedOutputStream(new FileOutputStream(new File(outFileName)));

                // Step 3: Construct fop with desired output format
                Fop fop = fopFactory.newFop(MimeConstants_.MIME_PDF, output);

                // Step 4: Setup JAXP using identity transformer
                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer transformer = factory.newTransformer(); // identity transformer

                // Step 5: Setup input and output for XSLT transformation
                // Setup input stream
                Source src = new StreamSource(new File(inFileName));

                // Resulting SAX events (the generated FO) must be piped through to FOP
                Result res = new SAXResult(fop.getDefaultHandler());

                // Step 6: Start XSLT transformation and FOP processing
                transformer.transform(src, res);
            }
            finally
            {
                // Clean-up
                if (output != null)
                {
                    output.close();
                }
            }
        }
Exemplo n.º 6
0
 private static void Init()
 {
     BridgeSetup bridgeSetup = new BridgeSetup(true);
     bridgeSetup.AddClassPath(".");
     bridgeSetup.AddClassPath("work");
     Bridge.CreateJVM(bridgeSetup);
     Bridge.RegisterAssembly(typeof(Thread).Assembly);
 }
Exemplo n.º 7
0
 public static void CreateJVM(params string[] options)
 {
     if (jvmLoaded)
     {
         throw new JNIException("Already initilized");
     }
     setup = new BridgeSetup(options);
     CreateJVM();
 }
Exemplo n.º 8
0
 public virtual void Setup()
 {
     Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
     Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
     var setup = new BridgeSetup(false) { Verbose = true, Debug = true };
     string prefix;
     if (Environment.CurrentDirectory.EndsWith("target"))
     {
         prefix = "../../";
     }
     else
     {
         prefix = "../../../";
     }
     string userHome = Environment.GetEnvironmentVariable("USERPROFILE");
     string version = typeof (BridgeSetup).Assembly.GetName().Version.ToString();
     setup.AddClassPath(userHome + @"/.m2/repository/org/picocontainer/picocontainer/2.6/picocontainer-2.6.jar");
     setup.AddClassPath(userHome + @"/.m2/repository/net/sf/jni4net/jni4net.j/" + version + "/jni4net.j-" +
                        version + ".jar");
     setup.AddClassPath(prefix + "../../robocode.api/target/Test-classes");
     setup.AddClassPath(prefix + "../../robocode.api/target/classes");
     setup.AddClassPath(prefix + "../../robocode.battle/target/Test-classes");
     setup.AddClassPath(prefix + "../../robocode.battle/target/classes");
     setup.AddClassPath(prefix + "../../robocode.core/target/Test-classes");
     setup.AddClassPath(prefix + "../../robocode.core/target/classes");
     setup.AddClassPath(prefix + "../../robocode.host/target/Test-classes");
     setup.AddClassPath(prefix + "../../robocode.host/target/classes");
     setup.AddClassPath(prefix + "../../robocode.repository/target/Test-classes");
     setup.AddClassPath(prefix + "../../robocode.repository/target/classes");
     setup.AddClassPath(prefix + "../../robocode.roborumble/target/Test-classes");
     setup.AddClassPath(prefix + "../../robocode.roborumble/target/classes");
     setup.AddClassPath(prefix + "../../robocode.samples/target/Test-classes");
     setup.AddClassPath(prefix + "../../robocode.samples/target/classes");
     setup.AddClassPath(prefix + "../../robocode.sound/target/Test-classes");
     setup.AddClassPath(prefix + "../../robocode.sound/target/classes");
     setup.AddClassPath(prefix + "../../robocode.tests/target/Test-classes");
     setup.AddClassPath(prefix + "../../robocode.tests/target/classes");
     setup.AddClassPath(prefix + "../../robocode.ui/target/Test-classes");
     setup.AddClassPath(prefix + "../../robocode.ui/target/classes");
     setup.AddClassPath(prefix + "../../robocode.ui.editor/target/Test-classes");
     setup.AddClassPath(prefix + "../../robocode.ui.editor/target/classes");
     setup.AddClassPath(prefix + "robocode.dotnet.api/target/Test-classes");
     setup.AddClassPath(prefix + "robocode.dotnet.api/target/classes");
     setup.AddClassPath(prefix + "robocode.dotnet.host/target/Test-classes");
     setup.AddClassPath(prefix + "robocode.dotnet.host/target/classes");
     setup.AddClassPath(prefix + "robocode.dotnet.nhost/target/Test-classes");
     setup.AddClassPath(prefix + "robocode.dotnet.nhost/target/classes");
     setup.AddClassPath(prefix + "robocode.dotnet.samples/target/Test-classes");
     setup.AddClassPath(prefix + "robocode.dotnet.samples/target/classes");
     setup.AddClassPath(prefix + "robocode.dotnet.tests/target/Test-classes");
     setup.AddClassPath(prefix + "robocode.dotnet.tests/target/classes");
     env = Bridge.CreateJVM(setup);
     Bridge.RegisterAssembly(typeof (TestBase).Assembly);
     Bridge.RegisterAssembly(typeof (DllRootHelper).Assembly);
 }
Exemplo n.º 9
0
 public static void Init(string robocodeHome)
 {
     BridgeSetup bridgeSetup = new BridgeSetup();
     bridgeSetup.BindStatic = true;
     bridgeSetup.BindNative = true;
     bridgeSetup.AddAllJarsClassPath(Path.Combine(robocodeHome, "libs"));
     Bridge.CreateJVM(bridgeSetup);
     Bridge.LoadAndRegisterAssemblyByName(typeof(RobocodeEngine).Assembly.FullName);
     //Bridge.Setup.BindNative = true;
     Bridge.Setup.BindStatic = true;
 }
Exemplo n.º 10
0
 public static JNIEnv CreateJVM(BridgeSetup setup)
 {
     if (jvmLoaded)
     {
         if (setup.Verbose)
         {
             Console.Error.WriteLine("Already initilized");
         }
         return JNIEnv.ThreadEnv;
     }
     Bridge.setup = setup;
     return CreateJVM();
 }
Exemplo n.º 11
0
 public static JNIEnv CreateJVM(BridgeSetup setup)
 {
     if (jvmLoaded)
     {
         if (setup.Verbose)
         {
             Console.Error.WriteLine("Already initilized");
         }
         return(JNIEnv.ThreadEnv);
     }
     Bridge.setup = setup;
     return(CreateJVM());
 }
Exemplo n.º 12
0
        internal static void BindCore(JNIEnv env, BridgeSetup newSetup)
        {
            if (CheckAlreadyLoaded(newSetup, env))
            {
                return;
            }

            if (newSetup.Verbose)
            {
                var homeDll = new Uri(typeof(Bridge).Assembly.GetName().CodeBase).AbsolutePath;
                Console.WriteLine("loading core from " + homeDll);
            }
            setup = newSetup;
            if (!setup.BindCoreOnly)
            {
                RegisterAssembly(typeof(Bridge).Assembly);
            }
            __Bridge.Init(env);

            if (Setup.Verbose)
            {
                Console.WriteLine("Initialized jni4net core");
            }
            if (Setup.BindNative)
            {
                JniLocalHandle br = env.FindClassPtr("net/sf/jni4net/Bridge");
                IntPtr         ir = env.GetStaticFieldIDPtr(br, "isRegistered", "Z");
                env.SetStaticBooleanField(br, ir, true);
                if (!env.GetStaticBooleanField(br, ir))
                {
                    Console.Error.WriteLine("Can't mark bridge");
                }
                Ref.Init();
                Out.Init();
            }
            if (Setup.Verbose)
            {
                var homeDll = new Uri(typeof(Bridge).Assembly.GetName().CodeBase).AbsolutePath;
                Console.WriteLine("core loaded from " + homeDll);
            }

            AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

            clrLoaded = true;
        }
Exemplo n.º 13
0
 public static void CreateJVM(params string[] options)
 {
     if (jvmLoaded)
     {
         throw new JNIException("Already initilized");
     }
     setup = new BridgeSetup(options);
     CreateJVM();
 }
Exemplo n.º 14
0
 private static bool CheckAlreadyLoaded(BridgeSetup newSetup, JNIEnv env)
 {
     if (clrLoaded)
     {
         return true;
     }
     if (newSetup.BindNative)
     {
         JniLocalHandle br = env.FindClassPtrNoThrow("net/sf/jni4net/Bridge");
         if (JniLocalHandle.IsNull(br))
         {
             throw new JNIException("Can't find class net.sf.jni4net.Bridge on classpath");
         }
         IntPtr ir = env.GetStaticFieldIDPtr(br, "isRegistered", "Z");
         bool isRegistered = env.GetStaticBooleanField(br, ir);
         if (isRegistered)
         {
             // rather neat. When called like Clr->Java->Clr this dll gets loaded twice.
             // which means two separate sets CLR of classes and static members
             if (newSetup.Verbose)
             {
                 Console.WriteLine("Already initialized jni4net core before");
             }
             return true;
         }
     }
     return false;
 }
Exemplo n.º 15
0
 internal static int initDotNetImpl(IntPtr envi, IntPtr clazz)
 {
     JNIEnv env = null;
     try
     {
         try
         {
             env = JNIEnv.Wrap(envi);
         }
         catch (Exception ex)
         {
             Console.Error.WriteLine("Can't bind env:\n" + ex.Message);
             Console.Error.WriteLine("Can't bind env:\n" + ex);
             return -3;
         }
         JniLocalHandle br = env.FindClassPtrNoThrow("net/sf/jni4net/Bridge");
         if (JniLocalHandle.IsNull(br))
         {
             Console.Error.WriteLine("Can't find net/sf/jni4net/Bridge class");
             return -2;
         }
         IntPtr vb = env.GetStaticFieldIDPtr(br, "verbose", "Z");
         IntPtr db = env.GetStaticFieldIDPtr(br, "debug", "Z");
         if (IntPtr.Zero == vb || IntPtr.Zero == db)
         {
             Console.Error.WriteLine("Can't find verbose or debug fields");
             return -6;
         }
         var newSetup = new BridgeSetup(false)
                            {
                                Verbose = env.GetStaticBooleanField(br, vb),
                                Debug = env.GetStaticBooleanField(br, db),
                                BindStatic = true,
                                BindNative = true
                            };
         BindCore(env, newSetup);
         if (Setup.JavaHome == null)
         {
             Setup.JavaHome = java.lang.System.getProperty("java.home");
         }
         DumpRuntimeVersions();
     }
     catch (Exception ex)
     {
         try
         {
             Console.Error.WriteLine("Can't bind bridge:" + ex.Message);
             Console.Error.WriteLine("Can't bind bridge:" + ex);
             Class exClazz = env.FindClass("net/sf/jni4net/inj/INJException");
             env.ThrowNew(exClazz, ex.Message);
             return -4;
         }
         catch (Exception)
         {
             return -5;
         }
     }
     return 0;
 }
Exemplo n.º 16
0
        internal static void BindCore(JNIEnv env, BridgeSetup newSetup)
        {
            if (CheckAlreadyLoaded(newSetup, env))
            {
                return;
            }

            if (newSetup.Verbose)
            {
                var homeDll = new Uri(typeof(Bridge).Assembly.GetName().CodeBase).AbsolutePath;
                Console.WriteLine("loading core from " + homeDll);
            }
            setup = newSetup;
            if (!setup.BindCoreOnly)
            {
                RegisterAssembly(typeof (Bridge).Assembly);
            }
            __Bridge.Init(env);

            if (Setup.Verbose)
            {
                Console.WriteLine("Initialized jni4net core");
            }
            if (Setup.BindNative)
            {
                JniLocalHandle br = env.FindClassPtr("net/sf/jni4net/Bridge");
                IntPtr ir = env.GetStaticFieldIDPtr(br, "isRegistered", "Z");
                env.SetStaticBooleanField(br, ir, true);
                if (!env.GetStaticBooleanField(br, ir))
                {
                    Console.Error.WriteLine("Can't mark bridge");
                }
                Ref.Init();
                Out.Init();
            }
            if (Setup.Verbose)
            {
                var homeDll = new Uri(typeof(Bridge).Assembly.GetName().CodeBase).AbsolutePath;
                Console.WriteLine("core loaded from " + homeDll);
            }

            AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;

            clrLoaded = true;
        }
        public void QuandoOCalculoDePosicaoECalculado()
        {
            var bridgeSetup = new BridgeSetup();
            bridgeSetup.AddAllJarsClassPath(".");
            bridgeSetup.IgnoreJavaHome = true;

            // Workaround: https://jira.talendforge.org/browse/TUP-477
            bridgeSetup.AddJVMOption("-Ddrools.dialect.java.compiler.lnglevel", "1.6");
            //bridgeSetup.Verbose = true;
            Bridge.CreateJVM(bridgeSetup);
            Bridge.RegisterAssembly(typeof(Date).Assembly);
            Bridge.RegisterAssembly(typeof(KnowledgeBaseFactory).Assembly);
            Bridge.RegisterAssembly(typeof(TypedCashflow_).Assembly);

            var fatos = new List<Object>();

            // Eventos
            foreach (var evento in ScenarioContext.Current.Get<List<Evento>>("EVENTOS"))
            {
                fatos.Add(Bridge.WrapCLR(evento));
            }

            // Escalas.
            foreach (var escala in ScenarioContext.Current.Get<List<Escala>>("ESCALAS"))
            {
                fatos.Add(Bridge.WrapCLR(escala));
            }

            var ksession = new RuleRunner().runRules(new string[] { "RegraPosicao.drl" }, fatos.ToArray());

            var objetos = ksession.getObjects();

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Resultado Final:");
            Console.WriteLine();

            var eventosComOcorrencia = new List<Evento>();

            foreach (var objeto in objetos.toArray())
            {
                Console.WriteLine(objeto.toString());

                try
                {
                    var objetoCrl = Bridge.UnwrapCLR<Evento>(objeto);

                    if (objetoCrl != null)
                    {
                        eventosComOcorrencia.Add(objetoCrl);
                    }
                }
                catch (InvalidCastException)
                {

                }

            }

            ScenarioContext.Current.Add("EVENTOS_COM_OCORRENCIA", eventosComOcorrencia);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 
        /// </summary>
        internal bool Start(bool alwaysStart)
        {
            if (!alwaysStart && !CheckCurrent()) return false;
            UpdateMenuState(DebuggerState.Starting);

            // load JVM.. only once
            if (!jvm_up)
            {
                try
                {
                    BridgeSetup bridgeSetup = null;
                    bridgeSetup = new BridgeSetup();

                    string flexSDKPath = null;
                    if (currentProject != null) flexSDKPath = currentProject.CurrentSDK;
                    else flexSDKPath = PluginCore.Helpers.PathHelper.ResolvePath(PluginBase.MainForm.ProcessArgString("$(FlexSDK)"));

                    if (flexSDKPath != null && Directory.Exists(flexSDKPath))
                    {
                        Dictionary<string, string> jvmConfig = JvmConfigHelper.ReadConfig(flexSDKPath);
                        String javaHome = JvmConfigHelper.GetJavaHome(jvmConfig, flexSDKPath);
                        if (!String.IsNullOrEmpty(javaHome)) bridgeSetup.JavaHome = javaHome;
                    }

                    bridgeSetup.AddAllJarsClassPath(PluginCore.Helpers.PathHelper.PluginDir);
                    bridgeSetup.AddAllJarsClassPath(Path.Combine(PluginCore.Helpers.PathHelper.ToolDir, @"flexlibs\lib"));
                    Bridge.CreateJVM(bridgeSetup);
                    Bridge.RegisterAssembly(typeof(IProgress).Assembly); // ??
                    Bridge.RegisterAssembly(typeof(Bootstrap).Assembly);
                    jvm_up = true;
                }
                catch (Exception ex)
                {

                    String msg = "Debugger startup error. For troubleshooting see: http://www.flashdevelop.org/wikidocs/index.php?title=F.A.Q\n";
                    TraceManager.Add(msg + "Error details: " + ex.ToString());
                    return false;
                }
            }

            PluginBase.MainForm.ProgressBar.Visible = true;
            PluginBase.MainForm.ProgressLabel.Visible = true;
            PluginBase.MainForm.ProgressLabel.Text = TextHelper.GetString("Info.WaitingForPlayer");
            if (bgWorker == null || !bgWorker.IsBusy)
            {
                // only run a debugger if one is not already runnin - need to redesign core to support multiple debugging instances
                // other option: detach old worker, wait for it to exit and start new one
                bgWorker = new BackgroundWorker();
                bgWorker.DoWork += bgWorker_DoWork;
                bgWorker.RunWorkerAsync();
            }
            return true;
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            try
            {

                String xml_results = "<Results><Row><billtocode>3DAKE</billtocode><billtodesc>l@K(&gt;ur(ZCxbt</billtodesc><billtoeffdt>2009-10-18 00:00:00</billtoeffdt><billtoexpdt>2011-07-04 00:00:00</billtoexpdt></Row><Row><billtocode>3DAKE</billtocode><billtodesc>l@K(&gt;ur(ZCxbt</billtodesc><billtoeffdt>2009-10-18 00:00:00</billtoeffdt><billtoexpdt>2011-07-04 00:00:00</billtoexpdt></Row></Results>";
                System.Xml.XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml_results);
                XmlNode root = doc.FirstChild;
                if (root.HasChildNodes)
                {
                    // These are row nodes
                    //for (int i = 0; i < root.ChildNodes.Count; i++)
                    //{
                    //    Debug.WriteLine(root.ChildNodes[i].Name);
                    //    for (int ii = 0; ii < root.ChildNodes[i].ChildNodes.Count; ii++)
                    //    {
                    //        Debug.WriteLine(root.ChildNodes[i].ChildNodes[ii].Name);
                    //    }
                    //}

                    foreach (XmlNode row_node in root.ChildNodes)
                    {
                        Debug.WriteLine(row_node.Name);
                        foreach (XmlNode field_node in row_node.ChildNodes)
                        {
                            Debug.WriteLine(field_node.Name + " = " + field_node.InnerText);
                        }

                    }

                }

                String local_path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                var bridgeSetup = new BridgeSetup();
                bridgeSetup.AddAllJarsClassPath(".");
                bridgeSetup.AddAllJarsClassPath(local_path);
                Bridge.CreateJVM(bridgeSetup);
                Bridge.RegisterAssembly(typeof(MojoHiveDriver).Assembly);

                String drivername = "org.apache.hive.jdbc.HiveDriver";
                String url = "jdbc:hive2://54.218.97.70:21050/;auth=noSasl";
                String username = "";
                String password = "";
                String queuename = "";

                IMojoHiveDriver driver = new MojoHiveDriver();

                int result = driver.TestConnection(drivername, url, queuename, username, password);

                Console.WriteLine("Connection successful.");

                String sql = "SELECT * FROM billtocodes WHERE billtocode LIKE '3D%'";

                String xml = driver.QueryResultSetAsXML(drivername, url, queuename, username, password, sql);

                Console.WriteLine("Results\r\n" + xml);

            }
            catch (System.Exception ex)
            {
                Console.WriteLine("***Error in Main(): " + ex.Message);
            }
        }
Exemplo n.º 20
0
        private static void Main(string[] args)
        {
            try
            {
                var bridgeSetup = new BridgeSetup();
                bridgeSetup.AddAllJarsClassPath(".");
                bridgeSetup.IgnoreJavaHome = true;

                // Workaround: https://jira.talendforge.org/browse/TUP-477
                bridgeSetup.AddJVMOption("-Ddrools.dialect.java.compiler.lnglevel", "1.6");
                //bridgeSetup.Verbose = true;
                Bridge.CreateJVM(bridgeSetup);
                Bridge.RegisterAssembly(typeof(Date).Assembly);
                Bridge.RegisterAssembly(typeof(KnowledgeBaseFactory).Assembly);
                Bridge.RegisterAssembly(typeof(TypedCashflow_).Assembly);

                //Example1();
                //Example2();
                //Example3();
                //Example4();
                //Example5();
                //Example6();
                RegraPosicao();
            }
            catch(System.Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        private IEnumerable<QvxDataRow> GetBillToCodes()
        {
            String tableName = "BillToCodes";
            String xml_results = "";

            try
            {

                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "GetBillToCodes()");
                _logger.LogMsg(log4net.Core.Level.Info, "Enter callback function GetBillToCodes()");

                // DEBUGGING: try to connect to named pipe from here.
                //Program.RunNamedPipeHandler(Program._parentWindowHandle, Program._commandQueue, _logger);

                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, String.Format("GetEvents(log: {0}, tableName: {1})", log, tableName));

                // TO DO: put this back in?
                //VerifyCredentials();

                // TO DO: put in basic validation of query ?
                //if (!EventLog.Exists(log))
                //{
                //    throw new QvxPleaseSendReplyException(QvxResult.QVX_TABLE_NOT_FOUND,
                //        String.Format("There is no EventLog with name: {0}", tableName));
                //}

                // Run the query, get a dataset in XML ?

                // Get the path to the executing program so we can add it to the Java CLASSPATH.
                String local_path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location );
                _logger.LogMsg(log4net.Core.Level.Info, "Working folder: " + local_path);

                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Opening DotNet-Java bridge.");
                _logger.LogMsg(log4net.Core.Level.Info, "Opening DotNet-Java bridge.");

                var bridgeSetup = new BridgeSetup();
                bridgeSetup.AddAllJarsClassPath(".");
                bridgeSetup.AddAllJarsClassPath(local_path);

                Bridge.CreateJVM(bridgeSetup);
                Bridge.RegisterAssembly(typeof(MojoHiveDriver).Assembly);

                String drivername = "org.apache.hive.jdbc.HiveDriver";
                String url = "jdbc:hive2://54.218.97.70:21050/;auth=noSasl";
                String username = "";
                String password = "";
                String queuename = "";

                // *** Create the Java proxy class
                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Creating MojoHiveDriver proxy.");
                _logger.LogMsg(log4net.Core.Level.Info, "Creating MojoHiveDriver proxy.");
                IMojoHiveDriver driver = new MojoHiveDriver();

                // *** Test Cloudera connection
                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, String.Format("Testing connection: driver={0} | url={1} | queuename={2} | username={3} | password={4}.", drivername, url, queuename, username, password));
                _logger.LogMsg(log4net.Core.Level.Info, String.Format("Testing connection: driver={0} | url={1} | queuename={2} | username={3} | password={4}.", drivername, url, queuename, username, password));
                int result = driver.TestConnection(drivername, url, queuename, username, password);
                if (result == 0)
                {
                    //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Connection successful.");
                    _logger.LogMsg(log4net.Core.Level.Info, "Connection successful.");
                }
                else
                {
                    //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Connection failed: " + driver.GetLastExceptionMessage());
                    _logger.LogMsg(log4net.Core.Level.Info, "Connection failed: " + driver.GetLastExceptionMessage());
                }

                // *** Run an actual query
                //TO DO: get this from QlikView ? Must use named pipes?
                //String sql = "SELECT * FROM billtocodes WHERE billtocode='3DAKE'";
                //String sql = "SELECT * FROM billtocodes WHERE billtocode LIKE '4P%'";
                String sql = "SELECT * FROM billtocodes WHERE billtoeffdt > '2008-02-01 00:00:00' AND billtoeffdt < '2008-02-28 00:00:00'";

                _logger.LogMsg(log4net.Core.Level.Info, "Running query: " + sql);
                xml_results = driver.QueryResultSetAsXML(drivername, url, queuename, username, password, sql);
                //_logger.LogMsg(log4net.Core.Level.Info, "XML results:\r\n" + xml_results);

            }
            catch (System.Exception ex)
            {
                _logger.LogMsg(log4net.Core.Level.Error, "Fatal exception: " + ex.Message);
            }

            _logger.LogMsg(log4net.Core.Level.Info, "Loading XML into parser." + xml_results);
            System.Xml.XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml_results);
            XmlNode root = doc.FirstChild;
            if (root.HasChildNodes)
            {
                _logger.LogMsg(log4net.Core.Level.Info, String.Format("Query returned {0} rows.", root.ChildNodes.Count.ToString()));

                _logger.LogMsg(log4net.Core.Level.Info, "Moving data from XML to QlikView objects." + xml_results);
                foreach (XmlNode row_node in root.ChildNodes)
                {
                    //Debug.WriteLine(row_node.Name);
                    yield return MakeEntry(row_node, FindTable(tableName, MTables));

                    //foreach (XmlNode field_node in row_node.ChildNodes)
                    //{
                    //    Debug.WriteLine(field_node.Name + " = " + field_node.InnerText);
                    //}

                }
            }
            else
            {
                _logger.LogMsg(log4net.Core.Level.Warn, "No rows returned!" + xml_results);
            }
        }
Exemplo n.º 22
0
		public static void SetJVM(JavaVM jvm)
		{
			jvmLoaded = true;
			clrLoaded = true;
			setup = new BridgeSetup();
		}
Exemplo n.º 23
0
 public static void Bind()
 {
     try
     {
         bool fullBind = (bool)domain.GetData("fullBind");
         if (fullBind)
         {
             var setup = new BridgeSetup(false);
             setup.BindCoreOnly = true;
             setup.BindNative = false;
             setup.BindStatic = false;
             setup.JavaHome = (string)domain.GetData("JavaHome");
             Bridge.CreateJVM(setup);
             JNIEnv env = JNIEnv.ThreadEnv;
             Registry.RegisterType(typeof(ByteBuffer), true, env);
             Registry.RegisterType(typeof(Buffer), true, env);
             Registry.RegisterType(typeof(DirectByteBuffer), true, env);
             Registry.RegisterType(typeof(java.lang.System), true, env);
             Registry.RegisterType(typeof(ByteOrder), true, env);
             Bridge.RegisterAssembly(typeof(RbSerializer).Assembly);
         }
     }
     catch (Exception ex)
     {
         LoggerN.logError(ex);
         throw;
     }
 }
Exemplo n.º 24
0
        public static IMojoHiveDriver CreateCustomDriver(String drivername)
        {
            IMojoHiveDriver driver = null;
            try
            {
                String local_path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                _logger.LogMsg(log4net.Core.Level.Debug, "Connector program folder: " + local_path);

                _logger.LogMsg(log4net.Core.Level.Debug, "Creating .NET-Java bridge.");
                var bridgeSetup = new BridgeSetup();

                // The local_path is the folder where the connector EXE itself is located.
                bridgeSetup.AddAllJarsClassPath(local_path);

                // Check to see if a specific folder has been configured as the location for the current driver.
                // If so, load all JARs in that folder.
                String driver_folder = "";
                Boolean found_the_folder = false;
                try
                {
                    if (Properties.Settings.Default.Drivers.Contains(drivername))
                    {
                        int driver_index = Properties.Settings.Default.Drivers.IndexOf(drivername);

                        if (Properties.Settings.Default.DriverLocations.Count > driver_index)
                        {
                            driver_folder = Properties.Settings.Default.DriverLocations[driver_index];
                            // First assume the folder is a full path, check if it exists.
                            if (Directory.Exists(driver_folder)) found_the_folder = true;
                            else
                            {
                                // Try to append to the driver folder to the current local EXE path as a sub-folder.
                                driver_folder = Path.Combine(local_path, driver_folder);
                                if (Directory.Exists(driver_folder)) found_the_folder = true;
                            }
                            // Always try to add the folder if it exists.
                            if (found_the_folder)
                            {
                                bridgeSetup.AddAllJarsClassPath(driver_folder);
                            }

                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogMsg(Level.Warn, String.Format("Error adding custom driver folder [{0}] to Java CLASSPATH: {1}.", driver_folder, ex.Message));
                }

                _logger.LogMsg(log4net.Core.Level.Debug, "Creating Java virtual machine (JVM).");
                Bridge.CreateJVM(bridgeSetup);

                _logger.LogMsg(log4net.Core.Level.Debug, "Registering custom driver assembly with .NET-Java bridge.");
                Bridge.RegisterAssembly(typeof(MojoHiveDriver).Assembly);

                _logger.LogMsg(log4net.Core.Level.Debug, "Creating custom driver proxy for .NET.");
                driver = new MojoHiveDriver();

            }
            catch (System.Exception ex)
            {
                _logger.LogMsg(log4net.Core.Level.Error, "Error creating MojoHiveDriver proxy: " + ex.Message);

            }

            return driver;
        }
Exemplo n.º 25
0
 public static void SetJVM(JavaVM jvm)
 {
     jvmLoaded = true;
     clrLoaded = true;
     setup     = new BridgeSetup();
 }