Ejemplo n.º 1
0
 private UserViewModel GetUser(int userId)
 {
     lock (UserVMs)
     {
         return UserVMs.FirstOrDefault(u => u.Id == userId);
     }
 }
Ejemplo n.º 2
0
 private void UserEntered(User user, bool notify)
 {
     UserViewModel uvm = null;
     if (!ApplicationVM.LocalCache.AllUserVMs.ContainsKey(user.Id))
     {
         uvm = new UserViewModel(user);
         uvm.Initialize();
         ApplicationVM.LocalCache.AllUserVMs.Add(user.Id, uvm);
     }
     else
     {
         uvm = ApplicationVM.LocalCache.AllUserVMs[user.Id];
         if (!uvm.IsInitialized)
             uvm.Initialize();
     }
     lock (UserVMs)
     {
         uvm.RoomWindowVM = this;
         if (!UserVMs.Contains(uvm))
         {
             UserVMs.Add(uvm);
         }
     }
     if (notify)
     {
         CallJavaScript("UserEntered", uvm.GetJson(false));
     }
 }
Ejemplo n.º 3
0
 public void SelectUser(UserViewModel uvm)
 {
     lock (UserVMs)
     {
         if (UserVMs.Contains(uvm))
         {
             SelectedUserVM = uvm;
         }
     }
 }
Ejemplo n.º 4
0
 public void SelectUser(int userId)
 {
     lock (UserVMs)
     {
         var uvm = UserVMs.FirstOrDefault(u => u.Id == userId);
         if (uvm != null)
         {
             SelectedUserVM = uvm;
         }
     }
 }
Ejemplo n.º 5
0
 public bool CanReceiveGift(int receiverId)
 {
     lock (UserVMs)
     {
         var uvm = UserVMs.FirstOrDefault(u => u.Id == receiverId);
         if (uvm != null)
         {
             return uvm.HasCommand(RoomVM.Id, Applications._9258App.FrontendCommands.ReceiveGiftCommandId, -1);
         }
         return false;
     }
 }
 private void UserLeftRoomEventHandler(int arg1, int arg2)
 {
     lock (UserVMs)
     {
         UserViewModel uvm = UserVMs.FirstOrDefault(u => u.Id == arg2);
         if (uvm != null)
         {
             uvm.DownMic();
             lock (UserVMs)
             {
                 UserVMs.Remove(uvm);
             }
             CallJavaScript("UserLeft", uvm.Id);
         }
     }
 }
