public async Task <string> ProcessFile( [OrchestrationTrigger] IDurableOrchestrationContext context ) { SFTPFile file = context.GetInput <SFTPFile>(); // We Process our File Here var retryOptions = new RetryOptions( firstRetryInterval: TimeSpan.FromSeconds(8), maxNumberOfAttempts: 2); var numberOfTotalData = 10000; var tasks = new Task <bool> [numberOfTotalData]; for (int i = 0; i < numberOfTotalData; i++) { // Map to Model and Save to Database var OurModel = new Transaction { Title = "Transaction Title", Amount = 100, CreatedDate = DateTime.UtcNow }; tasks[i] = context.CallActivityWithRetryAsync <bool>("EMG_SaveItemToDatabase", retryOptions, ""); } await Task.WhenAll(tasks); var ok = tasks.Count(x => x.Result == true); var failed = tasks.Count(x => x.Result == false); return($"Files Processed. OK = {ok}, Failed = {failed}"); }
/// <summary> /// 遍历路径 规则 一层一层的获取 先文件后子目录 /// /// 由于递归不便处理异常,特修改为循环遍历树形结构,以实现递归效果 xiecongwen 20140716 /// </summary> /// <param name="path"></param> /// <returns></returns> public IEnumerable Ls(SFTPFile file) { var sshlog = new Common.Util.SSHLogManager(); NTree <SFTPFile> parent = new NTree <SFTPFile>(file); //后序遍历树 NTree <SFTPFile> child = null; #region 自下而上 后序遍历 while (true) { string path = parent.Data.AbsolutePath; #region 判断是否有子节点 ps:将子目录添加到子节点,返回子文件 SFTPFile[] dirs = null; SFTPFile[] files = null; #region 获取 try { #region 获取子目录,并添加到子节点 dirs = sftp.TopDirLs(path); if (dirs != null && dirs.Count() > 0) { foreach (var dir in dirs) { parent.AddChild(dir); } } #endregion #region 获取子文件 files = sftp.TopFileLs(path); #endregion } catch (Exception ex) { parent.RemoveAllChildren(); //记录报错路径,并忽略其子目录 sshlog.WriteLog(new Common.Util.SSHLog() { DateTime = DateTime.Now, LogType = Common.Util.SSHLogType.Failure, Message = path }); logger.Error(ex.Message); //更新sftp连接对象 sftp = GetAvailableSFTP(); } #endregion //返回子文件 if (files != null && files.Count() > 0) { foreach (var f in files) { yield return(f); } } #endregion //判断是否有子节点 child = parent.PushChild(); if (child == null) { //如果没有子节点,则回溯至上层,否则跳出(表示遍历结束) again : if (parent.Depth > 0) { parent = parent.Parent; } else { yield break; } child = parent.PushChild(); if (child == null) { goto again; } } //作为父节点 进行循环 parent = child; } #endregion }