Exemple #1
0
        static void Main(string[] args)
        {
            // Trinity doesn't load the config file correctly if we don't tell it to.
            TrinityConfig.LoadConfig();
            TrinityConfig.CurrentRunningMode = RunningMode.Client;

            while (true)
            {
                Console.WriteLine("Input a command 'set key value' 'get key'");
                string   input  = Console.ReadLine();
                string[] fields = input.Split(" ");

                int partitionId = GetPartitionIdByKey(fields[0]);

                if (fields[0] == "get")
                {
                    using (var request = new GetMessageWriter(fields[1])) {
                        using (var response = Global.CloudStorage.GetToDHTServer(partitionId, request)) {
                            if (response.IsFound)
                            {
                                Console.WriteLine("Key:  {0} ; Value: {1}", request.Key, response.Value);
                            }
                            else
                            {
                                Console.WriteLine("Key: {0} wasn't found", request.Key);
                            }
                        }
                    }
                }
                else if (fields[0] == "set")
                {
                    using (var request = new SetMessageWriter(fields[1], fields[2])) {
                        Global.CloudStorage.SetToDHTServer(partitionId, request);
                    }
                }
            }
        }
Exemple #2
0
        static void HandlingUserInput()
        {
            TrinityConfig.CurrentRunningMode = RunningMode.Client;
            while (true)
            {
                Console.WriteLine("Please input a command (set|get):");
                string   input  = Console.ReadLine().Trim();
                string[] fields = input.Split(new char[] { '(', ',', ')' }, StringSplitOptions.RemoveEmptyEntries);

                if (fields.Length > 0)
                {
                    string command = fields[0].Trim().ToLower();

                    #region get
                    if (command.Equals("get"))
                    {
                        if (fields.Length < 2)
                        {
                            Console.WriteLine("example: get(key1) or get(\"key 2\")");
                            continue;
                        }
                        string key = fields[1].Trim().Trim(new char[] { '\"' });
                        using (var request = new GetMessageWriter(key))
                        {
                            using (var response = Global.CloudStorage.GetToDistributedHashtableServer(DistributedHashtableServer.GetServerIdByKey(key), request))
                            {
                                if (response.IsFound)
                                {
                                    Console.WriteLine("The value of \"{0}\" is \"{1}\"", key, response.Value);
                                }
                                else
                                {
                                    Console.WriteLine("The key is not found.");
                                }
                            }
                        }
                        continue;
                    }
                    #endregion

                    #region set
                    if (command.Equals("set"))
                    {
                        if (fields.Length < 3)
                        {
                            Console.WriteLine("example: set(key1, value1) or set(\"key 2\", \"value 2\")");
                            continue;
                        }
                        string key   = fields[1].Trim().Trim(new char[] { '\"' });
                        string value = fields[2].Trim().Trim(new char[] { '\"' });
                        using (var request = new SetMessageWriter(key, value))
                        {
                            Console.WriteLine("Set the value of \"{0}\" is \"{1}\"", key, value);
                            Global.CloudStorage.SetToDistributedHashtableServer(DistributedHashtableServer.GetServerIdByKey(key), request);
                        }
                        continue;
                    }
                    #endregion
                }
                Console.WriteLine("Please input a valid command (set|get):");
            }
        }