/// <summary> /// 任务监听 /// </summary> /// <param name="m"></param> protected override void DefWndProc(ref Message m) { switch (m.Msg) { case WM_COPYDATA: { COPYDATASTRUCT mystr = new COPYDATASTRUCT(); Type mytype = mystr.GetType(); mystr = (COPYDATASTRUCT)m.GetLParam(mytype); string taskInfo = mystr.lpData.Substring(0, mystr.cbData); taskInfo = taskInfo.Replace('$', ' '); string[] pms = taskInfo.Split('#'); Guid taskId = Guid.Parse(pms[0]); string sourceFileName = pms[1]; string destFileName = pms[2]; TaskType taskType = (TaskType)Enum.Parse(typeof(TaskType), pms[3]); RenameMode taskRenameMode = (RenameMode)Enum.Parse(typeof(RenameMode), pms[4]); TaskCategory taskCategory = (TaskCategory)Enum.Parse(typeof(TaskCategory), pms[5]); TransferTask task = new TransferTask(taskId, sourceFileName, destFileName, taskType, taskRenameMode, taskCategory); AddTransferTask(task); break; } default: base.DefWndProc(ref m); break; } }
private void Excute(object taskObj) { TransferTask task = taskObj as TransferTask; switch (task.Category) { case TaskCategory.Files: { TransferHelper.CopyFiles(task); break; } case TaskCategory.Features: { TransferHelper.CopyFeatures(task); break; } case TaskCategory.Raster: { TransferHelper.CopyRaster(task); break; } } string s = task.ID.ToString(); Int32 id = 1; Int32 WM_COPYDATA = 0x004A; COPYDATASTRUCT cd = new COPYDATASTRUCT(); cd.dwData = (IntPtr)id; cd.lpData = s; cd.cbData = s.Length; SendMessage((int)FindWindow(null, "MainForm"), WM_COPYDATA, 0, ref cd); }
/// <summary> /// 传输矢量 /// </summary> /// <param name="task"></param> public static void CopyFeatures(TransferTask task) { FeatureReadHelper inputReadHelper = new FeatureReadHelper(task.SourceFileName); FeatureReadHelper outputReadHelper = new FeatureReadHelper(task.DestFileName); string outputNameWithoutExtention = string.Empty; if (task.RenameMode.Equals(RenameMode.Overwrite)) { outputReadHelper.Delete(outputReadHelper.NameWithoutExtension + outputReadHelper.Extension); outputNameWithoutExtention = outputReadHelper.NameWithoutExtension; } else { outputNameWithoutExtention = inputReadHelper.AccumulativeName; } ESRI.ArcGIS.DataManagementTools.CopyFeatures CpyFeat = new ESRI.ArcGIS.DataManagementTools.CopyFeatures(task.SourceFileName, outputReadHelper.Directory + "\\" + outputNameWithoutExtention); Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = true; IGeoProcessorResult gpResult = gp.Execute(CpyFeat, null) as IGeoProcessorResult; if (gpResult == null || gpResult.Status == esriJobStatus.esriJobFailed) { for (int i = 0; i < gpResult.MessageCount; i++) { MessageBox.Show(gpResult.GetMessage(i)); } } }
private void AddTransferTask(TransferTask task) { if (taskList.Count == 0) { currentTaskID = task.ID; } taskList.Add(task); }
/// <summary> /// 文件传输 /// </summary> /// <param name="task"></param> public static void CopyFiles(TransferTask task) { if (task.RenameMode == RenameMode.Overwrite) { System.IO.File.Copy(task.SourceFileName, task.DestFileName, true); } else if (task.RenameMode == RenameMode.Accumulate) { FilesReadHelper inputReadHelper = new FilesReadHelper(task.SourceFileName); FilesReadHelper outputReadHelper = new FilesReadHelper(task.DestFileName); System.IO.File.Copy(task.SourceFileName, outputReadHelper.Directory + "\\" + inputReadHelper.AccumulativeName); } }
void TaskTM_Tick(object sender, EventArgs e) { if (currentTaskID == Guid.Empty) { return; } TransferTask currentTask = GetTaskByID(currentTaskID); if (currentTask.Status == TaskStatus.Completed || currentTask.Status == TaskStatus.Canceled || currentTask.Status == TaskStatus.Loading) { return; } TransferNext(); }
/// <summary> /// 传输入口函数 /// </summary> /// <param name="task"></param> private void BeginTransfer(TransferTask task) { System.Threading.Thread td = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Excute)); td.Start(task); }