예제 #1
0
        // Simple interactive method using IRIS native API to consult the data structure populated in storeAirfare()
        public static void checkAirfare(IRIS irisNative)
        {
            // Prompt for input
            Console.Write("Enter departure airport: (e.g. BOS)");
            String fromAirport = Console.ReadLine();

            Console.Write("Enter destination airport: (e.g. AUS)");
            String toAirport = Console.ReadLine();

            // ^airport(from, to) = distance
            Console.WriteLine("");
            Console.WriteLine("The distance in miles between " + fromAirport + " and " + toAirport +
                              " is: " + irisNative.GetString("^airport", fromAirport, toAirport) + ".");

            // Now loop through routes: ^airport(from, to, flight) = fare
            int isDefined = irisNative.IsDefined("^airport", fromAirport, toAirport);

            if (isDefined == 11)
            {
                Console.WriteLine("The following routes exist for this path:");
                IRISIterator iterator = irisNative.GetIRISIterator("^airport", fromAirport, toAirport);
                while (iterator.MoveNext())
                {
                    String fare         = (String)iterator.Current;
                    String flightNumber = (String)iterator.CurrentSubscript;
                    Console.WriteLine("  - " + flightNumber + ": " + fare + " USD");
                }
            }
            else
            {
                Console.WriteLine("No routes exist for this path.");
            }
        }
예제 #2
0
        public static void PrintNodes(IRIS irisNative, String globalName)
        {
            Console.WriteLine("Iterating over " + globalName + " globals");

            // Iterate over all nodes forwards
            IRISIterator iter = irisNative.GetIRISIterator(globalName);

            Console.WriteLine("walk forwards");
            foreach (var v in iter)
            {
                Console.WriteLine("subscript=" + iter.CurrentSubscript + ", value=" + iter.Current);
            }
        }
예제 #3
0
    public static void Main(String[] args)
    {
        try
        {
            // open connection to InterSystems IRIS instance using connection string
            IRISConnection conn = new IRISConnection();

            // edit this ConnectionString to match your environment
            conn.ConnectionString = "Server=localhost; Port=51773; Namespace=User; Password=SYS; User ID=_system; SharedMemory=false; logfile=./dbnative.log";
            conn.Open();


            // create IRIS Native object
            IRIS iris = IRIS.CreateIRIS(conn);

            Console.WriteLine("[1. Setting and getting a global]");

            // setting and getting a global
            // ObjectScript equivalent: set ^testglobal("1") = 8888
            iris.Set(8888, "^testglobal", "1");

            // ObjectScript equivalent: set globalValue = $get(^testglobal("1"))
            Int16?globalValue = iris.GetInt16("^testglobal", "1");

            Console.WriteLine("The value of ^testglobal(1) is " + globalValue);
            Console.WriteLine();


            Console.WriteLine("[2. Iterating over a global]");

            // modify global to iterate over
            // ObjectScript equivalent: set ^testglobal("1") = 8888
            // ObjectScript equivalent: set ^testglobal("2") = 9999
            iris.Set(8888, "^testglobal", "1");
            iris.Set(9999, "^testglobal", "2");

            // iterate over all nodes forwards
            Console.WriteLine("walk forwards");
            IRISIterator subscriptIter = iris.GetIRISIterator("^testglobal");
            foreach (var node in subscriptIter)
            {
                Console.WriteLine("subscript=" + subscriptIter.CurrentSubscript + ", value=" + node);
            }
            Console.WriteLine();


            Console.WriteLine("[3. Calling a class method]");

            // calling a class method
            // ObjectScript equivalent: set returnValue = ##class(%Library.Utility).Date(5)
            String returnValue = iris.ClassMethodString("%Library.Utility", "Date", 5);
            Console.WriteLine(returnValue);

            Console.WriteLine();

            // close IRIS object and connection
            iris.Close();
            conn.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }