public NotifyMessageEngine(NotifyMessageType notifyMessageType, INotifyMessageSender notifyMessageSender, IDatabase database, string notifyMessageTableName)
 {
     this.notifyMessageType      = notifyMessageType;
     this.notifyMessageSender    = notifyMessageSender;
     this.database               = database;
     this.notifyMessageTableName = notifyMessageTableName;
 }
Example #2
0
 public MessageEventArgs2(Authentication authentication, IUser[] users, string message, MessageType messageType, NotifyMessageType notifyMessageType)
     : base(authentication, users)
 {
     this.message           = message;
     this.messageType       = messageType;
     this.notifyMessageType = notifyMessageType;
 }
Example #3
0
 public ResultBase NotifyMessage2(string[] userIDs, string message, NotifyMessageType notifyMessageType)
 {
     return(this.Invoke(() =>
     {
         this.userContext.NotifyMessage2(this.authentication, userIDs, message, notifyMessageType);
     }));
 }
Example #4
0
        public NotifyAreaMessage(NotifyMessageType type, string title, string text, int timeout = DEFAULT_TIMEOUT)
        {
            Type = type;

            Title = title;
            Text  = text;

            Timeout = timeout;
        }
Example #5
0
 private void showNotifier(bool showCommandButton, string message, Chat chat)
 {
     this.messageLabel.Text     = message;
     this.acceptButton.Visible  = showCommandButton;
     this.declineButton.Visible = showCommandButton;
     this.chat = chat;
     this.notifyMessageType = NotifyMessageType.ChatRequest;
     timer.Interval         = showFadingTime;
     timer.Start();
     taskbarState = TaskbarStates.Appearing;
     this.Show();
     playChatReqSound();
 }
Example #6
0
 public void NotifyMessageRedirect(NotifyMessageType type, string message,string url)
 {
     switch (type)
     {
         case NotifyMessageType.Error:
             ClientScript.RegisterStartupScript(GetType(), "error", "jError('" + message + "'); setTimeout(function() {window.location.href ='" + url + "'}" + ",1500);", true);
             break;
         case NotifyMessageType.Info:
             ClientScript.RegisterStartupScript(GetType(), "notify", "jNotify('" + message + "'); setTimeout(function() {window.location.href ='" + url + "'}" + ",1500);", true);
             break;
         case NotifyMessageType.Success:
             ClientScript.RegisterStartupScript(GetType(), "success", "jSuccess('" + message + "'); setTimeout(function() {window.location.href ='" + url + "'}" + ",1500);", true);
             break;
     }
 }
