Exemple #1
0
        private static void MapAndPrint(ICollection <string> names)
        {
            var mapping = PaletteDistribution.Map(names.Select(name => name.GetHashCode()).ToImmutableArray(), s_predefinedPalette.Count);

            foreach (var name in names)
            {
                var color = s_predefinedPalette[mapping[name.GetHashCode()]];
                Console.ForegroundColor = color;
                Console.Write(name);
            }

            Console.WriteLine();
        }
Exemple #2
0
        // This method is very heavy with nested methods but they're not needed anywhere else,
        // so no benefit in cluttering up the codebase by having them outside of it.
        public static ColorDecider Create(Solution solution, PcfSettings options)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            IReadOnlyList <Color> loadPalette()
            {
                var keep          = options.IncludeDefaultPalette;
                var customPalette = options.CustomColors;

                var result = new List <Color>(PredefinedPalette.Count);

                if (keep || customPalette.IsNullOrEmpty())
                {
                    result.AddRange(PredefinedPalette);
                }

                // convert System.Drawing.Color to System.Windows.Media.Color
                var toAdd = from c in customPalette
                            select DrawingColorToMediaColor(c);

                result.AddRange(toAdd);

                return(new ReadOnlyCollection <Color>(result));
            }

            var signatureGenerator = new SignatureGenerator(options.FactorInSolutionPath);

            IReadOnlyDictionary <int, int> map(int paletteCount)
            {
                var signatures = (from project in solution.Projects.Cast <Project>()
                                  select signatureGenerator.GetSignature(project.UniqueName, solution.FullName))
                                 .ToList();

                return(PaletteDistribution.Map(signatures, paletteCount));
            }

            IReadOnlyList <Color> palette = loadPalette();
            var instance = new ColorDecider(
                solution.FullName,
                signatureGenerator,
                palette,
                map(palette.Count),
                new ReadOnlyCollection <ICustomMapping>(options.CustomMappings.Cast <ICustomMapping>().ToList()));

            instance.DebugLogMapping(solution);
            return(instance);
        }