Exemplo n.º 1
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void BeginExecute(CoroutineExecutionContext context)
        {
            var openFileDialog = new OpenFileDialog();

            openFileDialog.RestoreDirectory = true;
            openFileDialog.CheckFileExists  = true;
            openFileDialog.CheckPathExists  = true;

            openFileDialog.Multiselect      = _multiselect;
            openFileDialog.Filter           = _fileTypeFilter;
            openFileDialog.Title            = _title;
            openFileDialog.InitialDirectory = _initialDirectory;

            var activeWindow = CoTaskHelper.GetActiveWindow(context);

            bool fileSelected;

            try
            {
                fileSelected = openFileDialog.ShowDialog(activeWindow).GetValueOrDefault();
            }
            catch
            {
                if (string.IsNullOrEmpty(openFileDialog.InitialDirectory))
                {
                    throw;
                }
                openFileDialog.InitialDirectory = null;
                fileSelected = openFileDialog.ShowDialog(activeWindow).GetValueOrDefault();
            }

            OnCompleted(openFileDialog, new CoTaskCompletedEventArgs(null, !fileSelected));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void BeginExecute(CoroutineExecutionContext context)
        {
            var activeWindow = CoTaskHelper.GetActiveWindow(context);

            if (activeWindow != null)
            {
                Result = MessageBox.Show(activeWindow, _message, _caption, _button, _image);
            }
            else
            {
                Result = MessageBox.Show(_message, _caption, _button, _image);
            }

            OnCompleted(new CoTaskCompletedEventArgs(null, false));
        }
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void BeginExecute(CoroutineExecutionContext context)
        {
            var saveFileDialog = new SaveFileDialog();

            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.AddExtension     = true;
            saveFileDialog.CheckPathExists  = true;

            saveFileDialog.Filter     = _fileTypeFilter;
            saveFileDialog.DefaultExt = _defaultFileExtension;

            saveFileDialog.Title            = _title;
            saveFileDialog.FileName         = _fileName;
            saveFileDialog.CreatePrompt     = _promptForCreate;
            saveFileDialog.OverwritePrompt  = _promptForOverwrite;
            saveFileDialog.InitialDirectory = _initialDirectory;

            var activeWindow = CoTaskHelper.GetActiveWindow(context);

            bool fileSelected;

            try
            {
                fileSelected = saveFileDialog.ShowDialog(activeWindow).GetValueOrDefault();
            }
            catch
            {
                if (string.IsNullOrEmpty(saveFileDialog.InitialDirectory))
                {
                    throw;
                }
                saveFileDialog.InitialDirectory = null;
                fileSelected = saveFileDialog.ShowDialog(activeWindow).GetValueOrDefault();
            }

            if (fileSelected)
            {
                Result = new FileInfo(saveFileDialog.FileName);
            }

            OnCompleted(new CoTaskCompletedEventArgs(null, !fileSelected));
        }