// 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); }
private Color GetColorOf(Project project) { ThreadHelper.ThrowIfNotOnUIThread(); if (project == null) { return(Colors.Transparent); } foreach (var custom in _customMappings) { if (IsMatch(project.Name, custom.Wildcard)) { return(DrawingColorToMediaColor(custom.Color)); } } return(_mapping.TryGetValue(_signatureGenerator.GetSignature(project.UniqueName, _solutionFullName), out var index) ? _palette[index] : Colors.Transparent); }