Page 27 - MSDN Magazine, May 2018
P. 27

be called from the UI thread so it can successfully prompt the user. Once the user has granted or denied permission to the app, any sub- sequent calls will automatically return the user’s preference. For this app, this permission will be added to the session discovery because it’s called first in the workflow.
Note that all of the Remote System APIs can be found in the Windows.System.RemoteSystem namespace.
Before the app can access any of the Remote Systems APIs, it must first obtain permission from the user.
The first method to add to the RemoteSessionManager class is the CreateSession method. Because there are several results that can be returned from this method, I’ll wrap those up in a new enum— SessionCreationResult. SessionCreationResult has four possible values: success and three different failures. A session can fail to create because the user didn’t grant access to the app; the app currently has too many sessions running; or a system error failed to create the session:
public enum SessionCreationResult {
Success, PermissionError, TooManySessions, Failure
}
Remote sessions are managed by a RemoteSystemSession- Controller. When creating a new RemoteSystemSessionController instance, you must pass in a name that will be displayed to devices attempting to join the session.
Once the controller is requested, a session can be started by calling the CreateSession method. This method returns a Remote- SystemSessionCreationResult containing a status and the new instance of the session if it was successful. The RemoteSessionManager will store the new controller and session in private variables.
Figure 5 MainPage.xaml Codebehind
public sealed partial class MainPage : Page {
public MainPage() {
this.InitializeComponent(); ViewModel.SessionConnected += OnSessionConnected; ViewModel.ErrorConnecting += OnErrorConnecting;
}
private async void OnErrorConnecting(object sender, SessionCreationResult e) {
var dialog = new MessageDialog("Error connecting to a session");
await dialog.ShowAsync(); }
private void OnSessionConnected(object sender, EventArgs e) {
Frame.Navigate(typeof(MessagePage)); }
public MainViewModel ViewModel { get; } = new MainViewModel(); }
msdnmagazine.com
®
Instantly Search Terabytes
dtSearch’s document filters support: • popular file types
• emails with multilevel attachments • a wide variety of databases
• web data
Over 25 search options including:
• efficient multithreaded search •
• forensics options like credit card search
• SDKs for Windows, UWP, Linux, Mac, iOS in beta, Android in beta
• FAQs on faceted search, granular data classification, Azure and more
Visit dtSearch.com for
• hundreds of reviews and case studies
• fully-functional enterprise and developer evaluations
The Smart Choice for Text Retrieval® since 1991
easy
multicolor
hit-
highlighting
Developers:
• APIs for .NET, C++ and Java; ask about new cross-platform .NET Standard SDK with Xamarin and .NET Core
dtSearch.com 1-800-IT-FINDS


































































































   25   26   27   28   29