Example #7
0
 public void NotifyMessage(NotifyMessageType type, string message)
 {
     switch (type)
     {
         case NotifyMessageType.Error:
             ClientScript.RegisterStartupScript(GetType(), "error", "jError('" + message + "');", true);
             break;
         case NotifyMessageType.Info:
             ClientScript.RegisterStartupScript(GetType(), "notify", "jNotify('" + message + "');", true);
             break;
         case NotifyMessageType.Success:
             ClientScript.RegisterStartupScript(GetType(), "success", "jSuccess('" + message + "');", true);
             break;
     }
 }
            async Task Run()
            {
                this.started = true;
                while (this.started)
                {
                    DateTime start = DateTime.Now;

                    Dict message = await this.database.SelectRowAsync(
                        @"SELECT *
                        FROM " + this.notifyMessageTableName + @"
                        WHERE message_type=@messageType AND sent_at IS NULL
                        ORDER BY message_priority DESC, created_at", new {
                        messageType = (byte)this.notifyMessageType
                    });

                    if (message == null)
                    {
                        logger.Debug("Run():Waiting indefinitely");
                        try {
                            this.cancellationTokenSource = new CancellationTokenSource();
                            await Task.Delay(60000, cancellationTokenSource.Token);
                        }
                        catch (TaskCanceledException) {
                            this.cancellationTokenSource = null;
                        }
                        logger.Debug("Run():Waking up");
                    }
                    else
                    {
                        NotifyMessageType notifyMessageType = message.GetAs("type", NotifyMessageType.Email);
                        string            sentMessageId     = null;
                        string            error             = null;
                        try {
                            string from     = message.GetAs("message_from", (string)null);
                            string to       = message.GetAs("message_to", (string)null);
                            string subject  = message.GetAs("message_subject", (string)null);
                            string bodyText = message.GetAs("message_body_text", (string)null);
                            string bodyHtml = message.GetAs("message_body_html", (string)null);
                            logger.Debug($"Run():Sending message to {to}");

                            sentMessageId = await this.notifyMessageSender.SendAsync(from, to, subject, bodyText, bodyHtml);
                        }
                        catch (Exception e) {
                            error = e.Message;
                            logger.Error(e);
                        }

                        var id = message.GetAs("id", (string)null);
                        await this.database.UpdateAndCommitAsync(this.notifyMessageTableName, new {
                            id,
                            sent_at         = DateTime.Now,
                            sent_message_id = sentMessageId,
                            send_error      = error,
                        });

                        int totalMillis = (int)(this.notifyMessageSender.CanSendNextAt - DateTime.Now).TotalMilliseconds;
                        if (totalMillis > 0)
                        {
                            logger.Debug("Run():Sleeping for " + totalMillis + "ms");
                            await Task.Delay(totalMillis);
                        }
                    }
                }
            }
        /// <summary>
        ///
        /// </summary>
        /// <param name="priority">Higher number indicates higher priority</param>
        /// <param name="notifyMessage"></param>
        /// <returns></returns>
        public async Task Queue(ITransaction transaction, params NotifyMessage[] notifyMessages)
        {
            bool emailQueued     = false;
            bool phoneTextQueued = false;

            foreach (var notifyMessage in notifyMessages)
            {
                if (notifyMessage == null)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(notifyMessage.from))
                {
                    throw new Exception("From address cannot be blank");
                }
                string scrubbedFrom = Validate(notifyMessage.from);

                if (string.IsNullOrEmpty(notifyMessage.to))
                {
                    throw new Exception("To address cannot be blank");
                }
                string scrubbedTo = Validate(notifyMessage.to);

                NotifyMessageType notifyMessageType = this.DetectNotifyMessageType(scrubbedTo);
                switch (notifyMessageType)
                {
                case NotifyMessageType.Email:
                    if (this.emailNotifyMessageEngine == null)
                    {
                        throw new Exception("No email message sender configured");
                    }
                    await this.emailNotifyMessageEngine.Queue(transaction, scrubbedFrom, scrubbedTo, notifyMessage.subject, notifyMessage.bodyText, notifyMessage.bodyHtml, notifyMessage.priority, notifyMessage.extraData);

                    emailQueued = true;
                    break;

                case NotifyMessageType.PhoneText:
                    if (this.phoneTextNotifyMessageEngine == null)
                    {
                        throw new Exception("No phone text message sender configured");
                    }
                    await this.phoneTextNotifyMessageEngine.Queue(transaction, scrubbedFrom, scrubbedTo, notifyMessage.subject, notifyMessage.bodyText, notifyMessage.bodyHtml, notifyMessage.priority, notifyMessage.extraData);

                    phoneTextQueued = true;
                    break;
                }
            }

            transaction.OnCommit(() => {
                if (emailQueued)
                {
                    this.emailNotifyMessageEngine.Pulse();
                }
                if (phoneTextQueued)
                {
                    this.phoneTextNotifyMessageEngine.Pulse();
                }
                return(Task.FromResult(0));
            });
        }
Example #10
0
 public void OnMessageReceived2(SignatureDate signatureDate, string[] userIDs, string message, MessageType messageType, NotifyMessageType nofiMessageType)
 {
     throw new NotImplementedException();
 }
Example #11
0
 public static void NotifyMessage2(this IUserContext userContext, Authentication authentication, string message, NotifyMessageType type)
 {
     userContext.NotifyMessage2(authentication, new string[] { }, message, type);
 }
