Skip to content

Commit 32fa9f2

Browse files
Add files via upload
1 parent 1d135d7 commit 32fa9f2

File tree

91 files changed

+6520
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+6520
-0
lines changed

Diff for: dotNetFramework/DotNetFramework_Demo.iml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
<excludeFolder url="file://$MODULE_DIR$/src/Net/HttpListener" />
8+
<excludeFolder url="file://$MODULE_DIR$/src/Net/SslStream" />
9+
</content>
10+
<orderEntry type="inheritedJdk" />
11+
<orderEntry type="sourceFolder" forTests="false" />
12+
<orderEntry type="module-library">
13+
<library>
14+
<CLASSES>
15+
<root url="jar://$MODULE_DIR$/../../Java/JAR/Root/out/artifacts/JAR/Full/dotNet4Java-1.0.1.jar!/" />
16+
</CLASSES>
17+
<JAVADOC />
18+
<SOURCES />
19+
</library>
20+
</orderEntry>
21+
<orderEntry type="module-library">
22+
<library>
23+
<CLASSES>
24+
<root url="jar://$MODULE_DIR$/../../Java/JAR/Framework/out/artifacts/JAR/dotNet4Java_DotNetFramework-1.0.1.jar!/" />
25+
</CLASSES>
26+
<JAVADOC />
27+
<SOURCES />
28+
</library>
29+
</orderEntry>
30+
</component>
31+
</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package ADONet.SqlClient.SqlBulkCopy;
2+
3+
//The following console application demonstrates how to load data using the SqlBulkCopy class.
4+
// In this example, a SqlDataReader is used to copy data from the Production.Product table in
5+
// the SQL Server AdventureWorks database to a similar table in the same database.
6+
7+
import system.Console;
8+
import system.data.sqlclient.SqlBulkCopy;
9+
import system.data.sqlclient.SqlCommand;
10+
import system.data.sqlclient.SqlConnection;
11+
import system.data.sqlclient.SqlDataReader;
12+
13+
public class Program {
14+
15+
public static void main(String[] arg) {
16+
try {
17+
String connectionString = GetConnectionString();
18+
// Open a sourceConnection to the AdventureWorks database.
19+
SqlConnection sourceConnection = null;
20+
try {
21+
sourceConnection = new SqlConnection(connectionString);
22+
sourceConnection.Open();
23+
24+
// Perform an initial count on the destination table.
25+
SqlCommand commandRowCount = new SqlCommand("SELECT COUNT(*) FROM dbo.BulkCopyDemoMatchingColumns;", sourceConnection);
26+
long countStart = system.Convert.ToInt32(commandRowCount.ExecuteScalar());
27+
Console.WriteLine("Starting row count = {0}", countStart);
28+
29+
// Get data from the source table as a SqlDataReader.
30+
SqlCommand commandSourceData = new SqlCommand(
31+
"SELECT ProductID, Name, " +
32+
"ProductNumber " +
33+
"FROM Production.Product;", sourceConnection);
34+
SqlDataReader reader = commandSourceData.ExecuteReader().AsType(SqlDataReader.class);
35+
36+
// Open the destination connection. In the real world you would
37+
// not use SqlBulkCopy to move data from one table to the other
38+
// in the same database. This is for demonstration purposes only.
39+
SqlConnection destinationConnection = new SqlConnection(connectionString);
40+
try {
41+
destinationConnection.Open();
42+
43+
// Set up the bulk copy object.
44+
// Note that the column positions in the source
45+
// data reader match the column positions in
46+
// the destination table so there is no need to
47+
// map columns.
48+
SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection);
49+
try {
50+
bulkCopy.set_DestinationTableName("dbo.BulkCopyDemoMatchingColumns");
51+
52+
try {
53+
// Write from the source to the destination.
54+
bulkCopy.WriteToServer(reader);
55+
} catch (Exception ex) {
56+
Console.WriteLine(ex.getMessage());
57+
} finally {
58+
// Close the SqlDataReader. The SqlBulkCopy
59+
// object is automatically closed at the end
60+
// of the using block.
61+
reader.Close();
62+
}
63+
} finally {
64+
bulkCopy.close();
65+
}
66+
67+
// Perform a final count on the destination
68+
// table to see how many rows were added.
69+
long countEnd = system.Convert.ToInt32(commandRowCount.ExecuteScalar());
70+
71+
Console.WriteLine("Ending row count = {0}", countEnd);
72+
Console.WriteLine("{0} rows were added.", countEnd - countStart);
73+
Console.WriteLine("Press Enter to finish.");
74+
Console.ReadLine();
75+
} finally {
76+
destinationConnection.Dispose();
77+
destinationConnection.close();
78+
}
79+
} finally {
80+
if (sourceConnection != null) {
81+
sourceConnection.Dispose();
82+
sourceConnection.close();
83+
}
84+
}
85+
} catch (Exception e) {
86+
e.printStackTrace();
87+
}
88+
}
89+
90+
// To avoid storing the sourceConnection String in your code,
91+
// you can retrieve it from a configuration file.
92+
private static String GetConnectionString() {
93+
return "Data Source=(local); Integrated Security=true;Initial Catalog=AdventureWorks;";
94+
}
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package ADONet.SqlClient.SqlDataReader;
2+
3+
import com.dotNet4Java.api.EClrError;
4+
import system.Console;
5+
import system.data.IDataRecord;
6+
import system.data.sqlclient.SqlCommand;
7+
import system.data.sqlclient.SqlConnection;
8+
import system.data.sqlclient.SqlDataReader;
9+
10+
public class Program {
11+
public static void main(String[] arg) {
12+
String str = "Data Source=BIZZO\\SQLEXPRESS;Initial Catalog=Northwind;"
13+
+ "Integrated Security=SSPI";
14+
ReadOrderData(str);
15+
}
16+
17+
private static void ReadOrderData(String connectionString) {
18+
String queryString =
19+
"SELECT OrderID, CustomerID FROM dbo.Orders;";
20+
21+
try {
22+
SqlConnection connection = null;
23+
try {
24+
connection = new SqlConnection(connectionString);
25+
SqlCommand command = new SqlCommand(queryString, connection);
26+
connection.Open();
27+
28+
SqlDataReader reader = command.ExecuteReader().AsType(SqlDataReader.class);
29+
30+
// Call Read before accessing data.
31+
while (reader.Read()) {
32+
ReadSingleRow(reader.AsType(IDataRecord.class));
33+
}
34+
35+
// Call Close when done reading.
36+
reader.Close();
37+
38+
} finally {
39+
if (connection != null) {
40+
connection.Dispose();
41+
connection.close();
42+
}
43+
}
44+
} catch (Exception e) {
45+
e.printStackTrace();
46+
}
47+
}
48+
49+
private static void ReadSingleRow(IDataRecord record) throws EClrError {
50+
Console.WriteLine(system.String.Format("{0}, {1}", record.get_Item(0), record.get_Item(10)));
51+
}
52+
}

