Example #1
0
        public Dictionary<string, string> GetDocuemnts(GetMultipleRequest getRequest)
        {
            var hostUrl = ConfigurationManager.AppSettings["ApiHostUrl"];

            var requstJson = JsonConvert.SerializeObject(getRequest);
            var request = HttpWebRequest.Create(hostUrl + "/documents/") as HttpWebRequest;
            request.Method = "POST";
            request.ContentLength = requstJson.Length;
            request.GetRequestStream().Write(Encoding.ASCII.GetBytes(requstJson), 0, requstJson.Length);
            var response = request.GetResponse();
            var reader = new StreamReader(response.GetResponseStream());
            var message = reader.ReadToEnd();

            return JsonConvert.DeserializeObject<Dictionary<string, string>>(message);
        }
Example #2
0
        static void BulkGet(string commandLine)
        {
            commandLine = commandLine.Remove(0, 9);
            var client = new Client();

            var kv = commandLine.Split('|');
            var bucket = kv[0];
            var keyHead = kv[1];
            var from = int.Parse(kv[2]);
            var to = int.Parse(kv[3]);

            var keys = new List<string>();
            for (var i = from; i < to; i ++)
                keys.Add(keyHead + i);

            var reuqest = new GetMultipleRequest {BucketName = bucket, Keys = keys};

            var watch = Stopwatch.StartNew();
            var result = client.GetDocuemnts(reuqest);
            watch.Stop();
            System.Console.WriteLine("{0} results returned.", result.Count);
            System.Console.WriteLine("{0} documents found, {1} documents not found", result.Count(data => !string.IsNullOrEmpty(data.Value)), result.Count(data => string.IsNullOrEmpty(data.Value)));
            System.Console.WriteLine("Operation took {0} milliseconds", watch.ElapsedMilliseconds);
        }
Example #3
0
        static void GetFile(string commandLine)
        {
            commandLine = commandLine.Remove(0, 9);
            var kv = File.ReadAllLines(commandLine).Select(ln => ln.Split('|')).ToList();
            var lines = kv.Select(k => k[1]);
            var client = new Client();
            var watch = Stopwatch.StartNew();
            var request = new GetMultipleRequest { BucketName = kv[0][0], Keys = lines.ToList() };
            var result = client.GetDocuemnts(request);
            watch.Stop();

            result = result ?? new Dictionary<string, string>();

            foreach (var item in result)
                System.Console.WriteLine(item.Key + ":   " + item.Value);

            System.Console.WriteLine("{0} results returned.",result.Count);
            System.Console.WriteLine("{0} documents found, {1} documents not found", result.Count(data => !string.IsNullOrEmpty(data.Value)), result.Count(data => string.IsNullOrEmpty(data.Value)));
            System.Console.WriteLine("Operation took {0} milliseconds", watch.ElapsedMilliseconds);
        }