public static void Main(string[] args)
        {
            AerospikeClient client = null;
            try {
                Console.WriteLine ("Connecting to Aerospike cluster...");
                Stopwatch stopwatch = new Stopwatch ();
                //Thread[] array = new Thread[accountTotal];

                // Establish connection
                client = new AerospikeClient (asServerIP, asServerPort);

                // Check to see if the cluster connection succeeded
                if (client.Connected) {
                    Console.WriteLine ("Connection succeeded!\n");
                    int feature = 0;
                    while (feature != 99) {
                        // Present options
                        Console.WriteLine ("\n\nWhat would you like to do:");
                        Console.WriteLine ("1> Generate sequence data for last " + days + " days");
                        Console.WriteLine ("2> Reconsile sequence data");
                        Console.WriteLine ("3> Generate Position using CDT and LDT");
                        Console.WriteLine ("4> List CDT vs LDT - whole list");
                        Console.WriteLine ("5> List CDT vs LDT - one element");
                        Console.WriteLine ("99> Exit");
                        Console.Write ("\nSelect 1-5, 99 and hit enter:");
                        string input = Console.ReadLine ();
                        if (input.Trim().Length == 0)
                            feature = 99;
                        else
                            feature = int.Parse (input);
                        if (feature != 99) {
                            switch (feature) {
                            case 1:
                                Console.WriteLine ("Generating data...");
                                DateTime today = DateTime.Now;
                                today = today.Date;

                            // write yesterday to Aerospike
                                DateTime yesterday = today.AddDays (-1);
                                generateTimeSeries (yesterday.ToShortDateString (), client);

                            // write yesterday to file
                                generateTimeSeries (yesterday.ToShortDateString (), null);

                            // write n days
                                for (int dif = 2; dif < days; dif++) {
                                    DateTime dayBefore = today.AddDays (-dif);
                                    Console.WriteLine ("Writing: " + dayBefore.ToShortDateString ());
                                    generateTimeSeries (dayBefore.ToShortDateString (), client);
                                }
                                Console.WriteLine ("Generating data completed");
                                break;
                            case 2:
                                Console.WriteLine ("Reconsiling yesterday's data");

                                #region setup
                                // use admin tools to do this in production
                                RegisterTask rTask = client.Register(null,
                                    udfDir + "utility.lua",
                                    "utility.lua", Language.LUA);
                                while(!rTask.QueryIfDone()){
                                    Thread.Sleep(20);
                                }

            //								client.CreateIndex(null, ns, seqSet,
            //													"day-seq-index", dayBinName, IndexType.STRING);
                                #endregion
                                today = DateTime.Now;
                                today = today.Date;
                                yesterday = today.AddDays (-1);
                                string yesterdayString = yesterday.ToShortDateString ();
                                // purge first sequence
                                PurgeDay (yesterdayString, client);
                                /// reconciliation from file
                                ReconcileDay (yesterdayString, client);

                                Console.WriteLine ("Reconciliation complete");
                                break;
                            case 3:
                                Console.WriteLine ("Generating position data using CDT and LDT...");
                                generateCustomerProduct (client);
                                Console.WriteLine ("Generating data completed");
                                break;
                            case 4:

                                Console.WriteLine ("CDT vs LDT - Whole list...");
                                long cdtTotal = 0, ldtTotal = 0, cdtProdCount = 0, ldtProdCount = 0;

                                for (int acc = 0; acc < accountTotal; acc++) {
                                    string accString = (acc + 1).ToString ();
                                    Key cdtkey = new Key (ns, cdtSet, accString);
                                    Key ldtkey = new Key (ns, ldtSet, accString);
                                    Aerospike.Helper.Collection.LargeList clist = new Aerospike.Helper.Collection.LargeList (client, null, cdtkey, cdtBinName);
                                    LargeList llist = client.GetLargeList (null, ldtkey, ldtBinName);
                                    stopwatch.Start ();
                                    IList cresult = clist.Scan ();
                                    stopwatch.Stop ();
                                    if (cresult != null)
                                        cdtProdCount += cresult.Count;
                                    cdtTotal += stopwatch.ElapsedMilliseconds;
                                    stopwatch.Reset ();

                                    stopwatch.Start ();
                                    IList lresult = llist.Scan ();
                                    stopwatch.Stop ();
                                    if (lresult != null)
                                        ldtProdCount += lresult.Count;
                                    ldtTotal += stopwatch.ElapsedMilliseconds;
                                }

                                Console.WriteLine ("CDT avg latency: {0:F5} ms", (double)cdtTotal / cdtProdCount);
                                Console.WriteLine ("LDT avg latency: {0:F5} ms", (double)ldtTotal / ldtProdCount);

                                break;
                            case 5:
                                const int attempts = 50000;
                                Console.WriteLine ("CDT vs LDT - one element..., {0} customers, each product for a customer", attempts);
                                cdtTotal = 0;
                                ldtTotal = 0;
                                long prodCount = 0;
                                Random accRand = new Random (12121);
                                for (int i = 0; i < 50000; i++) {
                                    string accString = accRand.Next (1, accountTotal).ToString ();
                                    Key cdtkey = new Key (ns, cdtSet, accString);
                                    Key ldtkey = new Key (ns, ldtSet, accString);
                                    Aerospike.Helper.Collection.LargeList clist = new Aerospike.Helper.Collection.LargeList (client, null, cdtkey, cdtBinName);
                                    LargeList llist = client.GetLargeList (null, ldtkey, ldtBinName);
                                    IList prods = llist.Scan ();
                                    if (prods != null) {
                                        prodCount += prods.Count;
                                        foreach (IDictionary product in prods) {
                                            //Dictionary<string, Object> keyMap = makeKeyMap (product);
                                            // CDT
                                            stopwatch.Start ();

                                            clist.Find (Value.Get (product));

                                            stopwatch.Stop ();
                                            cdtTotal += stopwatch.ElapsedMilliseconds;

                                            stopwatch.Reset ();

                                            // LDT
                                            stopwatch.Start ();

                                            llist.Find (Value.Get (product));

                                            stopwatch.Stop ();
                                            ldtTotal += stopwatch.ElapsedMilliseconds;

                                        }
                                    }
                                }
                                Console.WriteLine ("CDT avg latency: {0:F5} ms", (double)cdtTotal / prodCount);
                                Console.WriteLine ("LDT avg latency: {0:F5} ms", (double)ldtTotal / prodCount);

                                break;
                            default:

                                break;
                            }
                        }
                    }
                }
            } catch (AerospikeException e) {
                Console.WriteLine ("AerospikeException - Message: " + e.Message);
                Console.WriteLine ("AerospikeException - StackTrace: " + e.StackTrace);
            } catch (Exception e) {
                Console.WriteLine ("Exception - Message: " + e.Message);
                Console.WriteLine ("Exception - StackTrace: " + e.StackTrace);
            } finally {
                if (client != null && client.Connected) {
                    // Close Aerospike server connection
                    client.Close ();
                }

            }
        }
 public static void Register(AerospikeClient client, Policy policy, string packageName)
 {
     string path = LuaDirectory + packageName;
     RegisterTask task = client.Register(policy, path, packageName, Language.LUA);
     task.Wait();
 }