Example #1
0
        protected async Task SetSourceBearerToken()
        {
            var response = await SourceClient.PostAsJsonAsync("v1/login",
                                                              new EmailPasswordApiModel { Email = "*****@*****.**", Password = "" });

            response.EnsureSuccessStatusCode();
            var content = await response.Content.ReadAsAsync <LoginResponseDto>();

            SourceClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", content.AccessToken);
        }
Example #2
0
        /// <summary>
        /// ThreadPool callback to process each partition
        /// </summary>
        /// <param name="pkRange">current PartitionKeyRange</param>
        public void CallbackProcessEachPartition(string pkRangeId)
        {
            string continuation = null;

            Checkpoints.TryGetValue(pkRangeId, out continuation);

            IDocumentQuery <Document> query = SourceClient.CreateDocumentChangeFeedQuery(
                Constants.SourceCollectionUri,
                new ChangeFeedOptions
            {
                PartitionKeyRangeId = pkRangeId,
                StartFromBeginning  = true,
                RequestContinuation = continuation,
                MaxItemCount        = -1
            });

            int numOfDocsUploaded = 0;

            while (query.HasMoreResults)
            {
                FeedResponse <Document> readChangesResponse = query.ExecuteNextAsync <Document>().Result;

                List <Task <bool> > taskList = new List <Task <bool> >();

                numOfDocsUploaded = 0;
                foreach (Document changedDocument in readChangesResponse)
                {
                    Task <bool> pTask = UploadToDestCollectionAsync(changedDocument);
                    taskList.Add(pTask);

                    // Wait for fixed number of tasks before creating new tasks
                    if (taskList.Count == 100)
                    {
                        Task.WaitAll(taskList.ToArray());

                        // Console.WriteLine("ThreadId: {0} Clearing the 100 tasks", Thread.CurrentThread.ManagedThreadId);
                        Console.Write(".");

                        taskList.Clear();
                    }

                    // Console.WriteLine("\t Debug: Read document {0} from the change feed.", changedDocument.ToString());

                    numOfDocsUploaded++;
                }

                Task.WaitAll(taskList.ToArray());

                Console.WriteLine("ThreadId: {0} Number of documents uploaded: {1}",
                                  Thread.CurrentThread.ManagedThreadId,
                                  numOfDocsUploaded);

                Checkpoints[pkRangeId] = readChangesResponse.ResponseContinuation;
            }

            // If this is the last thread to complete, set the event so that the main thread can continue
            if (Interlocked.Decrement(ref NumOfPartitions) == 0)
            {
                resetEvent.Set();
            }
        }
Example #3
0
 private void DestinationClient_DataReceived(object sender, DataReceivedEventArgs e)
 {
     SourceClient.Send(e.Data);
 }