public void TestAddAll() { var set = new HashSet<string>() { "a", "b", "c" }; Assert.False(set.AddAll(new[] { "b", "c" })); Assert.True(set.AddAll(new[] { "c", "d" })); Assert.True(set.AddAll(new[] { "e", "f" })); }
public virtual void TestIndexing() { DirectoryInfo tmpDir = CreateTempDir("TestNeverDelete"); BaseDirectoryWrapper d = NewFSDirectory(tmpDir); // We want to "see" files removed if Lucene removed // them. this is still worth running on Windows since // some files the IR opens and closes. if (d is MockDirectoryWrapper) { ((MockDirectoryWrapper)d).NoDeleteOpenFile = false; } RandomIndexWriter w = new RandomIndexWriter(Random(), d, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetIndexDeletionPolicy(NoDeletionPolicy.INSTANCE)); w.w.Config.SetMaxBufferedDocs(TestUtil.NextInt(Random(), 5, 30)); w.Commit(); ThreadClass[] indexThreads = new ThreadClass[Random().Next(4)]; long stopTime = Environment.TickCount + AtLeast(1000); for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x] = new ThreadAnonymousInnerClassHelper(w, stopTime); indexThreads[x].Name = "Thread " + x; indexThreads[x].Start(); } HashSet<string> allFiles = new HashSet<string>(); DirectoryReader r = DirectoryReader.Open(d); while (Environment.TickCount < stopTime) { IndexCommit ic = r.IndexCommit; if (VERBOSE) { Console.WriteLine("TEST: check files: " + ic.FileNames); } allFiles.AddAll(ic.FileNames); // Make sure no old files were removed foreach (string fileName in allFiles) { Assert.IsTrue(SlowFileExists(d, fileName), "file " + fileName + " does not exist"); } DirectoryReader r2 = DirectoryReader.OpenIfChanged(r); if (r2 != null) { r.Dispose(); r = r2; } Thread.Sleep(1); } r.Dispose(); foreach (ThreadClass t in indexThreads) { t.Join(); } w.Dispose(); d.Dispose(); System.IO.Directory.Delete(tmpDir.FullName, true); }
public virtual void Inform(IResourceLoader loader) { IEnumerable<string> files = SplitFileNames(stopTypesFiles); if (files.Count() > 0) { stopTypes = new HashSet<string>(); foreach (string file in files) { IEnumerable<string> typesLines = GetLines(loader, file.Trim()); stopTypes.AddAll(typesLines); } } }
public void TestAddAllAndForEach() { // Arrange var setA = new HashSet<int>(); setA.Add(1); setA.Add(2); setA.Add(3); var setB = new HashSet<int>(); setB.Add(2); setB.Add(4); setB.Add(6); var expectedValues = new int[] { 1, 2, 3, 4, 6 }; // Act setA.AddAll(setB); // Assert Assert.AreEqual(expectedValues.Length, setA.Count()); expectedValues.ForEach(expected => Assert.IsTrue(setA.Contains(expected))); }
private static async Task<SearchResult> AddLocationsReferenceSymbolsAsync( ISymbol symbol, Solution solution, CancellationToken cancellationToken) { var locations = new HashSet<RenameLocation>(); var referenceSymbols = await SymbolFinder.FindRenamableReferencesAsync(symbol, solution, cancellationToken).ConfigureAwait(false); foreach (var referencedSymbol in referenceSymbols) { locations.AddAll( await ReferenceProcessing.GetRenamableDefinitionLocationsAsync(referencedSymbol.Definition, symbol, solution, cancellationToken).ConfigureAwait(false)); locations.AddAll( await referencedSymbol.Locations.SelectManyAsync<ReferenceLocation, RenameLocation>( (l, c) => ReferenceProcessing.GetRenamableReferenceLocationsAsync(referencedSymbol.Definition, symbol, l, solution, c), cancellationToken).ConfigureAwait(false)); } var implicitLocations = new List<ReferenceLocation>(referenceSymbols.SelectMany(refSym => refSym.Locations).Where(loc => loc.IsImplicit)); var referencedSymbols = new List<ISymbol>(referenceSymbols.Select(r => r.Definition).Where(r => !r.Equals(symbol))); return new SearchResult(locations, implicitLocations, referencedSymbols); }
/// <summary> /// Increments the versions of sdmx objects /// </summary> /// <param name="sdmxObjects"> /// The sdmx objects. /// </param> public void IncrementVersions(ISdmxObjects sdmxObjects) { _log.Info("Update Versions of Structures if existing structures found"); //Store a map of old versions vs the new version IDictionary<IStructureReference, IStructureReference> oldVsNew = new Dictionary<IStructureReference, IStructureReference>(); IDictionary<IMaintainableObject, IMaintainableObject> oldMaintVsNew = new Dictionary<IMaintainableObject, IMaintainableObject>(); ISet<IMaintainableObject> updatedMaintainables = new HashSet<IMaintainableObject>(); ISet<IMaintainableObject> oldMaintainables = new HashSet<IMaintainableObject>(); foreach (IMaintainableObject currentMaint in sdmxObjects.GetAllMaintainables()) { _log.Debug("Auto Version - check latest version for maintainable: " + currentMaint); IMaintainableObject persistedMaintainable = this._structureVersionRetrievalManager.GetLatest(currentMaint); if (persistedMaintainable == null) { persistedMaintainable = this._beanRetrievalManager.GetMaintainableObject(currentMaint.AsReference); } if (persistedMaintainable != null) { if (VersionableUtil.IsHigherVersion(persistedMaintainable.Version, currentMaint.Version)) { //Modify version of maintainable to be the same as persisted maintainable IMaintainableMutableObject mutableInstance = currentMaint.MutableInstance; mutableInstance.Version = persistedMaintainable.Version; //Remove the Maintainable from the submission - as we've changed the versions sdmxObjects.RemoveMaintainable(currentMaint); //currentMaint = mutableInstance.ImmutableInstance; } if (persistedMaintainable.Version.Equals(currentMaint.Version)) { _log.Debug("Latest version is '" + persistedMaintainable.Version + "' perform update checks"); if (!currentMaint.DeepEquals(persistedMaintainable, true)) { ISet<IIdentifiableObject> allIdentifiables1 = currentMaint.IdentifiableComposites; ISet<IIdentifiableObject> allIdentifiables2 = persistedMaintainable.IdentifiableComposites; bool containsAll = allIdentifiables1.ContainsAll(allIdentifiables2) && allIdentifiables2.ContainsAll(allIdentifiables1); if (_log.IsInfoEnabled) { string increment = containsAll ? "Minor" : "Major"; _log.Info("Perform " + increment + " Version Increment for structure:" + currentMaint.Urn); } //Increment the version number IMaintainableObject newVersion = this.IncrmentVersion( currentMaint, persistedMaintainable.Version, !containsAll); //Remove the Maintainable from the submission sdmxObjects.RemoveMaintainable(currentMaint); //Store the newly updated maintainable in a container for further processing updatedMaintainables.Add(newVersion); oldMaintainables.Add(currentMaint); //Store the old version number mappings to the new version number oldMaintVsNew.Add(currentMaint, newVersion); oldVsNew.Add(currentMaint.AsReference, newVersion.AsReference); string oldVersionNumber = currentMaint.Version; AddOldVsNewReferences(oldVersionNumber, newVersion, oldVsNew); } } } } //Create a set of parent sdmxObjects to not update (regardless of version) ISet<IMaintainableObject> filterSet = new HashSet<IMaintainableObject>(updatedMaintainables); filterSet.AddAll(sdmxObjects.GetAllMaintainables()); //Get all the referencing structures to reversion them IEnumerable<IMaintainableObject> referencingStructures = this.RecurseUpTree(oldMaintainables, new HashSet<IMaintainableObject>(), filterSet); foreach (IMaintainableObject currentReferencingStructure in referencingStructures) { _log.Info("Perform Minor Version Increment on referencing structure:" + currentReferencingStructure); String newVersionNumber; if (oldMaintVsNew.ContainsKey(currentReferencingStructure)) { //The old maintainable is also in the submission and has had it's version number incremented, use this version var tmp = oldMaintVsNew[currentReferencingStructure]; //currentReferencingStructure = oldMaintVsNew[currentReferencingStructure]; updatedMaintainables.Remove(tmp); newVersionNumber = currentReferencingStructure.Version; } else { newVersionNumber = VersionableUtil.IncrementVersion(currentReferencingStructure.Version, false); } IMaintainableObject updatedMaintainable = this._crossReferenceReversionEngine.UdpateReferences( currentReferencingStructure, oldVsNew, newVersionNumber); AddOldVsNewReferences(currentReferencingStructure.Version, updatedMaintainable, oldVsNew); updatedMaintainables.Add(updatedMaintainable); } foreach (IMaintainableObject currentReferencingStructure in updatedMaintainables) { IMaintainableObject updatedMaintainable = this._crossReferenceReversionEngine.UdpateReferences( currentReferencingStructure, oldVsNew, currentReferencingStructure.Version); sdmxObjects.AddIdentifiable(updatedMaintainable); } //Update the references of any structures that existed in the submission foreach (IMaintainableObject currentReferencingStructure in sdmxObjects.GetAllMaintainables()) { IMaintainableObject updatedMaintainable = this._crossReferenceReversionEngine.UdpateReferences( currentReferencingStructure, oldVsNew, currentReferencingStructure.Version); sdmxObjects.AddIdentifiable(updatedMaintainable); } }
public static ISet Union(ISet a, ISet b) { IMutableSet union = new HashSet(a); union.AddAll(b); return union; }
private static async Task<IEnumerable<INamedTypeSymbol>> FindSourceTypesInProjectAsync( HashSet<INamedTypeSymbol> sourceAndMetadataTypes, Project project, Func<HashSet<INamedTypeSymbol>, INamedTypeSymbol, bool> sourceTypeImmediatelyMatches, Func<INamedTypeSymbol, bool> shouldContinueSearching, bool transitive, CancellationToken cancellationToken) { // We're going to be sweeping over this project over and over until we reach a // fixed point. In order to limit GC and excess work, we cache all the sematic // models and DeclaredSymbolInfo for hte documents we look at. // Because we're only processing a project at a time, this is not an issue. var cachedModels = new ConcurrentSet<SemanticModel>(); var cachedInfos = new ConcurrentSet<IDeclarationInfo>(); var finalResult = new HashSet<INamedTypeSymbol>(SymbolEquivalenceComparer.Instance); var typesToSearchFor = new HashSet<INamedTypeSymbol>(SymbolEquivalenceComparer.Instance); typesToSearchFor.AddAll(sourceAndMetadataTypes); var inheritanceQuery = new InheritanceQuery(sourceAndMetadataTypes); // As long as there are new types to search for, keep looping. while (typesToSearchFor.Count > 0) { // Compute the set of names to look for in the base/interface lists. inheritanceQuery.TypeNames.AddRange(typesToSearchFor.Select(c => c.Name)); // Search all the documents of this project in parallel. var tasks = project.Documents.Select(d => FindImmediatelyInheritingTypesInDocumentAsync( d, typesToSearchFor, inheritanceQuery, cachedModels, cachedInfos, sourceTypeImmediatelyMatches, cancellationToken)).ToArray(); await Task.WhenAll(tasks).ConfigureAwait(false); // Clear out the information about the types we're looking for. We'll // fill these in if we discover any more types that we need to keep searching // for. typesToSearchFor.Clear(); inheritanceQuery.TypeNames.Clear(); foreach (var task in tasks) { if (task.Result != null) { foreach (var derivedType in task.Result) { if (finalResult.Add(derivedType)) { if (transitive && shouldContinueSearching(derivedType)) { typesToSearchFor.Add(derivedType); } } } } } } return finalResult; }
public void Init() { var parent = Path.GetDirectoryName (DiskPath); var siblings = new SortedDictionary<string, Page> (); foreach (var i in Tacker.Pages) { if (i.DiskPath.Equals (parent)) { Parent = i; } if (parent.Equals (Path.GetDirectoryName (i.DiskPath)) && i != this && !i.IsFloating) { siblings.Add (Path.GetFileName (i.DiskPath), i); } } Siblings = new List<Page> (siblings.Values); var metadata = new Dictionary<string, object> (); var assets = new HashSet<string> (); foreach (var i in Files.GetAllFiles (DiskPath)) { var md = Tacker.ProcessMetadata (i); if (md != null) { Template = Template ?? Path.GetFileNameWithoutExtension (i); metadata.AddAll (md); continue; } var markup = Tacker.ProcessMarkup (i); if (markup != null) { metadata.Add (Path.GetFileNameWithoutExtension (i), markup); continue; } assets.Add (i); } var pagePaths = new HashSet<string> (); foreach (var page in Tacker.Pages) { pagePaths.Add (page.DiskPath); } foreach (var subdir in Files.EnumerateAllSubdirs (DiskPath)) { if (!pagePaths.Contains (subdir)) { assets.AddAll (Files.GetAllFiles (subdir)); } } Assets = new HashSet<string> (assets.Select (x => x.Replace (DiskPath, ""))); Variables = metadata; inited = true; }
/// <summary> /// Given a path to an assembly and a set of paths to possible dependencies, /// identifies which of the assembly's references are missing. May throw. /// </summary> /// <exception cref="IOException">If the files does not exist or cannot be accessed.</exception> /// <exception cref="BadImageFormatException">If one of the files is not an assembly or is somehow corrupted.</exception> public static ImmutableArray<AssemblyIdentity> IdentifyMissingDependencies(string assemblyPath, IEnumerable<string> dependencyFilePaths) { Debug.Assert(assemblyPath != null); Debug.Assert(PathUtilities.IsAbsolute(assemblyPath)); Debug.Assert(dependencyFilePaths != null); HashSet<AssemblyIdentity> assemblyDefinitions = new HashSet<AssemblyIdentity>(); foreach (var potentialDependency in dependencyFilePaths) { using (var reader = new PEReader(FileUtilities.OpenRead(potentialDependency))) { var metadataReader = reader.GetMetadataReader(); var assemblyDefinition = metadataReader.ReadAssemblyIdentityOrThrow(); assemblyDefinitions.Add(assemblyDefinition); } } HashSet<AssemblyIdentity> assemblyReferences = new HashSet<AssemblyIdentity>(); using (var reader = new PEReader(FileUtilities.OpenRead(assemblyPath))) { var metadataReader = reader.GetMetadataReader(); var references = metadataReader.GetReferencedAssembliesOrThrow(); assemblyReferences.AddAll(references); } assemblyReferences.ExceptWith(assemblyDefinitions); return ImmutableArray.CreateRange(assemblyReferences); }
public virtual void Inform(ResourceLoader loader) { IList<string> files = splitFileNames(stopTypesFiles); if (files.Count > 0) { stopTypes = new HashSet<string>(); foreach (string file in files) { IList<string> typesLines = getLines(loader, file.Trim()); stopTypes.AddAll(typesLines); } } }
/// <summary> /// Get subset workspace from <paramref name="query"/> /// </summary> /// <param name="query"> /// The query. /// </param> /// <returns> /// The <see cref="IStructureWorkspace"/>. /// </returns> public virtual IStructureWorkspace GetSubsetWorkspace(params IStructureReference[] query) { ISet<IMaintainableObject> maintainablesSubset = new HashSet<IMaintainableObject>(); IDictionaryOfSets<IIdentifiableObject, IIdentifiableObject> crossReferencedSubset = new DictionaryOfSets<IIdentifiableObject, IIdentifiableObject>(); for (int i = 0; i < query.Length; i++) { IStructureReference currentQuery = query[i]; ISet<IMaintainableObject> maintainableForStructure = this._sdmxObjects.GetMaintainables(currentQuery.MaintainableStructureEnumType.EnumType); ISet<IMaintainableObject> maintainableMatches = MaintainableUtil<IMaintainableObject>.FindMatches(maintainableForStructure, currentQuery); maintainablesSubset.AddAll(maintainableMatches); /* foreach */ foreach (IMaintainableObject currentMatch in maintainableMatches) { ISet<IIdentifiableObject> identifiables = (this._crossReferencedObjects == null) ? (new HashSet<IIdentifiableObject>()) : this._crossReferencedObjects[currentMatch]; if (identifiables != null) { crossReferencedSubset.Add(currentMatch, identifiables); } } } ISdmxObjects beansSubset = new SdmxObjectsImpl(this._sdmxObjects.Header, maintainablesSubset); return new StructureWorkspace(beansSubset, crossReferencedSubset); }
/// <summary> /// The resolve references internal. /// </summary> /// <param name="sdmxObjects"> The sdmxObjects. </param> /// <param name="retrievalManager"> The retrieval manager. </param> /// <param name="populateMissingMap"> The populate missing map. </param> /// <returns> The <see cref="IIdentifiableObject" /> dictionary. </returns> /// <exception cref="CrossReferenceException">Reference error</exception> private IDictionaryOfSets<IIdentifiableObject, IIdentifiableObject> ResolveReferencesInternal( ISdmxObjects sdmxObjects, IIdentifiableRetrievalManager retrievalManager, IDictionary<IIdentifiableObject, ISet<ICrossReference>> populateMissingMap) { _log.Info("Resolve References, bean retrieval manager: " + retrievalManager); /* foreach */ foreach (IAgency currentAgency in sdmxObjects.Agencies) { this._agencies.Add(currentAgency.FullId, currentAgency); } // Add all the top level sdmxObjects to the maintainables list this.AddObjectsToMap(sdmxObjects); // LOOP THROUGH ALL THE BEANS AND RESOLVE ALL THE REFERENCES if (this._resolveAgencies) { /* foreach */ foreach (IMaintainableObject currentBean in sdmxObjects.GetAllMaintainables()) { try { this.ResolveAgency(currentBean, retrievalManager); } catch (CrossReferenceException e) { throw new SdmxReferenceException(e, AgencyRef(currentBean.AgencyId)); } } } ISet<IMaintainableObject> loopSet = new HashSet<IMaintainableObject>(); loopSet.AddAll(sdmxObjects.GetAllMaintainables()); ISdmxObjectRetrievalManager retMan = new InMemoryRetrievalManager(sdmxObjects); /* foreach */ foreach (IMaintainableObject currentMaintainable in loopSet) { this._log.Debug("Resolving References For : " + currentMaintainable.Urn); ISet<ICrossReference> crossReferences0; if (_maintainableCrossReferenceRetrieverEngine != null) { crossReferences0 = _maintainableCrossReferenceRetrieverEngine.GetCrossReferences(retMan, currentMaintainable); } else { crossReferences0 = currentMaintainable.CrossReferences; } this._log.Debug("Number of References : " + crossReferences0.Count); int i = 0; /* foreach */ foreach (ICrossReference crossReference in crossReferences0) { i++; if (this._log.IsDebugEnabled) { this._log.Debug( "Resolving Reference " + i + ": " + crossReference + " - referenced from -" + crossReference.ReferencedFrom.StructureType); } try { this.StoreRef( crossReference.ReferencedFrom, this.ResolveCrossReference(crossReference, retrievalManager)); } catch (CrossReferenceException e) { if (populateMissingMap == null) { throw; } HandleMissingReference(e, populateMissingMap); //throw new ReferenceException(e, "Reference from structure '" + currentMaintainable.Urn + "' can not be resolved"); } } } return this._crossReferences; }
/// <summary> /// Returns a set of IdentifiableBeans that the IMaintainableObject cross references /// </summary> /// <param name="bean"> The bean. </param> /// <param name="resolveAgencies"> - if true will also resolve the agencies </param> /// <param name="numberLevelsDeep"> references, an argument of 0 (zero) implies there is no limit, and the resolver engine will continue re-cursing until it has found every directly and indirectly referenced artifact. Note that there is no risk of infinite recursion in calling this. </param> /// <param name="retrievalManager"> - Used to resolve the structure references. Can be null, if supplied this is used to resolve any references that do not exist in the supplied sdmxObjects </param> /// <exception cref="CrossReferenceException">- if any of the references could not be resolved</exception> /// <returns> a set of IdentifiableBeans that the IMaintainableObject cross references </returns> public virtual ISet<IIdentifiableObject> ResolveReferences( IMaintainableObject bean, bool resolveAgencies, int numberLevelsDeep, IIdentifiableRetrievalManager retrievalManager) { this.ResetMaps(); ISdmxObjects beans = new SdmxObjectsImpl(); beans.AddIdentifiable(bean); IDictionary<IIdentifiableObject, ISet<IIdentifiableObject>> references = this.ResolveReferences( beans, resolveAgencies, numberLevelsDeep, retrievalManager); ISet<IIdentifiableObject> returnSet = new HashSet<IIdentifiableObject>(); /* foreach */ foreach (KeyValuePair<IIdentifiableObject, ISet<IIdentifiableObject>> key in references) { returnSet.AddAll(key.Value); } return returnSet; }