Diff for: dotNetFramework/src/ActiveDirectory/Program.java

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ActiveDirectory;
2+
3+
import system.directoryservices.DirectoryEntry;
4+
import system.directoryservices.DirectorySearcher;
5+
import system.directoryservices.SearchResult;
6+
import system.directoryservices.SearchResultCollection;
7+
8+
public class Program {
9+
10+
public static void main(String[] arg) {
11+
try {
12+
DirectoryEntry Entry = new DirectoryEntry("LDAP://MCBcorp, DC=com");
13+
System.out.println("Name = " + Entry.get_Name());
14+
System.out.println("Path = " + Entry.get_Path());
15+
System.out.println("SchemaClassName = " + Entry.get_SchemaClassName());
16+
17+
DirectorySearcher DirSearcher = new DirectorySearcher(Entry);
18+
DirSearcher.set_Filter("(objectClass=*)");
19+
System.out.println("Active Directory Information");
20+
System.out.println("=====================================");
21+
22+
SearchResultCollection searchResultCollection = DirSearcher.FindAll();
23+
for (int i = 0; i < searchResultCollection.get_Count(); i++) {
24+
SearchResult searchResult = searchResultCollection.get_Item(i);
25+
System.out.println(searchResult.GetDirectoryEntry().get_Name());
26+
System.out.println(searchResult.GetDirectoryEntry().get_Name());
27+
System.out.println("===================================");
28+
}
29+
} catch (Exception E) {
30+
System.out.println(E.getMessage());
31+
}
32+
}
33+
}
34+

