private void ExportColors(object colorsToExport, GroupExportedColorsBy method) { var colors = SerializationHelper.ConvertToDesiredColorFormats((IList)colorsToExport, ColorRepresentations, method); var dialog = new SaveFileDialog { Title = "Save selected colors to", Filter = "Text Files (*.txt)|*.txt|Json Files (*.json)|*.json", }; if (dialog.ShowDialog() == true) { var extension = Path.GetExtension(dialog.FileName); var contentToWrite = extension.ToUpperInvariant() switch { ".TXT" => colors.ToTxt(';'), ".JSON" => colors.ToJson(), _ => string.Empty }; File.WriteAllText(dialog.FileName, contentToWrite); SessionEventHelper.Event.EditorColorsExported = true; } }
public static Dictionary <string, Dictionary <string, string> > ConvertToDesiredColorFormats( IList colorsToExport, IEnumerable <ColorFormatModel> colorRepresentations, GroupExportedColorsBy method) { var colors = new Dictionary <string, Dictionary <string, string> >(); var colorFormatModels = colorRepresentations.ToList(); var i = 1; switch (method) { case GroupExportedColorsBy.Color: { foreach (Color color in (IList)colorsToExport) { var tmp = new Dictionary <string, string>(); foreach (var colorFormatModel in colorFormatModels) { var colorInSpecificFormat = colorFormatModel.Convert(color); if (colorFormatModel.FormatName == "HEX") { colorInSpecificFormat = "#" + colorInSpecificFormat; } tmp.Add( colorFormatModel.FormatName, #pragma warning disable CA1308 // Normalize strings to uppercase colorInSpecificFormat.Replace( colorFormatModel.FormatName.ToLower(CultureInfo.InvariantCulture), string.Empty, StringComparison.InvariantCultureIgnoreCase)); #pragma warning restore CA1308 // Normalize strings to uppercase } colors.Add($"color{i++}", tmp); } } break; case GroupExportedColorsBy.Format: { foreach (var colorFormatModel in colorFormatModels) { var tmp = new Dictionary <string, string>(); i = 1; foreach (Color color in (IList)colorsToExport) { var colorInSpecificFormat = colorFormatModel.Convert(color); if (colorFormatModel.FormatName == "HEX") { colorInSpecificFormat = "#" + colorInSpecificFormat; } tmp.Add( $"color{i++}", #pragma warning disable CA1308 // Normalize strings to uppercase colorInSpecificFormat.Replace( colorFormatModel.FormatName.ToLower(CultureInfo.InvariantCulture), string.Empty, StringComparison.InvariantCultureIgnoreCase)); #pragma warning restore CA1308 // Normalize strings to uppercase } colors.Add(colorFormatModel.FormatName, tmp); } } break; } return(colors); }