/// <summary> /// Removes all listeners of the specified event. /// </summary> /// <param name="eventString">an event name</param> /// <returns>a reference to this object.</returns> public Emitter Off(string eventString) { try { ImmutableList <IListener> retrievedValue; if (!callbacks.TryGetValue(eventString, out retrievedValue)) { var log = LogManager.GetLogger(Global.CallerName()); log.Info(string.Format("Emitter.Off Could not remove {0}", eventString)); } if (retrievedValue != null) { callbacks = callbacks.Remove(eventString); foreach (var listener in retrievedValue) { _onceCallbacks.Remove(listener); } } } catch (Exception) { this.Off(); } return(this); }
public IDependency BeforeRemove( string projectPath, ITargetFramework targetFramework, IDependency dependency, ImmutableDictionary <string, IDependency> .Builder worldBuilder, ImmutableHashSet <IDependency> .Builder topLevelBuilder, out bool filterAnyChanges) { filterAnyChanges = _filterAnyChanges; if (_beforeRemove.TryGetValue(dependency.Id, out Tuple <IDependency, FilterAction> info)) { if (info.Item2 == FilterAction.Cancel) { return(null); } else if (info.Item2 == FilterAction.ShouldBeAdded) { worldBuilder.Remove(info.Item1.Id); worldBuilder.Add(info.Item1.Id, info.Item1); } else { worldBuilder.Remove(dependency.Id); topLevelBuilder.Remove(dependency); } } return(dependency); }
void FilePathChanged(object sender, ProjectFilePathChangedEventArgs e) { AssertCanWrite(); ProjectVirtualPathChanged(sender, e); files = files.Remove(e.OldPath); files = files.SetItem(e.NewPath, e.ProjectFile); }
private void OnUserLeft(ChannelMember member) { var changeOwner = member.IsOwner; member.User.ChatChannels.Remove(this); m_members.Remove(member.User.EntityId.Low); if (changeOwner) { member = m_members.Values.FirstOrDefault(); if (member != null) { if (Announces) { ChannelHandler.SendLeftReplyToEveryone(this, member.User.EntityId); } Owner = member; } else { m_group.DeleteChannel(this); m_owner = null; } } }
/// <summary> /// Removes all listeners of the specified event. /// </summary> /// <param name="eventString">an event name</param> /// <returns>a reference to this object.</returns> public Emitter Off(string eventString) { try { if (!callbacks.TryGetValue(eventString, out ImmutableList <IListener> retrievedValue)) { Logger.Log($"Emitter.Off Could not remove {eventString}"); } if (retrievedValue != null) { callbacks = callbacks.Remove(eventString); foreach (var listener in retrievedValue) { _onceCallbacks.Remove(listener); } } } catch (Exception) { Off(); } return(this); }
/// <summary> /// Removes the given part from this collection /// </summary> /// <param name="sop">The part to remove</param> public void RemovePart(SceneObjectPart sop) { lock (m_mutationLock) { m_partsByUuid = m_partsByUuid.Remove(sop.UUID); m_partsByLocalId = m_partsByLocalId.Remove(sop.LocalId); } }
private T PutToMemory <T>(Guid id, T state) where T : class { var key = GetCacheKey <T>(id); // _logger.Info(string.Format("PUT: mem:{0}/{1:n}", typeof (T).Name, id)); _cache = _cache.Remove(key); _cache = _cache.Add(key, state); return(state); }
public void RemoveStaticResource(string id) { if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException(nameof(id)); } objects = objects.Remove(id); }
public IBidirectionalMap <TKey, TValue> RemoveKey(TKey key) { if (!_forwardMap.TryGetValue(key, out var value)) { return(this); } return(new BidirectionalMap <TKey, TValue>( _forwardMap.Remove(key), _backwardMap.Remove(value))); }
/// <summary> /// Listens on the event. /// </summary> /// <param name="eventString">event name</param> /// <param name="fn"></param> /// <returns>a reference to this object</returns> public Emitter On(string eventString, IListener fn) { if (!callbacks.ContainsKey(eventString)) { callbacks = callbacks.Add(eventString, ImmutableList <IListener> .Empty); } var callbacksLocal = callbacks[eventString]; callbacksLocal = callbacksLocal.Add(fn); callbacks = callbacks.Remove(eventString).Add(eventString, callbacksLocal); return(this); }
/// <summary> /// Removes a key from this dictionary. /// </summary> /// <param name="key">The key to remove.</param> /// <returns> /// <c>true</c> if the key was removed; /// <c>false</c> if this dictionary didn't contain the /// key in the first place. /// </returns> public bool Remove(TKey key) { if (innerDictionary.Remove(key)) { orderedKeyList.Remove(key); return(true); } else { return(false); } }
public void NotifyOnDocumentClosing(string moniker) { if (_openedDocs.TryGetValue(moniker, out DocumentId id)) { // check if the doc is part of the current Roslyn workspace before notifying Roslyn. if (CurrentSolution.ContainsProject(id.ProjectId)) { OnDocumentClosed(id, new FileTextLoaderNoException(moniker, null)); _openedDocs = _openedDocs.Remove(moniker); } } }
protected void AddEntries(IEnumerable <AutorouteEntry> entries) { foreach (var entry in entries) { if (_paths.TryGetValue(entry.ContentItemId, out var previousContainerEntry) && String.IsNullOrEmpty(entry.ContainedContentItemId)) { _contentItemIds = _contentItemIds.Remove(previousContainerEntry.Path); } _contentItemIds = _contentItemIds.SetItem(entry.Path, entry); _paths = _paths.SetItem(entry.ContentItemId, entry); } }
/// <summary> /// Removes the given avatar from this collection /// </summary> /// <param name="sp">The avatar to remove</param> public bool RemoveAvatar(ScenePresence sp) { lock (m_mutationLock) { if (m_avatarsByUuid.ContainsKey(sp.UUID)) { m_avatarsByUuid = m_avatarsByUuid.Remove(sp.UUID); m_avatarsByLocalId = m_avatarsByLocalId.Remove(sp.LocalId); return(true); } } return(false); }
public bool Remove <T>() where T : class, IEntityComponent { // TODO : assert that fragment requirements are still satisfied after removal of fragment var type = typeof(T); if (!Contains <T>()) { return(false); } _lookup = _lookup.Remove(type); return(true); }
/// <summary> /// Removes the instance from the table /// </summary> public void RemoveInstance(int id) { lock (m_lock) { m_instances = m_instances.Remove(id); } }
/// <summary> /// Create a copy of the <see cref="HttpRequest"/>, adding the specified content formatter. /// </summary> /// <param name="request"> /// The <see cref="HttpRequest"/>. /// </param> /// <param name="formatterType"> /// The type of content formatter to remove. /// </param> /// <returns> /// The new <see cref="HttpRequest"/>. /// </returns> public static HttpRequest WithoutFormatter(this HttpRequest request, Type formatterType) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (formatterType == null) { throw new ArgumentNullException(nameof(formatterType)); } ImmutableDictionary <Type, IFormatter> formatters = request.GetFormatters(); if (formatters == null) { return(request); } if (!formatters.ContainsKey(formatterType)) { return(request); } return(request.Clone(properties => { properties[MessageProperties.ContentFormatters] = formatters.Remove(formatterType); })); }
private void ParseDocumentAsync(Document document) { var cancellationTokenSource = new CancellationTokenSource(); using (_stateLock.DisposableWrite()) { _workMap = _workMap.Add(document.Id, cancellationTokenSource); } var cancellationToken = cancellationTokenSource.Token; var task = _taskScheduler.ScheduleTask( () => document.GetSyntaxTreeAsync(cancellationToken), "BackgroundParser.ParseDocumentAsync", cancellationToken); // Always ensure that we mark this work as done from the workmap. task.SafeContinueWith( _ => { using (_stateLock.DisposableWrite()) { _workMap = _workMap.Remove(document.Id); } }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }
public IDependency BeforeAdd( string projectPath, ITargetFramework targetFramework, IDependency dependency, ImmutableDictionary <string, IDependency> .Builder worldBuilder, IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType, IImmutableSet <string> projectItemSpecs, out bool filterAnyChanges) { filterAnyChanges = _filterAnyChanges; if (_beforeAdd.TryGetValue(dependency.Id, out Tuple <IDependency, FilterAction> info)) { if (info.Item2 == FilterAction.Cancel) { return(null); } else if (info.Item2 == FilterAction.ShouldBeAdded) { worldBuilder.Remove(info.Item1.Id); worldBuilder.Add(info.Item1.Id, info.Item1); return(info.Item1); } else { throw new NotSupportedException(); } } return(dependency); }
public void RemoveEditor(IEditor editor) { var index = editors.IndexOf(editor); if (index < 0) { throw new ArgumentException("instance is not added", nameof(editor)); } editors = editors.RemoveAt(index); editorStateMap = editorStateMap.Remove(editor); IDisposable subscription; if (editorEventSubscriptions.TryGetValue(editor, out subscription)) { subscription.Dispose(); editorEventSubscriptions = editorEventSubscriptions.Remove(editor); } if (FocusedEditor == editor) { FocusedEditor = null; } }
public IImmutableDictionary <TKey, TValue> Remove(TKey key) { return(new ImmutableDictionaryKeepOrder <TKey, TValue>( _dictionary.Remove(key), _items.RemoveAll(i => EqualityComparer <TKey> .Default.Equals(key, i.Key)) )); }
public void Unregister(string commandName) { if (commands.TryGetValue(commandName, out Command command)) { commands = commands.Remove(commandName); } }
public bool BeforeRemove( string projectPath, ITargetFramework targetFramework, IDependency dependency, ImmutableDictionary <string, IDependency> .Builder worldBuilder, out bool filterAnyChanges) { filterAnyChanges = _filterAnyChanges; if (_beforeRemove.TryGetValue(dependency.Id, out Tuple <IDependency, FilterAction> info)) { if (info.Item2 == FilterAction.Cancel) { return(false); } else if (info.Item2 == FilterAction.ShouldBeAdded) { worldBuilder.Remove(info.Item1.Id); worldBuilder.Add(info.Item1.Id, info.Item1); } else { throw new NotSupportedException(); } } return(true); }
private void ParseDocumentAsync(Document document) { var cancellationTokenSource = new CancellationTokenSource(); using (_stateLock.DisposableWrite()) { _workMap = _workMap.Add(document.Id, cancellationTokenSource); } var cancellationToken = cancellationTokenSource.Token; var task = _taskScheduler.ScheduleTask( () => document.GetSyntaxTreeAsync(cancellationToken), "BackgroundParser.ParseDocumentAsync", cancellationToken); // Always ensure that we mark this work as done from the workmap. task.SafeContinueWith( _ => { using (_stateLock.DisposableWrite()) { // Check that we are still the active parse in the workmap before we remove it. // Concievably if this continuation got delayed and another parse was put in, we might // end up removing the tracking for another in-flight task. if (_workMap.TryGetValue(document.Id, out var sourceInMap) && sourceInMap == cancellationTokenSource) { _workMap = _workMap.Remove(document.Id); } } }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }
public SyntaxLintConfiguration Remove(string name) { return(new SyntaxLintConfiguration { _severities = _severities.Remove(name), }); }
public virtual void Rollback(string id) { TransactionState value; if (transactionStates.TryGetValue(id, out value) == false) { return; } lock (modifyTransactionStates) { transactionStates = transactionStates.Remove(id); } lock (value) { lock (modifyChangedInTransaction) { foreach (var change in value.Changes) { changedInTransaction = changedInTransaction.Remove(change.Key); } } value.Changes.Clear(); } }
/// <summary> /// Slices this collection, returning a new collection containing only /// positions with the specified <paramref name="side"/> /// </summary> public OptionPositionCollection Slice(PositionSide side, bool includeUnderlying = true) { var otherSides = GetOtherSides(side); var sides = _sides.Remove(otherSides[0]).Remove(otherSides[1]); var positions = ImmutableDictionary <Symbol, OptionPosition> .Empty; if (includeUnderlying && HasUnderlying) { positions = positions.Add(Underlying, UnderlyingPosition); } var rights = ImmutableDictionary <OptionRight, ImmutableHashSet <Symbol> > .Empty; var strikes = ImmutableSortedDictionary <decimal, ImmutableHashSet <Symbol> > .Empty; var expirations = ImmutableSortedDictionary <DateTime, ImmutableHashSet <Symbol> > .Empty; foreach (var symbol in sides.SelectMany(kvp => kvp.Value)) { var position = _positions[symbol]; rights = rights.Add(position.Right, symbol); positions = positions.Add(symbol, position); strikes = strikes.Add(position.Strike, symbol); expirations = expirations.Add(position.Expiration, symbol); } return(new OptionPositionCollection(positions, rights, sides, strikes, expirations)); }
private (IModelGraph, ImmutableDictionary <object, IModelNode>) UpdateNodeCore( [NotNull] IModelNode updatedNode, [NotNull] IModelGraph modelGraph, [NotNull] ImmutableDictionary <object, IModelNode> payloadToModelNodeMap, [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents) { var oldNode = GetNode(updatedNode.Id); itemEvents.Add(new ModelNodeUpdatedEvent(oldNode, updatedNode)); if (oldNode.Payload != null) { payloadToModelNodeMap = payloadToModelNodeMap.Remove(oldNode.Payload); } if (updatedNode.Payload != null) { payloadToModelNodeMap = payloadToModelNodeMap.Add(updatedNode.Payload, updatedNode); } return( modelGraph.UpdateVertex(updatedNode), payloadToModelNodeMap ); }
private void TombstoneRemovedNodePruning() { foreach (var performed in _pruningPerformed) { var removed = performed.Key; var timestamp = performed.Value; if ((_allReachableClockTime - timestamp) > _maxPruningDisseminationNanos && AllPruningPerformed(removed)) { _log.Debug("All pruning performed for {0}, tombstoned", removed); _pruningPerformed = _pruningPerformed.Remove(removed); _removedNodes = _removedNodes.Remove(removed); _tombstonedNodes = _tombstonedNodes.Add(removed); foreach (var entry in _dataEntries) { var key = entry.Key; var envelope = entry.Value.Item1; var pruning = envelope.Data as IRemovedNodePruning; if (pruning != null) { SetData(key, PruningCleanupTombstoned(envelope, removed)); } } } } }
private static ImmutableDictionary <DocumentId, SyntaxTree> RemoveOldTreeFromMap( Compilation newCompilation, ImmutableDictionary <DocumentId, SyntaxTree> oldMap, ImmutableDictionary <DocumentId, SyntaxTree> map, CancellationToken cancellationToken) { foreach (var oldIdAndTree in oldMap) { cancellationToken.ThrowIfCancellationRequested(); // check whether new compilation still has the tree if (newCompilation.ContainsSyntaxTree(oldIdAndTree.Value)) { continue; } var documentId = oldIdAndTree.Key; // check whether the tree has been updated if (!map.TryGetValue(documentId, out var currentTree) || currentTree != oldIdAndTree.Value) { continue; } // this has been removed map = map.Remove(documentId); } return(map); }
public void ImmutableDictionary_RemoveTest() { Dictionary<int, string> dictionary = new Dictionary<int, string> { {1,"asaas"}, {2,"sasas"}, {3,"tak"} }; ImmutableDictionary<int, string> test = new ImmutableDictionary<int, string>(dictionary); test.Remove(2); }
public DiagnosticAnalyzerMap(HostAnalyzerManager analyzerManager, string language, ImmutableDictionary<DiagnosticAnalyzer, StateSet> analyzerMap) { // hold directly on to compiler analyzer _compilerAnalyzer = analyzerManager.GetCompilerDiagnosticAnalyzer(language); // in test case, we might not have the compiler analyzer. if (_compilerAnalyzer == null) { _map = analyzerMap; return; } _compilerStateSet = analyzerMap[_compilerAnalyzer]; // hold rest of analyzers _map = analyzerMap.Remove(_compilerAnalyzer); }
private static void RemoveSyntaxTreeFromDeclarationMapAndTable( SyntaxTree tree, ref ImmutableDictionary<SyntaxTree, Lazy<RootSingleNamespaceDeclaration>> declMap, ref DeclarationTable declTable, ref bool referenceDirectivesChanged) { Lazy<RootSingleNamespaceDeclaration> lazyRoot; if (!declMap.TryGetValue(tree, out lazyRoot)) { throw new ArgumentException(string.Format(CSharpResources.SyntaxTreeNotFoundTo, tree), "trees"); } declTable = declTable.RemoveRootDeclaration(lazyRoot); declMap = declMap.Remove(tree); referenceDirectivesChanged = referenceDirectivesChanged || tree.HasReferenceDirectives(); }
private ImmutableDictionary<String, ParameterSet> RemoveCandidateIfParamDefault( ImmutableDictionary<String, ParameterSet> candidates, Parameter parameter ) { if (parameter.IsCommonParameter) { Logger.Debug( "Skipping common parameter {Parameter}", parameter.Name ); return candidates; } if (parameter.HasDefaultValue(Target)) { Logger.Debug( "Parameter {Parameter} has default value, removing {ParameterSetName} from candidates", parameter.Name, parameter.ParameterSetName ); return candidates.Remove( parameter.ParameterSetName ); } Logger.Debug( "Parameter {Parameter} has a value set, keeping {ParameterSetName} as a candidate", parameter.Name, parameter.ParameterSetName ); return candidates; }
public void Add_Test() { Dictionary<int, string> _dictionary = new Dictionary<int, string> { {1, "aabb"}, {2, "bbcc"}, {3, "ccdd"} }; ImmutableDictionary<int, string> _immutableDictionary = new ImmutableDictionary<int, string>(_dictionary); _immutableDictionary.Remove(new KeyValuePair<int, string>(1, "aabb")); }
private void ParseDocumentAsync(Document document) { var cancellationTokenSource = new CancellationTokenSource(); using (_stateLock.DisposableWrite()) { _workMap = _workMap.Add(document.Id, cancellationTokenSource); } var cancellationToken = cancellationTokenSource.Token; var task = _taskScheduler.ScheduleTask( () => document.GetSyntaxTreeAsync(cancellationToken), "BackgroundParser.ParseDocumentAsync", cancellationToken); // Always ensure that we mark this work as done from the workmap. task.SafeContinueWith( _ => { using (_stateLock.DisposableWrite()) { _workMap = _workMap.Remove(document.Id); } }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); }
private static ImmutableDictionary<DocumentId, SyntaxTree> RemoveOldTreeFromMap( Compilation newCompilation, ImmutableDictionary<DocumentId, SyntaxTree> oldMap, ImmutableDictionary<DocumentId, SyntaxTree> map, CancellationToken cancellationToken) { foreach (var oldIdAndTree in oldMap) { cancellationToken.ThrowIfCancellationRequested(); // check whether new compilation still has the tree if (newCompilation.ContainsSyntaxTree(oldIdAndTree.Value)) { continue; } var documentId = oldIdAndTree.Key; // check whether the tree has been updated SyntaxTree currentTree; if (!map.TryGetValue(documentId, out currentTree) || currentTree != oldIdAndTree.Value) { continue; } // this has been removed map = map.Remove(documentId); } return map; }