@@ -21,8 +21,8 @@ namespace ChangeFeedMigrationSample
21
21
using Microsoft . Azure . Documents . Client ;
22
22
23
23
/// ------------------------------------------------------------------------------------------------
24
- /// This sample demonstrates using change processor library to read changes from source collection
25
- /// to destination collection
24
+ /// <summary> This sample demonstrates using change processor library to read changes from source collection
25
+ /// to destination collection </summary>
26
26
/// ------------------------------------------------------------------------------------------------
27
27
public class Program
28
28
{
@@ -50,55 +50,83 @@ public class Program
50
50
private string destCollectionName = ConfigurationManager . AppSettings [ "destCollectionName" ] ;
51
51
private int destThroughput = int . Parse ( ConfigurationManager . AppSettings [ "destThroughput" ] ) ;
52
52
53
+ /// <summary>
54
+ /// Main program function; called when program runs
55
+ /// </summary>
56
+ /// <param name="args">Command line parameters (not used)</param>
53
57
public static void Main ( string [ ] args )
54
58
{
55
59
Console . WriteLine ( "Change Feed Migration Sample" ) ;
56
60
Program newApp = new Program ( ) ;
61
+ newApp . MainAsync ( ) . Wait ( ) ;
62
+ }
57
63
58
- // create collections
59
- newApp . CreateCollectionAsync (
60
- newApp . monitoredUri ,
61
- newApp . monitoredSecretKey ,
62
- newApp . monitoredDbName ,
63
- newApp . monitoredCollectionName ,
64
- newApp . monitoredThroughput ) . Wait ( ) ;
65
-
66
- newApp . CreateCollectionAsync (
67
- newApp . leaseUri ,
68
- newApp . leaseSecretKey ,
69
- newApp . leaseDbName ,
70
- newApp . leaseCollectionName ,
71
- newApp . leaseThroughput ) . Wait ( ) ;
72
-
73
- newApp . CreateCollectionAsync (
74
- newApp . destUri ,
75
- newApp . destSecretKey ,
76
- newApp . destDbName ,
77
- newApp . destCollectionName ,
78
- newApp . destThroughput ) . Wait ( ) ;
79
-
80
- // run change feed processor
81
- newApp . RunChangeFeedHostAsync ( ) . Wait ( ) ;
64
+ /// <summary>
65
+ /// Main Async function; checks for or creates monitored/lease collections and runs
66
+ /// Change Feed Host (RunChangeFeedHostAsync)
67
+ /// </summary>
68
+ /// <returns>A Task to allow asynchronous execution</returns>
69
+ public async Task MainAsync ( )
70
+ {
71
+ await this . CreateCollectionIfNotExistsAsync (
72
+ this . monitoredUri ,
73
+ this . monitoredSecretKey ,
74
+ this . monitoredDbName ,
75
+ this . monitoredCollectionName ,
76
+ this . monitoredThroughput ) ;
77
+
78
+ await this . CreateCollectionIfNotExistsAsync (
79
+ this . leaseUri ,
80
+ this . leaseSecretKey ,
81
+ this . leaseDbName ,
82
+ this . leaseCollectionName ,
83
+ this . leaseThroughput ) ;
84
+
85
+ await this . CreateCollectionIfNotExistsAsync (
86
+ this . destUri ,
87
+ this . destSecretKey ,
88
+ this . destDbName ,
89
+ this . destCollectionName ,
90
+ this . destThroughput ) ;
91
+
92
+ await this . RunChangeFeedHostAsync ( ) ;
82
93
}
83
94
84
- public async Task CreateCollectionAsync ( string newUri , string secretKey , string dbName , string collectionName , int throughput )
95
+ /// <summary>
96
+ /// Checks whether collections exists. Creates new collection if collection does not exist
97
+ /// WARNING: CreateCollectionIfNotExistsAsync will create a new
98
+ /// with reserved throughput which has pricing implications. For details
99
+ /// visit: https://azure.microsoft.com/en-us/pricing/details/cosmos-db/
100
+ /// </summary>
101
+ /// <param name="endPointUri">End point URI for account </param>
102
+ /// <param name="secretKey">Primary key to access the account </param>
103
+ /// <param name="databaseName">Name of database </param>
104
+ /// <param name="collectionName">Name of collection</param>
105
+ /// <param name="throughput">Amount of throughput to provision</param>
106
+ /// <returns>A Task to allow asynchronous execution</returns>
107
+ public async Task CreateCollectionIfNotExistsAsync ( string endPointUri , string secretKey , string databaseName , string collectionName , int throughput )
85
108
{
86
109
// connecting client
87
- using ( DocumentClient client = new DocumentClient ( new Uri ( newUri ) , secretKey ) )
110
+ using ( DocumentClient client = new DocumentClient ( new Uri ( endPointUri ) , secretKey ) )
88
111
{
89
- await client . CreateDatabaseIfNotExistsAsync ( new Database { Id = dbName } ) ;
112
+ await client . CreateDatabaseIfNotExistsAsync ( new Database { Id = databaseName } ) ;
90
113
91
- // create monitor collection if it does not exist
114
+ // create collection if it does not exist
92
115
// WARNING: CreateDocumentCollectionIfNotExistsAsync will create a new
93
- // with reserved through pul which has pricing implications. For details
116
+ // with reserved throughput which has pricing implications. For details
94
117
// visit: https://azure.microsoft.com/en-us/pricing/details/cosmos-db/
95
118
await client . CreateDocumentCollectionIfNotExistsAsync (
96
- UriFactory . CreateDatabaseUri ( dbName ) ,
119
+ UriFactory . CreateDatabaseUri ( databaseName ) ,
97
120
new DocumentCollection { Id = collectionName } ,
98
121
new RequestOptions { OfferThroughput = throughput } ) ;
99
122
}
100
123
}
101
124
125
+ /// <summary>
126
+ /// Registers change feed observer to update changes read on change feed to destination
127
+ /// collection. Deregisters change feed observer and closes process when enter key is pressed
128
+ /// </summary>
129
+ /// <returns>A Task to allow asynchronous execution</returns>
102
130
public async Task RunChangeFeedHostAsync ( )
103
131
{
104
132
string hostName = Guid . NewGuid ( ) . ToString ( ) ;
@@ -145,7 +173,7 @@ public async Task RunChangeFeedHostAsync()
145
173
146
174
using ( DocumentClient destClient = new DocumentClient ( destCollInfo . Uri , destCollInfo . MasterKey ) )
147
175
{
148
- DocumentFeedObserverFactory docObserverFactory = new DocumentFeedObserverFactory ( destCollInfo , destClient ) ;
176
+ DocumentFeedObserverFactory docObserverFactory = new DocumentFeedObserverFactory ( destClient , destCollInfo ) ;
149
177
150
178
ChangeFeedEventHost host = new ChangeFeedEventHost ( hostName , documentCollectionLocation , leaseCollectionLocation , feedOptions , feedHostOptions ) ;
151
179
0 commit comments