public void Can_Add_Items_To_Cache() { // Arrange ICache<string, object> cache = new AppCache(2); var key1 = "key1"; var key2 = "key2"; var val1 = 1; var val2 = 2; // Act cache.AddOrUpdate(key1, val1); cache.AddOrUpdate(key2, val2); object actual1; cache.TryGetValue(key1, out actual1); object actual2; cache.TryGetValue(key2, out actual2); // Assert cache.Count.Should().Be(2); actual1.Should().Be(val1); actual2.Should().Be(val2); }
public void Can_Not_Overflow_Cache_Count() { ICache<string, object> cache = new AppCache(3); cache.AddOrUpdate("1", 1); cache.AddOrUpdate("2", 2); cache.AddOrUpdate("3", 3); cache.AddOrUpdate("4", 4); cache.Count.Should().Be(3); }
private void CreateClass() { if (GlobalData.Instance.ConfigManager?.AudioInfo?.AudioSammpleDevice == null) { MessageQueueManager.Instance.AddError(MessageManager.NoAudioDevice); return; } if (string.IsNullOrEmpty(GlobalData.Instance.ConfigManager?.MainVideoInfo?.VideoDevice)) { MessageQueueManager.Instance.AddError(MessageManager.NoVideoDevice); return; } var invitees = from classroom in Classrooms where classroom.Selected select new MeetingSdk.Wpf.Participant(new AccountModel(int.Parse(classroom.Classroom.SchoolRoomNum), classroom.Classroom.SchoolRoomName)); AppCache.AddOrUpdate(CacheKey.Invitees, invitees); AppCache.AddOrUpdate(CacheKey.HostId, _windowManager.Participant.Account.AccountId); var intoClassView = new IntoClassView(IntoClassType.Create); intoClassView.Show(); _createClassView.Close(); }
private void JoinMeeting() { var currentWindow = Application.Current.Windows; var window = currentWindow[0]; //判断当前是否在课堂中 if (window is IntoClassView) { MessageQueueManager.Instance.AddError("已经在课堂中"); return; } //预约会议 var course = DoUpdateCurriculumMeetingN0(GlobalData.Instance.Courses); AppCache.AddOrUpdate(CacheKey.MeetingId, course.MeetingId); GlobalData.Instance.Course = course; //判断该课堂视讯号与当前登录人的视讯号是否相同,如果相同,设置为主讲 var mainclassroom = GlobalData.Instance.Classrooms.ToList().FirstOrDefault(o => o.Id == course.MainClassroomId.ToString()); if (mainclassroom != null) { AppCache.AddOrUpdate(CacheKey.HostId, mainclassroom.SchoolRoomNum); } var intoClassView = new IntoClassView(IntoClassType.Join); intoClassView.Show(); window?.Close(); }
public void Eviction_Policy_Evicts_Item2() { ICache<string, object> cache = new AppCache(3); object item1Result; object item2Result; cache.AddOrUpdate("1", 1); cache.AddOrUpdate("2", 2); cache.AddOrUpdate("3", 3); cache.TryGetValue("1", out item1Result); cache.AddOrUpdate("4", 4); cache.TryGetValue("2", out item2Result); item2Result.Should().BeNull(); cache.Count.Should().Be(3); }
public void Cannot_Add_Item_With_Null_Key() { var cache = new AppCache(5); Action action = () => cache.AddOrUpdate(null, 5); action.Should().Throw<ArgumentException>(); }
private async void IntoBtn_OnClick(object sender, RoutedEventArgs e) { var btn = (Button)sender; var course = (Course)btn.Tag; AppCache.AddOrUpdate(CacheKey.MeetingId, course.MeetingId); GlobalData.Instance.Course = course; //判断该课堂视讯号与当前登录人的视讯号是否相同,如果相同,设置为主讲 var mainclassroom = GlobalData.Instance.Classrooms.ToList().FirstOrDefault(o => o.Id == course.MainClassroomId.ToString()); if (mainclassroom != null) { AppCache.AddOrUpdate(CacheKey.HostId, mainclassroom.SchoolRoomNum); } var intoClassView = new IntoClassView(IntoClassType.Join); intoClassView.Show(); var meetingInfoResult = await _meetingService.GetMeetingInfo(course.MeetingId); var meetingList = _localDataManager.GetMeetingList() ?? new MeetingList() { MeetingInfos = new List <MeetingItem>() }; var cachedMeeting = meetingList.MeetingInfos.FirstOrDefault(meeting => meeting.MeetingId == course.MeetingId); if (cachedMeeting != null) { cachedMeeting.LastActivityTime = DateTime.Now; } else { meetingList.MeetingInfos.Add(new MeetingItem() { LastActivityTime = DateTime.Now, MeetingId = course.MeetingId, CreatorName = mainclassroom?.SchoolRoomName, IsClose = false, CreatorId = mainclassroom?.SchoolRoomNum, CreateTime = DateTime.Parse(meetingInfoResult.Result.StartTime), }); } _localDataManager.SaveMeetingList(meetingList); _view.Close(); }
public void Should_Not_Collided_When_Adding_Same_Key_From_Multiple_Treads() { ICache<string, object> cache = new AppCache(3); Task[] tasks = new Task[100]; for (var i = 0; i < 100; i++) { tasks[i] = Task.Run(() => { cache.AddOrUpdate("1", 1); Thread.Sleep(10); }); } Task.WaitAll(tasks); cache.Count.Should().Be(1); }
private async void WindowKeyDownHandler(object obj) { try { var keyEventArgs = obj as KeyEventArgs; switch (keyEventArgs?.Key) { case Key.Return: if (BtnEnable) { var reuslt = await _meetingService.IsMeetingExist(_meetingId); if (reuslt.StatusCode != 0) { MessageQueueManager.Instance.AddError(MessageManager.MeetingNoExistError); return; } var meetingList = _localDataManager.GetMeetingList() ?? new MeetingList() { MeetingInfos = new List <MeetingItem>() }; var localMeeting = meetingList.MeetingInfos.FirstOrDefault(o => o.MeetingId == _meetingId); var meeting = GlobalData.Instance.MeetingList?.FirstOrDefault(o => o.MeetingId == _meetingId); if (localMeeting == null && meeting != null) { meetingList.MeetingInfos.Add(new MeetingItem() { LastActivityTime = DateTime.Now, MeetingId = _meetingId, IsClose = false, CreatorId = meeting.Account.AccountId.ToString(), CreateTime = DateTime.Parse(meeting.StartTime), CreatorName = GlobalData.Instance.Classrooms.FirstOrDefault(cls => cls.SchoolRoomNum == meeting.HostId.ToString())?.SchoolRoomName, }); AppCache.AddOrUpdate(CacheKey.HostId, meeting.Account.AccountId); } else { if (localMeeting != null) { localMeeting.LastActivityTime = DateTime.Now; AppCache.AddOrUpdate(CacheKey.HostId, localMeeting?.CreatorId); } } _localDataManager.SaveMeetingList(meetingList); //此处跳转到课堂窗口 AppCache.AddOrUpdate(CacheKey.MeetingId, _meetingId); GlobalData.Instance.Course = new Course(); var intoClassView = new IntoClassView(IntoClassType.Join); intoClassView.Show(); _view.Close(); } keyEventArgs.Handled = true; break; case Key.Left: keyEventArgs.Handled = true; break; case Key.PageUp: InputSimulatorManager.Instance.InputSimu.Keyboard.ModifiedKeyStroke(VirtualKeyCode.SHIFT, VirtualKeyCode.TAB); break; case Key.PageDown: InputSimulatorManager.Instance.InputSimu.Keyboard.KeyPress(VirtualKeyCode.TAB); break; } } catch (Exception ex) { Log.Logger.Error($"加入课堂监听键盘事件发生异常 exception:{ex}"); } }
private async void ShareAsync() { if (_isProcessingShareOperation) { ShareToggleItem.IsChecked = !ShareToggleItem.IsChecked; return; } if (!_isProcessingShareOperation) { _isProcessingShareOperation = true; } try { MeetingResult <IList <VideoDeviceModel> > videoDeviceResult = _meetingService.GetVideoDevices(); MeetingResult <IList <string> > micResult = _meetingService.GetMicrophones(); ConfigManager configManager = _localDataManager.GetSettingConfigData(); IEnumerable <string> docCameras; if (!_deviceNameAccessor.TryGetName(DeviceName.Camera, (devName) => { return(devName.Option == "second"); }, out docCameras) || !videoDeviceResult.Result.Any(vdm => vdm.DeviceName == docCameras.FirstOrDefault())) { ShareToggleItem.IsChecked = false; MessageQueueManager.Instance.AddError("课件摄像头未配置!"); return; } if (configManager.DocVideoInfo?.DisplayWidth == 0 || configManager.DocVideoInfo?.DisplayHeight == 0 || configManager.DocVideoInfo?.VideoBitRate == 0) { ShareToggleItem.IsChecked = false; MessageQueueManager.Instance.AddError("课件采集参数未设置!"); return; } IEnumerable <string> docMics; if (!_deviceNameAccessor.TryGetName(DeviceName.Microphone, (devName) => { return(devName.Option == "second"); }, out docMics) || !micResult.Result.Any(mic => mic == docMics.FirstOrDefault())) { ShareToggleItem.IsChecked = false; MessageQueueManager.Instance.AddError("课件麦克风未配置!"); return; } if (!_windowManager.Participant.IsSpeaking) { ShareToggleItem.IsChecked = false; MessageQueueManager.Instance.AddError("发言状态才可以进行课件分享!"); return; } if (ShareToggleItem.IsChecked) { MeetingResult <int> publishDocCameraResult = await _windowManager.Publish(MeetingSdk.NetAgent.Models.MediaType.VideoDoc, docCameras.FirstOrDefault()); MeetingResult <int> publishDocMicResult = await _windowManager.Publish(MeetingSdk.NetAgent.Models.MediaType.AudioDoc, docMics.FirstOrDefault()); if (publishDocCameraResult.StatusCode != 0 || publishDocMicResult.StatusCode != 0) { ShareToggleItem.IsChecked = false; MessageQueueManager.Instance.AddError("打开课件失败!"); return; } AppCache.AddOrUpdate(CacheKey.DocVideoResourceId, publishDocCameraResult.Result); AppCache.AddOrUpdate(CacheKey.DocAudioResourceId, publishDocMicResult.Result); AppCache.AddOrUpdate(CacheKey.IsDocOpen, true); } else { object docCameraResourceIdObj = AppCache.TryGet(CacheKey.DocVideoResourceId); int docCameraResourceId; if (docCameraResourceIdObj == null || !int.TryParse(docCameraResourceIdObj.ToString(), out docCameraResourceId)) { return; } object docAudioResourceIdObj = AppCache.TryGet(CacheKey.DocAudioResourceId); int docAudioResourceId; if (docAudioResourceIdObj == null || !int.TryParse(docAudioResourceIdObj.ToString(), out docAudioResourceId)) { return; } MeetingResult stopShareCameraResult = await _windowManager.Unpublish(MeetingSdk.NetAgent.Models.MediaType.VideoDoc, docCameraResourceId); MeetingResult stopShareMicResult = await _windowManager.Unpublish(MeetingSdk.NetAgent.Models.MediaType.AudioDoc, docAudioResourceId); if (stopShareCameraResult.StatusCode != 0 || stopShareMicResult.StatusCode != 0) { ShareToggleItem.IsChecked = true; MessageQueueManager.Instance.AddError("关闭课件失败!"); return; } //CheckClassModeAsync(ModeDisplayerType.InteractionMode); AppCache.AddOrUpdate(CacheKey.IsDocOpen, false); } CheckClassMode(); } catch (Exception) { } finally { _isProcessingShareOperation = false; } }
public async void JoinClass(string classNo) { //1.判断课堂号是否存在 try { if (string.IsNullOrEmpty(classNo)) { MessageQueueManager.Instance.AddError("请输入课堂号!"); return; } int meetingId; var isNumber = int.TryParse(classNo, out meetingId); if (!isNumber) { MessageQueueManager.Instance.AddError(MessageManager.MeetingNoExistError); } else { if (meetingId <= 0) { MessageQueueManager.Instance.AddError(MessageManager.MeetingNoExistError); return; } //判断课堂是否存在 var reuslt = await _meetingService.IsMeetingExist(meetingId); if (reuslt.StatusCode != 0) { MessageQueueManager.Instance.AddError(MessageManager.MeetingNoExistError); } else { var meetingList = _localDataManager.GetMeetingList() ?? new MeetingList() { MeetingInfos = new List <MeetingItem>() }; var localMeeting = meetingList.MeetingInfos.FirstOrDefault(o => o.MeetingId == meetingId); var meeting = GlobalData.Instance.MeetingList?.FirstOrDefault(o => o.MeetingId == meetingId); if (localMeeting == null && meeting != null) { meetingList.MeetingInfos.Add(new MeetingItem() { LastActivityTime = DateTime.Now, MeetingId = meetingId, IsClose = false, CreatorId = meeting.Account.AccountId.ToString(), CreateTime = DateTime.Parse(meeting.StartTime), CreatorName = GlobalData.Instance.Classrooms.FirstOrDefault(cls => cls.SchoolRoomNum == meeting.HostId.ToString())?.SchoolRoomName, }); AppCache.AddOrUpdate(CacheKey.HostId, meeting.Account.AccountId); } else { if (localMeeting != null) { localMeeting.LastActivityTime = DateTime.Now; AppCache.AddOrUpdate(CacheKey.HostId, localMeeting?.CreatorId); } else { MeetingResult <MeetingModel> meetingModelResult = await _meetingService.GetMeetingInfo(meetingId); meeting = meetingModelResult.Result; meetingList.MeetingInfos.Add(new MeetingItem() { LastActivityTime = DateTime.Now, MeetingId = meetingId, IsClose = false, CreatorId = meeting.Account.AccountId.ToString(), CreateTime = DateTime.Parse(meeting.StartTime), CreatorName = GlobalData.Instance.Classrooms.FirstOrDefault(cls => cls.SchoolRoomNum == meeting.HostId.ToString())?.SchoolRoomName, }); AppCache.AddOrUpdate(CacheKey.HostId, meetingModelResult.Result.HostId); } } _localDataManager.SaveMeetingList(meetingList); //进入课堂 AppCache.AddOrUpdate(CacheKey.MeetingId, meetingId); GlobalData.Instance.Course = new Course(); var intoClassView = new IntoClassView(IntoClassType.Join); intoClassView.Show(); txt_classNo.Text = string.Empty; _view.Close(); } } } catch (Exception ex) { Log.Logger.Error($"加入课堂发生异常 exception:{ex}"); MessageQueueManager.Instance.AddError(MessageManager.JoinClassError); } }
public void _meetingManagerService_InvitationReceivedEvent(MeetingInvitationModel invitation) { Application.Current.Dispatcher.BeginInvoke(new Action(async() => { string creatorName; var currentWindows = Application.Current.Windows; Window window = currentWindows[0]; if (_exitDialog != null) { return; } var trueInvitor = GlobalData.Instance.Classrooms.FirstOrDefault(o => o.SchoolRoomNum == invitation.SenderId.ToString()); var inClass = false; //判断是否再课堂中,如果在课堂中,需要判断新邀请与当前课堂是否是同一个,如果是,则不需要处理,否则退出当前课堂,进入新课堂 int curMeetingId; object curMeetingIdObj = AppCache.TryGet(CacheKey.MeetingId); if (curMeetingIdObj != null && int.TryParse(curMeetingIdObj.ToString(), out curMeetingId)) { if (curMeetingId == invitation.MeetingId) { return; } //在课堂中 _exitDialog = new Dialog($"您当前正在课堂中,是否要结束当前课堂,加入到新课堂?", "加入新课堂", "留在当前课堂"); inClass = true; } else { _exitDialog = new Dialog($"{trueInvitor?.SchoolRoomName},邀请您听课", "去听课", "稍后"); } var result = _exitDialog.ShowDialog(); if (!result.HasValue || !result.Value) { return; } bool isSettingsValid = DeviceSettingsChecker.Instance.IsVideoAudioSettingsValid(window); if (!isSettingsValid) { return; } //判断课堂是否存在 var reuslt = await _meetingSdkAgent.IsMeetingExist(invitation.MeetingId); if (reuslt.StatusCode != 0) { MessageQueueManager.Instance.AddError(MessageManager.MeetingNoExistError); return; } if (inClass) { //退出当前课堂 //var clearResult = await ClearMeeting(); //if (!clearResult) //{ // MessageQueueManager.Instance.AddError(MessageManager.ExitMeetingError); // return; //} var exitMessage = await _meetingSdkAgent.LeaveMeeting(); await _windowManager.Leave(); if (exitMessage.StatusCode != 0) { MessageQueueManager.Instance.AddError(MessageManager.ExitMeetingError); return; } } var meetingList = _localDataManager.GetMeetingList() ?? new MeetingList() { MeetingInfos = new List <MeetingItem>() }; var localMeetingInfo = meetingList.MeetingInfos.FirstOrDefault(o => o.MeetingId == invitation.MeetingId); string createTime = string.Empty; if (localMeetingInfo != null && localMeetingInfo.CreatorId == GlobalData.Instance.Classroom.SchoolRoomNum) { createTime = localMeetingInfo.CreateTime.ToString(); AppCache.AddOrUpdate(CacheKey.HostId, GlobalData.Instance.Classroom.SchoolRoomNum); creatorName = GlobalData.Instance.Classroom.SchoolRoomName; } else { MeetingResult <MeetingModel> meetingInfo = await _meetingSdkAgent.GetMeetingInfo(invitation.MeetingId); if (meetingInfo.StatusCode != 0) { MessageQueueManager.Instance.AddError("获取会议信息时出错!"); return; } if (meetingInfo.Result.MeetingType == MeetingType.DatedMeeting && meetingInfo.Result.HostId == 0) { } AppCache.AddOrUpdate(CacheKey.HostId, meetingInfo.Result.HostId); createTime = meetingInfo.Result.StartTime; creatorName = GlobalData.Instance.Classrooms.FirstOrDefault(cls => cls.SchoolRoomNum == meetingInfo.Result.HostId.ToString())?.SchoolRoomName; } AppCache.AddOrUpdate(CacheKey.MeetingId, invitation.MeetingId); GlobalData.Instance.Course = new Course(); if (inClass) { //var mainView = new MainView(); //mainView.Show(); var wd = SetWindowsTop.FindWindow(null, "IntoClassView"); await Application.Current.Dispatcher.BeginInvoke(new Action(() => { //if (_viewLayoutService.IsDoubleScreenOn) //{ // _viewLayoutService.IsDoubleScreenOn = false; // _viewLayoutService.StopExtendedViewAsync(); // _viewLayoutService.ExtenedViewFrameList?.Clear(); // _viewLayoutService.ResetAsInitialStatus(); // Thread.Sleep(20); // foreach (Window item in Application.Current.Windows) // { // if (item is ExtendedScreenView) // { // item.Close(); // } // } // SetWindowsTop.SetWindowPos(wd, 0, int.MaxValue, int.MaxValue, 0, 0, 0); //} var intoClassView = new IntoClassView(IntoClassType.Join); intoClassView.Show(); //foreach (Window item in Application.Current.Windows) //{ // if (item is MainView) // { // item.Close(); // } //} Application.Current.Dispatcher.BeginInvoke(new Action(() => { SetWindowsTop.SendMessage(wd, WM_CLOSE, 0, 0); })); })); } else { var intoClassView = new IntoClassView(IntoClassType.Join); intoClassView.Show(); foreach (Window item in Application.Current.Windows) { if (!(item is IntoClassView || item is ExtendedScreenView)) { item.Close(); } } } UpdateMeeting(meetingList, creatorName, createTime); })); _exitDialog = null; }