コード例 #1
0
        // </SnippetOnCancel>


        // <SnippetFindSourcesClick>
        private async void findSourcesButton_Click(object sender, RoutedEventArgs e)
        {
            var sources = await PhotoImportManager.FindAllSourcesAsync();

            foreach (PhotoImportSource source in sources)
            {
                ComboBoxItem item = new ComboBoxItem();
                item.Content = source.DisplayName;
                item.Tag     = source;
                sourcesComboBox.Items.Add(item);
            }
        }
コード例 #2
0
        /// <summary>
        /// Enumerate all PTP / MTP sources when FindAllSources button is clicked.
        /// </summary>
        /// <param name="sender">The source of the click event</param>
        /// <param name="e">Details about the click event </param>
        private async void OnFindSourcesClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                rootPage.NotifyUser(String.Empty, NotifyType.StatusMessage);

                // clear our list of items to import
                this.itemsToImport            = null;
                this.fileListView.ItemsSource = this.itemsToImport;

                // reset UI elements
                this.progressBar.Value     = 0.0;
                this.propertiesTxtBox.Text = "";

                // disable all buttons until source selection is made
                setButtonState(false);

                // reenable source selection
                this.sourceListBox.IsEnabled = true;

                // clear find criteria
                this.OnlyImages.IsChecked     = false;
                this.OnlyVideo.IsChecked      = false;
                this.ImagesAndVideo.IsChecked = false;



                // Dispose any created import session
                if (this.session != null)
                {
                    this.session.Dispose();
                    this.session = null;
                }

                // Check to ensure API is supported
                bool importSupported = await PhotoImportManager.IsSupportedAsync();

                if (importSupported)
                {
                    // enumerate all available sources to where we can import from
                    sourceListBox.ItemsSource = await PhotoImportManager.FindAllSourcesAsync();
                }
                else
                {
                    rootPage.NotifyUser("Import is not supported.", NotifyType.ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser("FindAllSourcesAsync Failed. " + "Exception: " + ex.ToString(), NotifyType.ErrorMessage);
            }
        }
コード例 #3
0
        /// <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);
            }
        }
コード例 #4
0
ファイル: App.xaml.cs プロジェクト: HiepMa/go-sample
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = false;
            }
#endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active

            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                // Set the default language
                rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

                rootFrame.NavigationFailed += OnNavigationFailed;
                rootFrame.Navigate(typeof(MainPage));

                // if our app was previous terminated or wasn't running, check if there were pending progress
                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated || e.PreviousExecutionState == ApplicationExecutionState.NotRunning)
                {
                    try
                    {
                        bool isImportSupported = await PhotoImportManager.IsSupportedAsync();

                        if (isImportSupported)
                        {
                            // Determine if there was an in progress session
                            IReadOnlyList <PhotoImportOperation> ops = PhotoImportManager.GetPendingOperations();

                            // If there is at least one session and state isn't idle, restore session state

                            if (ops != null && ops.Count != 0)
                            {
                                var p = rootFrame.Content as MainPage;

                                if (ops.Count > 1)
                                {
                                    // If there is more than one operation, since this app handles single
                                    // download sessions only, the previous session(s) were not properly
                                    // disposed of, do this now.

                                    for (int x = 0; x < ops.Count - 1; x++)
                                    {
                                        ops[x].Session.Dispose();
                                    }
                                }

                                // Take the last operation from the list, and if some task was started, navigate to reconnect to the proper stage.

                                p.ImportOperation = ops[ops.Count - 1];

                                if (p.ImportOperation.Stage != PhotoImportStage.NotStarted)
                                {
                                    p.NavigateToReconnect();
                                }
                                else
                                {
                                    p.ImportOperation.Session.Dispose();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Exception: " + ex.Message);
                    }
                }

                // Place the frame in the current Window

                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }