/// <summary> /// execute before execute operation /// </summary> /// <returns></returns> public CommandBeforeExecuteResult ExecuteBeforeExecuteOperation() { #region execute async operation if (!AsyncBeforeOperations.IsNullOrEmpty()) { var internalMsgItem = new CommandBeforeOperationInternalMessageItem(AsyncBeforeOperations); InternalMessageQueue.Enqueue(internalMsgItem); } #endregion #region execut sync operation if (SyncBeforeOperations.IsNullOrEmpty()) { return(CommandBeforeExecuteResult.DefaultSuccess);; } CommandBeforeExecuteResult result = new CommandBeforeExecuteResult(); SyncBeforeOperations.ForEach(op => { var opResult = op.Item1(op.Item2); result.AllowExecuteCommand = result.AllowExecuteCommand && opResult.AllowExecuteCommand; }); return(result); #endregion }
/// <summary> /// execute callback operation /// </summary> /// <param name="success">command execute success</param> /// <returns></returns> public CommandCallbackResult ExecuteCallbackOperation(bool success) { #region execute async operation if (!AsyncCallbackOperations.IsNullOrEmpty()) { var internalMsgItem = new CommandCallbackInternalMessageItem(AsyncCallbackOperations); InternalMessageQueue.Enqueue(internalMsgItem); } #endregion #region execute sync operation if (!SyncCallbackOperations.IsNullOrEmpty()) { SyncCallbackOperations.ForEach(op => { if (op.Item2 != null) { op.Item2.ExecuteSuccess = success; } op.Item1(op.Item2); }); } return(CommandCallbackResult.Default); #endregion }
/// <summary> /// Send email /// </summary> /// <param name="emailAccount">Email account</param> /// <param name="sendInfos">Email send infos</param> /// <returns>Return the email send result</returns> public static async Task <List <EmailSendResult> > SendAsync(EmailAccount emailAccount, params EmailSendInfo[] sendInfos) { if (emailAccount == null || sendInfos.IsNullOrEmpty()) { return(new List <EmailSendResult>(0)); } List <EmailSendInfo> SyncInfos = new List <EmailSendInfo>(); List <EmailSendInfo> AsyncInfos = new List <EmailSendInfo>(); foreach (var sendInfo in sendInfos) { if (sendInfo == null) { continue; } if (sendInfo.Asynchronously) { AsyncInfos.Add(sendInfo); } else { SyncInfos.Add(sendInfo); } } if (!AsyncInfos.IsNullOrEmpty()) { SendEmailInternalMessageCommand emailInternalMessageCommand = new SendEmailInternalMessageCommand() { SendInfos = AsyncInfos, EmailAccount = emailAccount }; InternalMessageQueue.Enqueue(emailInternalMessageCommand); } if (SyncInfos.IsNullOrEmpty()) { return(new List <EmailSendResult>(1) { EmailSendResult.SuccessResult(null) }); } return(await ExecuteSendAsync(emailAccount, SyncInfos).ConfigureAwait(false)); }