public void initStatus(HutTaskActionResult r = HutTaskActionResult.NotApplicable) { status = HutTaskActionStatus.Ready; result = r; start = default(DateTime); end = default(DateTime); }
public HutTaskExecuteAction() { initStatus(); Procedure += () => { if (File.Exists(executablepath)) { // change status for processing result = HutTaskActionResult.Waiting; ActionStatus = HutTaskActionStatus.Processing; Process process = Process.Start(executablepath); start = process.StartTime; process.WaitForExit(); // update final status updateStatus(process.ExitCode, process.ExitTime); } else { result = HutTaskActionResult.Fail; end = DateTime.Now; ActionStatus = HutTaskActionStatus.Complete; Console.WriteLine(@"file not exists"); } }; }
public void resetStatus() { status = HutTaskActionStatus.Ready; result = HutTaskActionResult.NotApplicable; start = default(DateTime); end = default(DateTime); }
public HutTaskArchiveAction() { initStatus(); Procedure += () => { List <string> exceptions = new List <string>(); ActionStatus = HutTaskActionStatus.Processing; try { if (Directory.Exists(srcpath)) { if (!Directory.Exists(dstpath)) { Directory.CreateDirectory(dstpath); } // TODO: apply archive option List <string> files = Directory.GetFiles(srcpath).ToList(); // change status for processing start = DateTime.Now; result = HutTaskActionResult.Waiting; foreach (var pair in files.Select(s => new { src = s, dst = Path.Combine(dstpath, Path.GetFileName(s)) })) { if (File.Exists(pair.dst)) { File.Delete(pair.dst); } File.Move(pair.src, pair.dst); ArchiveStatus = pair.src + @" -> " + pair.dst; } } else { exceptions.Add(@"Directory" + srcpath + @" is not exist."); } } catch (IOException e) { exceptions.Add(e.Message); ArchiveStatus = e.Message; } finally { // update final status updateStatus(exceptions); } }; }
public void updateStatus(List <string> exceptionmessages) { result = exceptionmessages.Count == 0 ? HutTaskActionResult.Success : HutTaskActionResult.Fail; end = DateTime.Now; if (exceptionmessages.Count > 0) { ArchiveStatus = @"Summary of Errors in Task: " + Name; foreach (string message in exceptionmessages) { ArchiveStatus = @" " + message; } } ActionStatus = HutTaskActionStatus.Complete; }
private HutTaskResultLog generateResult(IHutTaskAction action, DateTime starttime, int additionalid = 0) { HutTaskActionResult result = action.ActionResult; return(new HutTaskResultLog() { Level = HutLogLevel.Info, Message = string.Format(@"Task {0}({1}) of {2} is {3}.", Name, Group, TaskType.ToString(), action.ActionStatus.ToString()), ID = ID + additionalid, Name = Name, Group = Group, Status = action.ActionStatus, Result = result, ExecuteTime = starttime, CompleteTime = action.EndTime, TaskType = TaskType, ActionID = action.GetHashCode(), ActionType = action.ActionType, }); }
public void updateStatus(int exitcode, DateTime exittime) { result = exitcode == 0 ? HutTaskActionResult.Success : HutTaskActionResult.Fail; end = exittime; ActionStatus = HutTaskActionStatus.Complete; }
private void TransferFiles(IHutFTPClient client, List <string> exceptions) { int transferfiles = 1; try { if (serverinfo.Direction == HutFTPTransferDirection.Upload) { // check local path if (!Directory.Exists(Path.GetDirectoryName(srcpath))) { TransferStatus = @"source path is not exists"; end = DateTime.Now; result = HutTaskActionResult.Fail; ActionStatus = HutTaskActionStatus.Complete; return; } if (client is HutFTPClient && ServerInfo.Address.StartsWith(@"s")) { transferstatus = @"can't open server sftp:// without SSL: " + serverinfo.Address; return; } List <string> uploaded = new List <string>(); do { // upload foreach (string srcfile in getUploadFiles(srcpath, ref exceptions).Where(w => !uploaded.Contains(Path.GetFileName(w)))) { string dstfile = string.Format(@"{0}/{1}", dstpath, Option.rename(Path.GetFileName(srcfile))).Replace(@"//", @"/"); TransferStatus = @"(" + ((uploaded.Count + 1).ToString()) + @")Upload Start : " + srcfile; client.upload(srcfile, dstfile); TransferStatus = @"(" + ((uploaded.Count + 1).ToString()) + @")Upload Complete: " + client.Addr + dstfile; uploaded.Add(Path.GetFileName(srcfile)); } // check one more if (getUploadFiles(srcpath, ref exceptions).Count <= uploaded.Count) { break; } Thread.Sleep(300); } while (true); TransferStatus = @"Total Sent Files: " + (uploaded.Count).ToString(); // cannot sent. if (uploaded.Count == 0) { exceptions.Add(Name + @": , No Matched File in Option = " + Option.SearchRule.ToString()); } // options if ((option.StorageMethod & HutStorageMethod.DeleteFile) == HutStorageMethod.DeleteFile) { foreach (var src in uploaded.Select((s, i) => new { File = Path.Combine(srcpath, s), Index = (i + 1) })) { File.Delete(src.File); TransferStatus = @"(" + (src.Index) + @")Delete Uploaded File: " + src.File; } } } // DOWNLOAD else { foreach (string srcfile in getDownloadFiles(client, srcpath, ref exceptions)) { string dstfile = Path.Combine(dstpath, Option.rename(Path.GetFileName(srcfile))); TransferStatus = @"(" + (transferfiles.ToString()) + @")Download Start : " + client.Addr + srcpath + srcfile; client.download(string.Format(@"{0}/{1}", srcpath, srcfile), dstfile); TransferStatus = @"(" + (transferfiles.ToString()) + @")Download Complete: " + dstfile; client.dele(string.Format(@"{0}/{1}", srcpath, srcfile)); TransferStatus = @"(" + (transferfiles.ToString()) + @")Delete Complete: " + srcfile; transferfiles++; } TransferStatus = @"Total Received Files: " + (transferfiles - 1).ToString(); } TransferStatus = @"FTP Disconnected"; } catch (Exception e) { //string dstfile = string.Format(@"{0}\{1}", dstpath, Option.rename(Path.GetFileName(srcfile))); TransferStatus = @"File Transfer Error Raised: "; exceptions.Add(TransferStatus); TransferStatus = @" Source Path: " + srcpath; exceptions.Add(TransferStatus); TransferStatus = @" Target Path: " + serverinfo.Address + @"/" + dstpath; exceptions.Add(TransferStatus); TransferStatus = @" FTP Error(s): " + e.Message; TransferStatus = @" " + e.StackTrace; exceptions.Add(TransferStatus); } finally { TransferStatus = @"End Transfer Action: " + Name; updateStatus(exceptions); } }
public void resetStatus() { status = HutTaskActionStatus.Ready; result = HutTaskActionResult.NotApplicable; }
public void initStatus(HutTaskActionResult r = HutTaskActionResult.NotApplicable) { status = HutTaskActionStatus.Ready; result = r; }