Ejemplo n.º 7
0
        public async Task GetUsers()
        {
            HttpResponseMessage response = await client.GetAsync("/api/Paint/GetUsers");

            if (response.IsSuccessStatusCode)
            {
                string json = await response.Content.ReadAsStringAsync();

                List <User> users = JsonConvert.DeserializeObject <List <User> >(json);
                foreach (User u in users)
                {
                    UserVMs.Add(new UserVM(u));
                }
            }
            else
            {
                MessageBox.Show(response.RequestMessage.ToString(), "RequestError");
            }
        }
        private void GiftSentEventHandler(RoomMessage msg, bool broadcastMsg)
        {
            switch (msg.GiftResult)
            {
            case SendGiftResult.Succeed:
                UserViewModel sender   = null;
                UserViewModel receiver = null;
                GiftViewModel gift     = ApplicationVM.LocalCache.AllGiftVMs.FirstOrDefault(g => g.Id == msg.ItemId);
                lock (UserVMs)
                {
                    sender = UserVMs.FirstOrDefault(u => u.Id == msg.SenderId);
                    if (sender == null)     //maybe comes from other room.(e.g. RunWay message)
                    {
                        sender = ApplicationVM.LocalCache.AllUserVMs[msg.SenderId];
                        if (sender != null && !sender.IsInitialized)
                        {
                            sender.Initialize();
                        }
                    }
                    receiver = UserVMs.FirstOrDefault(u => u.Id == msg.ReceiverId);
                    if (receiver == null)
                    {
                        receiver = ApplicationVM.LocalCache.AllUserVMs[msg.ReceiverId];
                        if (receiver != null && !receiver.IsInitialized)
                        {
                            receiver.Initialize();
                        }
                    }
                }
                if (sender != null && receiver != null && gift != null)
                {
                    string header = "<img title='" + sender.RoleVM.Name + "' src='" + sender.ImageVM.StaticImageFile + "'><u style='color:gold;margin-right:10px'><span  onclick='window.external.SelectUser(" + sender.Id + ")'" +
                                    " oncontextmenu='window.external.SelectUser(" + sender.Id + ")'/>" + sender.NickName + "(" + sender.Id + ")" + "</span></u></img> 送给 " +
                                    "<img title='" + receiver.RoleVM.Name + "' src='" + receiver.ImageVM.StaticImageFile + "'><u style='color:purple;margin-left:10px;margin-right:10px'><span onclick='window.external.SelectUser(" + receiver.Id + ")'" +
                                    "oncontextmenu='window.external.SelectUser(" + receiver.Id + ")'/>" + receiver.NickName + "(" + receiver.Id + ")" + "</span></u></img>";
                    string htmlmsg = header;

                    //for horn message
                    if (msg.Count >= gift.RoomBroadCast || msg.Count >= gift.WorldBroadCast)
                    {
                        htmlmsg    += "<span>" + msg.Count + gift.Unit + gift.Name + "<img src='" + gift.ImageVM.DynamicImageFile + "'/></span>";
                        msg.Content = htmlmsg;
                        ShowHornMsg(msg);
                    }

                    //for RunWay message
                    if (msg.Count >= gift.RunWay)
                    {
                        htmlmsg  = string.Empty;
                        htmlmsg += "<img style='margin-left:20px;margin-right:20px;' src='" + gift.ImageVM.DynamicImageFile + "'/>";
                        htmlmsg += header + msg.Count + gift.Unit + gift.Name +
                                   "<span style='color:blue;font-size:18px'>" + msg.Time + "</span>";
                        CallJavaScript("ScrollMessage", htmlmsg);
                    }

                    if (!broadcastMsg)
                    {
                        //for public gift message
                        htmlmsg  = header;
                        htmlmsg += "<span>一" + gift.Unit + gift.Name + "<img src='" + gift.ImageVM.DynamicImageFile + "'/>, 共";
                        CallJavaScript("GiftSent", htmlmsg, msg.Count, gift.Unit);

                        //for private gift message
                        if (Me.Id == msg.ReceiverId)
                        {
                            htmlmsg  = header;
                            htmlmsg += "<span>一" + gift.Unit + gift.Name;
                            JavaScriptSerializer js = new JavaScriptSerializer();
                            CallJavaScript("ShowPrivateChatMessage", htmlmsg, false);
                        }


                        if (Me.Id == msg.SenderId)
                        {
                            Me.Money -= msg.Count * gift.Price;
                            CallJavaScript("InitMe", Me.GetJson(true));
                        }

                        else if (Me.Id == msg.ReceiverId)
                        {
                            Me.Score += msg.Count * gift.Score;
                            CallJavaScript("InitMe", Me.GetJson(true));
                        }
                    }
                }
                break;

            case SendGiftResult.CannotReceiveGift:
            case SendGiftResult.CannotSendGift:
            case SendGiftResult.NotEnoughMoney:
            case SendGiftResult.UnkownError:
                CallJavaScript("AlertMessage", Messages.ResourceManager.GetString(msg.GiftResult.ToString()));
                break;

            default:
                break;
            }
        }
        private void MicStatusMessageReceivedEventHandler(int arg1, MicStatusMessage arg2)
        {
            if (arg1 == RoomVM.Id)
            {
                var uvm = UserVMs.FirstOrDefault(u => u.Id == arg2.UserId);
                if (uvm != null)
                {
                    switch (arg2.MicAction)
                    {
                        #region OnMic

                    case MicAction.OnMic:
                    {
                        switch (arg2.MicType)
                        {
                        case MicType.Public:
                        {
                            switch (arg2.MicIndex)
                            {
                            case 0:
                                FirstMicUserVM = uvm;
                                break;

                            case 1:
                                SecondMicUserVM = uvm;
                                break;

                            case 2:
                                ThirdMicUserVM = uvm;
                                break;
                            }
                        }
                        break;

                        case MicType.Private:
                            if (!PrivateMicUserVMs.Contains(uvm))
                            {
                                PrivateMicUserVMs.Add(uvm);
                            }
                            break;

                        case MicType.Secret:
                            if (!SecretMicUserVMs.Contains(uvm))
                            {
                                SecretMicUserVMs.Add(uvm);
                            }
                            break;

                        default:
                            break;
                        }
                        uvm.OnMic(arg2.MicType, arg2.MicIndex, arg2.StreamGuid, arg2.MicStatus);
                        updateMicImage(uvm.Id, true);
                    }
                    break;

                        #endregion

                        #region DownMic

                    case MicAction.DownMic:
                    {
                        switch (arg2.MicType)
                        {
                        case MicType.Public:
                            switch (arg2.MicIndex)
                            {
                            case 0:
                                FirstMicUserVM = null;
                                break;

                            case 1:
                                SecondMicUserVM = null;
                                break;

                            case 2:
                                ThirdMicUserVM = null;
                                break;
                            }
                            break;

                        case MicType.Private:
                            PrivateMicUserVMs.Remove(uvm);
                            break;

                        case MicType.Secret:
                            SecretMicUserVMs.Remove(uvm);
                            break;
                        }
                    }
                        uvm.DownMic();
                        updateMicImage(uvm.Id, false);
                        break;

                        #endregion

                        #region Toggle

                    case MicAction.Toggle:
                    {
                        uvm.Toggle(arg2.MicStatus);
                    }
                    break;

                        #endregion
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public override void LoadAsync()
        {
            //Task.Factory.StartNew(() =>
            //    {
                    lock (UserVMs)
                    {
                        var users = RoomClient.GetRoomUsers(RoomVM.Id);
                        if (users != null && users.Length > 0)
                        {
                            foreach (var user in users)
                            {
                                UserEntered(user, false);
                            }
                        }
                    }

                    var micUsers = RoomClient.GetMicUsers(RoomVM.Id, MicType.Public);
                    if (micUsers != null && micUsers.Count > 0)
                    {
                        if (micUsers.ContainsKey(0) && micUsers[0].MicStatus != MicStatusMessage.MicStatus_Off)
                        {
                            FirstMicUserVM = UserVMs.FirstOrDefault(u => u.Id == micUsers[0].UserId);
                            FirstMicUserVM.OnMic(MicType.Public, 0, micUsers[0].StreamGuid, micUsers[0].MicStatus);
                            if ((FirstMicUserVM.MicStatus & MicStatusMessage.MicStatus_Audio) != MicStatusMessage.MicStatus_Off)
                            {
                                StartAudioPlaying(FirstMicUserVM.Id);
                            }
                        }
                        if (micUsers.ContainsKey(1) && micUsers[1].MicStatus != MicStatusMessage.MicStatus_Off)
                        {
                            SecondMicUserVM = UserVMs.FirstOrDefault(u => u.Id == micUsers[1].UserId);
                            SecondMicUserVM.OnMic(MicType.Public, 1, micUsers[1].StreamGuid, micUsers[1].MicStatus);
                            if ((SecondMicUserVM.MicStatus & MicStatusMessage.MicStatus_Audio) != MicStatusMessage.MicStatus_Off)
                            {
                                StartAudioPlaying(SecondMicUserVM.Id);
                            }
                        }
                        if (micUsers.ContainsKey(2) && micUsers[2].MicStatus != MicStatusMessage.MicStatus_Off)
                        {
                            ThirdMicUserVM = UserVMs.FirstOrDefault(u => u.Id == micUsers[2].UserId);
                            ThirdMicUserVM.OnMic(MicType.Public, 2, micUsers[2].StreamGuid, micUsers[2].MicStatus);
                            if ((ThirdMicUserVM.MicStatus & MicStatusMessage.MicStatus_Audio) != MicStatusMessage.MicStatus_Off)
                            {
                                StartAudioPlaying(ThirdMicUserVM.Id);
                            }
                        }
                    }


                    micUsers = RoomClient.GetMicUsers(RoomVM.Id, MicType.Private);
                    if (micUsers != null && micUsers.Count > 0)
                    {
                        foreach (var mic in micUsers.Values)
                        {
                            if (mic.MicStatus != MicStatusMessage.MicStatus_Off)
                            {
                                var uvm = UserVMs.FirstOrDefault(u => u.Id == mic.UserId);
                                if (uvm != null)
                                {
                                    PrivateMicUserVMs.Add(uvm);
                                    uvm.OnMic(MicType.Private, mic.MicIndex, mic.StreamGuid, mic.MicStatus);
                                    if ((uvm.MicStatus & MicStatusMessage.MicStatus_Audio) != MicStatusMessage.MicStatus_Off)
                                    {
                                        StartAudioPlaying(uvm.Id);
                                    }
                                }
                            }
                        }
                    }

                    micUsers = RoomClient.GetMicUsers(RoomVM.Id, MicType.Secret);
                    if (micUsers != null && micUsers.Count > 0)
                    {
                        foreach (var mic in micUsers.Values)
                        {
                            if (mic.MicStatus != MicStatusMessage.MicStatus_Off)
                            {
                                var uvm = UserVMs.FirstOrDefault(u => u.Id == mic.UserId);
                                if (uvm != null)
                                {
                                    SecretMicUserVMs.Add(uvm);
                                    uvm.OnMic(MicType.Secret, mic.MicIndex, mic.StreamGuid, mic.MicStatus);
                                    if ((uvm.MicStatus & MicStatusMessage.MicStatus_Audio) != MicStatusMessage.MicStatus_Off)
                                    {
                                        StartAudioPlaying(uvm.Id);
                                    }
                                }
                            }
                        }
                    }

                    RoomMessage msg = RoomClient.GetRoomMessage(RoomMessageType.GiftMessage);
                    if (msg != null)
                    {
                        UserViewModel sender = null;
                        UserViewModel receiver = null;
                        lock (UserVMs)
                        {
                            sender = UserVMs.FirstOrDefault(u => u.Id == msg.SenderId);
                            if (sender == null)
                            {
                                sender = ApplicationVM.LocalCache.AllUserVMs[msg.SenderId];
                                if (sender == null)
                                {
                                    var usr = RoomClient.GetUser(msg.SenderId);
                                    if (usr != null)
                                    {
                                        sender = new UserViewModel(usr);
                                        sender.Initialize();
                                        ApplicationVM.LocalCache.AllUserVMs[msg.SenderId] = sender;
                                    }
                                }
                                else 
                                {
                                    if (!sender.IsInitialized)
                                    {
                                        sender.Initialize();
                                    }
                                }
                            }
                            receiver = UserVMs.FirstOrDefault(u => u.Id == msg.ReceiverId);
                            if (receiver == null)
                            {
                                receiver = ApplicationVM.LocalCache.AllUserVMs[msg.ReceiverId];
                                if (receiver == null)
                                {
                                    var usr = RoomClient.GetUser(msg.ReceiverId);
                                    if (usr != null)
                                    {
                                        receiver = new UserViewModel(usr);
                                        receiver.Initialize();
                                        ApplicationVM.LocalCache.AllUserVMs[msg.ReceiverId] = receiver;
                                    }
                                }
                                else
                                {
                                    if (!receiver.IsInitialized)
                                    {
                                        receiver.Initialize();
                                    }
                                }
                            }
                        }
                        GiftViewModel gift = ApplicationVM.LocalCache.AllGiftVMs.FirstOrDefault(g => g.Id == msg.ItemId);
                        if (sender != null && receiver != null && gift != null)
                        {
                            string header = "<img title='" + sender.RoleVM.Name + "' src='" + sender.ImageVM.StaticImageFile + "'><u style='color:gold;margin-right:10px'><span  onclick='window.external.SelectUser(" + sender.Id + ")'" +
                                       " oncontextmenu='window.external.SelectUser(" + sender.Id + ")'/>" + sender.NickName + "(" + sender.Id + ")" + "</span></u></img> 送给 " +
                                       "<img title='" + receiver.RoleVM.Name + "' src='" + receiver.ImageVM.StaticImageFile + "'><u style='color:purple;margin-left:10px;margin-right:10px'><span onclick='window.external.SelectUser(" + receiver.Id + ")'" +
                                       "oncontextmenu='window.external.SelectUser(" + receiver.Id + ")'/>" + receiver.NickName + "(" + receiver.Id + ")" + "</span></u></img>";
                            string htmlmsg = string.Empty;
                            htmlmsg += "<img style='margin-left:20px;margin-right:20px;' src='" + gift.ImageVM.DynamicImageFile + "'/>";
                            htmlmsg += header + msg.Count + gift.Unit + gift.Name +
                                "<span style='color:blue'>" + msg.Time + "</span>";
                            CallJavaScript("ScrollMessage", htmlmsg);
                        }
                    }

                    XmlLanguage enus = XmlLanguage.GetLanguage("en-us");
                    XmlLanguage zhcn = XmlLanguage.GetLanguage("zh-cn");
                    string fontname = "";
                    foreach (FontFamily fontfamily in Fonts.SystemFontFamilies)
                    {
                        if (fontfamily.FamilyNames.ContainsKey(zhcn))
                        {
                            fontfamily.FamilyNames.TryGetValue(zhcn, out fontname);
                            FontFamilies.Insert(0, fontname);
                        }
                        else if (fontfamily.FamilyNames.ContainsKey(enus))
                        {
                            fontfamily.FamilyNames.TryGetValue(enus, out fontname);
                            FontFamilies.Add(fontname);
                        }
                    }

                    FontSizes.Add(14);
                    FontSizes.Add(16);
                    FontSizes.Add(18);
                    FontSizes.Add(20);
                    FontSizes.Add(22);
                    FontSizes.Add(24);
                    FontSizes.Add(28);
                    FontSizes.Add(32);
                    FontSizes.Add(36);

                    CallJavaScript("InitUsers", UsersJson);
                    CallJavaScript("InitFonts", FontFamiliesJson, FontSizesJson);
                    CallJavaScript("InitStamp", StampImagesJson);
                    for (int i = 0; i < MotionImagesJson.Count; i++)
                    {
                        CallJavaScript("InitFaceTab", MotionImagesJson[i], i == MotionImagesJson.Count - 1);
                    }
                    
                    CallJavaScript("InitMoneyForHorn", ApplicationVM.LocalCache.HornMsgMoney, ApplicationVM.LocalCache.HallHornMsgMoney, ApplicationVM.LocalCache.GlobalHornMsgMoney);

                    int scoreToMoney = 0;
                    if (ApplicationVM.LocalCache.AllExchangeRateVMs.Count > 0)
                    {
                        try
                        {
                            var exchangeVM = ApplicationVM.LocalCache.AllExchangeRateVMs.OrderBy(r => r).Where(r =>
                                Convert.ToDateTime(r.ValidTime) >= (DateTime.Now)).ToList().FirstOrDefault();
                            if (exchangeVM != null)
                            {
                                scoreToMoney = exchangeVM.ScoreToMoney;
                            }
                        }
                        catch (Exception ex)
                        { }
                    }

                    CallJavaScript("InitExchangeRate", scoreToMoney);
                    
                //});
        }