Пример #1
0
        /// <summary>
        /// Commit message
        /// Send the messages which are registered
        /// </summary>
        /// <param name="asynchronously">Commit message asynchronously</param>
        /// <returns>Return send result</returns>
        public static async Task <SendMessageResult> CommitAsync(bool asynchronously = true)
        {
            if (CurrentMessageBox?.Messages?.IsNullOrEmpty() ?? true)
            {
                return(SendMessageResult.MessageIsNullOrEmpty());
            }
            SendMessageResult sendMessageResult = null;
            var currentMessages = CurrentMessageBox.Messages.Select(c => c).ToList();

            CurrentMessageBox.Clear();
            if (asynchronously)
            {
                InternalQueueMessageItem messageInternalCommand = new InternalQueueMessageItem(MessageProvider, currentMessages, WorkManager.Current);
                InternalQueueManager.GetQueue(EZNEWConstants.InternalQueueNames.Message).Enqueue(messageInternalCommand);
                sendMessageResult = SendMessageResult.SendSuccess();
            }
            else
            {
                sendMessageResult = await(MessageProvider?.SendAsync(new SendMessageOptions()
                {
                    Messages = currentMessages
                }) ?? Task.FromResult(SendMessageResult.NoProvider())).ConfigureAwait(false);
            }
            return(sendMessageResult);
        }
Пример #2
0
        /// <summary>
        /// Send sms
        /// </summary>
        /// <param name="sendSmsOptions">Sms options</param>
        /// <returns>Return send result</returns>
        public static async Task <SendSmsResult> SendAsync(SendSmsOptions sendSmsOptions)
        {
            if (sendSmsOptions == null)
            {
                throw new ArgumentNullException(nameof(sendSmsOptions));
            }
            //Set additions
            SetAdditions(sendSmsOptions);
            if (sendSmsOptions.Asynchronously)
            {
                InternalQueueSendSmsItem smsInternalMessageCommand = new InternalQueueSendSmsItem()
                {
                    SmsOptions = sendSmsOptions
                };
                InternalQueueManager.GetQueue(EZNEWConstants.InternalQueueNames.Message).Enqueue(smsInternalMessageCommand);
                return(SmsResult.SendSuccess <SendSmsResult>());
            }
            else
            {
                var smsProvider = GetSmsProvider();
                var sendResult  = await ExecuteAsync(sendSmsOptions, smsProvider.SendAsync).ConfigureAwait(false);

                //callback
                ThreadPool.QueueUserWorkItem(s =>
                {
                    SmsSentCallback?.Invoke(new SendSmsResult[1] {
                        sendResult.Clone()
                    });
                });
                return(sendResult);
            }
        }
Пример #3
0
        /// <summary>
        /// Called after a query command execute
        /// </summary>
        /// <typeparam name="T">Data type</typeparam>
        /// <param name="queryDataContext">Query data callback context</param>
        public virtual void OnQueryCallback <T>(QueryDataCallbackContext <T> queryDataCallbackContext) where T : BaseEntity <T>, new()
        {
            if (queryDataCallbackContext.Datas.IsNullOrEmpty())
            {
                return;
            }
            var query = queryDataCallbackContext.Query;
            var queryFieldsWithSign = query.GetActuallyQueryFieldsWithSign(typeof(T), true);

            //only store complete data
            if (queryFieldsWithSign?.Item1 ?? false)
            {
                var cacheOperationConfig = DataCacheManager.Configuration.GetDataCacheOperationConfiguration(DataOperationType.Get);
                if (cacheOperationConfig != null && (cacheOperationConfig.TriggerTime & DataCacheOperationTriggerTime.After) != 0)
                {
                    if (cacheOperationConfig.Synchronous)
                    {
                        AddCacheData(queryDataCallbackContext);
                    }
                    else
                    {
                        var internalMsgItem = new InternalQueueAddCacheDataItem <T>(AddCacheData, queryDataCallbackContext);
                        InternalQueueManager.GetQueue(EZNEWConstants.InternalQueueNames.DataCache).Enqueue(internalMsgItem);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Send email
        /// </summary>
        /// <param name="emailAccount">Email account</param>
        /// <param name="sendOptions">Email send options</param>
        /// <returns>Return the email send result</returns>
        public static async Task <List <SendEmailResult> > SendAsync(EmailAccount emailAccount, params SendEmailOptions[] sendOptions)
        {
            if (emailAccount == null || sendOptions.IsNullOrEmpty())
            {
                return(new List <SendEmailResult>(0));
            }
            List <SendEmailOptions> syncInfos  = new List <SendEmailOptions>();
            List <SendEmailOptions> asyncInfos = new List <SendEmailOptions>();

            foreach (var sendOption in sendOptions)
            {
                //Set additional
                SetAdditional(sendOption);

                if (sendOption == null)
                {
                    continue;
                }
                if (sendOption.Asynchronously)
                {
                    asyncInfos.Add(sendOption);
                }
                else
                {
                    syncInfos.Add(sendOption);
                }
            }
            if (!asyncInfos.IsNullOrEmpty())
            {
                InternalQueueSendEmailItem emailInternalMessageCommand = new InternalQueueSendEmailItem()
                {
                    Datas        = asyncInfos,
                    EmailAccount = emailAccount
                };
                InternalQueueManager.GetQueue(EZNEWConstants.InternalQueueNames.Message).Enqueue(emailInternalMessageCommand);
            }
            if (syncInfos.IsNullOrEmpty())
            {
                return(new List <SendEmailResult>(1)
                {
                    SendEmailResult.SuccessResult(null)
                });
            }
            return(await ExecuteSendAsync(emailAccount, syncInfos).ConfigureAwait(false));
        }
Пример #5
0
 /// <summary>
 /// Send sms
 /// </summary>
 /// <param name="account">Sms account</param>
 /// <param name="sendSmsOptions">Send sms options</param>
 /// <returns>Return send sms result</returns>
 public static async Task <SendSmsResult> SendAsync(SmsAccount account, SendSmsOptions sendSmsOptions)
 {
     if (sendSmsOptions == null)
     {
         throw new ArgumentNullException(nameof(sendSmsOptions));
     }
     if (sendSmsOptions.Asynchronously)
     {
         InternalQueueSendSmsItem smsInternalMessageCommand = new InternalQueueSendSmsItem()
         {
             SmsOptions = sendSmsOptions,
             SmsAccount = account
         };
         InternalQueueManager.GetQueue(EZNEWConstants.InternalQueueNames.Message).Enqueue(smsInternalMessageCommand);
         return(SmsResult.SendSuccess <SendSmsResult>());
     }
     else
     {
         var smsProvider = GetSmsProvider();
         return(await ExecuteAsync(account, sendSmsOptions, smsProvider.SendAsync).ConfigureAwait(false));
     }
 }