예제 #1
0
        public void Test()
        {
            var lookupTable = new LookupTable <string, int>(StringComparer.OrdinalIgnoreCase);

            lookupTable.Should().BeEmpty();
            lookupTable["first"].Should().BeEmpty();

            lookupTable.Add("first", value: 2);
            lookupTable.Add("first", value: 3);
            lookupTable.Add("first", value: 4);
            lookupTable.Add("second", value: 5);
            lookupTable.Should().HaveCount(2);
            lookupTable["first"].Should().HaveCount(3);
            lookupTable["first"].Should().BeEquivalentTo(2, 3, 4);

            lookupTable.Remove("first", value: 3);
            lookupTable["first"].Should().HaveCount(2);
            lookupTable["first"].Should().BeEquivalentTo(2, 4);

            lookupTable.Remove("first");
            lookupTable["first"].Should().BeEmpty();
            lookupTable.Should().HaveCount(1);

            var copy = new LookupTable <string, int>(lookupTable, StringComparer.OrdinalIgnoreCase);

            lookupTable.Add("second", value: 6);
            copy["second"].Should().HaveCount(1);

            lookupTable.Clear();
            lookupTable.Should().BeEmpty();
            copy.Should().NotBeEmpty();
        }
예제 #2
0
        protected virtual void GroupByDependencies(
            LookupTable <int, ExecutableTarget> groupedTargets,
            IEnumerable <ExecutableTarget> unorderedTargets,
            IReadOnlyCollection <ExecutableTarget> allTargets,
            int slot)
        {
            var remainingTargets = new List <ExecutableTarget>();

            foreach (ExecutableTarget target in unorderedTargets)
            {
                IEnumerable <ExecutableTarget> matchedDependencies = GetMatchedDependencies(groupedTargets, allTargets, target, slot);
                IEnumerable <ExecutableTarget> allDependencies     = target.ExecutionDependencies
                                                                     .Union(target.AllDependencies.Intersect(allTargets));

                if (allDependencies.Count() == matchedDependencies.Count())
                {
                    // add the target to the slot if all dependencies are matched
                    groupedTargets.Add(slot, target);
                }
                else
                {
                    remainingTargets.Add(target);
                }
            }

            if (remainingTargets.Any())
            {
                GroupByDependencies(groupedTargets, remainingTargets, allTargets, slot + 1);
            }
        }
예제 #3
0
        /// <summary>
        /// Get the lookup table for the given culture (creating if necessary)
        /// </summary>
        /// <param name="culture"></param>
        /// <returns></returns>
        private LookupTable GetLookupTable(CultureInfo culture)
        {
            LookupTable result;

            if (culture == null)
            {
                culture = CultureInfo.CurrentCulture;
            }

            if (!lookupTables.TryGetValue(culture, out result))
            {
                result = new LookupTable();
                var standardValues = GetStandardValues();
                if (standardValues != null)
                {
                    foreach (var value in standardValues)
                    {
                        var text = GetValueText(culture, value);
                        if (text != null)
                        {
                            result.Add(text, value);
                        }
                    }
                }
                lookupTables.Add(culture, result);
            }
            return(result);
        }
예제 #4
0
        protected virtual TeamCityProject GetProject(
            NukeBuild build,
            IReadOnlyCollection <ExecutableTarget> executableTargets)
        {
            var relevantTargets = VcsTriggeredTargets.Concat(ManuallyTriggeredTargets)
                                  .SelectMany(x => ExecutionPlanner.GetExecutionPlan(executableTargets, new[] { x }))
                                  .Distinct()
                                  .Where(x => !ExcludedTargets.Contains(x.Name) && !NonEntryTargets.Contains(x.Name)).ToList();

            var vcsRoot     = GetVcsRoot(build);
            var lookupTable = new LookupTable <ExecutableTarget, TeamCityBuildType>();
            var buildTypes  = relevantTargets
                              .SelectMany(x => GetBuildTypes(build, x, vcsRoot, lookupTable), (x, y) => (ExecutableTarget: x, BuildType: y))
                              .ForEachLazy(x => lookupTable.Add(x.ExecutableTarget, x.BuildType))
                              .Select(x => x.BuildType).ToArray();

            var parameters = GetGlobalParameters(build);

            if (Platform == TeamCityAgentPlatform.Windows)
            {
                parameters = parameters
                             .Concat(new TeamCityKeyValueParameter
                {
                    Key   = "teamcity.runner.commandline.stdstreams.encoding",
                    Value = "IBM-437"
                });
            }

            return(new TeamCityProject
            {
                VcsRoot = vcsRoot,
                BuildTypes = buildTypes,
                Parameters = parameters.ToArray()
            });
        }
예제 #5
0
        private static ILookup <string, string> ParseItemGroups(string[] lines)
        {
            var itemGroupLines = lines
                                 .SkipWhile(x => x != "Initial Items:").Skip(count: 1)
                                 .TakeWhile(x => !string.IsNullOrWhiteSpace(x)).ToList();

            var lookup = new LookupTable <string, string>(EqualityComparer <string> .Default);

            for (var i = 0; i < itemGroupLines.Count; i++)
            {
                var group = itemGroupLines[i];

                while (i < itemGroupLines.Count - 1 &&
                       char.IsWhiteSpace(itemGroupLines[i + 1][index: 0]))
                {
                    if (char.IsLetter(itemGroupLines[i + 1], index: 4))
                    {
                        lookup.Add(group, itemGroupLines[i + 1].Trim());
                    }

                    i++;
                }
            }

            return(lookup);
        }
예제 #6
0
        protected virtual TeamCityProject GetProject(NukeBuild build, IReadOnlyCollection <ExecutableTarget> relevantTargets)
        {
            var vcsRoot     = GetVcsRoot(build);
            var lookupTable = new LookupTable <ExecutableTarget, TeamCityBuildType>();
            var buildTypes  = relevantTargets
                              .SelectMany(x => GetBuildTypes(build, x, vcsRoot, lookupTable, relevantTargets), (x, y) => (ExecutableTarget: x, BuildType: y))
                              .ForEachLazy(x => lookupTable.Add(x.ExecutableTarget, x.BuildType))
                              .Select(x => x.BuildType).ToArray();

            var parameters = GetGlobalParameters(build, relevantTargets);

            if (Platform == TeamCityAgentPlatform.Windows)
            {
                parameters = parameters
                             .Concat(new TeamCityKeyValueParameter
                {
                    Key   = "teamcity.runner.commandline.stdstreams.encoding",
                    Value = "UTF-8"
                });
            }

            return(new TeamCityProject
            {
                VcsRoot = vcsRoot,
                BuildTypes = buildTypes,
                Parameters = parameters.ToArray()
            });
        }
예제 #7
0
        public override ConfigurationEntity GetConfiguration(
            NukeBuild build,
            IReadOnlyCollection <ExecutableTarget> relevantTargets
            )
        {
            var paramList  = new List <AzurePipelinesParameter>();
            var parameters =
                build.GetType()
                .GetInterfaces()
                .SelectMany(x => x.GetMembers())
                .Concat(
                    build.GetType()
                    .GetMembers(
                        BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic |
                        BindingFlags.Public | BindingFlags.FlattenHierarchy
                        )
                    )
                .Where(x => x.GetCustomAttribute <ParameterAttribute>() != null);

            foreach (var parameter in parameters)
            {
                if (Parameters.Any(
                        z => z.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase) || z.Equals(
                            parameter.GetCustomAttribute <ParameterAttribute>()?.Name,
                            StringComparison.OrdinalIgnoreCase
                            )
                        ))
                {
                    var value = parameter.GetValue(build);
                    if (value is AbsolutePath)
                    {
                        value = null;
                    }

                    paramList.Add(
                        new AzurePipelinesParameter
                    {
                        Name    = parameter.GetCustomAttribute <ParameterAttribute>()?.Name ?? parameter.Name,
                        Default = value?.ToString() ?? "",
                    }
                        );
                }
            }

            var lookupTable = new LookupTable <ExecutableTarget, AzurePipelinesStep>();
            var steps       = relevantTargets
                              .Select(x => (ExecutableTarget: x, Job: GetStep(x, relevantTargets, lookupTable)))
                              .ForEachLazy(x => lookupTable.Add(x.ExecutableTarget, x.Job))
                              .Select(x => x.Job).ToArray();

            return(new AzurePipelinesSteps
            {
                Parameters = paramList.ToArray(),
                Steps = steps
            });
        }
예제 #8
0
        /// <summary>
        /// LookupTable is created from the global BoundModules without shuffling.
        /// </summary>
        private static void CreateLookupTableNoShuffle()
        {
            // Create lookup table for later features.
            LookupTable.Clear();

            foreach (var item in Globals.BoundModules)
            {
                LookupTable.Add(item.Code, item.Code);
            }
        }
        public CommandLookupTable()
            : base(new DoFunction {
            Value = (ch, arg) => ch.SendTo("Huh?")
        })
        {
            LookupTable.Add("do_say", new DoFunction {
                Value = Say.do_say
            });

            // TODO Add command references here
        }
예제 #10
0
        /// <summary>
        /// 지정된 <see cref="CultureInfo"/>에 해당하는 Key-Value 쌍의 Loopup Table을 반환한다. 없으면 새로 만든다.
        /// </summary>
        private LookupTable GetLookupTable(CultureInfo culture)
        {
            if (IsDebugEnabled)
            {
                log.Debug("지정된 문화권의 Lookup Table을 로드합니다... culture=[{0}]", culture);
            }

            LookupTable lookup = null;

            // if (culture == null)
            if (culture.IsNullCulture())
            {
                culture = CultureInfo.CurrentCulture;

                if (IsDebugEnabled)
                {
                    log.Debug("지정한 Culture가 null 이어서, 현재 Culture를 사용합니다. culture=[{0}]", culture);
                }
            }

            lock (_sync) {
                if (_lookupTables.TryGetValue(culture, out lookup) == false)
                {
                    if (IsDebugEnabled)
                    {
                        log.Debug("lookup table for culture[{0}] doesn't exists, so create new lookup table.", culture);
                    }

                    lookup = new LookupTable();

                    var standardValues = GetStandardValues();
                    if (standardValues != null)
                    {
                        foreach (var value in standardValues)
                        {
                            var text = GetValueText(culture, value);

                            if (text != null)
                            {
                                lookup.Add(text, value);
                            }
                        }
                    }
                    _lookupTables.Add(culture, lookup);
                }
            }
            return(lookup);
        }
예제 #11
0
        public SpellLookupTable()
            : base(new SpellFunction
        {
            Value = (id, level, ch, vo) =>
            {
                ch.SendTo("That's not a spell!");
                return(ReturnTypes.None);
            }
        })
        {
            LookupTable.Add("spell_smaug", new SpellFunction {
                Value = Smaug.spell_smaug
            });

            // TODO Add spells here
        }
예제 #12
0
        internal LegacyEncoding(LegacyCharacterSet g0, LegacyCharacterSet g1)
        {
            G0 = g0;
            G1 = g1;

            if ((G0 == IR_6) && (G1 == null))
            {
                LookupTable.Add("", this);
                LookupTable.Add("ISO 2022 IR 6", this);
            }
            else
            {
                var registrationNumber = (G1 ?? G0).ISORegistrationNumber;
                LookupTable.Add($"ISO_IR {registrationNumber}", this);
                LookupTable.Add($"ISO 2022 IR {registrationNumber}", this);
            }
        }
예제 #13
0
        protected virtual TeamCityProject GetProject(NukeBuild build, IReadOnlyCollection <ExecutableTarget> relevantTargets)
        {
            var vcsRoot     = GetVcsRoot(build);
            var lookupTable = new LookupTable <ExecutableTarget, TeamCityBuildType>();
            var buildTypes  = relevantTargets
                              .SelectMany(x => GetBuildTypes(build, x, vcsRoot, lookupTable, relevantTargets), (x, y) => (ExecutableTarget: x, BuildType: y))
                              .ForEachLazy(x => lookupTable.Add(x.ExecutableTarget, x.BuildType))
                              .Select(x => x.BuildType).ToArray();

            var parameters = GetGlobalParameters(build, relevantTargets);

            return(new TeamCityProject
            {
                VcsRoot = vcsRoot,
                BuildTypes = buildTypes,
                Parameters = parameters.ToArray()
            });
        }
