Created
September 17, 2014 08:42
-
-
Save Tapanila/325bd3924714e5d9b9dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private async Task ConnectoToSignalR() | |
| { | |
| hubConnection = new HubConnection(App.MobileService.ApplicationUri.AbsoluteUri); | |
| hubConnection.Headers["x-zumo-application"] = App.MobileService.ApplicationKey; | |
| IHubProxy proxy = hubConnection.CreateHubProxy("ChatHub"); | |
| await hubConnection.Start(); | |
| hubConnection.StateChanged += hubConnection_StateChanged; | |
| proxy.On<string>("hello", async msg => | |
| { | |
| var callbackDialog = new MessageDialog(msg); | |
| callbackDialog.Commands.Add(new UICommand("OK")); | |
| await callbackDialog.ShowAsync(); | |
| }); | |
| proxy.On<CloudObject>("CloudHello", async msg => | |
| { | |
| var msgString = String.Format("name: {0} and owner {1} ", msg.Name, msg.Owner); | |
| var callbackDialog = new MessageDialog(msgString); | |
| callbackDialog.Commands.Add(new UICommand("OK")); | |
| CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => | |
| { | |
| await callbackDialog.ShowAsync(); | |
| }); | |
| }); | |
| } | |
| async void hubConnection_StateChanged(StateChange obj) | |
| { | |
| if (obj.NewState != ConnectionState.Connected) | |
| { | |
| var dialog = new MessageDialog("Not connected"); | |
| await dialog.ShowAsync(); | |
| } | |
| else | |
| { | |
| var dialog = new MessageDialog("Connected"); | |
| await dialog.ShowAsync(); | |
| } | |
| } |
Author
Tapanila
commented
Sep 17, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment