Skip to content

Commit 8e5fe05

Browse files
committed
Addressed Comments
-Used App config for parameters -removed redundant references -ran styleCop -passed client into observerfactory as parameter
1 parent 1315b0e commit 8e5fe05

File tree

6 files changed

+191
-138
lines changed

6 files changed

+191
-138
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ Thumbs.db
5858
ehthumbs.db
5959

6060
# Folder config file
61-
Desktop.ini
61+
Desktop.ini
62+
samples/ChangeFeedMigrationTool/packages.config

samples/ChangeFeedMigrationTool/App.config

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
<startup>
44
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
55
</startup>
6+
<appSettings>
7+
<add key="monitoredUri" value="monitoredURI" />
8+
<add key="monitoredSecretKey" value="monitoredKey" />
9+
<add key="monitoredDbName" value="monitoredDbName" />
10+
<add key="monitoredCollectionName" value="monitoredColl" />
11+
<add key="monitoredThroughput" value="400" />
12+
<add key="leaseUri" value="leaseURI" />
13+
<add key="leaseSecretKey" value="leaseKey" />
14+
<add key="leaseDbName" value="leaseDbName" />
15+
<add key="leaseCollectionName" value="leaseColl" />
16+
<add key="leaseThroughput" value="400" />
17+
<add key="destUri" value="destURI" />
18+
<add key="destSecretKey" value="destKey" />
19+
<add key="destDbName" value="destDbName" />
20+
<add key="destCollectionName" value="destColl" />
21+
<add key="destThroughput" value="400" />
22+
</appSettings>
623
<runtime>
724
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
825
<dependentAssembly>

samples/ChangeFeedMigrationTool/ChangeFeedMigrationSample.csproj

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
<ErrorReport>prompt</ErrorReport>
5151
<WarningLevel>4</WarningLevel>
5252
</PropertyGroup>
53+
<PropertyGroup>
54+
<StartupObject>ChangeFeedMigrationSample.Program</StartupObject>
55+
</PropertyGroup>
5356
<ItemGroup>
5457
<Reference Include="Microsoft.Azure.Documents.ChangeFeedProcessor, Version=1.14.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5558
<HintPath>..\packages\Microsoft.Azure.DocumentDB.ChangeFeedProcessor.1.0.0\lib\net45\Microsoft.Azure.Documents.ChangeFeedProcessor.dll</HintPath>
@@ -64,13 +67,7 @@
6467
<Private>True</Private>
6568
</Reference>
6669
<Reference Include="System" />
67-
<Reference Include="System.Core" />
68-
<Reference Include="System.Xml.Linq" />
69-
<Reference Include="System.Data.DataSetExtensions" />
70-
<Reference Include="Microsoft.CSharp" />
71-
<Reference Include="System.Data" />
72-
<Reference Include="System.Net.Http" />
73-
<Reference Include="System.Xml" />
70+
<Reference Include="System.Configuration" />
7471
</ItemGroup>
7572
<ItemGroup>
7673
<Compile Include="DocumentFeedObserver.cs" />
@@ -82,9 +79,7 @@
8279
<None Include="App.config">
8380
<SubType>Designer</SubType>
8481
</None>
85-
<None Include="packages.config">
86-
<SubType>Designer</SubType>
87-
</None>
82+
<None Include="packages.config" />
8883
</ItemGroup>
8984
<ItemGroup>
9085
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
@@ -98,6 +93,9 @@
9893
<Install>false</Install>
9994
</BootstrapperPackage>
10095
</ItemGroup>
96+
<ItemGroup>
97+
<WCFMetadata Include="Service References\" />
98+
</ItemGroup>
10199
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
102100
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.14.1\build\Microsoft.Azure.DocumentDB.targets')" />
103101
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

samples/ChangeFeedMigrationTool/DocumentFeedObserver.cs

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,66 @@
1-
using Microsoft.Azure.Documents.ChangeFeedProcessor;
2-
using Microsoft.Azure.Documents;
3-
using Microsoft.Azure.Documents.Client;
4-
using System;
5-
using System.Collections.Generic;
6-
using System.Threading;
7-
using System.Threading.Tasks;
1+
//---------------------------------------------------------------------------------
2+
// <copyright file="DocumentFeedObserver.cs" company="Microsoft">
3+
// Microsoft (R) Azure SDK
4+
// Software Development Kit
5+
//
6+
// Copyright (c) Microsoft Corporation. All rights reserved.
7+
//
8+
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
9+
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
10+
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
11+
// </copyright>
12+
//---------------------------------------------------------------------------------
813