Diff for: dotNetFramework/src/Array/Program.java

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package Array;
2+
3+
import system.Array;
4+
import system.Type;
5+
6+
public class Program {
7+
8+
static void printArrayByTypeName() throws Exception {
9+
Array oArray = Array.CreateInstance(Type.GetType("System.Double"), 6);
10+
oArray.SetValue(900, 0);
11+
oArray.SetValue(800, 1);
12+
oArray.SetValue(700, 2);
13+
oArray.SetValue(600, 3);
14+
oArray.SetValue(500, 4);
15+
oArray.SetValue(400, 5);
16+
17+
System.out.println("Double Array");
18+
System.out.println(" Count: " + oArray.get_Length());
19+
System.out.println(" Rank: " + oArray.getPropertyValue("Rank"));
20+
System.out.println(" Values:");
21+
22+
for (int i = 0; i < oArray.get_Length(); i++)
23+
System.out.println("\t\t " + oArray.GetValue(i));
24+
25+
System.out.println();
26+
}
27+
28+
static void printArrayByType() throws Exception {
29+
Type oType = Type.GetType("System.Double", true);
30+
Array oArray = Array.CreateInstance(oType, 6);
31+
oArray.SetValue(900, 0);
32+
oArray.SetValue(800, 1);
33+
oArray.SetValue(700, 2);
34+
oArray.SetValue(600, 3);
35+
oArray.SetValue(500, 4);
36+
oArray.SetValue(400, 5);
37+
38+
System.out.println("Double Array");
39+
System.out.println(" Count: " + oArray.get_Length());
40+
System.out.println(" Rank: " + oArray.getPropertyValue("Rank"));
41+
System.out.println(" Values:");
42+
43+
for (int i = 0; i < oArray.get_Length(); i++)
44+
System.out.println("\t\t " + oArray.GetValue(i));
45+
46+
System.out.println();
47+
}
48+
49+
static void printArrayByObjectType() throws Exception {
50+
Array oArray = Array.CreateInstance(Type.GetType("System.Object"), 6);
51+
oArray.SetValue(900, 0);
52+
oArray.SetValue(800, 1);
53+
oArray.SetValue(700, 2);
54+
oArray.SetValue(600, 3);
55+
oArray.SetValue(500, 4);
56+
oArray.SetValue(400, 5);
57+
58+
System.out.println("Object Array");
59+
System.out.println(" Count: " + oArray.get_Length());
60+
System.out.println(" Rank: " + oArray.getPropertyValue("Rank"));
61+
System.out.println(" Values:");
62+
63+
for (int i = 0; i < oArray.get_Length(); i++)
64+
System.out.println("\t\t " + oArray.GetValue(i));
65+
66+
System.out.println();
67+
}
68+
69+
public static void main(String[] arg) {
70+
System.out.println("Hello! Welcome to dotNet4Java .Net Framework");
71+
System.out.println("===========================================");
72+
System.out.println("This program prints out Array values.");
73+
System.out.println();
74+
try {
75+
printArrayByTypeName();
76+
printArrayByType();
77+
printArrayByObjectType();
78+
} catch (Exception eClrError) {
79+
eClrError.printStackTrace();
80+
}
81+
}
82+
}

Diff for: dotNetFramework/src/AssemblyResolve/Program.java

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package AssemblyResolve;
2+
3+
4+
import system.AppDomain;
5+
import system.Console;
6+
import system.ResolveEventArgs;
7+
import system.ResolveEventHandler;
8+
import system.reflection.Assembly;
9+
10+
public class Program {
11+
12+
public static void main(String[] args) {
13+
try {
14+
15+
AppDomain.get_CurrentDomain().add_AssemblyResolve(new ResolveEventHandler() {
16+
@Override
17+
public Assembly invoke(Object o, ResolveEventArgs e) throws Exception {
18+
Console.WriteLine("Resolving {0}", e.get_Name());
19+
return Assembly.Load(e.get_Name());
20+
//Alternatively, you can use
21+
// return TClrAssembly.load(e.get_Name());
22+
}
23+
});
24+
25+
AppDomain.get_CurrentDomain().CreateInstanceAndUnwrap("MyAssembly, version=1.2.3.4, culture=neutral, publicKeyToken=null", "MyType");
26+
27+
} catch (Exception ex) {
28+
ex.printStackTrace();
29+
}
30+
}
31+
}
32+
/*
33+
This example produces output similar to the following:
34+
35+
Resolving MyAssembly, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null
36+
Resolving MyAssembly, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null
37+
...
38+
Resolving MyAssembly, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null
39+
Resolving MyAssembly, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null
40+
41+
Process is terminated due to StackOverflowException.
42+
*/

0 commit comments

Comments
 (0)