PageRenderTime 81ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

/Raven.Database/Counters/Controllers/CounterStorageController.cs

https://github.com/nwendel/ravendb
C# | 43 lines | 39 code | 3 blank | 1 comment | 0 complexity | d91e9108d6f015f382ea9af2c3709b36 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Net.Http;
 5using System.Text;
 6using System.Threading;
 7using System.Threading.Tasks;
 8using System.Web.Http;
 9using Raven.Database.Server.Controllers;
10using Raven.Json.Linq;
11
12namespace Raven.Database.Counters.Controllers
13{
14    public class CounterStorageController : RavenDbApiController
15    {
16        [Route("counterStorage/conterStorages")]
17        [HttpGet]
18        public HttpResponseMessage GetCounterStoragesNames()
19        {
20            var names = GetCounterStorages();
21            return GetMessageWithObject(names);
22        }
23
24		[Route("counterStorage/stats")]
25		[HttpGet]
26		public HttpResponseMessage GetCounterStoragesStats()
27		{
28			//TODO: implement getting the stats about the counter storages
29			return GetEmptyMessage();
30		}
31
32        private string[] GetCounterStorages()
33        {
34            var start = GetStart();
35            var nextPageStart = start; // will trigger rapid pagination
36            var counterStorages = Database.Documents.GetDocumentsWithIdStartingWith("Raven/Counters/", null, null, start, GetPageSize(Database.Configuration.MaxPageSize), CancellationToken.None, ref nextPageStart);
37            var counterStoragesNames = counterStorages
38                                    .Select(x => x.Value<RavenJObject>("@metadata").Value<string>("@id").Replace("Raven/Counters/", string.Empty))
39                                    .ToArray();
40            return counterStoragesNames;
41        }
42    }
43}