-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
89 lines (76 loc) · 3.27 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
namespace Microsoft.Azure.CosmosDB.Aggregations
{
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Threading.Tasks;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.CosmosDB.Aggregations.DataGenerator;
using Microsoft.Azure.CosmosDB.Aggregations.ChangeFeed;
class Program
{
public static void Main(string[] args)
{
DocumentClient documentClient = CreateDocumentClient();
// List of 3 tasks - (1) Data Generator/Loader, (2) Aggregation Rules Generator, (3) Change Feed Processor to execute aggregations
var tasks = new List<Task>();
bool isGenerateAggregationRules = bool.Parse(ConfigurationManager.AppSettings["GenerateAggregationRules"]);
if (isGenerateAggregationRules)
{
IDataGenerator aggregationRuleGenerator = new AggregationRuleGenerator(documentClient);
tasks.Add(Task.Factory.StartNew(() =>
{
aggregationRuleGenerator.GenerateSampleData().Wait();
}));
}
Task.WaitAll(tasks.ToArray());
tasks = new List<Task>();
bool isGenerateSampleData = bool.Parse(ConfigurationManager.AppSettings["GenerateSampleData"]);
if (isGenerateSampleData)
{
IDataGenerator dataGenerator = new EmployeeSampleDataGenerator(documentClient);
tasks.Add(Task.Factory.StartNew(() =>
{
dataGenerator.GenerateSampleData().Wait();
}));
}
bool isExecuteChangeFeed = bool.Parse(ConfigurationManager.AppSettings["ExecuteChangeFeedProcessor"]);
if (isExecuteChangeFeed)
{
ChangeFeedExecutor changeFeedExecutor = new ChangeFeedExecutor(documentClient, "New Host");
tasks.Add(Task.Factory.StartNew(() =>
{
changeFeedExecutor.ExecuteChangeFeedProcessor().Wait();
}));
}
Task.WaitAll(tasks.ToArray());
Console.WriteLine("Completed!");
Console.ReadLine();
}
/// <summary>
/// Creates an instance of the DocumentClient to interact with the Azure Cosmos DB service
/// </summary>
/// <returns></returns>
private static DocumentClient CreateDocumentClient()
{
ConnectionPolicy ConnectionPolicy = new ConnectionPolicy
{
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp
};
DocumentClient documentClient = null;
try
{
string cosmosDBEndpointUri = ConfigurationManager.AppSettings["CosmosDBEndpointUri"];
string accountKey = ConfigurationManager.AppSettings["CosmosDBAuthKey"];
documentClient = new DocumentClient(new Uri(cosmosDBEndpointUri), accountKey, ConnectionPolicy);
}
catch (Exception ex)
{
Console.WriteLine("Exception while creating DocumentClient. Original exception message was: {0}", ex.Message);
}
return documentClient;
}
}
}