public void ConstructorShouldAddFileTypeFilters()
        {
            // arrange
            var expected = new[] { "*.*", "*.txt", "*.csv" };

            // act
            var interaction = new SelectFolderInteraction( "", expected );
            var actual = interaction.FileTypeFilter;

            // assert
            Assert.Equal( expected.AsEnumerable(), actual.AsEnumerable() );
        }
        public void ConstructorShouldSetTitle()
        {
            // arrange
            var expected = "test";

            // act
            var interaction = new SelectFolderInteraction( expected );
            var actual = interaction.Title;

            // assert
            Assert.Equal( expected, actual );
        }
        private static void InvokeCallbackCommand( SelectFolderInteraction interaction, IFolder selectedFolder )
        {
            Contract.Requires( interaction != null );

            if ( selectedFolder == null )
            {
                // execute cancel
                interaction.ExecuteCancelCommand();
            }
            else
            {
                // set selected folder and execute accept
                interaction.Folder = selectedFolder;
                interaction.ExecuteDefaultCommand();
            }
        }
        private void SelectFolder( SelectFolderInteraction selectFolder )
        {
            Contract.Requires( selectFolder != null );

            var commitButton = selectFolder.DefaultCommand;
            var dialog = new FolderPicker();

            dialog.ContinuationData.AddRange( selectFolder.ContinuationData );
            dialog.FileTypeFilter.AddRange( selectFolder.FileTypeFilter );
            dialog.SuggestedStartLocation = SuggestedStartLocation;
            dialog.ViewMode = ViewMode;

            if ( dialog.FileTypeFilter.Count == 0 )
                dialog.FileTypeFilter.Add( "*" );

            if ( !string.IsNullOrEmpty( SettingsIdentifier ) )
                dialog.SettingsIdentifier = SettingsIdentifier;

            if ( commitButton != null )
                dialog.CommitButtonText = commitButton.Name;

            dialog.PickFolderAndContinue();
        }
        private IAsyncOperation<StorageFolder> SelectFolderAsync( SelectFolderInteraction selectFolder )
        {
            Contract.Requires( selectFolder != null );
            Contract.Ensures( Contract.Result<IAsyncOperation<StorageFolder>>() != null );

            var commitButton = selectFolder.DefaultCommand;
            var dialog = new FolderPicker();

            dialog.FileTypeFilter.AddRange( selectFolder.FileTypeFilter );
            dialog.SuggestedStartLocation = SuggestedStartLocation;
            dialog.ViewMode = ViewMode;

            if ( dialog.FileTypeFilter.Count == 0 )
                dialog.FileTypeFilter.Add( "*" );

            if ( !string.IsNullOrEmpty( SettingsIdentifier ) )
                dialog.SettingsIdentifier = SettingsIdentifier;

            if ( commitButton != null )
                dialog.CommitButtonText = commitButton.Name;

            return dialog.PickSingleFolderAsync();
        }
        public static Task<IFolder> RequestAsync( this InteractionRequest<SelectFolderInteraction> interactionRequest, string title, string acceptButtonText, string cancelButtonText )
        {
            Arg.NotNull( interactionRequest, nameof( interactionRequest ) );
            Contract.Ensures( Contract.Result<Task<IFolder>>() != null );

            if ( string.IsNullOrEmpty( title ) )
                title = SR.SelectFolderTitle;

            if ( string.IsNullOrEmpty( acceptButtonText ) )
                acceptButtonText = SR.Select;

            if ( string.IsNullOrEmpty( cancelButtonText ) )
                cancelButtonText = SR.Cancel;

            var source = new TaskCompletionSource<IFolder>();
            SelectFolderInteraction interaction = null;

            interaction = new SelectFolderInteraction()
            {
                Title = title,
                DefaultCommandIndex = 0,
                CancelCommandIndex = 1,
                Commands =
                {
                    new NamedCommand<object>( "Select", acceptButtonText, p => source.TrySetResult( interaction.Folder ) ),
                    new NamedCommand<object>( "Cancel", cancelButtonText, p => source.TrySetResult( null ) )
                }
            };

            interactionRequest.Request( interaction );
            return source.Task;
        }