/// <summary> /// delete task /// </summary> /// <param name="id"></param> private static void DeleteTask(string id) { System.Threading.Monitor.Enter(_UploadingTaskList); UploadTask uploadTask = _UploadingTaskList.Where(t => t.UniqueID == id).FirstOrDefault(); if (uploadTask != null) { _UploadingTaskList.Remove(uploadTask); } System.Threading.Monitor.Exit(_UploadingTaskList); System.Threading.Monitor.Enter(_UploadingIDs); if (_UploadingIDs.Contains(id)) { _UploadingIDs.Remove(id); } System.Threading.Monitor.Exit(_UploadingIDs); }
private static void UploadFileTaskProcess(UploadTask uploadTask) { ThreadPool.QueueUserWorkItem((o) => { try { UploadFileItem uploadFileItem = new UploadFileItem(uploadTask); uploadFileItem.Upload(); } catch (Exception ex) { System.Threading.Monitor.Enter(_UploadingIDs); if (_UploadingIDs.Contains(uploadTask.UniqueID)) { _UploadingIDs.Remove(uploadTask.UniqueID); } System.Threading.Monitor.Exit(_UploadingIDs); _logger.Error("UploadFile error:" + ex.ToString()); } }); }
public static void UploadERMFile() { UploadERMFileProcess(); if (_UploadingTaskList.Count > _MaxThreadCount) { return; } //read xml, get dam //get reg status //load xml, read dam List <Dam> dams = DAMCommon.GetDamConfig(); foreach (Dam dam in dams) { DAMCommon.SetDamDetail(dam); } if (DAMCommon.CommonDamDetails.Count == 0) { System.Threading.Monitor.Enter(_UploadingIDs); _UploadingIDs.Clear(); System.Threading.Monitor.Exit(_UploadingIDs); System.Threading.Monitor.Enter(_UploadingTaskList); _UploadingTaskList.Clear(); System.Threading.Monitor.Exit(_UploadingTaskList); return; } string scrInfo = Utilities.GetProcessID(); _logger.Debug("scrInfo:" + scrInfo); try { foreach (DamDetail dam in DAMCommon.CommonDamDetails) { //get task using (var client = new HttpClient()) { var parameters = String.Format("/api/v1/upload/uploadtasks/{0}", scrInfo); _logger.Debug("url:" + dam.WebApiurl + parameters); HttpResponseMessage response = client.GetAsync(dam.WebApiurl + parameters).Result; if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsAsync <List <UploadFileTaskWorkDto> >().Result; foreach (UploadFileTaskWorkDto uploadFileTaskWorkDto in result) { UploadTask uploadTask = new UploadTask(); uploadTask.UniqueID = uploadFileTaskWorkDto.UniqueID; uploadTask.UploadFileTaskWorkDto = uploadFileTaskWorkDto; uploadTask.Dam = dam; System.Threading.Monitor.Enter(_UploadingTaskList); if (_UploadingTaskList.Where(t => t.UniqueID == uploadFileTaskWorkDto.UniqueID).FirstOrDefault() == null) { _UploadingTaskList.Add(uploadTask); _logger.Debug("new task:" + uploadFileTaskWorkDto.UniqueID); } System.Threading.Monitor.Exit(_UploadingTaskList); } } } } } catch (Exception ex) { System.Threading.Monitor.Enter(_UploadingIDs); _UploadingIDs.Clear(); System.Threading.Monitor.Exit(_UploadingIDs); System.Threading.Monitor.Enter(_UploadingTaskList); _UploadingTaskList.Clear(); System.Threading.Monitor.Exit(_UploadingTaskList); _logger.Error("UploadERMFile error:" + ex.ToString()); } }
public UploadFileItem(UploadTask uploadTask) { _uploadTask = uploadTask; ftpClient.ReadParam += OnProgress; }