/// <summary> /// 触发发送任务已添加事件 /// </summary> /// <param name="e">事件数据</param> protected virtual void OnSendTaskAdded(FileTaskEventArgs e) { if (SendTaskAdded == null) return; if (!IPMClient.NeedPostMessage) { SendTaskAdded(this, e); } else { if (_spcSendTaskAdded == null) _spcSendTaskAdded = (s) => SendTaskAdded(this, s as FileTaskEventArgs); IPMClient.SendSynchronizeMessage(_spcSendTaskAdded, e); } }
void cs_TaskDiscardRequired(object sender, FileTaskEventArgs e) { Env.IPMClient.Commander.SendReleaseFilesSignal((sender as IChatService).Host, e.PackageID); }
void cs_TaskAccepted(object sender, FileTaskEventArgs e) { FileTaskInfo taskinfo = e.TaskInfo; e.TaskInfo.TaskList.ForEach(s => { if (!s.IsFolder) s.FullPath = System.IO.Path.Combine(s.FullPath, s.Name); }); Env.IPMClient.FileTaskManager.AddReceiveTask(e.TaskInfo); }
/// <summary> /// 处理发送任务添加事件 /// </summary> /// <param name="task"></param> void SendTaskAdd(FileTaskEventArgs task) { IChatService cs = this.OpenChatTab(task.Host); cs.AddSendTask(task); }
/// <summary> /// Triggers the TaskAccepted event. /// </summary> public virtual void OnTaskAccepted(FileTaskEventArgs ea) { if (TaskAccepted != null) TaskAccepted(null/*this*/, ea); }
/// <summary> /// Triggers the TaskDiscardRequired event. /// </summary> public virtual void OnTaskDiscardRequired(FileTaskEventArgs ea) { if (TaskDiscardRequired != null) TaskDiscardRequired(this, ea); }
/// <summary> /// 引发请求释放文件事件 /// </summary> /// <param name="e"></param> protected virtual void OnReleaseFileRequired(FileTaskEventArgs e) { if (ReleaseFileRequired == null) return; if (IPMClient.NeedPostMessage) { ReleaseFileRequired(this, e); } else { if (cbReleaseFileReuired == null) cbReleaseFileReuired = s => ReleaseFileRequired(this, s as FileTaskEventArgs); IPMClient.SendSynchronizeMessage(cbReleaseFileReuired, e); } }
/// <summary> /// 引发任务超时事件 /// </summary> /// <param name="e"></param> protected virtual void OnTaskExpires(FileTaskEventArgs e) { if (TaskExpires == null) return; if (!IPMClient.NeedPostMessage) TaskExpires(this, e); else { if (_spcTaskExpires == null) _spcTaskExpires = (f) => TaskExpires(this, f as FileTaskEventArgs); IPMClient.SendASynchronizeMessage(_spcTaskExpires, e); } }
/// <summary> /// 触发接收状态更新事件 /// </summary> void RaiseReceiveStatusUpdateEvent() { FileTaskEventArgs e = new FileTaskEventArgs(null); activeReceiveItems.ForEach(s => { e.TaskInfo = s.TaskInfo; e.TaskItem = s; OnTaskItemProgressChanged(e); }); }
/// <summary> /// 标记一个任务项目状态,并检查任务是否完成 /// </summary> /// <param name="item">任务条目</param> /// <param name="state">状态</param> internal void MarkReceiveTaskItemState(FileTaskItem item, FileTaskItemState state) { if (item.State == state) return; if (state == FileTaskItemState.Finished || state == FileTaskItemState.Failure) { //退出传输状态 this.activeReceiveItems.Remove(item); OnTaskItemProgressChanged(new FileTaskEventArgs(item.TaskInfo, item)); this.EnsureReceiveStateUpdateTimerState(); } item.State = state; OnTaskItemStateChanged(new FileTaskEventArgs(item.TaskInfo, item)); //是否需要更新状态 if (state == FileTaskItemState.Processing) { this.activeReceiveItems.Add(item); this.EnsureReceiveStateUpdateTimerState(); } //如果是完成了,那就查找下这个任务是不是全部完成了,如果是的话,那就删掉任务 if ((state == FileTaskItemState.Finished || state == FileTaskItemState.Failure)) { //检测任务完成 if (item.TaskInfo.TaskList.Count(s => s.State != FileTaskItemState.Finished && s.State != FileTaskItemState.Failure) == 0) { FileTaskInfo task = item.TaskInfo; this.OnReceiveTaskFinished(new FileTaskEventArgs(task)); this.ReceiveTask.Remove(task); //检测是否有失败的,如果有就将请求重新发送以便重试 for (int i = task.TaskList.Count - 1; i >= 0; i--) { if (task.TaskList[i].State != FileTaskItemState.Failure) task.TaskList.RemoveAt(i); //如果是成功的,则移除 else { task.TaskList[i].State = FileTaskItemState.Scheduled; //重置任务的当前状态 if (!task.TaskList[i].IsFolder) task.TaskList[i].FullPath = System.IO.Path.GetDirectoryName(task.TaskList[i].FullPath); } } if (task.TaskList.Count > 0) { var e = new FileTaskEventArgs(task); OnFileReceiveTaskReDroped(e); if (!e.IsHandled) OnFileReceiveTaskDiscarded(e); } } StartReceive(); } }
/// <summary> /// 引发 <seealso cref="FSLib.IPMessager.Core.FileTaskManager.FileReceiveTaskDiscarded"/> 事件 /// <para>当上次文件接收中出现异常而导致引发的 <seealso cref="FSLib.IPMessager.Core.FileTaskManager.FileReceiveTaskReDroped"/> 事件并没有被处理时,将会引发此事件,请求发送信息通知对方文件已经取消接收。</para> /// </summary> /// <param name="e"></param> protected virtual void OnFileReceiveTaskDiscarded(FileTaskEventArgs e) { if (FileReceiveTaskDiscarded == null) return; if (IPMClient.NeedPostMessage) { if (callFileReceiveTaskDiscarded == null) callFileReceiveTaskDiscarded = s => FileReceiveTaskDiscarded(this, s as FileTaskEventArgs); IPMClient.SendSynchronizeMessage(callFileReceiveTaskDiscarded, e); } else FileReceiveTaskDiscarded(this, e); }
/// <summary> /// 触发接收任务开始事件 /// </summary> /// <param name="e">事件数据</param> protected virtual void OnReceiveItemStart(FileTaskEventArgs e) { if (ReceiveItemStart == null) return; if (!IPMClient.NeedPostMessage) ReceiveItemStart(this, e); else { if (spcReceiveItemStart == null) spcReceiveItemStart = (s) => ReceiveItemStart(this, s as FileTaskEventArgs); IPMClient.SendSynchronizeMessage(spcReceiveItemStart, e); } }
/// <summary> /// 触发接收任务已添加事件 /// </summary> /// <param name="e">事件数据</param> protected virtual void OnReceiveTaskAdded(FileTaskEventArgs e) { if (ReceiveTaskAdded == null) return; if (!IPMClient.NeedPostMessage) { ReceiveTaskAdded(this, e); } else { if (spcReceiveTaskAdded == null) spcReceiveTaskAdded = (s) => ReceiveTaskAdded(this, s as FileTaskEventArgs); IPMClient.SendSynchronizeMessage(spcReceiveTaskAdded, e); } }
/// <summary> /// 触发发送状态更新事件 /// </summary> void RaiseSendStatusUpdateEvent() { FileTaskEventArgs e = new FileTaskEventArgs(null); lock (_activeSendItems) { _activeSendItems.ForEach(s => { e.TaskInfo = s.TaskInfo; e.TaskItem = s; OnTaskItemProgressChanged(e); }); } }
/// <summary> /// 触发发送进度变化事件 /// </summary> /// <param name="e"></param> protected virtual void OnTaskItemProgressChanged(FileTaskEventArgs e) { if (TaskItemStateChanged == null) return; if (!IPMClient.NeedPostMessage) TaskItemProgressChanged(this, e); else { if (spcTaskItemProgressChanged == null) spcTaskItemProgressChanged = (s) => TaskItemProgressChanged(this, s as FileTaskEventArgs); IPMClient.SendSynchronizeMessage(spcTaskItemProgressChanged, e); } }