Example #1
0
        public async Task AddOrUpdateTwitchName(ulong guildId, ulong userId, string twitchName)
        {
            var uow = _db.UnitOfWork();

            uow.LiveUsers.UpdateTwitchName(guildId, userId, twitchName);
            await uow.SaveAsync().ConfigureAwait(false);

            var oldLiveUser = LiveUsers.FirstOrDefault(x => x.Key == guildId).FirstOrDefault(x => x.UserId == userId);

            LiveUser liveUser;

            if (oldLiveUser == null)
            {
                liveUser = new LiveUser
                {
                    GuildId    = guildId,
                    UserId     = userId,
                    TwitchName = twitchName
                };
                var liveUsers = LiveUsers.FirstOrDefault(x => x.Key == liveUser.GuildId).ToList();
                LiveUsers.RemoveAll(x => x.Key == liveUser.GuildId);
                liveUsers.Add(liveUser);
                var liveUserGroup = liveUsers.GroupBy(x => x.GuildId).First();
                LiveUsers.Add(liveUserGroup);
            }
            else
            {
                liveUser            = oldLiveUser;
                liveUser.TwitchName = twitchName;
            }
        }
Example #2
0
 private void SetUpAllStreamers()
 {
     try
     {
         var liveUsers   = new List <LiveUser>();
         var uow         = _db.UnitOfWork();
         var liveUsersDb = uow.LiveUsers.GetAll();
         foreach (var liveUserDb in liveUsersDb)
         {
             var liveUser = new LiveUser
             {
                 GuildId            = liveUserDb.GuildId,
                 UserId             = liveUserDb.UserId,
                 TwitchName         = liveUserDb.TwitchName,
                 PriorityUser       = liveUserDb.PriorityUser,
                 TwitchAlert        = liveUserDb.TwitchAlert,
                 IsStreaming        = liveUserDb.IsStreaming,
                 LastStreamed       = liveUserDb.LastStreamed,
                 StreamStateChanged = false,
                 HasRole            = liveUserDb.HasRole
             };
             liveUsers.Add(liveUser);
         }
         LiveUsers = liveUsers.GroupBy(x => x.GuildId).ToList();
     }
     catch (Exception ex)
     {
         AegisLog.Log(ex.Message, ex);
         return;
     }
     HasInit = true;
 }
Example #3
0
 public JsonResult SendFeed(LiveUser user)
 {
     Thread.Sleep(2000);
     if (ModelState.IsValid)
     {
         _emailSender.SendMail(user.UserName, user.FeedMessage, "Консультант:Сообщение с сайта!", user.Email);
         return(Json("Ok"));
     }
     throw new HttpException();
 }
        public void AddOrUpdateByLiveUser(LiveUser liveUser)
        {
            var liveUserDb = GetByGuildIdUserId(liveUser.GuildId, liveUser.UserId);

            liveUserDb.TwitchName   = liveUser.TwitchName;
            liveUserDb.PriorityUser = liveUser.PriorityUser;
            liveUserDb.TwitchAlert  = liveUser.TwitchAlert;
            liveUserDb.IsStreaming  = liveUser.IsStreaming;
            liveUserDb.LastStreamed = liveUser.LastStreamed;
            liveUserDb.HasRole      = liveUser.HasRole;
            _dbset.Update(liveUserDb);
        }
Example #5
0
        public async Task <ReturnMessage> interpretInput(string query)
        {
            try
            {
                var      inputData = JsonConvert.DeserializeObject <LiveLocationMessage>(query);
                LiveUser liveUser  = null;

                if ((liveUser = ZoneDB.LiveUser
                                .Where(c => c.UserID == inputData.UserID).SingleOrDefault()) == null)
                {
                    liveUser = new LiveUser()
                    {
                        UserID = Guid.NewGuid()
                    };
                    ZoneDB.LiveUser.Add(liveUser);
                }
                if (inputData.Location != null)
                {
                    ZoneDB.LiveLocation.Add(new LiveLocation
                    {
                        UserID  = liveUser.UserID,
                        GeoJson = inputData.Location
                    });
                }
                await ZoneDB.SaveChangesAsync();

                return(new ReturnMessage()
                {
                    Weather = "In development",
                    UserID = liveUser.UserID
                });
            }
            catch (Exception e)
            {
                throw new ArgumentException("Invalid user id or location");
            }
        }
