public void ApplyChangeOptimistically() { var n = new GenericParameterHelper(1); Assert.True(ThreadingTools.ApplyChangeOptimistically(ref n, i => new GenericParameterHelper(i.Data + 1))); Assert.Equal(2, n.Data); }
public void ApplyChangeOptimisticallyWithItem() { var n = new GenericParameterHelper(1); Assert.True(ThreadingTools.ApplyChangeOptimistically(ref n, 2, (i, j) => new GenericParameterHelper(i.Data + j))); Assert.Equal(3, n.Data); }
private void Update() { ThreadingTools.ExecuteUiThread(() => Panel.Children.Clear()); CardTitle.DataContext = _group.Title; foreach (LimpUser user in _group.Users) { ThreadingTools.ExecuteUiThread(() => Panel.Children.Add(new StudentSettingsControl(user, _group, _updateParentView))); } }
private void Update() { ThreadingTools.ExecuteUiThread(() => Panel.Children.Clear()); CardTitle.DataContext = _pack.Title; foreach (var problem in _pack.Problems) { ThreadingTools.ExecuteUiThread(() => Panel.Children.Add(new ProblemSettingsControl(_group, _pack, problem, _updateParentView))); } }
private void GetUserProfileData() { var studentsData = ProfilePreviewData.GetProfilePreview(_group); foreach (var currRes in studentsData) { ThreadingTools.ExecuteUiThread(() => Panel.Children.Add(new UserResPrewiew(currRes.Username, currRes.Points))); } }
public void UpdateUi() { ThreadingTools.ExecuteUiThread(() => PackListPanel.Children.Clear()); var packs = DataProvider.UserGroupRepository.Read(_userGroup.Title).ProblemsPacks; foreach (var pack in packs) { var settings = new ProblemTasksPreview(_userGroup, pack.Title, _navigateService); ThreadingTools.ExecuteUiThread(() => PackListPanel.Children.Add(settings)); } }
public void UpdateUi() { ThreadingTools.ExecuteUiThread(() => GroupListPanel.Children.Clear()); List <UserGroup> groups = DataProvider.UserGroupRepository.ReadAll(); foreach (UserGroup group in groups) { var preview = new StudentGroupPreview(group.Title, _navigateService); ThreadingTools.ExecuteUiThread(() => GroupListPanel.Children.Add(preview)); } }
public void UpdateUi() { ThreadingTools.ExecuteUiThread(() => GroupListPanel.Children.Clear()); List <UserGroup> groups = DataProvider.UserGroupRepository.ReadAll(); foreach (UserGroup group in groups) { var settings = new StudentGroupSettings(group, UpdateUi); ThreadingTools.ExecuteUiThread(() => GroupListPanel.Children.Add(settings)); } }
public void UpdateUi() { ThreadingTools.ExecuteUiThread(() => PackListPanel.Children.Clear()); var packs = DataProvider.UserGroupRepository.Read(_group.Title).ProblemsPacks; foreach (var pack in packs) { var settings = new ProblemPackSettings(_group, pack, UpdateUi); ThreadingTools.ExecuteUiThread(() => PackListPanel.Children.Add(settings)); } }
public void UnregisterContext(string contextId) { Requires.NotNullOrEmpty(contextId, nameof(contextId)); bool changed = ThreadingTools.ApplyChangeOptimistically(ref _contexts, projectContexts => projectContexts.Remove(contextId)); if (!changed) { throw new InvalidOperationException($"'{nameof(contextId)}' has not been registered or has already been unregistered"); } }
private void RegisterIcons(IEnumerable <ImageMoniker> icons) { Assumes.NotNull(icons); foreach (ImageMoniker icon in icons) { if (ThreadingTools.ApplyChangeOptimistically(ref _knownIcons, knownIcons => knownIcons.Add(icon))) { _imageService.TryAssociateNameWithMoniker(GetIconStringName(icon), icon); } } }
public void UnregisterContext(IWorkspaceProjectContext context) { Requires.NotNull(context, nameof(context)); bool changed = ThreadingTools.ApplyChangeOptimistically(ref _contexts, projectContexts => projectContexts.Remove(context)); if (!changed) { throw new InvalidOperationException("'context' has not been registered or has already been unregistered"); } }
public void RegisterContext(IWorkspaceProjectContext context, string contextId) { Requires.NotNull(context, nameof(context)); Requires.NotNullOrEmpty(contextId, nameof(contextId)); bool changed = ThreadingTools.ApplyChangeOptimistically(ref _contexts, projectContexts => projectContexts.SetItem(context, contextId)); if (!changed) { throw new InvalidOperationException("'context' has already been registered."); } }
/// <summary> /// Waits for a task to complete. If current thread is UI thread then switches thread /// context to <see cref="NoMessagePumpSyncContext"/>. If an exception occurs, the /// exception will be raised without being wrapped in a <see cref="AggregateException"/>. /// </summary> public static T WaitAndUnwrapExceptions <T>(this Task <T> task, Dispatcher dispatcher) { if (dispatcher.CheckAccess()) { using (ThreadingTools.Apply(new NoMessagePumpSyncContext(), true)) { return(task.GetAwaiter().GetResult()); } } else { return(task.GetAwaiter().GetResult()); } }
public DependencyIconSet GetOrAddIconSet(DependencyIconSet iconSet) { if (ThreadingTools.ApplyChangeOptimistically(ref _iconSets, iconSets => iconSets.Add(iconSet))) { // The cache did not already contain an equivalent icon set; use the one passed in. return(iconSet); } else { // The cache already has an equivalent icon set; retrieve and return that one. _iconSets.TryGetValue(iconSet, out DependencyIconSet existingIconSet); return(existingIconSet); } }
public void Update() { ThreadingTools.ExecuteUiThread(() => UpdateButton.IsEnabled = false); MultiThreadParser.LoadProfiles(_group); IEnumerable <ProfilePreviewData> studentsData = ProfilePreviewData.GetProfilePackPreview(_group, PackTitle); ThreadingTools.ExecuteUiThread(() => Panel.Children.Clear()); foreach (var currRes in studentsData) { ThreadingTools.ExecuteUiThread(() => Panel.Children.Add(new UserResPrewiew(currRes.Username, currRes.Points))); } ThreadingTools.ExecuteUiThread(() => UpdateButton.IsEnabled = true); }
private void Update() { ThreadingTools.ExecuteUiThread(() => UpdateButton.IsEnabled = false); MultiThreadParser.LoadProfiles(_group); IEnumerable <ProfilePreviewData> studentsData = ProfilePreviewData.GetProfilePreview(_group); ThreadingTools.ExecuteUiThread(() => Panel.Children.Clear()); foreach (var currRes in studentsData) { ThreadingTools.ExecuteUiThread(() => Panel.Children.Add(new UserResPrewiew(currRes.Username, currRes.Points))); } // ThreadingTools.ExecuteUiThread(() => StudentList.ItemsSource = studentsData); ThreadingTools.ExecuteUiThread(() => UpdateButton.IsEnabled = true); DataProvider.UserGroupRepository.Update(_group); //JsonBackupManager.SaveCardUserList(_group, _studentGroupTitle); }
public void RegisterContext(string contextId) { Requires.NotNullOrEmpty(contextId, nameof(contextId)); bool changed = ThreadingTools.ApplyChangeOptimistically(ref _contexts, projectContexts => { if (!projectContexts.Contains(contextId)) { projectContexts = projectContexts.Add(contextId); } return(projectContexts); }); if (!changed) { throw new InvalidOperationException($"'{nameof(contextId)}' has already been registered."); } }
public ProblemTasksPreview(UserGroup users, string packTitle, IViewNavigateService navigateService) { _navigateService = navigateService; InitializeComponent(); _group = users; PackTitle = packTitle; CardTitle.DataContext = packTitle; if (_group.ProblemsPacks.Capacity != 0) { var studentsData = ProfilePreviewData.GetProfilePackPreview(_group, packTitle); foreach (var currRes in studentsData) { ThreadingTools.ExecuteUiThread(() => Panel.Children.Add(new UserResPrewiew(currRes.Username, currRes.Points))); } }// ThreadingTools.ExecuteUiThread(() => StudentList.ItemsSource = studentsData); }
public void WithCancellationOfTNull() { Assert.Throws <ArgumentNullException>(new Action(() => ThreadingTools.WithCancellation <object>(null, CancellationToken.None))); }