1: using System;
2: using System.Net;
3: using InfiniTec.Exchange.Notifications;
4:
5: namespace ExchangeNotificationTestClient
6: {
7: internal class Program
8: {
9: private static void Main()
10: {
11: // Ignore any certificate errors
12: ServicePointManager.ServerCertificateValidationCallback +=
13: (sender, certificate, chain, sslPolicyErrors) => true;
14:
15: // Setup the adapter which will be used to call into the Exchange WebService
16: var adapter = new ExchangeWebServicesAdapter(
17: new Uri("https://casserver/ews/exchange.asmx"),
18: new NetworkCredential("administrator", "password", "contoso"));
19:
20: // Create a new subscription collection to manage all the subscriptions
21: var subscriptionCollection = new SubscriptionCollection(adapter);
22:
23: // Setup a listener that listens on port 80 on the local computer
24: using (var listener = new PushNotificationListener())
25: {
26: // Register for a NewMail notification on the inbox of the administrator
27: subscriptionCollection.Add(
28: new[] {new FolderReference(WellKnownFolderId.Inbox)},
29: EventTypes.NewMail);
30: Console.Out.WriteLine("Starting Notification Service...");
31: listener.Start();
32:
33: Console.Out.WriteLine("Creating subscription");
34:
35: foreach (var subscription in subscriptionCollection)
36: {
37: // Write a line to the console for each new mail received
38: subscription.NewMail += (sender, e) =>
39: Console.Out.WriteLine(string.Format("{0}: New Mail arrived in your inbox", e.Timestamp));
40: subscription.Start(listener);
41: }
42:
43: Console.Out.WriteLine("Waiting for notifications... Hit [Enter] to quit...");
44:
45: Console.ReadLine();
46: }
47: }
48: }
49: }