using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.IO;
using IReaper.FileData;
using IReaper.FileUtils;
using IReaper.PathManager;
namespace IReaper.Command{
class TransferFileCommand : CommandBase
{
public override void CommandBody(object sender, params object[] paras)
{
//There are 5 parameters at least.
if(paras.Length < 5)
{
throw new ArgumentException();
}
//get parameter from params
CourseFileData[] files = paras[0] as CourseFileData[]; //files.
OperationType operation = (OperationType)paras[1] ; //operation type : copy/ move
bool overwrite = (bool)paras[2];// overwrite or not.
string rootPath = paras[3] as string;
PathPolicyType policy = (PathPolicyType)paras[4]; // path policy.
//check parameter.
if(files == null || rootPath == null)
{
throw new ArgumentException();
}
DialogResult result = DialogResult.None;
//
if(operation == OperationType.Move)
{
//
if (!this.ShowPromotionForContinue())
{ return; }
else //
{
IReaper.Running.DownloadEngine.PauseDownloadEngine(true);
}
}
Statues.TransferFileWork work = new IReaper.Statues.TransferFileWork(files, operation, overwrite, rootPath, policy);
work.RunWorkerAsync();
}
public override CommandFamily Family
{
get { return CommandFamily.Command_FileTransfer; }
}
private bool ShowPromotionForContinue()
{
DialogResult result = DialogResult.None;
//CourseFileData.async
//
if(SynchronizationContext.Current == CourseFileData.async.SynchronizationContext)
{
result = MessageBox.Show(Properties.Resources.StopDownloadEngineWarningMessage,
Properties.Resources.StopDownloadEngineWarningCaptine,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
}
else
{
//create wait handle
AutoResetEvent wait = new AutoResetEvent(false);
//start the dialog
CourseFileData.async.Post(new SendOrPostCallback(delegate(object obj)
{
result = MessageBox.Show(Properties.Resources.StopDownloadEngineWarningMessage,
Properties.Resources.StopDownloadEngineWarningCaptine,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
//notify.
wait.Set();
}), null);
wait.WaitOne();
wait.Close();
}
return result == DialogResult.Yes;
}
}
}
|