Example #6
0
        public void Send(string message, string connId)
        {
            if (message.Contains("<script>"))
            {
                throw new HubException("Некорректное сообщение", new { user = Context.User.Identity.Name, message = message });
            }
            if (string.IsNullOrWhiteSpace(message))
            {
                //Clients.Caller.ShowErrorMessage("Пустое сообщение!");
                throw new HubException("Пустое сообщение!", new { user = Context.User.Identity.Name, message = message });
            }
            else
            {
                var mess   = HttpUtility.HtmlEncode(message);
                var connid = HttpUtility.HtmlEncode(connId);

                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    LiveUser user       = null;
                    LiveUser user1      = null;
                    LiveUser dialogUser = null;
                    user1      = db.LiveUsers.SingleOrDefault(x => x.IsAdmin);
                    user       = db.LiveUsers.SingleOrDefault(x => x.ConnId == connid);
                    dialogUser = db.LiveUsers.SingleOrDefault(x => x.ConnId == user1.GroupId);
                    // Тест работы виджета
                    //

                    //Clients.Client(user1.ConnId).Test(user1.GroupId, user1.ConnId, connid);
                    if (!Context.User.IsInRole("admin"))
                    {
                        //Сообщение пользователя
                        //

                        if (user.ConnId == user1.GroupId)
                        {
                            //Прямой диалог
                            //
                            var newM = new Message()
                            {
                                TextMess  = mess,
                                DateAdded = DateTime.Now,
                                Visited   = true,
                                UserID    = user.UserID
                            };
                            user.LiveMessages.Add(newM);
                        }
                        else
                        {
                            //Сообщение в очередь
                            //
                            var newM = new Message()
                            {
                                TextMess  = mess,
                                DateAdded = DateTime.Now,
                                Visited   = false,
                                UserID    = user.UserID
                            };
                            user.LiveMessages.Add(newM);
                            db.SaveChanges();
                            var newQuestions = db.LiveUsers.Where(x => x.LiveMessages.Any(y => !y.Visited)).Count();
                            Clients.Client(user1.ConnId)
                            .NotifyNewQuestion(user.UserName, user.LiveMessages.Where(x => !x.Visited).Count(),
                                               user.ConnId, newQuestions);
                        }

                        db.SaveChanges();
                        //Публикуем сообщение в группу пользователя
                        //
                        Clients.Group(user.ConnId).AddNewMessageToPage(DateTime.Now.ToString("dd MMM, hh:mm"),
                                                                       user.UserName, mess, false);
                    }
                    else
                    {
                        if (!db.LiveUsers.Any(x => x.ConnId == user1.GroupId))
                        {
                            throw new HubException("Вас никто не видит", new { user = Context.User.Identity.Name, message = message });
                        }
                        else
                        {
                            //Публикуем сообщение консультанта
                            //

                            Clients.Group(user1.GroupId).AddNewMessageToPage(DateTime.Now.ToString("dd MMM, hh:mm"),
                                                                             "Консультант", mess, true);
                            Clients.Client(dialogUser.ConnId).NotifyAdmAnswear();
                        }
                    }
                }
            }
        }
Example #7
0
        public JsonResult AllowUser(LiveUser user, string connId)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                if (User.IsInRole("admin"))
                {
                    var user2 = db.LiveUsers.SingleOrDefault(x => x.IsAdmin);
                    user2.ConnId   = connId;
                    user2.IsOnline = true;
                    db.SaveChanges();
                    return(Json(new { usersOnline = db.LiveUsers.Count() - 1, id = connId }));
                }
            }
            if (ModelState.IsValid)
            {
                if (user.UserName == null || user.Email == null)
                {
                    throw new HttpException();
                }
                System.Threading.Thread.Sleep(2500);

                LiveUser user1 = null;
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    user1             = new LiveUser();
                    user1.FeedMessage = "txt";
                    user1.UserName    = user.UserName;
                    user1.Email       = user.Email;
                    user1.IsAdmin     = false;
                    user1.IsOnline    = true;
                    user1.ConnId      = connId;
                    //user1.LiveMessages = new List<Message>();
                    db.LiveUsers.Add(user1);
                    db.SaveChanges();
                }
                HttpCookie cookie  = Request.Cookies["_LiveChat-username"];
                HttpCookie cookie1 = Request.Cookies["_LiveChat-email"];

                if (cookie != null && cookie1 != null)
                {
                    cookie.Value  = user.UserName;
                    cookie1.Value = user.Email;
                    Response.Cookies.Add(cookie);
                    Response.Cookies.Add(cookie1);
                }
                else
                {
                    cookie          = new HttpCookie("_LiveChat-username");
                    cookie.Value    = user.UserName;
                    cookie.Expires  = DateTime.Now.AddYears(1);
                    cookie1         = new HttpCookie("_LiveChat-email");
                    cookie1.Value   = user.Email;
                    cookie1.Expires = DateTime.Now.AddYears(1);

                    Response.Cookies.Add(cookie);
                    Response.Cookies.Add(cookie1);
                }
                return(Json(new { Name = user.UserName, Email = user.Email }));
            }
            throw new HttpException();
        }