예제 #14
0
        protected virtual AzurePipelinesStage GetStage(
            AzurePipelinesImage image,
            IReadOnlyCollection <ExecutableTarget> relevantTargets)
        {
            var lookupTable = new LookupTable <ExecutableTarget, AzurePipelinesJob>();
            var jobs        = relevantTargets
                              .Select(x => (ExecutableTarget: x, Job: GetJob(x, lookupTable)))
                              .ForEachLazy(x => lookupTable.Add(x.ExecutableTarget, x.Job))
                              .Select(x => x.Job).ToArray();

            return(new AzurePipelinesStage
            {
                Name = image.GetValue().Replace("-", "_"),
                DisplayName = image.GetValue(),
                Image = image,
                Dependencies = new AzurePipelinesStage[0],
                Jobs = jobs
            });
        }
        /// <summary>
        /// Initializes the implementation details of a <see cref="CyclicRedundancyCheck"/> related polynomial lookup table.
        /// </summary>
        /// <param name="currentBit">The current bit ranging from 0 to 7.</param>
        /// <param name="currentTableIndex">The current index of the associated polynomial <see cref="CyclicRedundancyCheck.LookupTable"/> ranging from 0 to 255.</param>
        /// <remarks>This method is - on first run - invoked 8 times per entry in the associated polynomial <see cref="CyclicRedundancyCheck.LookupTable"/>, given a total of 2048 times.</remarks>
        protected override void InitializePolynomialLookupTable(byte currentBit, ushort currentTableIndex)
        {
            bool hasIndex = ListUtility.HasIndex(currentTableIndex, LookupTable);

            if (!hasIndex)
            {
                LookupTable.Add(currentTableIndex);
            }
            long value = LookupTable[currentTableIndex];

            if ((value & 1) == 1)
            {
                value = (value >> 1) ^ Polynomial;
            }
            else
            {
                value >>= 1;
            }
            LookupTable[currentTableIndex] = value;
        }
예제 #16
0
        /// <summary>
        /// Recupera o dicionário de valores para caché (criando se necessário)
        /// </summary>
        /// <param name="culture"></param>
        private LookupTable GetLookupTable(CultureInfo culture)
        {
            LookupTable lookupTable = null;

            culture = culture == null ? CultureInfo.CurrentCulture : culture;

            if (!_lookupTables.TryGetValue(culture, out lookupTable))
            {
                lookupTable = new LookupTable();
                foreach (object value in base.GetStandardValues())
                {
                    string text = GetValueText(culture, value);
                    if (text != null)
                    {
                        lookupTable.Add(text, value);
                    }
                }
                _lookupTables.Add(culture, lookupTable);
            }
            return(lookupTable);
        }
예제 #17
0
        public static ILookup<string, string> ExtractAndRemoveRegions(List<string> content, string beginPrefix, string endPrefix)
        {
            var regions = new LookupTable<string, string>(StringComparer.OrdinalIgnoreCase);

            for (var i = 0; i < content.Count; i++)
            {
                if (!content[i].TrimStart().StartsWith(beginPrefix))
                    continue;

                var regionName = content[i].TrimStart().TrimStart(beginPrefix).TrimStart();
                i++;

                while (i < content.Count && !content[i].TrimStart().StartsWith(endPrefix))
                {
                    regions.Add(regionName, content[i]);
                    content.RemoveAt(i);
                }
            }

            return regions;
        }
예제 #18
0
        /// <summary>
        /// Get the lookup table for the given culture (creating if necessary)
        /// </summary>
        /// <param name="culture"></param>
        /// <returns></returns>
        private LookupTable GetLookupTable(CultureInfo culture)
        {
            if (culture == null)
            {
                culture = CultureInfo.CurrentCulture;
            }

            if (!_lookupTables.TryGetValue(culture, out var result))
            {
                result = new LookupTable();
                foreach (var value in GetStandardValues())
                {
                    var text = GetValueText(culture, value);
                    if (text != null)
                    {
                        result.Add(text, value);
                    }
                }
                _lookupTables.Add(culture, result);
            }
            return(result);
        }
