示例#1
0
        /// <summary>
        /// Display the source properties when a new source is selected.
        /// </summary>
        /// <param name="sender">The source of the selection changed event</param>
        /// <param name="e">Details about the selection chagned event</param>
        private void  SourceList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // reset any previous items
            this.itemsToImport            = null;
            this.fileListView.ItemsSource = null;

            // enable find options
            this.OnlyImages.IsEnabled     = true;
            this.OnlyVideo.IsEnabled      = true;
            this.ImagesAndVideo.IsEnabled = true;

            // set the default to find Images and Video
            this.ImagesAndVideo.IsChecked = true;

            // clear any values in the source properties
            this.propertiesTxtBox.Text = "";

            if (e.AddedItems.Count != 0)
            {
                this.importSource = e.AddedItems.First() as PhotoImportSource;
                DisplaySourceProperties();

                // enable Find New and Find All buttons, disable the rest
                this.findNewItemsButton.IsEnabled = true;
                this.findAllItemsButton.IsEnabled = true;
                this.selectNewButton.IsEnabled    = false;
                this.selectNoneButton.IsEnabled   = false;
                this.selectAllButton.IsEnabled    = false;
                this.deleteButton.IsEnabled       = false;
                this.importButton.IsEnabled       = false;
            }
        }
示例#2
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);
            }
        }
示例#3
0
        // </SnippetDeclareImportSource>

        // <SnippetSourcesSelectionChanged>
        private void sourcesComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.importSource = (PhotoImportSource)((ComboBoxItem)sourcesComboBox.SelectedItem).Tag;
            FindItems();
        }
        /// <summary>
        /// Display the source properties when a new source is selected.
        /// </summary>
        /// <param name="sender">The source of the selection changed event</param>
        /// <param name="e">Details about the selection chagned event</param>
        private void  SourceList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // reset any previous items
            this.itemsToImport = null;
            this.fileListView.ItemsSource = null;

            // clear any values in the source properties
            this.propertiesTxtBox.Text = "";

            if (e.AddedItems.Count != 0)
            {
                // enable find options
                this.OnlyImages.IsEnabled = true;
                this.OnlyVideo.IsEnabled = true;
                this.ImagesAndVideo.IsEnabled = true;

                // set the default to find Images and Video
                this.ImagesAndVideo.IsChecked = true;

                this.importSource = e.AddedItems.First() as PhotoImportSource;
                DisplaySourceProperties();
                    
                // enable Find New and Find All buttons, disable the rest
                this.findNewItemsButton.IsEnabled = true;
                this.findAllItemsButton.IsEnabled = true;
                this.selectNewButton.IsEnabled = false;
                this.selectNoneButton.IsEnabled = false;
                this.selectAllButton.IsEnabled = false;
                this.deleteButton.IsEnabled = false;
                this.importButton.IsEnabled = false;
            }
        }