Skip to content

Commit 5cefe73

Browse files
committed
New Jni4Net, IE automation and O2 process tools
Couple new installers
1 parent 759e473 commit 5cefe73

File tree

9 files changed

+370
-24
lines changed

9 files changed

+370
-24
lines changed

3rdParty/Jni4Net/API_Jni4Net.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public static API_Jni4Net setUpBride(this API_Jni4Net jni4Net, BridgeSetup _brid
4242
{
4343
jni4Net.bridgeSetup = _bridgeSetup;
4444
try
45-
{
46-
45+
{
4746
Bridge.CreateJVM(jni4Net.bridgeSetup);
4847
jni4Net.jniEnv = JNIEnv.ThreadEnv;
4948
return jni4Net;
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
O2Setup.extractEmbededConfigZips();
2+
3+
//Set value of Bridge.homeDir
4+
var jni4NetDir = PublicDI.config.ToolsOrApis.pathCombine(@"Jni4Net\lib");
5+
var fieldInfo = (FieldInfo)typeof(Bridge).field("homeDir");
6+
PublicDI.reflection.setField(fieldInfo, jni4NetDir);
7+
//return typeof(Bridge).fieldValue("homeDir");
8+
9+
"jni4net.j-0.8.6.0.jar location: {0}".info(Bridge.FindJar());
10+
11+
//stand-alone tool not working (not finding the "jni4net.j-0.8.6.0.jar");
12+
13+
//"jni4net.n-0.8.6.0.dll is at: {0}".info("jni4net.n-0.8.6.0.dll".assembly_Location());
14+
var topPanel = "Util - JavaBean REPL - {0}".format(clr.details()).popupWindow(800,400)
15+
.insert_LogViewer();
16+
//var topPanel = panel.clear().add_Panel();
17+
18+
Action execute =null;
19+
20+
var replGui = topPanel.add_REPL_Gui();
21+
replGui.On_ExecuteCode = ()=> execute();
22+
23+
replGui.Output_Panel.insert_Below("Console Out").add_ConsoleOut();
24+
25+
"test console out".console_WriteLine();
26+
27+
var codeText = replGui.Code_Panel.add_SourceCodeViewer();
28+
var toolStrip = topPanel.insert_Above_ToolStrip()
29+
.add_Button("Run", "btExecuteSelectedMethod_Image".formImage(),()=> execute())
30+
.toolStrip();
31+
var samplesMenu = toolStrip.add_DropDown("Java BeanShell Code Samples", "help_browser".formImage());
32+
var beanShellJar = "http://www.beanshell.org/bsh-2.0b4.jar".uri().download(false);
33+
//configure Jni4Net bridge and BeanShell
34+
"Configuring Jnu4Net".info();
35+
var jni4Net = new API_Jni4Net();
36+
jni4Net.setUpBride();
37+
"Default Jni4Net bridge setup ".info();
38+
39+
var interpreterClass = beanShellJar.java_Jar_Class("bsh.Interpreter");
40+
if(interpreterClass.isNull() && clr.x86()) // most likely means it couldn't find a compatible
41+
{
42+
var javaHomeLocation = @"C:\Program Files (x86)\Java\jre7";
43+
"interpretreClass was null, and this is a 32bit process, so to set-up bridge with JavaHome: {0}".error(javaHomeLocation);
44+
var bridgeSetup = new BridgeSetup() { JavaHome = javaHomeLocation};
45+
jni4Net.setUpBride(bridgeSetup);
46+
interpreterClass = beanShellJar.java_Jar_Class("bsh.Interpreter");
47+
}
48+
var interpreter = interpreterClass.ctor();
49+
50+
if (interpreter.isNull())
51+
{
52+
"Failed to create interpreter instance".error();
53+
}
54+
55+
[email protected]("Hello Java world!");
56+
57+
//set execute method
58+
execute =
59+
()=>{
60+
var code = codeText.get_Text().java_String();
61+
try
62+
{
63+
var result = interpreter.java_Invoke_UsingSignature("eval","(Ljava/lang/String;)Ljava/lang/Object;",code);
64+
replGui.showOutput(result.str());
65+
}
66+
catch(System.Exception ex)
67+
{
68+
ex.log("Execution error");
69+
replGui.showErrorMessage(ex.Message);
70+
}
71+
};
72+
Action<string,string> addCodeSample =
73+
(title, codeSample)=> samplesMenu.add_Button(title,
74+
()=>{
75+
codeText.set_Text(codeSample);
76+
execute();
77+
});
78+
Func<string> getJni4NetReplCode =
79+
()=>{
80+
return "return jni4Net.bridgeSetup;".line().line() +
81+
"//O2Ref:jni4net.n-0.8.6.0.dll".line() +
82+
"//O2Ref:{0}".format(jni4Net.type().Assembly.ManifestModule.str());
83+
};
84+
85+
86+
toolStrip.add_DropDown("REPL", "text_x_script".formImage())
87+
.add_Button("REPL Form" , ()=>topPanel.parentForm().script_Me("form"))
88+
.add_Button("REPL Jni4Net" , ()=>jni4Net.script_Me("jni4Net").set_Code(getJni4NetReplCode()))
89+
.add_Button("REPL Jni4Net Assembly" , ()=>jni4Net.type().Assembly.script_Me("assembly"));
90+
91+
toolStrip.add_Button("Open BeanSheel website", "internet_web_browser".formImage(), ()=>"http://www.beanshell.org/".startProcess())
92+
.add_Button("View Jni4Net O2 Blog posts", "internet_web_browser".formImage(), ()=>"http://blog.diniscruz.com/search/label/Jni4Net".startProcess());
93+
94+
//Code samples
95+
96+
addCodeSample("Hello World", "return \"Hello World (from java bean)\";");
97+
addCodeSample("Java Properties", "return java.lang.System.getProperties();");
98+
99+
addCodeSample("Int sums",
100+
@"int a = 12;
101+
return a + 30;");
102+
103+
addCodeSample("Hashtable and date",
104+
@"Hashtable hashtable = new Hashtable();
105+
Date date = new Date();
106+
hashtable.put( ""today"", date );
107+
return hashtable.get(""today"");");
108+
109+
110+
addCodeSample("Create java button",
111+
@"button = new JButton( ""My Button"" );
112+
frame = new JFrame( ""My Frame"" );
113+
frame.getContentPane().add( button, ""Center"" );
114+
frame.pack();
115+
frame.setVisible(true);
116+
117+
return ""You should have a Java button"" +
118+
""somewhere on your screen"";");
119+
120+
121+
addCodeSample("System.out.println (not working)",
122+
@"java.lang.System.out.println(""Hello Java world!"");
123+
return ""done"";");
124+
125+
samplesMenu.items().first()
126+
.PerformClick();
127+
128+
replGui.Execute_Button.click();
129+
replGui.Output_Panel.splitterDistance(50);
130+
131+
return "done";
132+
133+
134+
//using System.Reflection
135+
//using net.sf.jni4net
136+
//using net.sf.jni4net.jni;
137+
//using java.lang;
138+
//using java.net;
139+
//O2File:API_Jni4Net.cs
140+
//O2Ref:Jni4Net\lib\jni4net.n-0.8.6.0.dll
141+
//O2Embed:java.ico
142+
//O2EmbedTool:Jni4Net
Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
<?xml version="1.0"?>
2-
<H2>
3-
<SourceCode>var topPanel = O2Gui.open&lt;Panel&gt;("Tool - Take Screenshots of NMap Web Ports",1200,400);
1+
var topPanel = O2Gui.open<Panel>("Tool - Take Screenshots of NMap Web Ports",1200,400);
42
topPanel.insert_LogViewer();
53
//var topPanel = panel.clear().add_Panel();
64
var actionsPanel = topPanel.insert_Above(40,"Actions");
75

8-
Func&lt;string, List&lt;string&gt;&gt; resolveWebHosts =
9-
(nmapSavedFile) =&gt;{
6+
Func<string, List<string>> resolveWebHosts =
7+
(nmapSavedFile) =>{
108
var nmap = nmaprun.Load(nmapSavedFile);
11-
var webHosts = new List&lt;string&gt;();
9+
var webHosts = new List<string>();
1210
foreach(var host in nmap.host)
1311
foreach(var hostPort in host.ports)
1412
foreach(var port in hostPort.port)
@@ -26,15 +24,15 @@ Func&lt;string, List&lt;string&gt;&gt; resolveWebHosts =
2624

2725

2826
var targetFolder = "_nmapScreenshots".tempDir(false);
29-
var urls = new List&lt;string&gt;();
27+
var urls = new List<string>();
3028
var urls_TreeView = topPanel.insert_Left(400,"Urls (click to take screenshot)").add_TreeView();
3129
var screenshots_TreeView = topPanel.insert_Left(400, "Screenshots").add_TreeView();
3230
var ie = topPanel.add_IE_with_NavigationBar();//.silent(true);
3331
var alertsHandler = ie.getAlertsHandler(); // auto closes popup-windows
3432
var stopExecution = false;
3533

36-
Action&lt;string&gt; takeScreenshotOfWebPage =
37-
(url)=&gt;{
34+
Action<string> takeScreenshotOfWebPage =
35+
(url)=>{
3836
"taking screenshot of page: {0}".debug(url);
3937
ie.open(url);
4038
var screenshot = topPanel.screenshot();
@@ -45,32 +43,32 @@ Action&lt;string&gt; takeScreenshotOfWebPage =
4543

4644

4745
Action takeScreenShotsOfAllPages =
48-
()=&gt;{
46+
()=>{
4947
screenshots_TreeView.clear();
5048
stopExecution = false;
5149
foreach(var url in urls)
5250
if(stopExecution.isFalse())
5351
takeScreenshotOfWebPage(url);
5452
};
5553

56-
screenshots_TreeView.afterSelect&lt;string&gt;(
57-
(bitmapFile)=&gt;{
54+
screenshots_TreeView.afterSelect<string>(
55+
(bitmapFile)=>{
5856
"here".info();
5957
ie.open_ASync(bitmapFile);
6058
});
6159

62-
urls_TreeView.afterSelect&lt;string&gt;(
63-
(url)=&gt; {
60+
urls_TreeView.afterSelect<string>(
61+
(url)=> {
6462
screenshots_TreeView.pink();
6563
O2Thread.mtaThread(
66-
()=&gt;{
64+
()=>{
6765
takeScreenshotOfWebPage(url);
6866
screenshots_TreeView.white();
6967
});
7068
});
7169

72-
Action&lt;string&gt; loadNmapXmlFile=
73-
(file)=&gt;{
70+
Action<string> loadNmapXmlFile=
71+
(file)=>{
7472
urls_TreeView.clear();
7573
urls = resolveWebHosts(file);
7674
urls.add("http://www.google.com");
@@ -80,8 +78,8 @@ Action&lt;string&gt; loadNmapXmlFile=
8078

8179
urls_TreeView.onDrop(loadNmapXmlFile);
8280
actionsPanel.add_Link("take screnshots of all pages", takeScreenShotsOfAllPages)
83-
.append_Link("stop execution", ()=&gt; stopExecution = true)
84-
.append_Link("View Folder with Screenshots", ()=&gt; targetFolder.startProcess());
81+
.append_Link("stop execution", ()=> stopExecution = true)
82+
.append_Link("View Folder with Screenshots", ()=> targetFolder.startProcess());
8583

8684
//if ("o2platform.com.xml".local().fileExists())
8785
// loadNmapXmlFile(@"o2platform.com.xml".local());
@@ -93,6 +91,3 @@ return "ok";
9391
//O2File:WatiN_IE_ExtensionMethods.cs
9492
//O2Ref:O2_Misc_Microsoft_MPL_Libs.dll
9593
//O2Ref:WatiN.Core.1x.dll
96-
</SourceCode>
97-
<ReferencedAssemblies />
98-
</H2>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Diagnostics;
3+
using O2.Kernel;
4+
using O2.Kernel.ExtensionMethods;
5+
using O2.DotNetWrappers.ExtensionMethods;
6+
7+
//O2File:Tool_API.cs
8+
9+
namespace O2.XRules.Database.APIs
10+
{
11+
public class Installer_Test
12+
{
13+
public void test()
14+
{
15+
new Cassini_Installer().start();
16+
}
17+
}
18+
public class Cassini_Installer : Tool_API
19+
{
20+
public Cassini_Installer()
21+
{
22+
config("Cassini",
23+
"CassiniDev 3.5.1.8-4.1.0.8 release.zip",
24+
"http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=cassinidev&DownloadId=123473&FileTime=129287707016900000&Build=20006".uri(),
25+
@"deploy\Debug\WebDev.WebServer40.exe");
26+
installFromZip_Web();
27+
}
28+
public Process start()
29+
{
30+
if (isInstalled())
31+
return this.Executable.startProcess();
32+
return null;
33+
}
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Diagnostics;
3+
using O2.Kernel;
4+
using O2.Kernel.ExtensionMethods;
5+
using O2.DotNetWrappers.ExtensionMethods;
6+
7+
//O2File:Tool_API.cs
8+
9+
namespace O2.XRules.Database.APIs
10+
{
11+
public class Installer_Test
12+
{
13+
public void test()
14+
{
15+
new IIS_Express_Installer().start();
16+
}
17+
}
18+
public class IIS_Express_Installer : Tool_API
19+
{
20+
public IIS_Express_Installer()
21+
{
22+
config("IIS Express",
23+
"http://download.microsoft.com/download/D/C/4/DC4EC38C-A6AA-449D-9B19-7ABC6DF72B34/iisexpress_1_11_x86_en-US.msi".uri(),
24+
"IIS.exe");
25+
InstallProcess_Arguments = "";
26+
install_JustMsiExtract_into_TargetDir();
27+
}
28+
public Process start()
29+
{
30+
if (isInstalled())
31+
return this.Executable.startProcess();
32+
return null;
33+
}
34+
}
35+
}

3rdParty/_Installers/Scratch.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Diagnostics;
3+
using O2.Kernel;
4+
using O2.Kernel.ExtensionMethods;
5+
using O2.DotNetWrappers.ExtensionMethods;
6+
using O2.XRules.Database.Utils;
7+
8+
//O2File:Tool_API.cs
9+
10+
namespace O2.XRules.Database.APIs
11+
{
12+
public class Install_Test
13+
{
14+
public void test()
15+
{
16+
new Scratch_Installer().start();
17+
}
18+
}
19+
public class Scratch_Installer : Tool_API
20+
{
21+
public Scratch_Installer()
22+
{
23+
config("Scratch",
24+
"http://download.scratch.mit.edu/WinScratch1.4.zip".uri(),
25+
@"WinScratch1.4\Scratch\Scratch.exe");
26+
installFromZip_Web();
27+
}
28+
29+
public Process start()
30+
{
31+
if (isInstalled())
32+
return Executable.startProcess();
33+
return null;
34+
}
35+
}
36+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//var ie = "ie_aenoN".o2Cache<WatiN_IE>(()=> panel.clear().add_IE()).silent(false);
2+
var ie = "Util - Login into the cloud Wifi".popupWindow()
3+
.add_IE();
4+
5+
Action<string,string> loginIntoTheCloud =
6+
(email, password)=>
7+
{
8+
ie.open("https://service.thecloud.net/service-platform/");
9+
ie.links()
10+
.where((link)=> link.text().contains("Get Online")).first().click();
11+
ie.links()
12+
.where((link)=> link.text().contains("Free Cloud WiFi")).first().click();
13+
ie.link(@"").click();
14+
15+
ie.eval("$('#username').val('{0}')".format(email));
16+
ie.field("password").value(password);
17+
ie.buttons().first().click();
18+
};
19+
20+
var credentials = ie.askUserForUsernameAndPassword();
21+
22+
loginIntoTheCloud(credentials.UserName, credentials.Password);
23+
ie.waitForComplete();
24+
ie.open("http://www.google.com");
25+
26+
//O2File:WatiN_IE_ExtensionMethods.cs
27+
//O2Ref:WatiN.Core.1x.dll
28+
//O2Tag_DontAddExtraO2Files;

0 commit comments

Comments
 (0)