public static IEnumerable <Card> GroupBySuitAscending(this IEnumerable <Card> self, params Suit[] suitOrder) { var result = new UniqueList <Card>(); foreach (var suit in suitOrder) { result.AddRange(self.OfSuit(suit).Ascending()); } // Add any suits not specified result.AddRange(self.OrderBy(i => i.Suit).ThenBy(_ => _.Kind)); return(result); }
public void AddRangeEnforcesSameRulesAsAdd() { var ins = new System.Collections.Generic.List<string> {"one", "one", null}; _uniqueList = new UniqueList<string>(); _uniqueList.AddRange(ins); Assert.AreEqual(1, _uniqueList.Count); }
internal void SyncPairRequests(IEnumerable <AssetPair> pairs) { lock (_timerLock) { _pairRequests.Clear(); _pairRequests.AddRange(pairs); } }
public Network Get(string name) { lock (_lock) { if (!_collected) { _collected = true; KnownNetworks.AddRange(TypeCatalogue.I.ImplementInstances <INetworkProvider>().Select(x => x.Network)); } } return(_cache.GetOrAdd(Network.GetHash(name), k => new Network(name))); }
public void TestRemove() { UniqueList <int> l = new UniqueList <int>(); l.AddRange(new int[] { 1, 2, 3, 4, 5, 6 }); l.Remove(6); Assert.AreEqual(5, l.Count); l.RemoveRange(0, 2); Assert.AreEqual(3, l.Count); l.RemoveAt(0); Assert.AreEqual(2, l.Count); Assert.AreEqual(4, l[0]); }
public void TestAdd() { UniqueList <int> l = new UniqueList <int>(); l.Add(1); Assert.AreEqual(1, l.Count); l.Add(1); Assert.AreEqual(1, l.Count); l.Add(2); Assert.AreEqual(2, l.Count); l.AddRange(new int[] { 2, 3, 4 }); Assert.AreEqual(4, l.Count); l.AddRange(new int[] { 1, 2, 3, 4 }); Assert.AreEqual(4, l.Count); l.Insert(0, 42); Assert.AreEqual(42, l[0]); Assert.AreEqual(5, l.Count); l.InsertRange(0, new int[] { 2, 99 }); Assert.AreEqual(99, l[0]); Assert.AreEqual(6, l.Count); }
public async Task <AssetPairs> GetAssetPairsAsync(NetworkProviderContext context) { if (_pairs.Any()) { return(new AssetPairs(_pairs)); } var rates = await GetRatesAsync().ConfigureAwait(false); lock (_lock) { var pairs = new AssetPairs(rates.Select(x => x.Key)); _pairs.Clear(); _pairs.AddRange(pairs); return(pairs); } }
public void InsertRemoveFromUniqueList() { int[] list = { 4, 5, 6 }; var uniquelist = new UniqueList <int>(); uniquelist.Insert(0, 3); uniquelist.Insert(0, 2); uniquelist.Insert(0, 1); uniquelist.AddRange(list); Assert.AreEqual(1, uniquelist[0]); Assert.AreEqual(2, uniquelist[1]); Assert.AreEqual(3, uniquelist[2]); uniquelist.RemoveAt(0); uniquelist.RemoveAt(0); uniquelist.RemoveAt(0); Assert.AreEqual(4, uniquelist[0]); }
public static void TestAddRange() { UniqueList <string> uniqueList = new UniqueList <string> { "AA", "BBB", "CC", "DDD" }; IEnumerable <string> listParams = new List <string> { "EE", "FFF", "GG", "H" }; uniqueList.AddRange(listParams); Assert.AreEqual("AA,BBB,CC,DDD,EE,FFF,GG,H", uniqueList.ToString()); }
protected bool _Load(DBConnectionPool pool, BlaCommonStorage platform, int johQueryIndex) { var b = true; try { _kitems.AddRange(platform.EntityReader[johQueryIndex].Query(pool, platform.Variant) .Select(d => _KarObjCreation(d))); platform.Reporter.AddMessage(new RoReMessage { Caller = GetType().Name, EvType = RoReEventType.Info, Message = $"Ilość elementów: {_kitems.Count}" }); } catch (Exception e) { b = false; platform.Reporter.AddException(e, GetType().Name); } return(b); }
public void StoreRange(OhlcData data, TimeRange rangeAttempted) { lock (Lock) { if (data == null) { return; } if (CoverageMap.Found.Covers(rangeAttempted)) { return; } Parallel.ForEach(data, x => x.SeriesId = _adapter.SeriesId); MemoryCache.AddRange(data); CoverageMap.Include(rangeAttempted, data); } }
internal void AddRange_WhenSomeElementsUnique_OnlyAddsUniqueElementsInOrder() { // Arrange var unique = new UniqueList <string> { "0" }; var elements = new List <string> { "1", "2", "2", "3", "4", "4", "4", "5" }; // Act unique.AddRange(elements); // Assert Assert.Equal(6, unique.Count); Assert.Equal("0", unique[0]); Assert.Equal("1", unique[1]); Assert.Equal("2", unique[2]); Assert.Equal("3", unique[3]); Assert.Equal("4", unique[4]); Assert.Equal("5", unique[5]); }
private static bool GenerateMasterBffFile(Builder builder, ConfigurationsPerBff configurationsPerBff) { string masterBffFilePath = Util.GetCapitalizedPath(configurationsPerBff.BffFilePathWithExtension); string masterBffDirectory = Path.GetDirectoryName(masterBffFilePath); string masterBffFileName = Path.GetFileName(masterBffFilePath); // Global configuration file is in the same directory as the master bff but filename suffix added to its filename. string globalConfigFullPath = GetGlobalBffConfigFileName(masterBffFilePath); string globalConfigFileName = Path.GetFileName(globalConfigFullPath); var solutionProjects = configurationsPerBff.ResolvedProjects; if (solutionProjects.Count == 0 && configurationsPerBff.ProjectsWereFiltered) { // We are running in filter mode for submit assistant and all projects were filtered out. // We need to skip generation and delete any existing master bff file. Util.TryDeleteFile(masterBffFilePath); return(false); } // Start writing Bff var fileGenerator = new FileGenerator(); var masterBffInfo = new MasterBffInfo(); var bffPreBuildSection = new Dictionary <string, string>(); var bffCustomPreBuildSection = new Dictionary <string, string>(); var bffMasterSection = new Dictionary <string, string>(); var masterBffCopySections = new List <string>(); var masterBffCustomSections = new UniqueList <string>(); // section that is not ordered bool mustGenerateFastbuild = false; var platformBffCache = new Dictionary <Platform, IPlatformBff>(); var verificationPostBuildCopies = new Dictionary <string, string>(); foreach (Solution.Configuration solutionConfiguration in configurationsPerBff) { foreach (var solutionProject in solutionProjects) { var project = solutionProject.Project; // Export projects do not have any bff if (project.GetType().IsDefined(typeof(Export), false)) { continue; } // When the project has a source file filter, only keep it if the file list is not empty if (project.SourceFilesFilters != null && (project.SourceFilesFiltersCount == 0 || project.SkipProjectWhenFiltersActive)) { continue; } Solution.Configuration.IncludedProjectInfo includedProject = solutionConfiguration.GetProject(solutionProject.Project.GetType()); bool perfectMatch = includedProject != null && solutionProject.Configurations.Contains(includedProject.Configuration); if (!perfectMatch) { continue; } var conf = includedProject.Configuration; if (!conf.IsFastBuildEnabledProjectConfig()) { continue; } mustGenerateFastbuild = true; IPlatformBff platformBff = platformBffCache.GetValueOrAdd(conf.Platform, PlatformRegistry.Query <IPlatformBff>(conf.Platform)); platformBff.AddCompilerSettings(masterBffInfo.CompilerSettings, conf); if (FastBuildSettings.WriteAllConfigsSection && includedProject.ToBuild == Solution.Configuration.IncludedProjectInfo.Build.Yes) { masterBffInfo.AllConfigsSections.Add(Bff.GetShortProjectName(project, conf)); } using (fileGenerator.Declare("conf", conf)) using (fileGenerator.Declare("target", conf.Target)) using (fileGenerator.Declare("project", conf.Project)) { var preBuildEvents = new Dictionary <string, Project.Configuration.BuildStepBase>(); if (conf.Output == Project.Configuration.OutputType.Exe || conf.ExecuteTargetCopy) { var copies = ProjectOptionsGenerator.ConvertPostBuildCopiesToRelative(conf, masterBffDirectory); foreach (var copy in copies) { var sourceFile = copy.Key; var sourceFileName = Path.GetFileName(sourceFile); var destinationFolder = copy.Value; var destinationFile = Path.Combine(destinationFolder, sourceFileName); // use the global root for alias computation, as the project has not idea in which master bff it has been included var destinationRelativeToGlobal = Util.GetConvertedRelativePath(masterBffDirectory, destinationFolder, conf.Project.RootPath, true, conf.Project.RootPath); { string key = sourceFileName + destinationRelativeToGlobal; string currentSourceFullPath = Util.PathGetAbsolute(masterBffDirectory, sourceFile); string previous; if (verificationPostBuildCopies.TryGetValue(key, out previous)) { if (previous != currentSourceFullPath) { builder.LogErrorLine("A post-build copy to the destination '{0}' already exist but from different sources: '{1}' and '{2}'!", Util.PathGetAbsolute(masterBffDirectory, destinationFolder), previous, currentSourceFullPath); } } else { verificationPostBuildCopies.Add(key, currentSourceFullPath); } } string fastBuildCopyAlias = UtilityMethods.GetFastBuildCopyAlias(sourceFileName, destinationRelativeToGlobal); { using (fileGenerator.Declare("fastBuildCopyAlias", fastBuildCopyAlias)) using (fileGenerator.Declare("fastBuildCopySource", sourceFile)) using (fileGenerator.Declare("fastBuildCopyDest", destinationFile)) { if (!bffMasterSection.ContainsKey(fastBuildCopyAlias)) { bffMasterSection.Add(fastBuildCopyAlias, fileGenerator.Resolver.Resolve(Bff.Template.ConfigurationFile.CopyFileSection)); } } } } foreach (var eventPair in conf.EventPreBuildExecute) { preBuildEvents.Add(eventPair.Key, eventPair.Value); } foreach (var buildEvent in conf.ResolvedEventPreBuildExe) { string eventKey = ProjectOptionsGenerator.MakeBuildStepName(conf, buildEvent, Vcxproj.BuildStep.PreBuild); preBuildEvents.Add(eventKey, buildEvent); } WriteEvents(fileGenerator, preBuildEvents, bffPreBuildSection, masterBffDirectory); } var customPreBuildEvents = new Dictionary <string, Project.Configuration.BuildStepBase>(); foreach (var eventPair in conf.EventCustomPrebuildExecute) { customPreBuildEvents.Add(eventPair.Key, eventPair.Value); } foreach (var buildEvent in conf.ResolvedEventCustomPreBuildExe) { string eventKey = ProjectOptionsGenerator.MakeBuildStepName(conf, buildEvent, Vcxproj.BuildStep.PreBuildCustomAction); customPreBuildEvents.Add(eventKey, buildEvent); } WriteEvents(fileGenerator, customPreBuildEvents, bffCustomPreBuildSection, masterBffDirectory); if (includedProject.ToBuild == Solution.Configuration.IncludedProjectInfo.Build.Yes) { MergeBffIncludeTreeRecursive(conf, ref masterBffInfo.BffIncludeToDependencyIncludes); } } } } if (!mustGenerateFastbuild) { throw new Error("Sharpmake-FastBuild : Trying to generate a MasterBff with none of its projects having a FastBuild configuration, or having a platform supporting it, or all of them having conf.DoNotGenerateFastBuild = true"); } masterBffCopySections.AddRange(bffMasterSection.Values); masterBffCopySections.AddRange(bffPreBuildSection.Values); masterBffCustomSections.AddRange(bffCustomPreBuildSection.Values); var result = new StringBuilder(); foreach (var projectBffFullPath in GetMasterIncludeList(masterBffInfo.BffIncludeToDependencyIncludes)) { string projectFullPath = Path.GetDirectoryName(projectBffFullPath); var projectPathRelativeFromMasterBff = Util.PathGetRelative(masterBffDirectory, projectFullPath, true); string bffKeyRelative = Path.Combine(Bff.CurrentBffPathKey, Path.GetFileName(projectBffFullPath)); string include = string.Join( Environment.NewLine, "{", $" {Bff.CurrentBffPathVariable} = \"{projectPathRelativeFromMasterBff}\"", $" #include \"{bffKeyRelative}\"", "}" ); result.AppendLine(include); } string fastBuildMasterBffDependencies = result.Length == 0 ? FileGeneratorUtilities.RemoveLineTag : result.ToString(); GenerateMasterBffGlobalSettingsFile(builder, globalConfigFullPath, masterBffInfo); using (fileGenerator.Declare("fastBuildProjectName", masterBffFileName)) using (fileGenerator.Declare("fastBuildGlobalConfigurationInclude", $"#include \"{globalConfigFileName}\"")) { fileGenerator.Write(Bff.Template.ConfigurationFile.HeaderFile); foreach (Platform platform in platformBffCache.Keys) // kind of cheating to use that cache instead of the masterBffInfo.CompilerSettings, but it works :) { using (fileGenerator.Declare("fastBuildDefine", Bff.GetPlatformSpecificDefine(platform))) fileGenerator.Write(Bff.Template.ConfigurationFile.Define); } fileGenerator.Write(Bff.Template.ConfigurationFile.GlobalConfigurationInclude); } WriteMasterCopySection(fileGenerator, masterBffCopySections); WriteMasterCustomSection(fileGenerator, masterBffCustomSections); using (fileGenerator.Declare("fastBuildProjectName", masterBffFileName)) using (fileGenerator.Declare("fastBuildOrderedBffDependencies", fastBuildMasterBffDependencies)) { fileGenerator.Write(Bff.Template.ConfigurationFile.Includes); } if (masterBffInfo.AllConfigsSections.Count != 0) { using (fileGenerator.Declare("fastBuildConfigs", UtilityMethods.FBuildFormatList(masterBffInfo.AllConfigsSections, 4))) { fileGenerator.Write(Bff.Template.ConfigurationFile.AllConfigsSection); } } // remove all line that contain RemoveLineTag fileGenerator.RemoveTaggedLines(); MemoryStream bffCleanMemoryStream = fileGenerator.ToMemoryStream(); // Write master .bff file FileInfo bffFileInfo = new FileInfo(masterBffFilePath); bool updated = builder.Context.WriteGeneratedFile(null, bffFileInfo, bffCleanMemoryStream); foreach (var confsPerSolution in configurationsPerBff) { confsPerSolution.Solution.PostGenerationCallback?.Invoke(masterBffDirectory, Path.GetFileNameWithoutExtension(masterBffFileName), FastBuildSettings.FastBuildConfigFileExtension); } return(updated); }
public IndexCollection[] GetCollections(Options options) { if (options is null) { throw new ArgumentNullException(nameof(options)); } var result = new UniqueList(); if (options.RandomizeDungeon) { result.AddRange(TriforceRoom.AllIndexCollections); result.AddRange(ExtraPalettes.DungeonMainBG); } result.AddRange(ExtraPalettes.GetOverlayPalettes( options.RandomizeDungeon, options.RandomizeDungeon, options.RandomizeHudPalettes)); result.AddRange(ExtraPalettes.GetPlayerPalettes( options.RandomizeLinkSpritePalette, options.RandomizeSwordPalette, options.RandomizeShieldPalette)); if (options.RandomizeOverworld) { result.AddRange(LightWorldAndMap.AllIndexCollections); result.AddRange(DarkWorldAndMap.AllIndexCollections); result.AddRange(LightWorld.MiscIndexCollections); result.AddRange(LightWorld.HyruleCastle.MiscIndexCollections); result.AddRange(LightWorld.Sanctuary.MiscIndexCollections); result.AddRange(LightWorld.Kakariko.AllIndexCollections); result.AddRange(LightWorld.DeathMountain.MiscIndexCollections); result.AddRange(DarkWorld.MiscIndexCollections); result.AddRange(DarkWorld.PalaceOfDarkness.AllIndexCollections); result.AddRange(DarkWorld.SkullWoods.AllIndexCollections); result.AddRange(DarkWorld.ThievesTown.AllIndexCollections); result.AddRange(DarkWorld.Swamp.AllIndexCollections); result.AddRange(DarkWorld.DarkMountain.MiscIndexCollections); } if (options.RandomizeSpritePalettes || options.RandomizeAdvancedSpritePalettes) { Console.Error.WriteLine( "Randomizing sprite palettes is currently not supported."); } return(result.ToArray()); }