Beispiel #1
0
        private static void CreateDocumentCollection(DocumentClient documentClient)
        {
            // Create the database if it doesn't exist.

            try
            {
                documentClient.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName))
                    .GetAwaiter()
                    .GetResult();
            }
            catch (DocumentClientException de)
            {
                // If the document collection does not exist, create it
                if (de.StatusCode == HttpStatusCode.NotFound)
                {
                    var collectionInfo = new DocumentCollection
                    {
                        Id = CollectionName,
                        IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.String) { Precision = -1 })
                    };

                    documentClient.CreateDocumentCollectionAsync(
                        UriFactory.CreateDatabaseUri(DatabaseName),
                        collectionInfo,
                        new RequestOptions { OfferThroughput = 400 }).GetAwaiter().GetResult();
                }
                else
                {
                    throw;
                }
            }
        }
        static void Main(string[] args)
        {
            DocumentClient client = new DocumentClient(new Uri(endpointUrl), authorizationKey);
            DocumentCollection collection = client.ReadDocumentCollectionAsync(documentCollectionLink).Result;

            Point point = new Point(-87.636836, 41.884615);
            int minDistance = 100;
            int maxDistance = 5000;
            int maxPoints = 500;

            IEnumerable<dynamic> points = SpatialHelper.Near(client, collection.DocumentsLink, propertyName, point, minDistance, maxDistance, maxPoints);

            long count = 0;
            foreach(dynamic p in points)
            {
                Console.WriteLine(@"Point ID: {0}", p.id);
                ++count;
            }

            Console.WriteLine(@"Found {0} points", count);
        }
Beispiel #3
0
        private static async Task<bool> CheckSize(DocumentCollection dc, DocumentClient client)
        {
            double backRate = (double) 2/100000;
            var res = await client.ReadDocumentCollectionAsync(dc.SelfLink);
            var size = res.CollectionSizeUsage;
            var totalSize = res.CollectionSizeQuota;

            return size > totalSize*backRate;
        }
Beispiel #4
0
        private static async Task UpdateDc(DocumentCollection oldDc, DocumentClient client,
            Database database, DocumentCollection origin)
        {
            var res = await client.ReadDocumentCollectionAsync(oldDc.SelfLink);
            var size = res.CollectionSizeUsage;
            var totalSize = res.CollectionSizeQuota;
            if (size > totalSize*2/100000)
            {
                var ds =
                    from d in client.CreateDocumentQuery<PostMessage>(oldDc.DocumentsLink)
                    where d.Type == "Post"
                    select d;

                Hashtable hs = new Hashtable();
                var n = ds.ToList().Count;
                foreach (var d in ds)
                {
                    if (!hs.ContainsKey(d.Path.District))
                    {
                        hs.Add(d.Path.District, 1);
                    }
                    else
                    {
                        hs[d.Path.District] = (int) hs[d.Path.District] + 1;
                    }
                }
                Hashtable newList = new Hashtable();
                Hashtable oldList = new Hashtable();

                foreach (DictionaryEntry h in hs)
                {
                    var c = 0;
                    foreach (DictionaryEntry hh in newList)
                    {
                        c = c + (int) hh.Value;
                    }
                    if (c < n*0.45 && (c + (int) h.Value < n*0.55))
                    {
                        newList.Add(h.Key, h.Value);
                    }
                    else
                    {
                        oldList.Add(h.Key, h.Value);
                    }
                }


                if (newList.Count > 0)
                {
                    //create new collection
                    /*var t = (long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
                  DocumentCollection newDc=await client.CreateDocumentCollectionAsync(database.CollectionsLink,
                                                        new DocumentCollection
                                                        {
                                                            Id = "LMSCollection"+t
                                                        });*/

                    //search collection
                    DocumentCollection newDc = client.CreateDocumentCollectionQuery(database.SelfLink)
                        .Where(c => c.Id == "LMSCollection1444075919174")
                        .AsEnumerable()
                        .FirstOrDefault();

                    await SaveDisList(newList, oldList, origin, oldDc, newDc, client);

                    await TransferDc(oldDc, newDc, client, database, newList);
                }
            }
        }