using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using IReaper.FileData;
using IReaper.FileUtils;
namespace IReaper.Command{
class ImportFileCommand:CommandBase
{
public override void CommandBody(object sender, params object[] paras)
{
string path = this.GetImportLogFilePath();
if (path == null)
return;
bool isOverwrite = this.ShowPromotionForOverwrite();
Statues.ImportFileWork work = new IReaper.Statues.ImportFileWork(path, isOverwrite);
work.RunWorkerAsync();
}
public override CommandFamily Family
{
get{ return CommandFamily.Command_ImportFiles; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private bool ShowPromotionForOverwrite()
{
DialogResult result = DialogResult.None;
//CourseFileData.async
//
if (SynchronizationContext.Current == CourseFileData.async.SynchronizationContext)
{
result = MessageBox.Show(Properties.Resources.AutomaticOverwriteInformationMessage,
Properties.Resources.AutomaticOverwriteInformationCaptine,
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.AutomaticOverwriteInformationMessage,
Properties.Resources.AutomaticOverwriteInformationCaptine,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
//notify.
wait.Set();
}), null);
wait.WaitOne();
wait.Close();
}
return result == DialogResult.Yes;
}
private string GetImportLogFilePath()
{
string path = null;
OpenFileDialog Open = new OpenFileDialog();
Open.Multiselect = false;
Open.Filter = "|*.export";
//CourseFileData.async
//
if (SynchronizationContext.Current == CourseFileData.async.SynchronizationContext)
{
if (Open.ShowDialog() == DialogResult.OK)
{
path = Open.FileName;
}
}
else
{
//create wait handle
AutoResetEvent wait = new AutoResetEvent(false);
//start the dialog
CourseFileData.async.Post(new SendOrPostCallback(delegate(object obj)
{
if (Open.ShowDialog() == DialogResult.OK)
{
path = Open.FileName;
} //notify.
wait.Set();
}), null);
wait.WaitOne();
wait.Close();
}
return path;
}
}
}
|