コード例 #1
0
        public static void SetTestGlobal(IRIS irisNative)
        {
            // Write to a test global
            irisNative.Set(8888, "^testglobal", "1");
            int globalValue = (int)irisNative.GetInt32("^testglobal", "1");

            Console.WriteLine("The value of ^testglobal(1) is " + globalValue);
        }
        public void ImportJsonStringToGlobal(string jsonStr)
        {
            var o        = JsonConvert.DeserializeObject <JToken>(jsonStr);
            var pathList = ExtractJsonPath(jsonStr);

            foreach (var path in pathList)
            {
                object data    = (object)o.SelectToken(path);
                string dataStr = JsonConvert.SerializeObject(data);
                _irisNative.Set(dataStr, GlobalName, "Node", path);
            }

            IRISList irisList = new IRISList();

            irisList.AddRange(pathList);
            _irisNative.Set(irisList, GlobalName, "Nodes");

            _irisNative.Set(jsonStr, GlobalName, "ActualJson");
        }
コード例 #3
0
        // Create a custom data structure to store airfare in a graph-like structure and retrieve airfare based on nodes
        // Takes departure airport and arrival airport as arguments
        public static void StoreAirfare(IRIS irisNative)
        {
            // Store routes and distance between airports
            // This API sets the value, for a global, with the following keys
            // For example, ^AIRPORT("BOS","AUS") = 1698
            irisNative.Set("1698", "^AIRPORT", "BOS", "AUS");
            irisNative.Set("450", "^AIRPORT", "BOS", "AUS", "AA150");
            irisNative.Set("550", "^AIRPORT", "BOS", "AUS", "AA290");
            irisNative.Set("200", "^AIRPORT", "BOS", "PHL", "UA110");
            irisNative.Set("700", "^AIRPORT", "BOS", "BIS", "AA330");
            irisNative.Set("710", "^AIRPORT", "BOS", "BIS", "UA208");

            // Start interactive prompt
            Console.WriteLine("Enter departure airport: ");
            String fromAirport = Console.ReadLine();

            Console.WriteLine("Enter destination airport: ");
            String toAirport = Console.ReadLine();

            // Query for routes based on input
            String hasRoutes = "This path has no routes";
            int    isDefined = irisNative.IsDefined("^AIRPORT", fromAirport, toAirport);

            if (isDefined == 11 || isDefined == 1)
            {
                hasRoutes = "This path has routes";
            }
            Console.WriteLine("");
            Console.WriteLine("Printed to ^AIRPORT global. The distance in miles between " + fromAirport + " and " + toAirport +
                              " is: " + irisNative.GetString("^AIRPORT", fromAirport, toAirport) + ". " + hasRoutes);
        }
        private void Initialize()
        {
            var itemList = _irisNative.GetIRISList(GlobalsNativeConstants.CollectionGlobals, CollectionName);

            if (itemList == null)
            {
                itemList = new IRISList();
                _irisNative.Set(itemList, GlobalsNativeConstants.CollectionGlobals, CollectionName);
            }
        }
コード例 #5
0
        public static void StoreStockData(IRIS irisNative, IRISConnection dbconnection)
        {
            // Clear global from previous runs
            irisNative.Kill("^nyse");
            Console.WriteLine("Storing stock data using Native API...");

            // Get stock data using JDBC and write global

            try {
                String         sql    = "select top 1000 TransDate, Name, StockClose, StockOpen, High, Low, Volume from Demo.Stock";
                IRISCommand    cmd    = new IRISCommand(sql, dbconnection);
                IRISDataReader reader = cmd.ExecuteReader();
                ArrayList      list   = new ArrayList();
                string         result;

                while (reader.Read())
                {
                    DateTime dt = (DateTime)reader[reader.GetOrdinal("TransDate")];
                    result = (string)reader[reader.GetOrdinal("Name")] +
                             dt.ToString("MM/dd/yyyy") +
                             reader[reader.GetOrdinal("High")] +
                             reader[reader.GetOrdinal("Low")] +
                             reader[reader.GetOrdinal("StockOpen")] +
                             reader[reader.GetOrdinal("StockClose")] +
                             (int)reader[reader.GetOrdinal("Volume")];
                    list.Add(result);
                }

                Console.WriteLine("Duong");

                int  id           = list.Count;
                long startConsume = DateTime.Now.Ticks;

                for (int i = 0; i < id; i++)
                {
                    irisNative.Set(list[i], "^nyse", i + 1);
                }

                long totalConsume = DateTime.Now.Ticks - startConsume;
                Console.WriteLine("Stored natively successfully. Execution time: " + totalConsume / TimeSpan.TicksPerMillisecond + " ms");
            }
            catch (Exception e) {
                Console.WriteLine("Error either retrieving data using JDBC or storing to globals: " + e);
            }
        }
コード例 #6
0
        // Create a custom data structure to store airport distance and airfare information in a graph-like structure.
        // Query this information with the interactive checkAirfare() method
        public static void storeAirfare(IRIS irisNative)
        {
            // Store routes and distance between airports
            // The global we'll populate has two levels:
            // ^airport(from, to) = distance
            // ^airport(from, to, flight) = fare

            // This IRIS native API sets the value for a global at the specified subscript level(s)
            // For example, to set ^airport("BOS","AUS") = 1698
            irisNative.Set("1698", "^airport", "BOS", "AUS");
            irisNative.Set("450", "^airport", "BOS", "AUS", "AA150");
            irisNative.Set("550", "^airport", "BOS", "AUS", "AA290");

            irisNative.Set("280", "^airport", "BOS", "PHL");
            irisNative.Set("200", "^airport", "BOS", "PHL", "UA110");

            irisNative.Set("1490", "^airport", "BOS", "BIS");
            irisNative.Set("700", "^airport", "BOS", "BIS", "AA330");
            irisNative.Set("710", "^airport", "BOS", "BIS", "UA208");

            Console.WriteLine("Stored fare and distance data in ^airport global.");
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: wdbacker/iris-node12
    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);
        }
    }