static void Main(string[] args) { var client = TeamHavenClient.CreateHttpClient(ApplicationName, ApplicationEmail, Username, Password, Account); var proxy = new TeamHavenClient(client); var monitor = new IntegrationEventMonitor { // Use the TeamHaven WebAPI to retrieve the information needed to access the Windows Azure queue GetQueueAccessInformation = () => proxy.GetEventsAuthorisation().Result, // This code processes a single IntegrationEvent and should return TRUE if the event // was successfully processed. ProcessEvent = (e) => ProcessIntegrationEvent(e), // This code should return TRUE until you want the monitoring loop to stop ContinueMonitoring = () => true, // This code handles errors thrown by the ProcessEvent delegate. It should return TRUE if // the failed message should be deleted from the queue. OnError = (ex, msg) => { Console.WriteLine(ex.Message); return(true); } }; // Start the monitoring loop monitor.MonitorQueue(); }
static void Main(string[] args) { var client = TeamHavenClient.CreateHttpClient(ApplicationName, ApplicationEmail, Username, Password, Account, useHttpForEasyDebugging: true, serverUrl: Server); var proxy = new TeamHavenClient(client); var pictureSaver = new PictureSavingCallProcessor(proxy); var monitor = new IntegrationEventMonitor { // Use the TeamHaven WebAPI to retrieve the information needed to access the Windows Azure queue GetQueueAccessInformation = () => { var task = proxy.GetEventsAuthorisation(); return(task.Result); }, // This code processes a single IntegrationEvent and should return TRUE if the event // was successfully processed. ProcessEvent = (e) => { if (e.Object.ObjectType == ObjectType.Call && e.EventType == IntegrationEventType.Answered) { var task = pictureSaver.Process(e); task.Wait(); return(task.Result); } return(true); }, // This code should return TRUE until you want the monitoring loop to stop ContinueMonitoring = () => true, // This code handles errors thrown by the ProcessEvent delegate. It should return TRUE if // the failed message should be deleted from the queue. OnError = (ex, msg) => { Console.WriteLine(ex.Message); // The message causing the error is not deleted so that you have a chance to investigate and // process it correctly. Make sure you never delete mesasges that you have not processed! // Consider moving failures into an Azure Queue of your own, or to some other persistent medium // so that you can clear them out of the main processing queue. return(false); } }; // Start the monitoring loop monitor.MonitorQueue(); }
static void Main(string[] args) { // Create an HttpClient instance and initialise it with TeamHaven specific defaults var httpClient = TeamHavenClient.CreateHttpClient(ApplicationName, ApplicationEmail, Username, Password, Account, useHttpForEasyDebugging: true); // Create a proxy that fetches data using the HttpClient we just created var proxy = new TeamHavenClient(httpClient); // Example: Use the proxy to call the Server Information API proxy.GetServerInfo().ContinueWith(x => { if (!x.IsFaulted) { Console.WriteLine("Server identifies itself as " + x.Result.Name); Console.WriteLine("Server's preferred base address is " + (x.Result.HttpsUrl ?? x.Result.HttpUrl)); } else { Console.WriteLine("/api/server failed: ", x.Exception.InnerException.Message); } }); // Example: Display some information about the authenticated user proxy.GetUser().ContinueWith(x => { if (!x.IsFaulted) { Console.WriteLine("Authorized as " + x.Result.DisplayName); } else { Console.WriteLine("/api/user failed: {0}", x.Exception.InnerException.Message); } }); Console.ReadKey(); }