9-
class DocumentFeedObserver : IChangeFeedObserver
14+
namespace ChangeFeedMigrationSample
1015
{
11-
private static int s_totalDocs = 0;
12-
private DocumentCollectionInfo collectionInfo;
13-
private DocumentClient client;
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Threading;
19+
using System.Threading.Tasks;
20+
using Microsoft.Azure.Documents;
21+
using Microsoft.Azure.Documents.ChangeFeedProcessor;
22+
using Microsoft.Azure.Documents.Client;
1423

15-
public DocumentFeedObserver(DocumentClient client, DocumentCollectionInfo destCollInfo)
24+
/// <summary>
25+
/// Cass to create instance of document feed observer.
26+
/// </summary>
27+
public class DocumentFeedObserver : IChangeFeedObserver
1628
{
17-
this.client = client;
18-
this.collectionInfo = destCollInfo;
19-
}
29+
private static int s_totalDocs = 0;
30+
private DocumentCollectionInfo collectionInfo;
31+
private DocumentClient client;
32+
private Uri destinationCollectionUri;
2033

21-
public Task OpenAsync(ChangeFeedObserverContext context)
22-
{
23-
Console.WriteLine("Worker opened, {0}", context.PartitionKeyRangeId);
24-
return Task.CompletedTask;
25-
}
34+
public DocumentFeedObserver(DocumentClient client, DocumentCollectionInfo destCollInfo)
35+
{
36+
this.client = client;
37+
this.collectionInfo = destCollInfo;
38+
this.destinationCollectionUri = UriFactory.CreateDocumentCollectionUri(this.collectionInfo.DatabaseName, this.collectionInfo.CollectionName);
39+
}
2640

27-
public Task CloseAsync(ChangeFeedObserverContext context, ChangeFeedObserverCloseReason reason)
28-
{
29-
Console.WriteLine("Worker closed, {0}", context.PartitionKeyRangeId);
30-
Console.WriteLine("Reason for shutdown, {0}", reason);
31-
return Task.CompletedTask;
32-
}
41+
public Task OpenAsync(ChangeFeedObserverContext context)
42+
{
43+
Console.WriteLine("Worker opened, {0}", context.PartitionKeyRangeId);
44+
return Task.CompletedTask;
45+
}
3346

34-
public Task ProcessChangesAsync(ChangeFeedObserverContext context, IReadOnlyList<Document> docs)
35-
{
47+
public Task CloseAsync(ChangeFeedObserverContext context, ChangeFeedObserverCloseReason reason)
48+
{
49+
Console.WriteLine("Worker closed, {0}", context.PartitionKeyRangeId);
50+
Console.WriteLine("Reason for shutdown, {0}", reason);
51+
return Task.CompletedTask;
52+
}
3653

37-
Console.WriteLine("Change feed: total {0} doc(s)", Interlocked.Add(ref s_totalDocs, docs.Count));
38-
foreach (Document doc in docs)
54+
public Task ProcessChangesAsync(ChangeFeedObserverContext context, IReadOnlyList<Document> docs)
3955
{
40-
Console.WriteLine(doc.ToString());
41-
this.client.UpsertDocumentAsync(
42-
UriFactory.CreateDocumentCollectionUri(this.collectionInfo.DatabaseName, this.collectionInfo.CollectionName),
43-
doc);
56+
Console.WriteLine("Change feed: total {0} doc(s)", Interlocked.Add(ref s_totalDocs, docs.Count));
57+
foreach (Document doc in docs)
58+
{
59+
Console.WriteLine(doc.Id.ToString());
60+
this.client.UpsertDocumentAsync(this.destinationCollectionUri, doc);
61+
}
62+
63+
return Task.CompletedTask;
4464
}
45-
return Task.CompletedTask;
4665
}
4766
}
48-
Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1-
using Microsoft.Azure.Documents.ChangeFeedProcessor;
2-
using Microsoft.Azure.Documents;
3-
using Microsoft.Azure.Documents.Client;
1+
//---------------------------------------------------------------------------------
2+
// <copyright file="DocumentFeedObserverFactory.cs" company="Microsoft">
3+
// Microsoft (R) Azure SDK
4+
// Software Development Kit
5+
//
6+
// Copyright (c) Microsoft Corporation. All rights reserved.
7+
//
8+
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
9+
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
10+
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
11+
// </copyright>
12+
//---------------------------------------------------------------------------------
413

5-
public class DocumentFeedObserverFactory: IChangeFeedObserverFactory
14+
namespace ChangeFeedMigrationSample
615
{
7-
DocumentClient client;
8-
DocumentCollectionInfo collectionInfo;
16+
using Microsoft.Azure.Documents.ChangeFeedProcessor;
17+
using Microsoft.Azure.Documents.Client;
918

10-
public DocumentFeedObserverFactory(DocumentCollectionInfo destCollInfo)
19+
/// <summary>
20+
/// Factory class to create instance of document feed observer.
21+
/// </summary>
22+
public class DocumentFeedObserverFactory : IChangeFeedObserverFactory
1123
{
12-
this.collectionInfo = destCollInfo;
13-
this.client = new DocumentClient(destCollInfo.Uri, destCollInfo.MasterKey);
14-
this.client.CreateDatabaseIfNotExistsAsync(new Database { Id = destCollInfo.DatabaseName });
24+
private DocumentClient client;
25+
private DocumentCollectionInfo collectionInfo;
1526

16-
// create dest collection if it does not exist
17-
DocumentCollection destCollection = new DocumentCollection();
18-
destCollection.Id = destCollInfo.CollectionName;
27+
public DocumentFeedObserverFactory(DocumentCollectionInfo destCollInfo, DocumentClient destClient)
28+
{
29+
this.collectionInfo = destCollInfo;
30+
this.client = destClient;
31+
}
1932

20-
//destCollection.PartitionKey.Paths.Add("add partition key if applicable");
21-
this.client.CreateDocumentCollectionIfNotExistsAsync(
22-
UriFactory.CreateDatabaseUri(destCollInfo.DatabaseName),
23-
destCollection,
24-
new RequestOptions { OfferThroughput = 500 });
33+
public IChangeFeedObserver CreateObserver()
34+
{
35+
DocumentFeedObserver newObserver = new DocumentFeedObserver(this.client, this.collectionInfo);
36+
return newObserver;
37+
}
2538
}
26-
27-
~DocumentFeedObserverFactory()
28-
{
29-
if (this.client != null) this.client.Dispose();
30-
}
31-
32-
public IChangeFeedObserver CreateObserver()
33-
{
34-
DocumentFeedObserver newObserver = new DocumentFeedObserver(this.client, this.collectionInfo);
35-
return newObserver;
36-
}
37-
}
39+
}

0 commit comments

Comments
 (0)