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);
        }
        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);
        }
示例#3
0
        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");
            }
        }
示例#4
0
        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.");
            }
        }
示例#7
0
 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);
     }
 }
示例#8
0
        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.");
            }
        }