예제 #19
0
        /// <summary>
        /// LookupTable is created from the global BoundModules after shuffling included modules.
        /// </summary>
        private static void CreateLookupTableShuffle()
        {
            List <string> excluded = Globals.BoundModules.Where(x => x.Omitted).Select(x => x.Code).ToList();
            List <string> included = Globals.BoundModules.Where(x => !x.Omitted).Select(x => x.Code).ToList();

            // Shuffle the list of included modules.
            List <string> shuffle = new List <string>(included);

            Randomize.FisherYatesShuffle(shuffle);
            LookupTable.Clear();

            for (int i = 0; i < included.Count; i++)
            {
                LookupTable.Add(included[i], shuffle[i]);
            }

            // Include the unmodified list of excluded modules.
            foreach (string name in excluded)
            {
                LookupTable.Add(name, name);
            }
        }
예제 #20
0
        /// <summary>
        /// Get the lookup table for the given culture (creating if necessary)
        /// </summary>
        /// <param name="culture"></param>
        /// <returns></returns>
        private LookupTable GetLookupTable(CultureInfo culture)
        {
            LookupTable result = null;

            if (culture == null)
            {
                culture = CultureInfo.CurrentCulture;
            }

            if (!_lookupTables.TryGetValue(culture, out result))
            {
                result = new LookupTable();
                foreach (object value in GetStandardValues())
                {
                    string text = GetValueText(culture, value);
                    if (text != null)
                    {
                        result.Add(value.ToString(), text);
                    }
                }
                _lookupTables.Add(culture, result);
            }
            return(result);
        }
