Updating existing applications

The latest 1010data .NET SDK is designed for developing applications in a style that is more closely compatible with .NET development, specifically object-oriented programming.

Applications developed with the original 1010data .NET SDK must be updated to use the object-oriented 1010data .NET SDK. When you're updating your existing application, keep that applications developed for the original 1010data .NET SDK:
  • Required you to instantiate exactly one instance of the CppCLISDK1010 class. The object-oriented 1010data .NET SDK does not require you to instantiate any instance of the CppCLISDK1010 class.
  • Required you to synchronize multiple threads yourself. The object-oriented 1010data .NET SDK, handles thread synchronization. As a best practice, each thread should create its own Session object. For more information, see Best practices or Establishing a session.
  • Required you to check for error codes after each method invocation. The object-oriented .NET SDK uses an exception-based model. For more information, see Exception handling.
  • Required applications using a SAM pool to manually acquire a UID via calls to GetUID1010. In the object-oriented 1010data .NET SDK, this is not required. For more information, see Shared Access Management (SAM).
  • Required you to manually clean up a 1010data Insights Platform session. In the object-oriented .NET SDK, you can take advantage of the using pattern, which cleans up the session automatically.

This example contains code written for the original 1010data .NET SDK:

using System;

public class PrintTable {
    public static void Main(String[] args) {
        CppCLISDK1010 link;
        int login;
        String username = "USERNAME";
        String password = "PASSWORD";
        String gateway;
        String queryXML;
        String tablePath;
        int queryID, block, windowSize, finRows;
        long numRows;
        String[][] colInfo;
        Object[][] table;

        gateway = "https://www2.1010data.com/cgi-bin/gw";
        queryXML = "<sel value=\"(year&gt;1900)\"/>";
        tablePath = "pub.demo.baseball.batting";
        windowSize = 10000;
        block = 40000;
        finRows = 0;

        // Create exactly one CppCLISDK1010 Object.
        link = new CppCLISDK1010();
        login = link.login1010(gateway, username, password, 1);
        // We need to check the return code after every action to
        // make sure it succeeded.
        if (login < 0) {
            Console.Error.WriteLine("Failed " + login + ": " +
                                    link.msg1010(login));
            Environment.Exit(1);
        }
        try {
            queryID = link.newquery1010();
            if(queryID < 0) {
                Console.Error.WriteLine("Failed to create query: (" +
                                   link.rc1010(login) + ") " +
                                   link.msg1010(login));
                Environment.Exit(1);
            }
            // -2 is COMPRESSED_BINARY
            link.querymode1010(queryID, windowSize, -2);
            link.prepquery1010(queryID, tablePath, queryXML);

            // Run the query.
            if(link.runquery1010(login, queryID) < 0) {
                Console.Error.WriteLine("Failed to run query: (" +
                                   link.rc1010(login) + ") " +
                                   link.msg1010(login));
                Environment.Exit(1);
            }
            colInfo = link.querycols1010(queryID);
            if(colInfo == null) {
                Console.Error.WriteLine("Failed to get column info: (" +
                                   link.rc1010(login) + ") " +
                                   link.msg1010(login));
                Environment.Exit(1);
            }

            numRows = link.queryrows1010(queryID);

            // For testing, limit the number of rows to 5000.
            numRows = Math.Min(5000, numRows);
            block = 1000;

            while (finRows < numRows) {
                // Pull down one block at a time.
                // Start at finRows and get all the columns.
                table = link.getdataRM1010(queryID, finRows, block, colInfo);
                if(table == null) {
                    Console.Error.WriteLine("Failed to get data: (" +
                                   link.rc1010(login) + ") " +
                                   link.msg1010(login));
                    Environment.Exit(1);
                }
                finRows += block;

                // For each row in this block...
                for (int i = 0; i < table.Length; i++) {
                    // for each column in this row...
                    for (int j = 0; j < table[i].Length; j++) {
                        Console.Write(table[i][j] + "\t");
                    }
                    Console.WriteLine();
                }
                // It is important to set the table to null
                // when you are finished using it.
                table = null;
            }
        }
        finally {
            link.logout1010(login);
        }
    }
}

This example contains code written for the object-oriented 1010data .NET SDK:

using System;
using System.Linq;
using TenTenSDK;

public class PrintTable
{
    public static void Main(string[] args) {
        String username;
        String password;
        Uri gateway;
        String queryXML;
        String tablePath;
        Session session;
        Query query;
        Table results;

        username = "USERNAME";
        password = "PASSWORD";

        gateway = new Uri("https://www2.1010data.com/cgi-bin/gw");
        queryXML = "<sel value=\"(year&gt;1900)\"/>";
        tablePath = "pub.demo.baseball.batting";

        try {
            using (session = new Session(gateway, username, password, LoginType.POSSESS)) {
                query = new Query(tablePath, queryXML);
                using (results = query.RunOn(session)) {
                    int count = 0;
                    foreach (Row row in results.Rows) {
                        Console.WriteLine(String.Join("\t", row.Select(d => d.ToString())));
                        count++;
                        // Limit rows to 5000 for testing purposes.
                        if (count > 5000) {
                            break;
                        }
                    }
                }
            }
        }
        catch (TenTenSDK.Exceptions.TenTenException exc) {
            Console.Error.WriteLine("1010 Exception occurred: " + exc.ToString());
        }
    }
}