Exemplo n.º 1
0
        } //batchGetUserTweets

        public void updatePasswordUsingUDF()
        {
            //Assembly assembly = Assembly.GetExecutingAssembly();
            ////Policy policy = new Policy();
            ////policy.SetTimeout(100);
            //RegisterTask rtask = client.Register(policy, "updateUserPwd.lua", "updateUserPwd.lua", Language.LUA);
            //rtask.Wait();



            Record userRecord = null;
            Key    userKey    = null;

            // Get username
            string username;

            Console.WriteLine("\nEnter username:"******"test", "users", username);
                userRecord = client.Get(null, userKey);
                if (userRecord != null)
                {
                    // Get new password
                    string password;
                    Console.WriteLine("Enter new password for " + username + ":");
                    password = Console.ReadLine();

                    //string luaDirectory = @"..\..\udf";
                    //LuaConfig.PackagePath = luaDirectory + @"\?.lua";
                    //string filename = "updateUserPwd.lua";
                    //string path = Path.Combine(luaDirectory, filename);
                    //RegisterTask rt = client.Register(null, path, filename, Language.LUA);
                    //rt.Wait();

                    Assembly assembly = Assembly.GetExecutingAssembly();
                    Policy   policy   = new Policy();
                    policy.SetTimeout(100);
                    RegisterTask rtask = client.Register(policy, "updateUserPwd.lua", "updateUserPwd.lua", Language.LUA);
                    rtask.Wait();

                    string updatedPassword = client.Execute(null, userKey, "updateUserPwd", "updatePassword", Value.Get(password)).ToString();
                    Console.WriteLine("\nINFO: The password has been set to: " + updatedPassword);
                }
                else
                {
                    Console.WriteLine("ERROR: User record not found!");
                }
            }
            else
            {
                Console.WriteLine("ERROR: User record not found!");
            }
        } //updatePasswordUsingUDF
Exemplo n.º 2
0
        } //getUserTweets

        public void updatePasswordUsingUDF()
        {
            Record userRecord = null;
            Key    userKey    = null;

            // Get username
            string username;

            Console.WriteLine("\nEnter username:"******"test", "users", username);
                userRecord = client.Get(null, userKey);
                if (userRecord != null)
                {
                    //Get new password
                    string password;
                    Console.WriteLine("Enter new password for " + username + ":");
                    password = Console.ReadLine();

                    // TODO: Update userRecord using UDF
                    // Exercise R2
                    // NOTE: UDF registration has been included here for convenience and to demonstrate the syntax.
                    // NOTE: The recommended way of registering UDFs in production env is via AQL
                    string luaDirectory = @"..\..\udf";
                    LuaConfig.PackagePath = luaDirectory + @"\?.lua";
                    string       filename = "updateUserPwd.lua";
                    string       path     = Path.Combine(luaDirectory, filename);
                    RegisterTask rt       = client.Register(null, path, filename, Language.LUA);
                    rt.Wait();

                    // TODO: Execute the UDF updatePassword.lua
                    // Exercise R2
                    string updatedPassword = client.Execute(null, userKey, "updateUserPwd", "updatePassword", Value.Get(password)).ToString();

                    // TODO: Output the updated passord returned by the UDF
                    // Exercise R2
                    Console.WriteLine("\nINFO: The password has been set to: " + updatedPassword);
                }
                else
                {
                    Console.WriteLine("\nERROR: User record not found.");
                }
            }
            else
            {
                Console.WriteLine("\nERROR: Invalid user name.");
            }
        } //updatePasswordUsingUDF
        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();
        }
Exemplo n.º 4
0
        } //getUser

        public void updatePasswordUsingUDF()
        {
            Record userRecord = null;
            Key    userKey    = null;

            // Get username
            string username;

            Console.WriteLine("\nEnter username:"******"test", "users", username);
                userRecord = client.Get(null, userKey);
                if (userRecord != null)
                {
                    // Get new password
                    string password;
                    Console.WriteLine("Enter new password for " + username + ":");
                    password = Console.ReadLine();

                    // NOTE: UDF registration has been included here for convenience and to demonstrate the syntax. The recommended way of registering UDFs in production env is via AQL
                    string luaDirectory = @"..\..\udf";
                    LuaConfig.PackagePath = luaDirectory + @"\?.lua";
                    string       filename = "updateUserPwd.lua";
                    string       path     = Path.Combine(luaDirectory, filename);
                    RegisterTask rt       = client.Register(null, path, filename, Language.LUA);
                    rt.Wait();

                    string updatedPassword = client.Execute(null, userKey, "updateUserPwd", "updatePassword", Value.Get(password)).ToString();
                    Console.WriteLine("\nINFO: The password has been set to: " + updatedPassword);
                }
                else
                {
                    Console.WriteLine("ERROR: User record not found!");
                }
            }
            else
            {
                Console.WriteLine("ERROR: User record not found!");
            }
        } //updatePasswordUsingUDF