예제 #21
0
        public static void texture_rando(KPaths paths)
        {
            // Prepare lists for new randomization.
            MaxRando.Clear();
            TypeLists.Clear();

            // Load in texture pack.
            string pack_name;

            switch (Properties.Settings.Default.TexturePack)
            {
            default:
            case TexturePack.HighQuality:
                pack_name = "\\swpc_tex_tpa.erf";
                break;

            case TexturePack.MedQuality:
                pack_name = "\\swpc_tex_tpb.erf";
                break;

            case TexturePack.LowQuality:
                pack_name = "\\swpc_tex_tpc.erf";
                break;
            }

            ERF e = new ERF(paths.TexturePacks + pack_name);

            foreach (var key in e.Key_List)
            {
                if (!NameLookup.ContainsKey(key.ResID))
                {
                    NameLookup.Add(key.ResID, key.ResRef);
                }
            }

            // Handle categories.
            HandleCategory(e, RegexCubeMaps, Properties.Settings.Default.TextureRandomizeCubeMaps);
            HandleCategory(e, RegexCreatures, Properties.Settings.Default.TextureRandomizeCreatures);
            HandleCategory(e, RegexEffects, Properties.Settings.Default.TextureRandomizeEffects);
            HandleCategory(e, RegexItems, Properties.Settings.Default.TextureRandomizeItems);
            HandleCategory(e, RegexPlanetary, Properties.Settings.Default.TextureRandomizePlanetary);
            HandleCategory(e, RegexNPC, Properties.Settings.Default.TextureRandomizeNPC);
            HandleCategory(e, RegexPlayHeads, Properties.Settings.Default.TextureRandomizePlayHeads);
            HandleCategory(e, RegexPlayBodies, Properties.Settings.Default.TextureRandomizePlayBodies);
            HandleCategory(e, RegexPlaceables, Properties.Settings.Default.TextureRandomizePlaceables);
            HandleCategory(e, RegexParty, Properties.Settings.Default.TextureRandomizeParty);
            HandleCategory(e, RegexStunt, Properties.Settings.Default.TextureRandomizeStunt);
            HandleCategory(e, RegexVehicles, Properties.Settings.Default.TextureRandomizeVehicles);
            HandleCategory(e, RegexWeapons, Properties.Settings.Default.TextureRandomizeWeapons);

            // Handle other.
            switch (Properties.Settings.Default.TextureRandomizeOther)
            {
            default:
            case RandomizationLevel.None:
                break;     // Do nothing.

            case RandomizationLevel.Type:
                List <int> type = new List <int>(e.Key_List.Where(x => Matches_None(x.ResRef) && !Is_Forbidden(x.ResRef)).Select(x => x.ResID));
                TypeLists.Add(type);
                break;

            case RandomizationLevel.Max:
                MaxRando.AddRange(e.Key_List.Where(x => Matches_None(x.ResRef) && !Is_Forbidden(x.ResRef)).Select(x => x.ResID));
                break;
            }

            // Max Rando.
            List <int> Max_Rando_Iterator = new List <int>(MaxRando);

            Randomize.FisherYatesShuffle(MaxRando);
            int j = 0;

            foreach (ERF.Key k in e.Key_List.Where(x => Max_Rando_Iterator.Contains(x.ResID)))
            {
                LookupTable.Add(k.ResID, MaxRando[j]);
                k.ResID = MaxRando[j];
                j++;
            }

            // Type Rando.
            foreach (List <int> li in TypeLists)
            {
                List <int> type_copy = new List <int>(li);
                Randomize.FisherYatesShuffle(type_copy);
                j = 0;
                foreach (ERF.Key k in e.Key_List.Where(x => li.Contains(x.ResID)))
                {
                    LookupTable.Add(k.ResID, type_copy[j]);
                    k.ResID = type_copy[j];
                    j++;
                }
            }

            e.WriteToFile(paths.TexturePacks + pack_name);
        }
        public override ConfigurationEntity GetConfiguration(
            NukeBuild build,
            IReadOnlyCollection <ExecutableTarget> relevantTargets
            )
        {
            var steps = new List <GitHubActionsStep> {
                new CheckoutStep("Checkout"),
                // new SetupDotNetStep("Install .NET Core Sdk"),
            };


            var globalToolStep = new RunStep("Install Nuke Global Tool")
            {
                Run = "dotnet tool install -g Nuke.GlobalTool"
            };
            var dotnetTools = Path.Combine(NukeBuild.RootDirectory, ".config/dotnet-tools.json");
            var localTool   = false;

            if (File.Exists(dotnetTools))
            {
                steps.Add(new RunStep("dotnet tool restore")
                {
                    Run = "dotnet tool restore"
                });
                if (!File.ReadAllText(dotnetTools).Contains("\"nuke.globaltool\": {"))
                {
                    steps.Add(globalToolStep);
                }
                else
                {
                    localTool = true;
                }
            }
            else
            {
                steps.Add(globalToolStep);
            }

            var stepParameters = GetParameters(build).Select(z => $"--{z.Name.ToLowerInvariant()} '${{{{ env.{z.Name.ToUpperInvariant()} }}}}'")
                                 .ToArray()
                                 .JoinSpace();

            var lookupTable = new LookupTable <ExecutableTarget, ExecutableTarget[]>();

            foreach (var(execute, targets) in relevantTargets
                     .Select(x => (ExecutableTarget: x, Targets: GetInvokedTargets(x, relevantTargets).ToArray()))
                     .ForEachLazy(x => lookupTable.Add(x.ExecutableTarget, x.Targets.ToArray()))
                     )
            {
                steps.Add(new RunStep(execute.Name.Humanize(LetterCasing.Title))
                {
                    Run = $"{( localTool ? "dotnet nuke" : "nuke" )} {targets.Select(z => z.Name).JoinSpace()} --skip {stepParameters}".TrimEnd()
                });
            }

            var config = new RocketSurgeonGitHubActionsConfiguration()
            {
                Name             = _name,
                DetailedTriggers = GetTriggers().ToList(),
                Jobs             = new List <RocketSurgeonsGithubActionsJob> {
                    new RocketSurgeonsGithubActionsJob("Build")
                    {
                        Steps  = steps,
                        Images = _images,
                    }
                }
            };

            if (Enhancements?.Any() == true)
            {
                foreach (var method in Enhancements.Join(build.GetType().GetMethods(), z => z, z => z.Name, (_, e) => e))
                {
                    config = method.IsStatic
                        ? method.Invoke(null, new object[] { config }) as RocketSurgeonGitHubActionsConfiguration ?? config
                        : method.Invoke(build, new object[] { config }) as RocketSurgeonGitHubActionsConfiguration ?? config;
                }
            }

            return(config);
        }
예제 #23
0
        private static LookupTable LoadMAVTable(string TableName)
        {
            var lookupTable = new LookupTable();

            string sql = "select Wt, MAV from " + TableName + " order by Wt";

            DbDataReader dr = WWD.GetSysReader(sql);

            while (dr.Read())
            {
                lookupTable.Add(dr.GetFloat(0), dr.GetFloat(1));
            }

            dr.Close();

            return lookupTable;
        }