Ejemplo n.º 1
0
 public static async Task sendChatToAll(ChatNotification chat)
 {
     foreach (LobbyServerConnection con in ConnectedClients)
     {
         await con.SendMessage(chat);
     }
 }
        public ActionResult DeleteConfirmed(int id)
        {
            ChatNotification chatNotification = db.ChatNotifications.Find(id);

            db.ChatNotifications.Remove(chatNotification);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public async Task OnMessage(LobbyServerConnection connection, object requestData)
        {
            ChatNotification notification = (ChatNotification)requestData;
            //notification.SenderAccountId = connection.PlayerInfo.GetAccountId();
            //notification.SenderHandle = connection.PlayerInfo.GetHandle();

            await LobbyServer.sendChatAsync(notification, connection);
        }
Ejemplo n.º 4
0
 private async Task Send_ChatConnectedNotification(ClientConnection connection)
 {
     ChatNotification connectedMessage = new ChatNotification()
     {
         Text = $"{connection.UserName} has connected", ConsoleMessageType = ConsoleMessageType.SystemMessage
     };
     await Program.sendChatToAll(connectedMessage);
 }
Ejemplo n.º 5
0
        public async Task OnMessage(ClientConnection connection, object requestData)
        {
            ChatNotification notification = (ChatNotification)requestData;

            notification.SenderAccountId = connection.AccountId;
            notification.SenderHandle    = connection.UserName;

            await LobbyServer.Program.sendChatAsync(notification, connection);
        }
Ejemplo n.º 6
0
        public bool  EnqueueChatNotification(ChatNotification chatNotification)
        {
            bool   result       = false;
            string notification = JsonConvert.SerializeObject(chatNotification);
            string queueName    = ConfigurationManager.AppSettings["azure-queue-chatnotification"];

            QueueManager.InsertMessage(notification, queueName);
            result = true;
            return(result);
        }
Ejemplo n.º 7
0
        private void SendNewMessageNotification(Message message)
        {
            object inAppNotificationWithButtonsTemplate = null;
            bool?  isTemplatePresent = Resources.TryGetValue("InAppNotificationWithButtonsTemplate", out inAppNotificationWithButtonsTemplate);

            if (isTemplatePresent == true && inAppNotificationWithButtonsTemplate is DataTemplate template)
            {
                Messaging.ReceivedMessage = message.Preview();
                ChatNotification.Show(template, 10_000);
            }
        }
 public ActionResult Edit([Bind(Include = "Id,ChatId,RecipientId,SenderId,Created,Subject,NotificationBody,Read")] ChatNotification chatNotification)
 {
     if (ModelState.IsValid)
     {
         db.Entry(chatNotification).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.RecipientId = new SelectList(db.Users, "Id", "FirstName", chatNotification.RecipientId);
     ViewBag.SenderId    = new SelectList(db.Users, "Id", "FirstName", chatNotification.SenderId);
     return(View(chatNotification));
 }
Ejemplo n.º 9
0
 public void UpdateChatNotification(Message message, string sender)
 {
     using (ApplicationDbContext db = new ApplicationDbContext())
     {
         ChatNotification chatNot = db.ChatNotifications.FirstOrDefault(x => x.ChatId == message.ChatId);
         chatNot.MessageId  = message.Id;
         chatNot.senderName = sender;
         db.ChatNotifications.Attach(chatNot);
         db.Entry(chatNot).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Ejemplo n.º 10
0
        public void AddChatNotification(int chatId)
        {
            ChatNotification chatNotification = new ChatNotification
            {
                ChatId = chatId,
            };

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                db.ChatNotifications.Add(chatNotification);
                db.SaveChanges();
            }
        }
Ejemplo n.º 11
0
 public virtual bool sendMessage(UserAccount user, string messageBody)
 {
     if (messageBody == "")
     {
         throw new ArgumentException("messageBody");
     }
     if (messageBody == null)
     {
         throw new ArgumentNullException("messageBody");
     }
     ChatNotification?.Invoke(this, ChatEvents.message);
     return(true);
 }
        // GET: ChatNotifications/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChatNotification chatNotification = db.ChatNotifications.Find(id);

            if (chatNotification == null)
            {
                return(HttpNotFound());
            }
            return(View(chatNotification));
        }
        // GET: ChatNotifications/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChatNotification chatNotification = db.ChatNotifications.Find(id);

            if (chatNotification == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RecipientId = new SelectList(db.Users, "Id", "FirstName", chatNotification.RecipientId);
            ViewBag.SenderId    = new SelectList(db.Users, "Id", "FirstName", chatNotification.SenderId);
            return(View(chatNotification));
        }
        public ActionResult Create([Bind(Include = "Id,ChatId,RecipientId,SenderId,Created,Subject,NotificationBody,Read")] ChatNotification chatNotification)
        {
            if (ModelState.IsValid)
            {
                db.ChatNotifications.Add(chatNotification);
                db.SaveChanges();


                //ChatNotificationHelper.ChatNotify(chatNotification);

                return(RedirectToAction("Index"));
            }

            ViewBag.RecipientId = new SelectList(db.Users, "Id", "FirstName", chatNotification.RecipientId);
            ViewBag.SenderId    = new SelectList(db.Users, "Id", "FirstName", chatNotification.SenderId);
            return(View(chatNotification));
        }
Ejemplo n.º 15
0
        public static void  GenerateNewChatNotification(ChatNotification chatnotification)
        {
            var notification = new ChatNotification
            {
                Created          = DateTime.Now,
                Subject          = $"You are requested to come to chat room on {DateTime.Now}",
                Read             = false,
                RecipientId      = chatnotification.RecipientId,
                SenderId         = HttpContext.Current.User.Identity.GetUserId(),
                NotificationBody = $"Mark Read, if you have read this notification",
                ChatId           = chatnotification.ChatId
            };


            db.ChatNotifications.Add(notification);
            db.SaveChanges();
        }
        private void ReceiveStatusResponse(byte[] body)
        {
            Log.Trace("Receiving Reveal Response", "ReceiveRevealResponse");

            StatusResponse response = StatusResponse.FromBytes(body);

            String result = "Server is ";

            result += response.ServerRunning ? "Running." : "Terminated.";

            Notification notice = new ChatNotification()
            {
                Text   = result,
                Sender = "GP"
            };

            notice.Raise();
        }
        private void ReceiveChangeSettingResponse(byte[] body)
        {
            Log.Trace("Receiving Reveal Response", "ReceiveRevealResponse");

            ChangeSettingResponse response = ChangeSettingResponse.FromBytes(body);

            String result = response.Success ?
                            "Successfully changed setting" :
                            "Failed to change setting (not yet implemented)";

            Notification notice = new ChatNotification()
            {
                Text   = result,
                Sender = "GP"
            };

            notice.Raise();
        }
        private void ReceiveRevealResponse(byte[] body)
        {
            Log.Trace("Receiving Reveal Response", "ReceiveRevealResponse");

            RevealResponse response = RevealResponse.FromBytes(body);

            String result = response.Success ?
                            "Successfully queued for reveal" :
                            "Failed to reveal";

            result += " grid " + response.EntityId;

            Notification notice = new ChatNotification()
            {
                Text   = result,
                Sender = "GP"
            };

            notice.Raise();
        }
Ejemplo n.º 19
0
        public void ProcessChatNotification(string message, Dictionary <string, int> userPriority)
        {
            try
            {
                // Obtenemos la notificacion de la queue: notifications
                ChatNotification chatNotification = JsonConvert.DeserializeObject <ChatNotification>(message);


                //Aumentamos la prioridad del usuario
                int Priority = AddUserIfNotExist(userPriority, new Guid(chatNotification.idUser));

                // Encolamos la notificacion al topic de service bus
                // para que tambien llegue en tiempo real
                dynamic data = chatNotification;
                sbmanager.SendMessageAsync(Priority, data, new Guid(chatNotification.idUser), chatNotification.label);
            }
            catch (Exception e)
            {
                var messageException = telemetry.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name);
                telemetry.Critical(messageException);
            }
        }
Ejemplo n.º 20
0
        public static void ChatNotify(ChatNotification chatnotification)

        {
            if (chatnotification.SenderId != chatnotification.RecipientId)

            {
                var notification = new ChatNotification

                {
                    Created = DateTime.Now,

                    NotificationBody = db.Users.Find(chatnotification.SenderId).FullName + " invited to chat room ",

                    SenderId = chatnotification.RecipientId,

                    ChatId = chatnotification.ChatId
                };

                db.ChatNotifications.Add(notification);

                db.SaveChanges();
            }
        }
Ejemplo n.º 21
0
        public static async Task sendChatAsync(ChatNotification chat, LobbyServerConnection sender)
        {
            switch (chat.ConsoleMessageType)
            {
            case ConsoleMessageType.GlobalChat:
                sendChatToAll(chat);
                break;

            case ConsoleMessageType.WhisperChat:
                await sender.SendMessage(chat);

                LobbyServerConnection recipient = GetPlayerByHandle(chat.RecipientHandle);
                if (recipient != null)
                {
                    await recipient.SendMessage(chat);
                }
                break;

            default:
                Log.Print(LogType.Warning, $"Unhandled chat type: {chat.ConsoleMessageType.ToString()}");
                break;
            }
        }
Ejemplo n.º 22
0
 /// <summary>
 /// When the user sends a message to chat
 /// </summary>
 /// <param name="notification"></param>
 /// <returns></returns>
 public async static Task OnChat(LobbyServerConnection client, ChatNotification notification)
 {
     await new ChatNotificationHandler().OnMessage(client, notification);
 }
Ejemplo n.º 23
0
 protected virtual void OnDestroy()
 {
     ChatNotification?.Invoke(this, ChatEvents.delete);
 }