Example #12
0
 private void showNotifier(bool showCommandButton, string message, Chat chat)
 {
     this.messageLabel.Text = message;
     this.acceptButton.Visible = showCommandButton;
     this.declineButton.Visible = showCommandButton;
     this.chat = chat;
     this.notifyMessageType = NotifyMessageType.ChatRequest;
     timer.Interval = showFadingTime;
     timer.Start();
     taskbarState = TaskbarStates.Appearing;
     this.Show();
     playChatReqSound();
 }
Example #13
0
 void IUserServiceCallback.OnMessageReceived2(SignatureDate signatureDate, string[] userIDs, string message, MessageType messageType, NotifyMessageType nofiMessageType)
 {
     this.InvokeAsync(() =>
     {
         var authentication = this.Authenticate(signatureDate);
         if (messageType == MessageType.None)
         {
             foreach (var item in userIDs)
             {
                 var user = this.Users[item];
                 this.Users.InvokeSendMessageEvent2(authentication, user, message, nofiMessageType);
             }
         }
         else if (messageType == MessageType.Notification)
         {
             var users = new User[userIDs.Length];
             for (var i = 0; i < userIDs.Length; i++)
             {
                 var user = this.Users[userIDs[i]];
                 users[i] = user;
             }
             this.Users.InvokeNotifyMessageEvent2(authentication, users, message, nofiMessageType);
         }
     }, nameof(IUserServiceCallback.OnMessageReceived));
 }
Example #14
0
        public void NotifyMessage2(Authentication authentication, string[] userIDs, string message, NotifyMessageType notifyMessageType)
        {
            if (notifyMessageType == NotifyMessageType.Modal)
            {
                this.NotifyMessage(authentication, userIDs, message);
                return;
            }

            this.Dispatcher.VerifyAccess();
            this.CremaHost.DebugMethod(authentication, this, nameof(NotifyMessage), this, userIDs, message);
            this.ValidateSendMessage(authentication, userIDs, message);
            var users = userIDs == null ? new User[] { } : userIDs.Select(item => this.Users[item]).ToArray();

            authentication.Sign();
            this.Users.InvokeNotifyMessageEvent2(authentication, users, message, notifyMessageType);
        }
Example #15
0
        public void InvokeSendMessageEvent2(Authentication authentication, User user, string message, NotifyMessageType notifyMessageType)
        {
            var eventLog = EventLogBuilder.Build(authentication, this, nameof(InvokeSendMessageEvent), user, message);
            var comment  = EventMessageBuilder.SendMessage(authentication, user, message);

            this.CremaHost.Debug(eventLog);
            this.CremaHost.Info(comment);
            this.OnMessageReceived2(new MessageEventArgs2(authentication, new IUser[] { user, }, message, MessageType.None, notifyMessageType));
        }
Example #16
0
        public void InvokeNotifyMessageEvent2(Authentication authentication, User[] users, string message, NotifyMessageType notifyMessageType)
        {
            var target   = users.Any() == false ? "all users" : string.Join(",", users.Select(item => item.ID).ToArray());
            var eventLog = EventLogBuilder.Build(authentication, this, nameof(InvokeNotifyMessageEvent), target, message);
            var comment  = EventMessageBuilder.NotifyMessage(authentication, users, message);

            this.CremaHost.Debug(eventLog);
            this.CremaHost.Info(comment);
            this.OnMessageReceived2(new MessageEventArgs2(authentication, users, message, MessageType.Notification, notifyMessageType));
        }
Example #17
0
        public void NotifyMessage2(Authentication authentication, string[] userIDs, string message, NotifyMessageType notifyMessageType)
        {
            this.Dispatcher.VerifyAccess();
            this.CremaHost.DebugMethod(authentication, this, nameof(NotifyMessage), this, userIDs, message);
            var result = this.service.NotifyMessage(userIDs, message);

            result.Validate(authentication);
            var users = userIDs == null ? new User[] { } : userIDs.Select(item => this.Users[item]).ToArray();

            this.Users.InvokeNotifyMessageEvent2(authentication, users, message, notifyMessageType);
        }