Пример #1
0
        void DoAction()
        {
            if (btnSkip.Checked)
            {
                _arguments.Skip();
            }
            else if (btnOverwrite.Checked)
            {
                _arguments.Overwrite();
                _overwriteCondition = FileOverwriteCondition.None;
            }
            else if (btnOverwriteOlder.Checked)
            {
                _arguments.Overwrite(FileOverwriteCondition.Older);
                _overwriteCondition = FileOverwriteCondition.Older;
            }
            else if (btnOverwriteDiffSize.Checked)
            {
                _arguments.Overwrite(FileOverwriteCondition.SizeDiffers);
                _overwriteCondition = FileOverwriteCondition.SizeDiffers;
            }
            else if (btnOverwriteDiffChecksum.Checked)
            {
                _arguments.Overwrite(FileOverwriteCondition.ChecksumDiffers);
                _overwriteCondition = FileOverwriteCondition.ChecksumDiffers;
            }
            else if (btnFollowLink.Checked)
            {
                _arguments.FollowLink();
            }
            else if (btnResume.Checked)
            {
                _arguments.Resume();
            }

            Close();
        }
Пример #2
0
        /// <summary>
        /// Shows the form as a modal dialog box.
        /// The form's buttons are shown according to possible actions taken from the given event argument.
        /// </summary>
        /// <param name="e">Event argument describing the type of a problem.</param>
        public void ShowModal(Control form, IssueEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            // if the user chose to skip this problem type, skip it
            if (_skipProblemTypes.ContainsKey(e.IssueType))
            {
                if (e.IssueType == TransferIssueType.FileExists)
                {
                    e.Overwrite(_overwriteCondition);
                }
                else
                {
                    e.Skip();
                }
                return;
            }

            // if the problem is FileExists check, whether the user have chosen any default action already
            if (e.IssueType == TransferIssueType.FileExists)
            {
                // format the text according to action in progress (Downloading or Uploading)
                string messageFormat = "Overwrite file: {0}\n\t{1} Bytes, {2}\n\nwith file: {3}\n\t{4} Bytes, {5}";
                if (e.Action == FileTransferType.Downloading)
                {
                    lblMessage.Text = string.Format(messageFormat,
                                                    e.LocalPath, e.LocalItem.Length, e.LocalItem.LastWriteTime,
                                                    e.RemotePath, e.RemoteItem.Length, e.RemoteItem.LastWriteTime);
                }
                else
                {
                    lblMessage.Text = string.Format(messageFormat,
                                                    e.RemotePath, e.RemoteItem.Length, e.RemoteItem.LastWriteTime,
                                                    e.LocalPath, e.LocalItem.Length, e.LocalItem.LastWriteTime);
                }

                lblMessage.TextAlign = ContentAlignment.MiddleLeft;
                this.Text            = "Target file already exists";
            }
            else
            {
                lblMessage.Text      = e.Exception.Message;
                lblMessage.TextAlign = ContentAlignment.MiddleCenter;
            }

            // store the event arguments for later use at button click handler
            _arguments = e;

            // only enable buttons that represent a possible action
            cancelBtn.Enabled                = e.IsReactionPossible(FileTransferIssueReaction.Cancel);
            btnSkip.Enabled                  = e.IsReactionPossible(FileTransferIssueReaction.Skip);
            retryBtn.Enabled                 = e.IsReactionPossible(FileTransferIssueReaction.Retry);
            btnRename.Enabled                = e.IsReactionPossible(FileTransferIssueReaction.Rename);
            btnOverwrite.Enabled             = e.IsReactionPossible(FileTransferIssueReaction.Overwrite);
            btnOverwriteOlder.Enabled        = e.IsReactionPossible(FileTransferIssueReaction.Overwrite);
            btnOverwriteDiffSize.Enabled     = e.IsReactionPossible(FileTransferIssueReaction.Overwrite);
            btnOverwriteDiffChecksum.Enabled = e.IsOverwriteConditionPossible(FileOverwriteCondition.ChecksumDiffers);
            btnFollowLink.Enabled            = e.IsReactionPossible(FileTransferIssueReaction.FollowLink);
            btnResume.Enabled                = e.IsReactionPossible(FileTransferIssueReaction.Resume);

            // select default action button
            SetDefaultActionButton(e);

            ShowDialog(form);
        }