/// <summary> /// Invoked when the application is activated. /// This is the entry point for Device Autoplay when a device is attached to the PC. /// Other activation kinds (such as search and protocol activation) may also be handled here. /// /// This code was adapted from the "Removable storage sample" on MSDN. /// </summary> /// <param name="args">Details about the activation request.</param> protected override void OnActivated(IActivatedEventArgs args) { if (args.Kind == ActivationKind.Device) { // Load the UI if (Window.Current.Content == null) { Frame rootFrame = new Frame(); rootFrame.Navigate(typeof(MainPage)); // Place the frame in the current Window Window.Current.Content = rootFrame; } // Ensure the current window is active or else the app will freeze at the splash screen Window.Current.Activate(); // Launched from Autoplay for device, notify the app what device launched this app DeviceActivatedEventArgs deviceArgs = (DeviceActivatedEventArgs)args; if (deviceArgs != null) { // The DeviceInformationId is the same id found in a DeviceInformation object, so it can potentially be used // with UsbDevice.FromIdAsync() // The deviceArgs->Verb is the verb that is provided in the appxmanifest for this specific device MainPage.Current.NotifyUser( "The app was launched by device id: " + deviceArgs.DeviceInformationId + "\nVerb: " + deviceArgs.Verb, NotifyType.StatusMessage); } } }
/// <summary> /// Invoked when the application is activated. /// This is the entry point for Device Autoplay when a device is attached to the PC. /// Other activation kinds (such as search and protocol activation) may also be handled here. /// </summary> /// <param name="args">Details about the activation request.</param> protected override void OnActivated(IActivatedEventArgs args) { if (args.Kind == ActivationKind.Device) { Frame rootFrame = null; if (Window.Current.Content == null) { rootFrame = new Frame(); rootFrame.Navigate(typeof(MainPage)); Window.Current.Content = rootFrame; } else { rootFrame = Window.Current.Content as Frame; } Window.Current.Activate(); MainPage mainPage = (MainPage)rootFrame.Content as MainPage; // Launched from Autoplay for device, receiving the device information identifier. DeviceActivatedEventArgs deviceArgs = args as DeviceActivatedEventArgs; mainPage.AutoplayNonFileSystemDeviceId = deviceArgs.DeviceInformationId; // Clear any saved drive or file so we always use the latest connected device mainPage.AutoplayFileSystemDeviceFolder = null; mainPage.FileActivationFiles = null; // Select the Autoplay scenario mainPage.LoadAutoplayScenario(); } }
/// <summary /// This app is registered as a hanlder for WPD\IMageSourceAutoPlay event. /// When a user connects a WPD device (ie: Camera), OnNavigatedTo is called with DeviceInformationId /// that we can call FromIdAsync() and preselect the device. /// /// We also need to handle the situation where the client was terminated while an import operation was in flight. /// Import will continue and we attempt to reconnect back to the session. /// </summary> /// <param name="e">Details about the NavigationEventArgs</param> protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); rootPage = MainPage.Current; try { //An photo import session was in progress if (e.Parameter is PhotoImportOperation) { PhotoImportOperation op = e.Parameter as PhotoImportOperation; switch (op.Stage) { // file enumeration was running case PhotoImportStage.FindingItems: cts = new CancellationTokenSource(); rootPage.NotifyUser("Reconnected back to the file enumeration stage", NotifyType.StatusMessage); // Set up progress handler for existing file enumeration var findAllItemsProgress = new Progress <uint>((result) => { rootPage.NotifyUser(String.Format("Found {0} Files", result.ToString()), NotifyType.StatusMessage); }); // retrieve previous session this.session = op.Session; // get to the operation for the existing FindItemsAsync session this.itemsResult = await op.ContinueFindingItemsAsync.AsTask(cts.Token, findAllItemsProgress); // display the items we found in the previous session setIncrementalFileList(this.itemsResult); this.selectAllButton.IsEnabled = true; this.selectNoneButton.IsEnabled = true; this.selectNewButton.IsEnabled = true; this.importButton.IsEnabled = true; DisplayFindItemsResult(); cts = null; break; // Import was running case PhotoImportStage.ImportingItems: rootPage.NotifyUser("Reconnected back to the importing stage.", NotifyType.StatusMessage); setButtonState(false); cts = new CancellationTokenSource(); // Set up progress handler for the existing import session var importSelectedItemsProgress = new Progress <PhotoImportProgress>((result) => { progressBar.Value = result.ImportProgress; }); // retrieve the previous operation this.session = op.Session; // get the itemsResult that were found in the previous session this.itemsResult = await op.ContinueFindingItemsAsync.AsTask(); // hook up the ItemImported Handler to show progress this.itemsResult.ItemImported += async(s, a) => { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser(String.Format("Imported: {0}", a.ImportedItem.Name), NotifyType.StatusMessage); }); }; // Get the operation for the import operation that was in flight this.importedResult = await op.ContinueImportingItemsAsync.AsTask(cts.Token, importSelectedItemsProgress); DisplayImportedSummary(); this.findSourceButton.IsEnabled = true; this.deleteButton.IsEnabled = true; cts = null; break; // Delete operation is in progress case PhotoImportStage.DeletingImportedItemsFromSource: rootPage.NotifyUser("Reconnected to the deletion stage.", NotifyType.StatusMessage); this.findSourceButton.IsEnabled = false; this.deleteButton.IsEnabled = false; cts = new CancellationTokenSource(); var progress = new Progress <double>((result) => { this.progressBar.Value = result; }); // get the operation for the existing delete session this.deleteResult = await op.ContinueDeletingImportedItemsFromSourceAsync.AsTask(cts.Token, progress); DisplayDeletedResults(); if (!deleteResult.HasSucceeded) { rootPage.NotifyUser("Deletion did not succeeded or was cancelled.", NotifyType.StatusMessage); } this.findSourceButton.IsEnabled = true; // Set the CancellationTokenSource to null when the work is complete. cts = null; break; // Idle State. case PhotoImportStage.NotStarted: rootPage.NotifyUser("No import tasks was started.", NotifyType.StatusMessage); this.session = op.Session; break; default: break; } } // Activated by AutoPlay if (e.Parameter is DeviceActivatedEventArgs) { this.arguments = e.Parameter as DeviceActivatedEventArgs; bool importSupported = await PhotoImportManager.IsSupportedAsync(); this.sourceListBox.Items.Clear(); List <PhotoImportSource> source = new List <PhotoImportSource>(); // Create the source from a device Id source.Add(await PhotoImportSource.FromIdAsync(this.arguments.DeviceInformationId)); // bind and preselects source this.sourceListBox.ItemsSource = source; this.sourceListBox.SelectedIndex = 0; rootPage.NotifyUser("Device selected from AutoPlay", NotifyType.StatusMessage); } } catch (Exception ex) { rootPage.NotifyUser("Exception: " + ex.ToString(), NotifyType.ErrorMessage); } }
private static void input_OnMouseDetected(object sender, DeviceActivatedEventArgs e) { Console.WriteLine("Mouse detected with deviceId {0}", e.DeviceId); _isMouseAvailable = true; }
private static void input_OnKeyboardDetected(object sender, DeviceActivatedEventArgs e) { Console.WriteLine("Keyboard detected with deviceId {0}", e.DeviceId); _isKeyAvailable = true; }
protected virtual Task HandleActivation(DeviceActivatedEventArgs args) { return(Task.CompletedTask); }
private void getCameraDevice(DeviceActivatedEventArgs args) { Device = args.DeviceInformationId; }