Пример #1
0
        public static async Task <string> PutValue(int id, string value)
        {
            string nodePort = Nodes.Ports[ProxyModel.GetShardNumber(id)];

            string   url = "http://localhost:" + nodePort + "/database/" + id.ToString();
            string   responseContent;
            ValueDTO data = new ValueDTO {
                Value = value
            };
            string postBody = JsonConvert.SerializeObject(data);

            using (var client = new HttpClient())
            {
                var response = await client.PutAsync(url, new StringContent(postBody, Encoding.UTF8, "application/json"));

                string content = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    responseContent = JsonConvert.DeserializeObject(content).ToString();
                }
                else
                {
                    responseContent = value;
                }
                return(responseContent);
            }
        }
Пример #2
0
        public static void Resharding(int port, List <int> reshard)
        {
            List <string> ports = new List <string>();

            ports.AddRange(Nodes.Ports);
            ports.Add(port.ToString());
            for (int i = 0; i < reshard.Count; ++i)
            {
                var resp = ProxyModel.GetValue(reshard[i]).Result;
                var del  = ProxyModel.DeleteValue(reshard[i]).Result;
                var t    = ProxyModel.SendReshardingValuesAsync(reshard[i], resp).Result;
            }
            Nodes.Ports.Add(port.ToString());
        }
Пример #3
0
        public static async Task <string> DeleteValue(int id)
        {
            string nodePort = Nodes.Ports[ProxyModel.GetShardNumber(id)];

            string url = "http://localhost:" + nodePort + "/database/" + id.ToString();

            using (var client = new HttpClient())
            {
                var response = await client.DeleteAsync(url);

                string content = await response.Content.ReadAsStringAsync();

                var responseContent = JsonConvert.DeserializeObject(content).ToString();
                return(responseContent);
            }
        }