public static IGCompilationUnit CompilationUnitDefaultConfigurationConstructor(String gNamespaceName, string gRelativePath = default, List <string> gAdditionalStatements = default, GPatternReplacement gPatternReplacement = default) { GCompilationUnit gCompilationUnit = new GCompilationUnit(gName: "DefaultConfiguration", gRelativePath, gPatternReplacement: gPatternReplacement); foreach (var o in new List <IGUsing>() { new GUsing("System.Collections.Generic") }) { gCompilationUnit.GUsings.Add(o.Id, o); } GNamespace gNamespace = new GNamespace(gNamespaceName); GClass gClass = new GClass("DefaultConfiguration", gVisibility: "public", gAccessModifier: "static"); GStaticVariable gStaticVariable = new GStaticVariable(gName: "Production", gType: "Dictionary<string,string>", gVisibility: "public", gAccessModifier: "", gBody: new GBody(new List <string>() { "new Dictionary<string, string> {", //" {StringConstants.PlaceholderConfigKey, StringConstants.PlaceholderStringDefault},", "}", }), gAdditionalStatements: gAdditionalStatements ); gClass.GStaticVariables.Add(gStaticVariable.Id, gStaticVariable); gNamespace.GClasss[gClass.Id] = gClass; gCompilationUnit.GNamespaces.Add(gNamespace.Id, gNamespace); return(gCompilationUnit); }
public static IGCompilationUnit CompilationUnitStringConstantsConstructor(String gNamespaceName, string gRelativePath = default, IGPatternReplacement gPatternReplacement = default) { GClass gClass = new GClass("StringConstants", gVisibility: "public", "static"); GConstStringGroup gConstStringGroup = new GConstStringGroup(gName: "Settings File Names"); foreach (var kvp in new Dictionary <string, string>() { { "SettingsFileName", "AssemblyUnitNameReplacementPattern" }, { "SettingsFileNameSuffix", "json" }, }) { GConstString gConstString = new GConstString(kvp.Key, kvp.Value); gConstStringGroup.GConstStrings.Add(gConstString.Id, gConstString); } gClass.GConstStringGroups[gConstStringGroup.Id] = gConstStringGroup; gConstStringGroup = new GConstStringGroup(gName: "Temporary File Names"); foreach (var kvp in new Dictionary <string, string>() { { "TemporaryDirectoryBaseConfigRootKey", "TemporaryDirectoryBase" }, { "TemporaryDirectoryBaseDefault", "D:/Temp/AssemblyUnitNameReplacementPattern/" }, }) { GConstString gConstString = new GConstString(kvp.Key, kvp.Value); gConstStringGroup.GConstStrings[gConstString.Id] = gConstString; } gClass.GConstStringGroups[gConstStringGroup.Id] = gConstStringGroup; GNamespace gNamespace = new GNamespace(gNamespaceName); gNamespace.GClasss.Add(gClass.Id, gClass); var gCompilationUnit = new GCompilationUnit(gName: "StringConstants", gRelativePath, gPatternReplacement: gPatternReplacement); gCompilationUnit.GNamespaces.Add(gNamespace.Id, gNamespace); return(gCompilationUnit); }
// If HasInterfaces public static IGAssemblyGroupBasicConstructorResult MAssemblyGroupBasicConstructor(string gAssemblyGroupName = default, string subDirectoryForGeneratedFiles = default, string baseNamespaceName = default, bool hasInterfaces = true, IGPatternReplacement gPatternReplacement = default) { var _gPatternReplacement = gPatternReplacement == default ? new GPatternReplacement() : gPatternReplacement; #region Determine the names of the Titular Base and Derived CompilationUnits, Namespaces, Classes // everything to the right of the last "." character, returns original string if no "." var pos = gAssemblyGroupName.LastIndexOf(".") + 1; var gTitularCommonName = gAssemblyGroupName.Substring(pos, gAssemblyGroupName.Length - pos); var gTitularAssemblyUnitName = gAssemblyGroupName; var gNamespaceName = $"{baseNamespaceName}{gTitularCommonName}"; var gCompilationUnitCommonName = gTitularCommonName; var gTitularDerivedCompilationUnitName = gCompilationUnitCommonName; var gTitularBaseCompilationUnitName = gCompilationUnitCommonName + "Base"; var gClassDerivedName = gCompilationUnitCommonName; var gClassBaseName = gCompilationUnitCommonName + "Base"; #endregion // If HasInterfaces #region Determine the names TitularInterfaces Base and Derived CompilationUnits, Namespaces, Classes var gTitularInterfaceAssemblyUnitName = gAssemblyGroupName + ".Interfaces"; var gTitularInterfaceDerivedCompilationUnitName = "I" + gCompilationUnitCommonName; var gTitularInterfaceBaseCompilationUnitName = "I" + gCompilationUnitCommonName + "Base"; var gTitularInterfaceDerivedName = "I" + gCompilationUnitCommonName; var gTitularInterfaceBaseName = "I" + gCompilationUnitCommonName + "Base"; #endregion #region GReplacementPatternDictionary for gAssemblyGroup var gAssemblyGroupPatternReplacement = new GPatternReplacement(gName: "gAssemblyGroupPatternReplacement", gDictionary: new Dictionary <Regex, string>() { { new Regex("AssemblyGroupNameReplacementPattern"), gAssemblyGroupName }, }); // add the PatternReplacements specified as the gPatternReplacement argument foreach (var kvp in gPatternReplacement.GDictionary) { gAssemblyGroupPatternReplacement.GDictionary.Add(kvp.Key, kvp.Value); } #endregion #region Instantiate the GAssemblyGroup var gAssemblyGroup = new GAssemblyGroup(gName: gAssemblyGroupName, gPatternReplacement: gAssemblyGroupPatternReplacement); #endregion #region Titular AssemblyUnit #region GReplacementPatternDictionary for the Titular AssemblyUnit var gTitularAssemblyUnitPatternReplacement = new GPatternReplacement(gName: "gAssemblyUnitPatternReplacement", gDictionary: new Dictionary <Regex, string>() { { new Regex("AssemblyUnitNameReplacementPattern"), gTitularAssemblyUnitName } }); // add the AssemblyGroup PatternReplacements to the Titular AssemblyUnit PatternReplacements gTitularAssemblyUnitPatternReplacement.GDictionary.AddRange(gAssemblyGroupPatternReplacement.GDictionary); #endregion #region ProjectUnit for the Titular AssemblyUnit #region GPatternReplacement for the ProjectUnit var gTitularAssemblyUnitProjectUnitPatternReplacement = new GPatternReplacement(gName: "TitularAssemblyUnitProjectUnitPatternReplacement"); gTitularAssemblyUnitProjectUnitPatternReplacement.GDictionary.AddRange( gTitularAssemblyUnitPatternReplacement.GDictionary); #endregion var gTitularAssemblyUnitProjectUnit = new GProjectUnit(gName: gTitularAssemblyUnitName, gPatternReplacement: gTitularAssemblyUnitProjectUnitPatternReplacement); #endregion #region Instantiate the gTitularAssemblyUnit var gTitularAssemblyUnit = new GAssemblyUnit(gName: gTitularAssemblyUnitName, gRelativePath: gTitularAssemblyUnitName, gProjectUnit: gTitularAssemblyUnitProjectUnit, gPatternReplacement: gTitularAssemblyUnitPatternReplacement); #endregion #endregion gAssemblyGroup.GAssemblyUnits.Add(gTitularAssemblyUnit.Philote, gTitularAssemblyUnit); #region Titular Derived CompilationUnit #region Pattern Replacements for Titular Derived CompilationUnit var gTitularDerivedCompilationUnitPatternReplacement = new GPatternReplacement(gName: "GTitularDerivedCompilationUnitPatternReplacement", gDictionary: new Dictionary <Regex, string>() { { new Regex("CompilationUnitNameReplacementPattern"), gTitularDerivedCompilationUnitName }, //{new Regex("DataInitializationReplacementPattern"), tempdatainitialization}, //{new Regex("DataDisposalReplacementPattern"), "" // // "SubscriptionToConsoleReadLineAsyncAsObservableDisposeHandle.Dispose();" //}, }); // add the AssemblyUnit PatternReplacements to the Derived CompilationUnit PatternReplacements gTitularDerivedCompilationUnitPatternReplacement.GDictionary.AddRange(gTitularAssemblyUnitPatternReplacement .GDictionary); #endregion #region Instantiate the Titular Derived CompilationUnit var gTitularDerivedCompilationUnit = new GCompilationUnit(gTitularDerivedCompilationUnitName, gFileSuffix: ".cs", gRelativePath: subDirectoryForGeneratedFiles, gPatternReplacement: gTitularDerivedCompilationUnitPatternReplacement); #endregion gTitularAssemblyUnit.GCompilationUnits.Add(gTitularDerivedCompilationUnit.Philote, gTitularDerivedCompilationUnit); #region Instantiate the gNamespaceDerived var gNamespaceDerived = new GNamespace(gNamespaceName); #endregion gTitularDerivedCompilationUnit.GNamespaces.Add(gNamespaceDerived.Philote, gNamespaceDerived); #region Instantiate the gClassDerived // If hasInterfaces, the derived class Implements the Interface GClass gClassDerived; if (hasInterfaces) { gClassDerived = new GClass(gClassDerivedName, "public", gAccessModifier: "partial", gInheritance: gClassBaseName, gImplements: new List <string> { gTitularInterfaceDerivedName } //gDisposesOf: new List<string> { "CompilationUnitNameReplacementPatternDerivedData" } ); } else { gClassDerived = new GClass(gClassDerivedName, "public", gAccessModifier: "partial", gInheritance: gClassBaseName //Implements: new List<string> {gTitularInterfaceDerivedName} -- No Interfaces in this AssemblyGroup //gDisposesOf: new List<string> { "CompilationUnitNameReplacementPatternDerivedData" } ); } #endregion gNamespaceDerived.GClasss.Add(gClassDerived.Philote, gClassDerived); #endregion #region Titular Base CompilationUnit #region Pattern Replacements for Derived CompilationUnit var gTitularBaseCompilationUnitPatternReplacement = new GPatternReplacement(gName: "GTitularBaseCompilationUnitPatternReplacement", gDictionary: new Dictionary <Regex, string>() { { new Regex("CompilationUnitNameReplacementPattern"), gTitularBaseCompilationUnitName }, //{new Regex("DataInitializationReplacementPattern"), tempdatainitialization}, { // new Regex("DataDisposalReplacementPattern"), // //"SubscriptionToConsoleReadLineAsyncAsObservableDisposeHandle.Dispose();" // "" //}, }); // add the AssemblyUnit PatternReplacements to the Base CompilationUnit PatternReplacements foreach (var kvp in gTitularAssemblyUnitPatternReplacement.GDictionary) { gTitularBaseCompilationUnitPatternReplacement.GDictionary.Add(kvp.Key, kvp.Value); } #endregion #region Instantiate the Titular Base CompilationUnit var gTitularBaseCompilationUnit = new GCompilationUnit(gTitularBaseCompilationUnitName, gFileSuffix: ".cs", gRelativePath: subDirectoryForGeneratedFiles, gPatternReplacement: gTitularBaseCompilationUnitPatternReplacement); #endregion gTitularAssemblyUnit.GCompilationUnits.Add(gTitularBaseCompilationUnit.Philote, gTitularBaseCompilationUnit); #region Instantiate the gNamespaceBase var gNamespaceBase = new GNamespace(gNamespaceName); #endregion gTitularBaseCompilationUnit.GNamespaces.Add(gNamespaceBase.Philote, gNamespaceBase); #region Instantiate the gClassBase var gClassBase = new GClass(gClassBaseName, "public", gAccessModifier: "partial", //gInheritance: baseClass.GName // If HasInterfaces gImplements: new List <string> { gTitularInterfaceBaseName } //, "IDisposable" //gDisposesOf: new List<string> { "CompilationUnitNameReplacementPatternBaseData" } ); #endregion gNamespaceBase.GClasss.Add(gClassBase.Philote, gClassBase); #region Instantiate the gPrimaryConstructorBase (Primary Constructor for the Titular Base Class) var gPrimaryConstructorBase = new GMethod(new GMethodDeclaration(gClassBaseName, isConstructor: true, gVisibility: "public")); #endregion gClassBase.GMethods.Add(gPrimaryConstructorBase.Philote, gPrimaryConstructorBase); #endregion //#region Data Initialization (startup?) //// ToDo: encapsulate and refactor //string tempdatainitialization = @" // /* // #region configurationRoot for this HostedService // // Create the configurationBuilder for this HostedService. This creates an ordered chain of configuration providers. The first providers in the chain have the lowest priority, the last providers in the chain have a higher priority. // // The Environment has been configured by the GenericHost before this point is reached // // InitialStartupDirectory has been set by the GenericHost before this point is reached, and is where the GenericHost program or service was started // // LoadedFromDirectory has been configured by the GenericHost before this point is reached. It is the location where this assembly resides // // ToDo: Implement these two values into the GenericHost configurationRoot somehow, then remove from the constructor signature // // var loadedFromDirectory = hostConfiguration.GetValue<string>(\SomeStringConstantConfigrootKey\ \./\); //ToDo suport dynamic assembly loading form other Startup directories - Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); // // var initialStartupDirectory = hostConfiguration.GetValue<string>(\SomeStringConstantConfigrootKey\ \./\); // // Build the configurationRoot for this service // // var configurationBuilder = ConfigurationExtensions.StandardConfigurationBuilder(loadedFromDirectory, initialStartupDirectory, ConsoleMonitorDefaultConfiguration.Production, ConsoleMonitorStringConstants.SettingsFileName, ConsoleMonitorStringConstants.SettingsFileNameSuffix, StringConstants.CustomEnvironmentVariablePrefix, LoggerFactory, stringLocalizerFactory, hostEnvironment, hostConfiguration, linkedCancellationToken); // // ConfigurationRoot = configurationBuilder.Build(); // #endregion // // Embedded object as Data // //AssemblyUnitNameReplacementPatternBaseData = new AssemblyUnitNameReplacementPatternBaseData(); // */"; //#endregion /* ************************************************************************************ */ // If HasInterfaces #region Titular Interfaces AssemblyUnit #region GReplacementPatternDictionary for Titular Interfaces AssemblyUnit var gTitularInterfaceAssemblyUnitPatternReplacement = new GPatternReplacement( gDictionary: new Dictionary <Regex, string>() { { new Regex("AssemblyUnitNameReplacementPattern"), gTitularInterfaceAssemblyUnitName } }); // add the AssemblyGroup PatternReplacements to the Titular Interface AssemblyUnit PatternReplacements gTitularInterfaceAssemblyUnitPatternReplacement.GDictionary.AddRange(gAssemblyGroupPatternReplacement.GDictionary); #endregion #region ProjectUnit for the Titular Interface AssemblyUnit #region GPatternReplacement for the ProjectUnit var gTitularInterfaceAssemblyUnitProjectUnitPatternReplacement = new GPatternReplacement(gName: "TitularInterfaceAssemblyUnitProjectUnitPatternReplacement"); gTitularInterfaceAssemblyUnitProjectUnitPatternReplacement.GDictionary.AddRange( gTitularInterfaceAssemblyUnitPatternReplacement.GDictionary); #endregion var gTitularInterfaceAssemblyUnitProjectUnit = new GProjectUnit(gTitularInterfaceAssemblyUnitName, gPatternReplacement: gTitularInterfaceAssemblyUnitProjectUnitPatternReplacement); #endregion #region Instantiate the gTitularInterfaceAssemblyUnit var gTitularInterfaceAssemblyUnit = new GAssemblyUnit(gName: gTitularInterfaceAssemblyUnitName, gRelativePath: gTitularInterfaceAssemblyUnitName, gProjectUnit: gTitularInterfaceAssemblyUnitProjectUnit, gPatternReplacement: gTitularInterfaceAssemblyUnitPatternReplacement); #endregion gAssemblyGroup.GAssemblyUnits.Add(gTitularInterfaceAssemblyUnit.Philote, gTitularInterfaceAssemblyUnit); #region Titular Interface Derived CompilationUnit #region Pattern Replacements for Titular Interface Derived CompilationUnit var gInterfaceDerivedCompilationUnitPatternReplacement = new GPatternReplacement(gName: "gTitularInterfaceDerivedCompilationUnitPatternReplacement", gDictionary: new Dictionary <Regex, string>() { { new Regex("CompilationUnitNameReplacementPattern"), gTitularInterfaceDerivedCompilationUnitName } }); // add the interface AssemblyUnit PatternReplacements to the Interface Derived CompilationUnit PatternReplacements gInterfaceDerivedCompilationUnitPatternReplacement.GDictionary.AddRange(gTitularInterfaceAssemblyUnitPatternReplacement .GDictionary); #endregion #region instantiate the Titular Interface Derived CompilationUnit var gTitularInterfaceDerivedCompilationUnit = new GCompilationUnit(gTitularInterfaceDerivedCompilationUnitName, gFileSuffix: ".cs", gRelativePath: subDirectoryForGeneratedFiles, gPatternReplacement: gInterfaceDerivedCompilationUnitPatternReplacement); #endregion gTitularInterfaceAssemblyUnit.GCompilationUnits.Add(gTitularInterfaceDerivedCompilationUnit.Philote, gTitularInterfaceDerivedCompilationUnit); #region Namespace For Titular Interface Derived CompilationUnit var gTitularInterfaceDerivedNamespace = new GNamespace(gNamespaceName); #endregion gTitularInterfaceDerivedCompilationUnit.GNamespaces.Add(gTitularInterfaceDerivedNamespace.Philote, gTitularInterfaceDerivedNamespace); #region Create Titular Interface Derived Interface var gTitularInterfaceDerivedInterface = new GInterface(gTitularInterfaceDerivedName, "public"); #endregion gTitularInterfaceDerivedNamespace.GInterfaces.Add(gTitularInterfaceDerivedInterface.Philote, gTitularInterfaceDerivedInterface); #endregion #endregion #region Titular Interface Base CompilationUnit #region Pattern Replacements for Interface Base CompilationUnit var gInterfaceBaseCompilationUnitPatternReplacement = new GPatternReplacement( gDictionary: new Dictionary <Regex, string>() { { new Regex("CompilationUnitNameReplacementPattern"), "AssemblyUnitNameReplacementPattern" } }); gInterfaceBaseCompilationUnitPatternReplacement.GDictionary.AddRange(gTitularInterfaceAssemblyUnitPatternReplacement.GDictionary); #endregion #region instantiate the Titular Interface Base CompilationUnit var gTitularInterfaceBaseCompilationUnit = new GCompilationUnit(gTitularInterfaceBaseCompilationUnitName, gFileSuffix: ".cs", gRelativePath: subDirectoryForGeneratedFiles, gPatternReplacement: gInterfaceBaseCompilationUnitPatternReplacement); #endregion gTitularInterfaceAssemblyUnit.GCompilationUnits.Add(gTitularInterfaceBaseCompilationUnit.Philote, gTitularInterfaceBaseCompilationUnit); #region Namespace For Titular Interface Base CompilationUnit var gTitularInterfaceBaseNamespace = new GNamespace(gNamespaceName); #endregion gTitularInterfaceBaseCompilationUnit.GNamespaces.Add(gTitularInterfaceBaseNamespace.Philote, gTitularInterfaceBaseNamespace); #region Create Titular Interface Base Interface var gTitularInterfaceBaseInterface = new GInterface(gTitularInterfaceBaseName, "public"); #endregion gTitularInterfaceBaseNamespace.GInterfaces.Add(gTitularInterfaceBaseInterface.Philote, gTitularInterfaceBaseInterface); #endregion /* ************************************************************************************ */ #region Update the ProjectUnits for both AssemblyUnits #region PropertyGroups common to both AssemblyUnits new List <IGPropertyGroupInProjectUnit>() { PropertyGroupInProjectUnitForProjectUnitIsLibrary(), PropertyGroupInProjectUnitForPackableOnBuild(), PropertyGroupInProjectUnitForLifecycleStage(), PropertyGroupInProjectUnitForBuildConfigurations(), PropertyGroupInProjectUnitForVersionInfo() }.ForEach(gP => { gTitularAssemblyUnit.GProjectUnit.GPropertyGroupInProjectUnits.Add(gP.Philote, gP); gTitularInterfaceAssemblyUnit.GProjectUnit.GPropertyGroupInProjectUnits.Add(gP.Philote, gP); }); #endregion #region ItemGroups common to both AssemblyUnits new List <IGItemGroupInProjectUnit>() { //TBD }.ForEach(o => { gTitularAssemblyUnit.GProjectUnit.GItemGroupInProjectUnits.Add(o.Philote, o); gTitularInterfaceAssemblyUnit.GProjectUnit.GItemGroupInProjectUnits.Add(o.Philote, o); }); #endregion #region PropertyGroups only in Titular AssemblyUnit #endregion #region ItemGroups only in Titular AssemblyUnit #endregion #region Link the Titular Interfaces AssemblyUnit back to the ProjectUnit in the Titular AssemblyUnit var gItemGroupInProjectUint = new GItemGroupInProjectUnit( gName: "the Titular Interfaces AssemblyUnit", gDescription: "The Interfaces for the Classes specified in this assembly", gBody: new GBody(gStatements: new List <string>() { $"<PackageReference Include=\"{gTitularInterfaceAssemblyUnit.GName}\" />" })); gTitularAssemblyUnit.GProjectUnit.GItemGroupInProjectUnits.Add(gItemGroupInProjectUint.Philote, gItemGroupInProjectUint); #endregion #endregion GAssemblyGroupBasicConstructorResult mCreateAssemblyGroupResult = new GAssemblyGroupBasicConstructorResult() { SubDirectoryForGeneratedFiles = subDirectoryForGeneratedFiles, BaseNamespaceName = baseNamespaceName, GAssemblyGroupName = gAssemblyGroupName, GTitularAssemblyUnitName = gTitularAssemblyUnitName, GTitularBaseCompilationUnitName = gTitularBaseCompilationUnitName, GAssemblyGroup = gAssemblyGroup, gAssemblyGroupPatternReplacement = gAssemblyGroupPatternReplacement, GTitularAssemblyUnit = gTitularAssemblyUnit, GTitularAssemblyUnitPatternReplacement = gTitularAssemblyUnitPatternReplacement, GTitularDerivedCompilationUnit = gTitularDerivedCompilationUnit, GTitularDerivedCompilationUnitPatternReplacement = gTitularDerivedCompilationUnitPatternReplacement, GTitularBaseCompilationUnit = gTitularBaseCompilationUnit, GTitularBaseCompilationUnitPatternReplacement = gTitularBaseCompilationUnitPatternReplacement, GNamespaceDerived = gNamespaceDerived, GNamespaceBase = gNamespaceBase, GClassBase = gClassBase, GClassDerived = gClassDerived, GPrimaryConstructorBase = gPrimaryConstructorBase, // If HasInterfaces gTitularInterfaceAssemblyUnit = gTitularInterfaceAssemblyUnit, GTitularInterfaceDerivedCompilationUnit = gTitularInterfaceDerivedCompilationUnit, GTitularInterfaceBaseCompilationUnit = gTitularInterfaceBaseCompilationUnit, GTitularInterfaceDerivedInterface = gTitularInterfaceDerivedInterface, GTitularInterfaceBaseInterface = gTitularInterfaceBaseInterface }; return(mCreateAssemblyGroupResult); }