示例#1
0
        public bool HasCommand(UserViewModel target, CommandViewModel cmd, RoomViewModel room)
        {
            if (RoleVM != null && target.RoleVM != null)
            {
                var rcv =  RoleVM.RoleCommandVMs.FirstOrDefault(rc => rc.TargetRoleVM == target.RoleVM && rc.CommandVM == cmd);
                if (rcv != null)
                {
                    if (rcv.IsManagerCommand)
                    {
						return IsRoleInRoom(room, BuiltIns.RoomAdministratorRole);
                    }
                    return true;
                }
            }
            return false;
        }
        public void Login(string userid, string pwd, bool remember, bool autoLogin)
        {
            try
            {
                var mac = Utility.GetMacAddress();

                int r = ApplicationVM.ChatClient.CanUserLogin(int.Parse(userid), mac);
                if (r == 0)
                {
                    User user = ApplicationVM.ChatClient.Login(int.Parse(userid), pwd, mac);
                    if (user != null)
                    {
                        UserViewModel uvm = new UserViewModel(user);
                        uvm.Initialize();
                        ApplicationVM.LocalCache.AllUserVMs.Add(user.Id, uvm);
                        ApplicationVM.LocalCache.CurrentUserVM = uvm;
                        ApplicationVM.HallWindowVM.Notify<UserViewModel>(() => Me);
                        ApplicationVM.IsAuthenticated = true;
                        UpdateLoginInfo(userid, pwd, remember, autoLogin);
                        Notify<bool>(() => IsAuthenticated);
                        CallJavaScript("LoginSucceed");
                    }
                    else
                    {
						CallJavaScript("AlertMessage", Resource.Messages.InvalidToken);
                    }
                }
                else
                {
                    var block = ApplicationVM.Cache.BlockTypes.FirstOrDefault(b => b.Id == r);
					CallJavaScript("AlertMessage", string.Format(Resource.Messages.UserBlocked, block.Name));
                }
            }
            catch
            {
				CallJavaScript("AlertMessage", Resource.Messages.InvalidToken);
            }
        }
示例#3
0
        public void Login(string userid, string pwd, bool remember)
        {
            try
            {
                User user = Singleton<ApplicationViewModel>.Instance.ChatClient.Login(int.Parse(userid), pwd, Utility.GetMacAddress());
                if (user != null)
                {
                    UserViewModel uvm = new UserViewModel(user);
                    uvm.Initialize();
                    ApplicationVM.LocalCache.AllUserVMs.Add(user.Id, uvm);
                    Singleton<ApplicationViewModel>.Instance.LocalCache.CurrentUserVM = uvm;
                    Singleton<ApplicationViewModel>.Instance.HallVM.User = uvm;
                    Messenger.Default.Send<EnumNotificationMessage<object, MainWindowAction>>(new EnumNotificationMessage<object, MainWindowAction>(MainWindowAction.LoginSuccess, uvm));
                }
                else
                {
                    Messenger.Default.Send<EnumNotificationMessage<object, MainWindowAction>>(new EnumNotificationMessage<object, MainWindowAction>(MainWindowAction.LoginFail));
                }
            }
            catch(Exception ex)
            {

            }
        }
 void UserLoggedInEventHandler(User obj)
 {
     if (!ApplicationVM.LocalCache.AllUserVMs.ContainsKey(obj.Id))
     {
         UserViewModel uvm = new UserViewModel(obj);
         ApplicationVM.LocalCache.AllUserVMs.Add(obj.Id, uvm);
     }
     OnlinieUserCount++;
 }
		public VideoWindowViewModel(UserViewModel uvm)
		{
			UserVM = uvm;
		}
 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));
     }
 }
 public void SelectUser(UserViewModel uvm)
 {
     lock (UserVMs)
     {
         if (UserVMs.Contains(uvm))
         {
             SelectedUserVM = uvm;
         }
     }
 }
        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);
                    
                //});
        }
示例#9
0
 private void initUserInfo()
 {
     UserViewModel uvm = new UserViewModel(currentUser);
     uvm.Initialize();
     hallVM.ApplicationVM.LocalCache.AllUserVMs.Add(currentUser.Id, uvm);
     hallVM.ApplicationVM.LocalCache.CurrentUserVM = uvm;
     
 }