using System;
using System.Collections.Generic;
using System.Text;
using IReaper.FileData;
using IReaper.Statues;
using System.ComponentModel;
namespace IReaper.Command{
/// <summary>
/// Command
/// </summary>
class RemoveFileCommand:CommandBase
{
/// <summary>
/// Command_RemoveFile
/// </summary>
public override CommandFamily Family
{
get { return CommandFamily.Command_RemoveFile; }
}
/*
* RemoveFileCommand
*/
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="paras"></param>
public override void CommandBody(object sender,
params object[] paras)//1.
{
if (paras == null || paras.Length != 2)
return;
//get files
IList<CourseFileData> Files = paras[0] as IList<CourseFileData>;
if (Files == null)
{
return;
}
//get task type
if (!Enum.IsDefined(typeof(RemoveFileTaskTypeEnum), paras[1]))
{
return;
}
RemoveFileTaskTypeEnum taskType = (RemoveFileTaskTypeEnum)paras[1];
// Filter
for (int i = 0; i < Files.Count;)
{
if (IsValidated(Files[i], taskType))
{
i++;
}
else
{
Files.RemoveAt(i);
}
}
RemoveFileWork work = new RemoveFileWork();
work.Data = Files;
BindBackgroundWorker(work);
work.RunWorkerAsync();
}
/// <summary>
/// CourseFileDataRemoveFileTaskTypeEnum
/// </summary>
/// <param name="cfd"></param>
/// <param name="?"></param>
/// <returns></returns>
private static bool IsValidated(CourseFileData cfd,RemoveFileTaskTypeEnum TaskType)
{
//empty file get false result
if (cfd == null)
{ return false; }
//check by path.
switch (TaskType)
{
case RemoveFileTaskTypeEnum.Completed:
return CourseFileData.IsCourseFileFinished(cfd);
case RemoveFileTaskTypeEnum.Incompleted:
return CourseFileData.IsCourseFileRunnable(cfd);
default:
return false;
}
}
}
/// <summary>
///
/// </summary>
public enum RemoveFileTaskTypeEnum
{
/// <summary>
///
/// </summary>
Completed,
/// <summary>
///
/// </summary>
Incompleted
}
}
|