Exemplo n.º 5
0
        } //updatePasswordUsingCAS

        public void aggregateUsersByTweetCountByRegion()
        {
            // TODO: Create NUMERIC index on tweetcount in users set (Same as Exercise Q4)
            // Exercise A2
            // NOTE: Index creation has been included in here for convenience and to demonstrate the syntax
            // The recommended way of creating indexes in production env is via AQL
            // or create once using a standalone application.
            //IndexTask task = client.CreateIndex(null, "test", "users", "tweetcount_index", "tweetcount", IndexType.NUMERIC);
            //task.Wait();

            ResultSet rs = null;

            try
            {
                int min;
                int max;
                Console.WriteLine("\nEnter Min Tweet Count:");
                min = int.Parse(Console.ReadLine());
                Console.WriteLine("Enter Max Tweet Count:");
                max = int.Parse(Console.ReadLine());

                // TODO: Register UDF
                // Exercise A2
                // NOTE: UDF registration has been included here for convenience and to demonstrate the syntax.
                // The recommended way of registering UDFs in production env is via AQL
                // or standalone application using code similar to below.
                string luaDirectory = @"..\..\udf";
                LuaConfig.PackagePath = luaDirectory + @"\?.lua";

                string filename = "aggregationByRegion.lua";
                string path     = Path.Combine(luaDirectory, filename);

                RegisterTask rt = client.Register(null, path, filename, Language.LUA);
                rt.Wait();

                // TODO: Create string array of bins that you would like to retrieve
                // In this example, we want to display which region has how many tweets.
                // Exercise A2
                string[] bins = { "tweetcount", "region" };

                // TODO: Create Statement instance
                // Exercise A2
                Statement stmt = new Statement();

                // TODO: Set namespace on the instance of the Statement
                // Exercise A2
                stmt.SetNamespace("test");

                // TODO: Set the name of the set on the instance of the Statement
                // Exercise A2
                stmt.SetSetName("users");

                // TODO: Set the name of index on the instance of the Statement
                // Exercise A2
                stmt.SetIndexName("tweetcount_index");

                // TODO: Set the list of bins to retrieve on the instance of the Statement
                // Exercise A2
                stmt.SetBinNames(bins);

                // TODO: Set the range Filter on tweetcount on the instance of the Statement
                // Exercise A2
                stmt.SetFilters(Filter.Range("tweetcount", min, max));

                Console.WriteLine("\nAggregating users with " + min + "-" + max + " tweets by region. Hang on...\n");

                // TODO: Execute the Aggregation Query passing null policy and Statement instance,
                // Lua Module and module function to call.
                // Exercise A2
                rs = client.QueryAggregate(null, stmt, "aggregationByRegion", "sum");

                if (rs.Next())
                {
                    // TODO: Iterate through returned RecordSet and output text in format "Total Users in <region>: <#>"
                    // Exercise A2
                    Dictionary <object, object> result = (Dictionary <object, object>)rs.Object;
                    Console.WriteLine("Total Users in North: " + result["n"]);
                    Console.WriteLine("Total Users in South: " + result["s"]);
                    Console.WriteLine("Total Users in East: " + result["e"]);
                    Console.WriteLine("Total Users in West: " + result["w"]);
                }
            }
            finally
            {
                // TODO: Close the RecordSet
                // Exercise A2
                if (rs != null)
                {
                    // Close record set
                    rs.Close();
                }
            }
        } //aggregateUsersByTweetCountByRegion
Exemplo n.º 6
0
        } //main

        public void aggregateUsersByTweetCountByRegion(AerospikeClient client)
        {
            ResultSet rs = null;

            try
            {
                int min;
                int max;
                Console.WriteLine("\nEnter Min Tweet Count:");
                min = int.Parse(Console.ReadLine());
                Console.WriteLine("Enter Max Tweet Count:");
                max = int.Parse(Console.ReadLine());

                Console.WriteLine("\nAggregating users with " + min + "-" + max + " tweets by region. Hang on...\n");

                // NOTE: Index creation has been included in here for convenience and to demonstrate the syntax.
                // NOTE: The recommended way of creating indexes in production env is via AQL.
                IndexTask task = client.CreateIndex(null, "test", "testusers", "tweetcountindex", "tweetcount", IndexType.NUMERIC);
                task.Wait();

                // NOTE: UDF registration has been included here for convenience and to demonstrate the syntax.
                // NOTE: The recommended way of registering UDFs in production env is via AQL
                string luaDirectory = @"..\..\udf";
                LuaConfig.PackagePath = luaDirectory + @"\?.lua";

                string filename = "aggregationByRegion.lua";
                string path     = Path.Combine(luaDirectory, filename);

                RegisterTask rt = client.Register(null, path, filename, Language.LUA);
                rt.Wait();

                Statement stmt = new Statement();
                stmt.SetNamespace("test");
                stmt.SetSetName("testusers");
                stmt.SetIndexName("tweetcountindex");
                stmt.SetFilters(Filter.Range("tweetcount", min, max));

                rs = client.QueryAggregate(null, stmt, "aggregationByRegion", "sum");

                if (rs.Next())
                {
                    Dictionary <object, object> result = (Dictionary <object, object>)rs.Object;

                    Console.WriteLine("Here's the breakdown...\n");
                    Console.WriteLine("Total Users in North: " + result["n"]);
                    Console.WriteLine("Total Users in South: " + result["s"]);
                    Console.WriteLine("Total Users in East: " + result["e"]);
                    Console.WriteLine("Total Users in West: " + result["w"]);
                }
            }
            catch (AerospikeException e)
            {
                Console.WriteLine("AerospikeException - Message: " + e.Message);
                Console.WriteLine("AerospikeException - StackTrace: " + e.StackTrace);
            }
            finally
            {
                if (rs != null)
                {
                    // Close record set
                    rs.Close();
                }
            }
        } //aggregateUsersByTweetCountByRegion