コード例 #1
0
        private async Task Databasecall()    ///database list
        {
            this.client = new DocumentClient(new Uri(EndpointUrl), PrimaryKey);

            string          continuation = string.Empty;
            List <Database> databases    = new List <Database>();

            do
            {
                // Read the feed 10 items at a time until there are no more items to read
                FeedResponse <Database> response = await client.ReadDatabaseFeedAsync(new FeedOptions
                {
                    MaxItemCount        = -1,
                    RequestContinuation = continuation
                });

                databases.AddRange(response.AsEnumerable <Database>());

                // Get the continuation so that we know when to stop.
                continuation = response.ResponseContinuation;
            } while (!string.IsNullOrEmpty(continuation));
            comboBox1.DataSource    = databases;
            comboBox1.DisplayMember = "id";
            DatabaseId = comboBox1.GetItemText(comboBox1.SelectedItem);;
            Colecall();
        }
コード例 #2
0
        private async Task Colecall()       //colletion list!
        {
            this.client = new DocumentClient(new Uri(EndpointUrl), PrimaryKey);

            //***
            Database database = client.CreateDatabaseQuery().Where(db => db.Id == DatabaseId).AsEnumerable().FirstOrDefault();

            var collections = client.CreateDocumentCollectionQuery(database.SelfLink).ToArray();

            //**
            string          continuation = string.Empty;
            List <Database> databases    = new List <Database>();

            do
            {
                // Read the feed 10 items at a time until there are no more items to read
                FeedResponse <Database> response = await client.ReadDatabaseFeedAsync(new FeedOptions
                {
                    MaxItemCount        = -1,
                    RequestContinuation = continuation
                });

                collections = client.CreateDocumentCollectionQuery(database.SelfLink).ToArray();
                databases.AddRange(response.AsEnumerable <Database>());


                // Get the continuation so that we know when to stop.
                continuation = response.ResponseContinuation;
            } while (!string.IsNullOrEmpty(continuation));

            comboBox2.DataSource    = collections;
            comboBox2.DisplayMember = "id";
            CollectionID            = comboBox2.GetItemText(this.comboBox2.SelectedItem);
            Doccall();
        }
コード例 #3
0
        private Document GetRandomDocumentFromPartition(Uri documentCollectionUri, PartitionKeyRange pkRange)
        {
            FeedResponse <Document> response = Client.CreateDocumentChangeFeedQuery(documentCollectionUri,
                                                                                    new ChangeFeedOptions {
                StartFromBeginning = true, PartitionKeyRangeId = pkRange.Id, MaxItemCount = 1
            }).ExecuteNextAsync <Document>().Result;
            Document sampleDocument = response.AsEnumerable().FirstOrDefault();

            return(sampleDocument);
        }
コード例 #4
0
        /// <inheritdoc/>
        public async Task <IEnumerable <T> > GetAsync <T>(DocumentQueryModel query)
            where T : BaseEntity
        {
            FeedOptions feedOptions = new FeedOptions
            {
                MaxItemCount = query.Top ?? int.MaxValue
            };

            IDocumentQuery <T> documentQuery = _documentClient
                                               .CreateDocumentQuery <T>(_collectionUri, feedOptions)
                                               .BuildQuery(query)
                                               .AsDocumentQuery();

            FeedResponse <T> response = await documentQuery.ExecuteNextAsync <T>();

            return(response.AsEnumerable());
        }
コード例 #5
0
        public static T GetDocument <T>(ICollectionContext context, String Id = null, object partitionKeyValue = null) where T : Resource
        {
            var request = context.Client.CreateDocumentQuery <T>(context.CollectionUri
                                                                 , String.Format("SELECT * FROM c WHERE c.id = \"{0}\"", Id)
                                                                 , new FeedOptions()
            {
                PartitionKey = new PartitionKey(partitionKeyValue)
            }
                                                                 )
                          .AsDocumentQuery();

            FeedResponse <T> response = request.ExecuteNextAsync <T>().Result;

            Debug.WriteLine(String.Format("Read response request charge: {0}", response.RequestCharge));

            return(response.AsEnumerable().FirstOrDefault());
        }
        public async Task <List <MigrationConfig> > GetActiveMigrationsAsync()
        {
            try
            {
                FeedResponse <MigrationConfig> response = await this.container
                                                          .GetItemQueryIterator <MigrationConfig>("select * from c where NOT c.completed")
                                                          .ReadNextAsync()
                                                          .ConfigureAwait(false);

                return(response.AsEnumerable <MigrationConfig>().ToList());
            }
            catch (Exception error)
            {
                TelemetryHelper.Singleton.LogError(
                    "MigrationConfigDal.GetActiveMigrationsAsync failed: {0}",
                    error);

                throw;
            }
        }
コード例 #7
0
        public async Task RunAsync()
        {
            await Task.Yield();

            using (CosmosClient client =
                       KeyVaultHelper.Singleton.CreateCosmosClientFromKeyVault(
                           EnvironmentConfig.Singleton.MigrationMetadataCosmosAccountName,
                           MigrationClientUserAgentPrefix,
                           useBulk: false,
                           retryOn429Forever: true))
            {
                Database db = await client.CreateDatabaseIfNotExistsAsync(
                    EnvironmentConfig.Singleton.MigrationMetadataDatabaseName);

                Container container = await db.CreateContainerIfNotExistsAsync(
                    new ContainerProperties(EnvironmentConfig.Singleton.MigrationMetadataContainerName, "/id"));

                while (true)
                {
                    FeedResponse <MigrationConfig> response = await container
                                                              .GetItemQueryIterator <MigrationConfig>("select * from c where NOT c.completed")
                                                              .ReadNextAsync()
                                                              .ConfigureAwait(false);

                    List <MigrationConfig> configDocs = response.AsEnumerable <MigrationConfig>().ToList();

                    if (configDocs.Count == 0)
                    {
                        TelemetryHelper.Singleton.LogInfo("No job for process: {0}", Process.GetCurrentProcess().Id);
                        await Task.Delay(SleepTime);

                        continue;
                    }

                    foreach (MigrationConfig config in configDocs)
                    {
                        if (!config.Completed &&
                            !this.changeFeedProcessorHosts.ContainsKey(config.ProcessorName))
                        {
                            TelemetryHelper.Singleton.LogInfo(
                                "Starting new changefeed processor '{0}' for uncompleted migration",
                                config.ProcessorName);

                            ChangeFeedProcessorHost host = new ChangeFeedProcessorHost(config);
                            await host.StartAsync().ConfigureAwait(false);

                            this.changeFeedProcessorHosts.Add(
                                config.ProcessorName,
                                host);
                        }
                    }

                    foreach (string key in this.changeFeedProcessorHosts.Keys.ToArray())
                    {
                        if (!configDocs.Exists((c) => !c.Completed && c.ProcessorName == key))
                        {
                            TelemetryHelper.Singleton.LogInfo(
                                "Closing changefeed processor '{0} because migration has been completed",
                                key);

                            // Migration has been completed for this processor
                            await this.changeFeedProcessorHosts[key].CloseAsync().ConfigureAwait(false);
                            this.changeFeedProcessorHosts.Remove(key);
                        }
                    }

                    await Task.Delay(SleepTime);
                }
            }
        }