public static Merge ( IEnumerable |
||
styles | IEnumerable |
Sequence of DefaultStyles. |
리턴 |
/// <summary> /// Merge a sequence of DefaultStyles into a single style. /// </summary> /// <param name="styles">Sequence of DefaultStyles.</param> /// <returns>Merged DefaultStyle.</returns> public static DefaultStyle Merge(IEnumerable <DefaultStyle> styles) { DefaultStyle combined = new DefaultStyle(); if (styles != null) { foreach (DefaultStyle style in styles) { combined.Merge(style); } } return(combined); }
public override bool Execute() { Log.LogMessage(MessageImportance.Low, "Merging default styles into Generic.xaml."); // Get the original generic.xaml string originalPath = Path.Combine(ProjectDirectory, Path.Combine("Themes", "Generic.xaml")); if (!File.Exists(originalPath)) { Log.LogError("{0} does not exist!", originalPath); return(false); } Log.LogMessage(MessageImportance.Low, "Found original Generic.xaml at {0}.", originalPath); string original = null; Encoding encoding = Encoding.Default; try { using (StreamReader reader = new StreamReader(File.Open(originalPath, FileMode.Open, FileAccess.Read))) { original = reader.ReadToEnd(); encoding = reader.CurrentEncoding; } } catch (Exception ex) { Log.LogErrorFromException(ex); return(false); } // Create the merged Generic.xaml List <DefaultStyle> styles = new List <DefaultStyle>(); foreach (ITaskItem item in DefaultStyles) { string path = Path.Combine(ProjectDirectory, item.ItemSpec); if (!File.Exists(path)) { Log.LogWarning("Ignoring missing DefaultStyle {0}.", path); continue; } try { Log.LogMessage(MessageImportance.Low, "Processing file {0}.", item.ItemSpec); styles.Add(DefaultStyle.Load(path)); } catch (Exception ex) { Log.LogErrorFromException(ex); } } string merged = null; try { merged = DefaultStyle.Merge(styles).GenerateXaml(); } catch (InvalidOperationException ex) { Log.LogErrorFromException(ex); return(false); } // Write the new generic.xaml if (original != merged) { Log.LogMessage(MessageImportance.Low, "Writing merged Generic.xaml."); if (EnableTfs && TryTfs.Checkout(originalPath)) { Log.LogMessage("Checked out Generic.xaml."); } else { // Remove read-only flag File.SetAttributes(originalPath, FileAttributes.Normal); } try { File.WriteAllText(originalPath, merged, encoding); Log.LogMessage("Successfully merged Generic.xaml."); } catch (Exception ex) { Log.LogErrorFromException(ex); return(false); } } else { Log.LogMessage("Existing Generic.xaml was up to date."); } return(true); }
/// <summary> /// Merge a sequence of DefaultStyles into a single style. /// </summary> /// <param name="styles">Sequence of DefaultStyles.</param> /// <returns>Merged DefaultStyle.</returns> public static DefaultStyle Merge(IEnumerable<DefaultStyle> styles) { DefaultStyle combined = new DefaultStyle(); if (styles != null) { foreach (DefaultStyle style in styles) { combined.Merge(style); } } return combined; }