using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace AWSPowerShellGenerator.Utils { /// /// Collector class for various project file fragments that we want to inject into /// the final AWSPowerShell project file ahead of build. /// internal class ProjectFileFragmentStore { /// /// Collects the various .cs file fragments for compilation, organised by service (for /// easier debugging/inspection) /// Dictionary _csfileFragments = new Dictionary(); ProjectFileFragmentStore() { } static ProjectFileFragmentStore _this; public static ProjectFileFragmentStore Instance { get { if (_this == null) _this = new ProjectFileFragmentStore(); return _this; } } /// /// Add one or more C# files to the relevant item group for the named service, creating the group /// if necessary /// /// Service namespace, eg 'AmazonEC2' /// Full or relative name to the generated C# source file public void AddCSFileForCompilation(string serviceItemGroup, params string[] csFiles) { StringWriter itemGroupFragment; if (_csfileFragments.ContainsKey(serviceItemGroup)) itemGroupFragment = _csfileFragments[serviceItemGroup]; else { itemGroupFragment = new StringWriter(); _csfileFragments.Add(serviceItemGroup, itemGroupFragment); } foreach (string csFile in csFiles) { itemGroupFragment.WriteLine(@"", csFile); } } /// /// Returns the full collection of C# file item groups as one string, /// public string Serialize() { StringWriter sw = new StringWriter(); sw.WriteLine(""); foreach (string key in _csfileFragments.Keys) { sw.WriteLine(_csfileFragments[key].ToString()); } sw.WriteLine(""); return sw.ToString(); } /// /// Returns the C# item group for a specific service as one string /// /// Service namespace, eg 'AmazonEC2' /// public string Serialize(string serviceItemGroup) { if (_csfileFragments.ContainsKey(serviceItemGroup)) { return _csfileFragments[serviceItemGroup].ToString(); } // warn? return string.Empty; } } }