public static ViewOptions GetOptions(this IPageableModel model) { var options = new ViewOptions(); options.Descending = model.Descending; options.StartKey.Add(model.StartKey); options.Skip = model.Skip; options.Stale = model.Stale; options.StartKeyDocId = model.StartKeyDocId; options.EndKeyDocId = model.EndKeyDocId; options.Limit = model.Limit.HasValue ? model.Limit : 10; return(options); }
private ViewResult <T> ProcessGenericResults <T>(string uri, ViewOptions options) { CouchRequest req = GetRequest(options, uri); CouchResponse resp = req.GetCouchResponse(); bool includeDocs = false; if (options != null) { includeDocs = options.IncludeDocs ?? false; } return(new ViewResult <T>(resp, req.GetRequest(), ObjectSerializer, includeDocs)); }
public IEnumerable<long> Produce(int freshnessInMinutes, int limit) { try { var options = new ViewOptions { Limit = limit }; options.EndKey.Add(freshnessInMinutes); return GetSummonerIds(options); } catch (Exception ex) { Log.Error("Error reading from the CouchDB index.", ex); return Enumerable.Empty<long>(); } }
private CouchRequest GetRequest(ViewOptions options, string uri) { if (options != null) { uri += options.ToString(); } CouchRequest request = GetRequest(uri, options == null ? null : options.Etag).Get().Json(); if (options.isAtKeysSizeLimit) { // Encode the keys parameter in the request body and turn it into a POST request. string keys = "{\"keys\": [" + String.Join(",", options.Keys.Select(k => k.ToRawString()).ToArray()) + "]}"; request.Post().Data(keys); } return(request); }
private void ScavengeByDate(int deleteBatchSize) { if (ConfigurationManager.AppSettings["MessageExpiryDays"] == null) return; var expiryDays = double.Parse(ConfigurationManager.AppSettings["MessageExpiryDays"]); var options = new ViewOptions(); options.StartKey.Add(MessageIdManager.Create(new DateTime(1970, 1, 1)).ToDocId()); options.EndKey.Add(MessageIdManager.Create(DateTime.UtcNow.AddDays(-expiryDays)).ToDocId()); options.Limit = deleteBatchSize; var db = new CouchClient(ConfigurationManager.AppSettings["HydraServer"], int.Parse(ConfigurationManager.AppSettings["Port"]), null, null, false, AuthenticationType.Basic). GetDatabase(ConfigurationManager.AppSettings["Database"]); var rows = db.GetAllDocuments(options).Rows; while (rows.Any()) { DeleteDocs(rows, db); rows = db.GetAllDocuments(options).Rows; } }
public Task<IEnumerable<long>> ProduceAsync(int freshnessInMinutes, int limit) { var source = new TaskCompletionSource<IEnumerable<long>>(); try { var options = new ViewOptions { Limit = limit }; options.EndKey.Add(freshnessInMinutes); source.TrySetResult(GetSummonerIds(options)); } catch (Exception ex) { Log.Error("Error reading from the CouchDB index.", ex); source.TrySetException(ex); } return source.Task; }
private ViewResult <T> ProcessGenericResults <T>(string uri, ViewOptions options) { CouchRequest req = GetRequest(options, uri); var resp = req.GetResponse(); if (resp.StatusCode == HttpStatusCode.BadRequest) { throw new CouchException(req.GetRequest(), resp, resp.GetResponseString() + "\n" + req.GetRequest().RequestUri); } bool includeDocs = false; if (options != null) { includeDocs = options.IncludeDocs ?? false; } return(new ViewResult <T>(resp, req.GetRequest(), ObjectSerializer, includeDocs)); }
private LoveSeat.ViewOptions ToLoveSeatOptions(CouchViewOptions odmViewOptions) { var opt = new LoveSeat.ViewOptions { Limit = odmViewOptions.Limit, IncludeDocs = odmViewOptions.IncludeDocs, Descending = odmViewOptions.Descending, Reduce = odmViewOptions.Reduce, Group = odmViewOptions.Group, Keys = odmViewOptions.Keys.Count == 0 ? null : odmViewOptions.Keys.Select(x => new KeyOptions(x)).ToArray() }; CopyKeys(odmViewOptions.Key, opt.Key); CopyKeys(odmViewOptions.StartKey, opt.StartKey); CopyKeys(odmViewOptions.EndKey, opt.EndKey); return(opt); }
public static IEnumerable<ImageAnnotation> GetAnnotations(string library) { List<ImageAnnotation> annotations = new List<ImageAnnotation>(); if (library != null) { CouchDatabase db = GetDatabase(library); var options = new ViewOptions(); options.IncludeDocs = true; var cannotations = db.View<CouchDbAnnotation>("all", options, "annotations"); foreach (CouchDbAnnotation ca in cannotations.Items) { BoundingBox bb = new BoundingBox(ca.left, ca.top, ca.width, ca.height); ImageAnnotation ia = new ImageAnnotation(bb, ca.data, ca.screenshotId); annotations.Add(ia); } } return annotations; }
public IListResult List(string listName, string viewName, ViewOptions options) { ThrowDesignDocException(); return(List(listName, viewName, options, defaultDesignDoc)); }
public static IEnumerable<string> GetAllImageIds(string library) { List<string> images = new List<string>(); if (library != null) { CouchDatabase db = GetDatabase(library); var options = new ViewOptions(); options.IncludeDocs = true; var imgDocs = db.View<JObject>("all", options, "screenshots"); foreach (JObject doc in imgDocs.Items) { images.Add(doc["_id"].Value<string>()); } } return images; }
public static ViewOptions GetOptions(this IPageableModel model) { var options = new ViewOptions(); options.Descending = model.Descending; options.StartKey.Add(model.StartKey); options.Skip = model.Skip; options.Stale = model.Stale; options.StartKeyDocId = model.StartKeyDocId; options.EndKeyDocId = model.EndKeyDocId; options.Limit = model.Limit.HasValue ? model.Limit : 10; return options; }
public ViewResult View(string viewName, ViewOptions options, string designDoc) { var uri = string.Format("{0}/_design/{1}/_view/{2}", databaseBaseUri, designDoc, viewName); return(ProcessResults(uri, options)); }
public ViewResult View(string viewName, ViewOptions options) { ThrowDesignDocException(); return(View(viewName, options, this.defaultDesignDoc)); }
public void Should_Get_Results_Quickly() { var db = client.GetDatabase("accounting"); var startTime = DateTime.Now; var options = new ViewOptions {Limit = 20}; var result= db.View<Company>("companies_by_name", options,"accounting"); foreach ( var item in result.Items) { Console.WriteLine(item.Name); } var endTime = DateTime.Now; Assert.Less((endTime - startTime).TotalMilliseconds, 80); }
private IEnumerable<long> GetSummonerIds(ViewOptions options) { return _summoners.View<long[]>("awaiting_refresh", options) .Items.Select(el => el[1]); }
public static List<ImageAnnotation> GetAllAnnotationsForImage(string library, string imageId, IBoundingBox region) { CouchClient client = new CouchClient(); CouchDatabase db = GetDatabase(library); var options = new ViewOptions(); options.Key.Add(imageId); options.IncludeDocs = true; var cannotations = db.View<CouchDbAnnotation>("by_screenshot", options, "annotations"); List<ImageAnnotation> annotations = new List<ImageAnnotation>(); foreach (CouchDbAnnotation ca in cannotations.Items) { BoundingBox bb = new BoundingBox(ca.left, ca.top, ca.width, ca.height); if (BoundingBox.Equals(region, bb)) { ImageAnnotation ia = new ImageAnnotation(bb, ca.data, ca.screenshotId); annotations.Add(ia); } } return annotations; }
public ViewResult GetAllDocuments(ViewOptions options) { var uri = databaseBaseUri + "/_all_docs"; return(ProcessResults(uri, options)); }
/// <summary> /// Allows you to specify options and uses the defaultDesignDoc Specified. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="viewName"></param> /// <param name="options"></param> /// <returns></returns> public ViewResult <T> View <T>(string viewName, ViewOptions options) { ThrowDesignDocException(); return(View <T>(viewName, options, defaultDesignDoc)); }
public ViewResult View(string viewName, ViewOptions options, string designDoc) { var uri = databaseBaseUri + "/_design/" + designDoc + "/_view/" + viewName; return(ProcessResults(uri, options)); }
private void ScavengeByNumber(int deleteBatchSize) { if (ConfigurationManager.AppSettings["MaxDocsInDatabase"] == null) return; var maxDocs = long.Parse(ConfigurationManager.AppSettings["MaxDocsInDatabase"]); var options = new ViewOptions(); options.StartKey.Add(MessageIdManager.Create(new DateTime(1970, 1, 1)).ToDocId()); options.EndKey.Add(MessageIdManager.Create(DateTime.UtcNow).ToDocId()); var db = new CouchClient(ConfigurationManager.AppSettings["HydraServer"], int.Parse(ConfigurationManager.AppSettings["Port"]), null, null, false, AuthenticationType.Basic). GetDatabase(ConfigurationManager.AppSettings["Database"]); // Getting the empty document returns general database info var deleteCount = db.GetDocument("").Value<long>("doc_count") - maxDocs; while (deleteCount > 0) { options.Limit = (int) Math.Min(deleteCount, deleteBatchSize); var rows = db.GetAllDocuments(options).Rows; if (!rows.Any()) break; DeleteDocs(rows, db); deleteCount -= deleteBatchSize; } }
public void Should_Populate_Items_When_IncludeDocs_Set_In_ViewOptions() { string designDoc = "test"; string viewName = "testView"; var settings = new JsonSerializerSettings(); var converters = new List<JsonConverter> { new IsoDateTimeConverter() }; settings.Converters = converters; settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); settings.NullValueHandling = NullValueHandling.Ignore; var doc = new { _id = "_design/" + designDoc, Language = "javascript", Views = new { TestView = new { Map = "function(doc) {\n if(doc.type == 'company') {\n emit(doc._id, null);\n }\n}" } } }; var db = client.GetDatabase(baseDatabase); db.CreateDocument(doc._id, JsonConvert.SerializeObject(doc, Formatting.Indented, settings)); var company = new Company(); company.Name = "foo"; db.CreateDocument(company); // Without IncludeDocs Assert.IsNull(db.View<Company>(viewName, designDoc).Items.ToList()[0]); // With IncludeDocs ViewOptions options = new ViewOptions { IncludeDocs = true }; Assert.AreEqual("foo", db.View<Company>(viewName, options, designDoc).Items.ToList()[0].Name); }
/// <summary> /// Gets the results of the view using any and all parameters /// </summary> /// <param name="viewName">The name of the view</param> /// <param name="options">Options such as startkey etc.</param> /// <param name="designDoc">The design doc on which the view resides</param> /// <returns></returns> public ViewResult <T> View <T>(string viewName, ViewOptions options, string designDoc) where T : class { var uri = string.Format("{0}/_design/{1}/_view/{2}", databaseBaseUri, designDoc, viewName); return(ProcessGenericResults <T>(uri, options)); }