public Discovery(TransportProxy proxy) { _proxy = proxy; }
public Authentication(TransportProxy proxy) { _proxy = proxy; }
public Events(TransportProxy proxy, Uri uri) { _proxy = proxy; EventsUri = uri; }
static void Main(string[] args) { _proxy = new TransportProxy(new SimpleTransport()); _discovery = new Discovery(_proxy); _authentication = new Authentication(_proxy); System.Console.WriteLine("Enter discovery domain"); var discoveryDomain = System.Console.ReadLine(); System.Console.WriteLine("Enter username"); var username = System.Console.ReadLine(); System.Console.WriteLine("Enter password"); var password = System.Console.ReadLine(); System.Console.WriteLine("Starting discovery..."); var discoveryTask = _discovery.Start(!string.IsNullOrWhiteSpace(discoveryDomain) ? discoveryDomain : username); discoveryTask.Wait(); var discoveryUri = new Uri(discoveryTask.Result.Links.User.Href); System.Console.WriteLine("Starting authentication"); try { var authenticationTask = _authentication.Start(discoveryUri); authenticationTask.Wait(); } catch (AggregateException ex) { if (ex != null && ex.InnerException.GetType() == typeof(AuthenticationException)) { var challenge = (ex.InnerException as AuthenticationException).Challenge; var authTokenTask = _authentication.GetAuthToken(challenge.MsRtcOAuth, new Credentials { GrantType = Constants.Password, Username = username, Password = password }); authTokenTask.Wait(); var rootTask = _authentication.Start(discoveryUri, authTokenTask.Result); rootTask.Wait(); if (rootTask.Result != null) { System.Console.WriteLine("Creating Application"); var applications = new Application { Culture = "en-US", EndpointId = Guid.NewGuid().ToString(), UserAgent = "tester" }; var response = _proxy.ExecuteRequest(new Request { Uri = new Uri(rootTask.Result.Links.Applications.Href), Method = HttpMethod.Post, Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }, Data = applications.ToBytes() }); if (response != null) { applications = response.Data.FromBytes<Application>(); if (applications != null) { var makeMeAvailable = new MakeMeAvailable { SupportedModalities = new List<string> { "Messaging" } }; response = _proxy.ExecuteRequest(new Request { Uri = new Uri(applications.Embedded.Me.Links.MakeMeAvailable.Href, UriKind.Relative), Method = HttpMethod.Post, Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }, Data = makeMeAvailable.ToBytes() }); if (response != null) { var events = new Events(_proxy, new Uri(applications.Links.Events.Href, UriKind.Relative)); events.OnEventReceived += OnEventReceived; events.Start(); } } } } } } System.Console.ReadLine(); }