Exemplo n.º 1
0
        static void Main(string[] args)
        {
            ConnectionPolicy policy = new ConnectionPolicy()
            {
                ConnectionMode = ConnectionMode.Direct,
                ConnectionProtocol = Protocol.Tcp
            };
            Uri endPoint = new Uri(EndpointUrl);
            using (DocumentClient client = new DocumentClient(endPoint, AuthKey, policy))
            {
                Database database =
                    client.CreateDatabaseQuery().Where(db => db.Id == DatabasebId).AsEnumerable().First();
                DocumentCollection collection =
                    client.CreateDocumentCollectionQuery(database.SelfLink)
                        .Where(c => c.Id == CollectionId)
                        .AsEnumerable()
                        .First();

                IEnumerable<DataClass> dataSet = GetDataObjects(100);

                Task<ResourceResponse<Document>>[] documentTasks =
                    dataSet.Select(d => client.CreateDocumentAsync(collection.DocumentsLink, d)).ToArray();

                Task.WaitAll(documentTasks);

                Document[] docs = documentTasks.Select(t => t.Result.Resource).ToArray();

                Document doc = docs.First();

                Task<ResourceResponse<Attachment>>[] attachmentTasks =
                    docs.Select(d => client.CreateAttachmentAsync(doc.AttachmentsLink, GetStream(1024))).ToArray();

                Task.WaitAll(attachmentTasks);

                DataClass[] data =
                    client.CreateDocumentQuery<DataClass>(collection.DocumentsLink).Select(d => d).ToArray();
                Attachment[] attachments = client.CreateAttachmentQuery(doc.AttachmentsLink).ToArray();

                string sql = "SELECT c.Name FROM c Where c.ObjectKey < 30 AND c.ObjectKey > 20";
                dynamic[] dataArray = client.CreateDocumentQuery(collection.DocumentsLink, sql).ToArray();
            }
        }