static void Main(String[] args) { // If you are using a remote instance, update IP and password here String user = "******"; String password = "******"; String IP = "localhost"; int port = 51773; try { // Connect to database using EventPersister, which is based on IRISDataSource // For more details on EventPersister, visit // https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=BNETXEP_xep EventPersister xepPersister = PersisterFactory.CreatePersister(); xepPersister.Connect(IP, port, "User", user, password); Console.WriteLine("Connected to InterSystems IRIS"); xepPersister.DeleteExtent("Demo.Airport"); // Remove old test data xepPersister.ImportSchemaFull("Demo.Airport"); // Import flat schema // Create XEP Event for object access Event xepEvent = xepPersister.GetEvent("Demo.Airport"); // Create IRIS Native object IRISADOConnection connection = (IRISADOConnection)xepPersister.GetAdoNetConnection(); IRIS irisNative = IRIS.CreateIRIS(connection); Console.WriteLine("Generating airport table..."); // Populate 5 airport objects and save to the database using XEP populateAirports(xepEvent); // Get all airports using ADO.NET getAirports(connection); // Store natively - Uncomment the following line for task 3 // StoreAirfare(irisNative); Console.ReadLine(); // Close everything xepEvent.Close(); xepPersister.Close(); } catch (Exception e) { Console.WriteLine("Error creating airport listing: " + e); } }
static void Main(string[] args) { String ip = "localhost"; int port = 51773; String username = "******"; String password = "******"; String Namespace = "USER"; String className = "myApp.StockInfo"; try { // Connect to database using EventPersister EventPersister xepPersister = PersisterFactory.CreatePersister(); xepPersister.Connect(ip, port, Namespace, username, password); Console.WriteLine("Connected to InterSystems IRIS."); xepPersister.DeleteExtent(className); // remove old test data xepPersister.ImportSchema(className); // import flat schema // Create Event Event xepEvent = xepPersister.GetEvent(className); IRISADOConnection connection = (IRISADOConnection) xepPersister.GetAdoNetConnection(); IRIS native = IRIS.CreateIRIS(connection); // Task 2 // Uncomment the line below to run task 2 // Task2(connection); // Task 3 // Uncomment the line below to run task 3 // Task3(connection, xepEvent); // Task 4 // Comment out Task 2, Task 3 and uncomment the line below to run task 4 // Task4(connection, native, xepEvent); xepEvent.Close(); xepPersister.Close(); } catch (Exception e) { Console.WriteLine("Interactive prompt failed:\n" + e); } }
// Save trade into database using ADO.NET - which is slower than using XEP public static long StoreUsingADO(EventPersister persist, Trade[] sampleArray) { long totalTime = new long(); long startTime = DateTime.Now.Ticks; // Loop through objects to insert try { IRISDataAdapter da = new IRISDataAdapter(); String ClassName = "myApp.Trade"; IRISADOConnection con = (IRISADOConnection)persist.GetAdoNetConnection(); String SQL = "select purchaseDate, purchasePrice, stockName, shares, traderName from " + ClassName; da.SelectCommand = con.CreateCommand(); da.SelectCommand.CommandText = SQL; SQL = "INSERT INTO myApp.Trade (purchaseDate, purchasePrice, stockName, shares, traderName) VALUES (?,?,?,?,?)"; IRISCommand cmd = con.CreateCommand(); cmd.CommandText = SQL; da.InsertCommand = cmd; IRISParameter date_param = new IRISParameter("purchaseDate", IRISDbType.DateTime); cmd.Parameters.Add(date_param); date_param.SourceColumn = "purchaseDate"; IRISParameter price_param = new IRISParameter("purchasePrice", IRISDbType.Double); cmd.Parameters.Add(price_param); price_param.SourceColumn = "purchasePrice"; IRISParameter name_param = new IRISParameter("stockName", IRISDbType.NVarChar); cmd.Parameters.Add(name_param); name_param.SourceColumn = "stockName"; IRISParameter shares_param = new IRISParameter("shares", IRISDbType.Int); cmd.Parameters.Add(shares_param); shares_param.SourceColumn = "shares"; IRISParameter trader_param = new IRISParameter("traderName", IRISDbType.NVarChar); cmd.Parameters.Add(trader_param); trader_param.SourceColumn = "traderName"; da.TableMappings.Add("Table", ClassName); DataSet ds = new DataSet(); da.Fill(ds); for (int i = 0; i < sampleArray.Length; i++) { DataRow newRow = ds.Tables[0].NewRow(); newRow["purchaseDate"] = sampleArray[i].purchaseDate; newRow["purchasePrice"] = sampleArray[i].purchasePrice; newRow["stockName"] = sampleArray[i].stockName; newRow["shares"] = sampleArray[i].shares; newRow["traderName"] = sampleArray[i].traderName; ds.Tables[0].Rows.Add(newRow); } da.Update(ds); Console.WriteLine("Inserted " + sampleArray.Length + " item(s) via ADO.NET successfully."); totalTime = DateTime.Now.Ticks - startTime; } catch (Exception e) { Console.WriteLine("There was a problem storing items using ADO.NET.\n" + e); } return(totalTime / TimeSpan.TicksPerMillisecond); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); // Initialize dictionary to store connection details from config.txt IDictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary = generateConfig("..\\..\\..\\config.txt"); // Retrieve connection information from configuration file string ip = dictionary["ip"]; int port = Convert.ToInt32(dictionary["port"]); string Namespace = dictionary["namespace"]; string username = dictionary["username"]; string password = dictionary["password"]; String className = "myApp.StockInfo"; try { // Connect to database using EventPersister EventPersister xepPersister = PersisterFactory.CreatePersister(); xepPersister.Connect(ip, port, Namespace, username, password); Console.WriteLine("Connected to InterSystems IRIS."); xepPersister.DeleteExtent(className); // Remove old test data xepPersister.ImportSchema(className); // Import flat schema // Create Event Event xepEvent = xepPersister.GetEvent(className); IRISADOConnection connection = (IRISADOConnection)xepPersister.GetAdoNetConnection(); IRIS native = IRIS.CreateIRIS(connection); // Starting interactive prompt bool always = true; while (always) { Console.WriteLine("1. Retrieve all stock names"); Console.WriteLine("2. Create objects"); Console.WriteLine("3. Populate properties"); Console.WriteLine("4. Quit"); Console.WriteLine("What would you like to do? "); String option = Console.ReadLine(); switch (option) { // Task 2 case "1": Task2(connection); break; // Task 3 case "2": Task3(connection, xepEvent); break; // Task 4 case "3": Task4(connection, native, xepEvent); break; case "4": Console.WriteLine("Exited."); always = false; break; default: Console.WriteLine("Invalid option. Try again!"); break; } } xepEvent.Close(); xepPersister.Close(); } catch (Exception e) { Console.WriteLine("Interactive prompt failed:\n" + e); } }