コード例 #1
0
 private ColorDecider(
     string solutionFullName,
     SignatureGenerator signatureGenerator,
     IReadOnlyList <Color> palette,
     IReadOnlyDictionary <int, int> mapping,
     IReadOnlyList <ICustomMapping> customMappings)
 {
     _solutionFullName   = solutionFullName;
     _signatureGenerator = signatureGenerator;
     _palette            = palette;
     _mapping            = mapping;
     _customMappings     = customMappings;
 }
コード例 #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);
        }