public static IGAssemblyGroup MGenericHostService03(string gAssemblyGroupName, string subDirectoryForGeneratedFiles = default, string baseNamespaceName = default, bool hasInterfaces = true, GPatternReplacement gPatternReplacement = default) { GPatternReplacement _gPatternReplacement = gPatternReplacement == default ? new GPatternReplacement() : gPatternReplacement; var gAssemblyGroupBasicConstructorResult = MGenericHostService(gAssemblyGroupName, subDirectoryForGeneratedFiles, baseNamespaceName, hasInterfaces, _gPatternReplacement); return(gAssemblyGroupBasicConstructorResult.GAssemblyGroup); }
// 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); }
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); }
static void Main(string[] args) { // ToDo: Get the Artifacts directory from the host string artifactsPath = "D:/Temp/GenerateProgramArtifacts/"; // Source Code Directory and Tests Code Directory relative to the artifactsPath string sourceRelativePath = "src/"; string sourceArtifactsPath = Path.Combine(artifactsPath, sourceRelativePath); string testRelativePath = "tests/"; string testArtifactsPath = Path.Combine(artifactsPath, testRelativePath); string baseNamespaceName = "ATAP.Utilities."; var interfaces = ".Interfaces"; string subDirectoryForGeneratedFiles = "Generated"; #region Projects under development, their relative paths under the source and tests directory, and the delegate to create each string genericHostProgramsRelativeNextPath = "GenericHostPrograms/"; string genericHostProgramsRelativeNextNamespace = "GenericHostPrograms."; string gHPBaseNamespaceName = baseNamespaceName + genericHostProgramsRelativeNextNamespace; string genericHostServicesRelativeNextPath = "GenericHostServices/"; string genericHostServicesRelativeNextNamespace = "GenericHostServices."; string gHSBaseNamespaceName = baseNamespaceName + genericHostServicesRelativeNextNamespace; (string name, string sourceRelativePath, string testRelativePath, string subDirectoryForGeneratedFiles, string baseNamespaceName, bool hasInterfaces, MCreateAssemblyGroupDelegate mCreateAssemblyGroupDelegate)gPrimaryExecutingProgram = ("Service03", Path.Combine(sourceArtifactsPath, genericHostProgramsRelativeNextPath, "Service03/"), Path.Combine(testArtifactsPath, genericHostProgramsRelativeNextPath, "Service03/"), subDirectoryForGeneratedFiles, gHSBaseNamespaceName, false, new MCreateAssemblyGroupDelegate(MGenericHostService03)); var projectsUnderDevelopment = new List <(string name, string sourceRelativePath, string testRelativePath, string subDirectoryForGeneratedFiles, string baseNamespaceName, bool hasInterfaces, MCreateAssemblyGroupDelegate mCreateAssemblyGroupDelegate)>() { ("ATAP.Utilities.Stateless", Path.Combine(sourceArtifactsPath, "StateMachine/"), Path.Combine(testArtifactsPath, "StateMachine/"), subDirectoryForGeneratedFiles, baseNamespaceName, true, new MCreateAssemblyGroupDelegate(MAUStateless)), ("TimerGHS", Path.Combine(sourceArtifactsPath, genericHostServicesRelativeNextPath, "TimerGHS/"), Path.Combine(testArtifactsPath, genericHostServicesRelativeNextPath, "TimerGHS/"), subDirectoryForGeneratedFiles, gHSBaseNamespaceName, true, new MCreateAssemblyGroupDelegate(MTimerGHS)), ("FileSystemWatcherGHS", Path.Combine(sourceArtifactsPath, genericHostServicesRelativeNextPath, "FileSystemWatcherGHS/"), Path.Combine(testArtifactsPath, genericHostServicesRelativeNextPath, "FileSystemWatcherGHS/"), subDirectoryForGeneratedFiles, gHSBaseNamespaceName, true, new MCreateAssemblyGroupDelegate(MFileSystemWatcherGHS)), ("ConsoleSourceGHS", Path.Combine(sourceArtifactsPath, genericHostServicesRelativeNextPath, "ConsoleSourceGHS/"), Path.Combine(testArtifactsPath, genericHostServicesRelativeNextPath, "ConsoleSourceGHS/"), subDirectoryForGeneratedFiles, gHSBaseNamespaceName, true, new MCreateAssemblyGroupDelegate(MConsoleSourceGHS)), ("ConsoleSinkGHS", Path.Combine(sourceArtifactsPath, genericHostServicesRelativeNextPath, "ConsoleSinkGHS/"), Path.Combine(testArtifactsPath, genericHostServicesRelativeNextPath, "ConsoleSinkGHS/"), subDirectoryForGeneratedFiles, gHSBaseNamespaceName, true, new MCreateAssemblyGroupDelegate(MConsoleSinkGHS)), ("ConsoleMonitorGHS", Path.Combine(sourceArtifactsPath, genericHostServicesRelativeNextPath, "ConsoleMonitorGHS/"), Path.Combine(testArtifactsPath, genericHostServicesRelativeNextPath, "ConsoleMonitorGHS/"), subDirectoryForGeneratedFiles, gHSBaseNamespaceName, true, new MCreateAssemblyGroupDelegate(MConsoleMonitorGHS)), ("TopLevelBackgroundGHS", Path.Combine(sourceArtifactsPath, genericHostServicesRelativeNextPath, "TopLevelBackgroundGHS/"), Path.Combine(testArtifactsPath, genericHostServicesRelativeNextPath, "TopLevelBackgroundGHS/"), subDirectoryForGeneratedFiles, gHSBaseNamespaceName, true, new MCreateAssemblyGroupDelegate(MTopLevelBackgroundGHS)), ("FileSystemToObjectGraphGHS", Path.Combine(sourceArtifactsPath, genericHostServicesRelativeNextPath, "FileSystemToObjectGraphGHS/"), Path.Combine(testArtifactsPath, genericHostServicesRelativeNextPath, "FileSystemToObjectGraphGHS/"), subDirectoryForGeneratedFiles, gHSBaseNamespaceName, true, new MCreateAssemblyGroupDelegate(MFileSystemToObjectGraphGHS)), }; #endregion #region Conversion of nonReleased Packages from PackageReference to ProjectReference #region The structure of the project and package includes lines found in a ProjectUnit's ItemGroup var fromPatternP = "<PackageReference Include=\""; var fromPatternS = "\"\\s*/>"; var toPatternP = "<ProjectReference Include=\""; var toPatternS = "\" />"; #endregion List <KeyValuePair <Regex, string> > nonReleasedPackageKVPs = new List <KeyValuePair <Regex, string> >(); foreach (var package in projectsUnderDevelopment) { nonReleasedPackageKVPs.Add(new KeyValuePair <Regex, string>( new Regex(fromPatternP + package.name + fromPatternS), toPatternP + package.sourceRelativePath + package.name + "/" + package.name + ".csproj" + toPatternS )); nonReleasedPackageKVPs.Add(new KeyValuePair <Regex, string>( new Regex(fromPatternP + package.name + interfaces + fromPatternS), toPatternP + package.sourceRelativePath + package.name + interfaces + "/" + package.name + interfaces + ".csproj" + toPatternS )); } var nonReleasedPackageReplacementDictionary = new Dictionary <Regex, string>(); foreach (var kvp in nonReleasedPackageKVPs) { nonReleasedPackageReplacementDictionary.Add(kvp.Key, kvp.Value); } #region GReplacementPatternDictionary for NonReleasedPackages var gNonReleasedPackagesPatternReplacement = new GPatternReplacement(gName: "NonReleasedPackages", gDictionary: nonReleasedPackageReplacementDictionary); #endregion #region GReplacementPatternDictionary for SolutionReferencedProjectPaths var gSolutionReferencedProjectPathsPatternReplacement = new GPatternReplacement( gName: "SolutionReferencedProjectPaths", gDictionary: new Dictionary <Regex, string>() { { new Regex("SolutionReferencedProjectsBasePathReplacementPattern"), @"C:/Dropbox/whertzing/GitHub/ATAP.Utilities/" }, { new Regex("SolutionReferencedProjectsLocalBasePathReplacementPattern"), sourceArtifactsPath }, }); #endregion #endregion StringBuilder sb = new StringBuilder(0x2000); StringBuilder indent = new StringBuilder(64); string indentDelta = " "; string eol = Environment.NewLine; CancellationTokenSource cts = new CancellationTokenSource(); CancellationToken ct = cts.Token; var session = new System.Collections.Generic.Dictionary <string, object>(); R1Top r1Top; W1Top w1Top; var gAssemblyGroupReplacementPatternDictionary = new Dictionary <Regex, string>(); gAssemblyGroupReplacementPatternDictionary.AddRange(gNonReleasedPackagesPatternReplacement.GDictionary); gAssemblyGroupReplacementPatternDictionary.AddRange(gSolutionReferencedProjectPathsPatternReplacement .GDictionary); var gAssemblyGroupPatternReplacement = new GPatternReplacement( gName: gNonReleasedPackagesPatternReplacement.GName + gSolutionReferencedProjectPathsPatternReplacement.GName, gDictionary: gAssemblyGroupReplacementPatternDictionary); string assemblyGroupTestArtifactsPath; #region executable if present IGAssemblyGroup gPrimaryExecutableAssemblyGroup = gPrimaryExecutingProgram.mCreateAssemblyGroupDelegate(gPrimaryExecutingProgram.name, gPrimaryExecutingProgram.subDirectoryForGeneratedFiles, gPrimaryExecutingProgram.baseNamespaceName, gPrimaryExecutingProgram.hasInterfaces); session.Add("assemblyUnits", gPrimaryExecutableAssemblyGroup.GAssemblyUnits); r1Top = new R1Top(session, sb, indent, indentDelta, eol, ct); w1Top = new W1Top(basePath: gPrimaryExecutingProgram.sourceRelativePath, force: true); r1Top.Render(w1Top); session.Clear(); #endregion IGAssemblyGroup gAssemblyGroup; foreach (var projectUnderDevelopment in projectsUnderDevelopment) { assemblyGroupTestArtifactsPath = projectUnderDevelopment.testRelativePath; gAssemblyGroup = projectUnderDevelopment.mCreateAssemblyGroupDelegate(projectUnderDevelopment.name, projectUnderDevelopment.subDirectoryForGeneratedFiles, projectUnderDevelopment.baseNamespaceName, projectUnderDevelopment.hasInterfaces); #region Update the GPatternReplacement properties for every element of every projectsUnderDevelopment MUpdateGPatternReplacement(gAssemblyGroup, gAssemblyGroupPatternReplacement); #endregion session.Add("assemblyUnits", gAssemblyGroup.GAssemblyUnits); r1Top = new R1Top(session, sb, indent, indentDelta, eol, ct); w1Top = new W1Top(basePath: projectUnderDevelopment.sourceRelativePath, force: true); r1Top.Render(w1Top); session.Clear(); } //assemblyGroupName = "ATAP.Utilities.Stateless"; // assemblyGroupSourceArtifactsPath = Path.Combine(artifactsPath, sourceRelativePath, assemblyGroupName); //var GAssemblyGroup = MAUStateless(assemblyGroupName, SubDirectoryForGeneratedFiles, "ATAP.Utilities", // gAssemblyGroupPatternReplacement); //session.Add("assemblyUnits", GAssemblyGroup.GAssemblyUnits); //r1Top = new R1Top(session, sb, indent, indentDelta, eol, ct); //w1Top = new W1Top(basePath: assemblyGroupSourceArtifactsPath, force: true); //r1Top.Render(w1Top); //session.Clear(); //string baseNamespaceNameForGHSServices = "ATAP.Utilities.GHS.Services"; //string genericHostServicesPath = "GenericHostServices"; //assemblyGroupSourceArtifactsPath = Path.Combine(artifactsPath, sourceRelativePath, genericHostServicesPath); //GAssemblyGroup = MTimerGHS(SubDirectoryForGeneratedFiles, baseNamespaceNameForGHSServices, // gAssemblyGroupPatternReplacement); //session.Add("assemblyUnits", GAssemblyGroup.GAssemblyUnits); //r1Top = new R1Top(session, sb, indent, indentDelta, eol, ct); //w1Top = new W1Top(basePath: assemblyGroupSourceArtifactsPath, force: true); //r1Top.Render(w1Top); //session.Clear(); //GAssemblyGroup = MFileSystemWatcherGHS(SubDirectoryForGeneratedFiles, baseNamespaceNameForGHSServices, // gAssemblyGroupPatternReplacement); //session.Add("assemblyUnits", GAssemblyGroup.GAssemblyUnits); //r1Top = new R1Top(session, sb, indent, indentDelta, eol, ct); //w1Top = new W1Top(basePath: assemblyGroupSourceArtifactsPath, force: true); //r1Top.Render(w1Top); //session.Clear(); //GAssemblyGroup = MConsoleSourceGHS(SubDirectoryForGeneratedFiles, baseNamespaceNameForGHSServices, // gPatternReplacement: gAssemblyGroupPatternReplacement); //session.Add("assemblyUnits", GAssemblyGroup.GAssemblyUnits); //r1Top = new R1Top(session, sb, indent, indentDelta, eol, ct); //w1Top = new W1Top(basePath: assemblyGroupSourceArtifactsPath, force: true); //r1Top.Render(w1Top); //session.Clear(); //GAssemblyGroup = MConsoleSinkGHS(SubDirectoryForGeneratedFiles, baseNamespaceNameForGHSServices, // gPatternReplacement: gAssemblyGroupPatternReplacement); //session.Add("assemblyUnits", GAssemblyGroup.GAssemblyUnits); //r1Top = new R1Top(session, sb, indent, indentDelta, eol, ct); //w1Top = new W1Top(basePath: assemblyGroupSourceArtifactsPath, force: true); //r1Top.Render(w1Top); //session.Clear(); //GAssemblyGroup = MConsoleMonitorGHS(SubDirectoryForGeneratedFiles, baseNamespaceNameForGHSServices, // gPatternReplacement: gAssemblyGroupPatternReplacement); //session.Add("assemblyUnits", GAssemblyGroup.GAssemblyUnits); //r1Top = new R1Top(session, sb, indent, indentDelta, eol, ct); //w1Top = new W1Top(basePath: assemblyGroupSourceArtifactsPath, force: true); //r1Top.Render(w1Top); //session.Clear(); //GAssemblyGroup = MTopLevelBackgroundGHS(SubDirectoryForGeneratedFiles, baseNamespaceNameForGHSServices, // gPatternReplacement: gAssemblyGroupPatternReplacement); //session.Add("assemblyUnits", GAssemblyGroup.GAssemblyUnits); //r1Top = new R1Top(session, sb, indent, indentDelta, eol, ct); //w1Top = new W1Top(basePath: assemblyGroupSourceArtifactsPath, force: true); //r1Top.Render(w1Top); //session.Clear(); //GAssemblyGroup = MFileSystemToObjectGraphGHS(SubDirectoryForGeneratedFiles, baseNamespaceNameForGHSServices, // gPatternReplacement: gAssemblyGroupPatternReplacement); //session.Add("assemblyUnits", GAssemblyGroup.GAssemblyUnits); //r1Top = new R1Top(session, sb, indent, indentDelta, eol, ct); //w1Top = new W1Top(basePath: assemblyGroupSourceArtifactsPath, force: true); //r1Top.Render(w1Top); //session.Clear(); // Invoke Editor or Compiler or IDE or Tests on the output files //Console.WriteLine(r1Top.Sb); //Console.WriteLine("Press any Key to exit"); //var wait = Console.ReadLine(); }
public static IGAssemblyGroup MConsoleSinkGHS(string gAssemblyGroupName, string subDirectoryForGeneratedFiles = default, string baseNamespaceName = default, bool hasInterfaces = true, GPatternReplacement gPatternReplacement = default) { GPatternReplacement _gPatternReplacement = gPatternReplacement == default ? new GPatternReplacement() : gPatternReplacement; var mCreateAssemblyGroupResult = MAssemblyGroupGHHSConstructor(gAssemblyGroupName, subDirectoryForGeneratedFiles, baseNamespaceName, hasInterfaces, _gPatternReplacement); #region Initial StateMachine Configuration mCreateAssemblyGroupResult.GPrimaryConstructorBase.GStateConfiguration.GDOTGraphStatements.Add( @" WaitingForInitialization -> WaitingForRequestToWriteSomething [label = ""InitializationCompleteReceived""] WaitingForRequestToWriteSomething -> WaitingForWriteToComplete [label = ""WriteStarted""] WaitingForWriteToComplete -> WaitingForRequestToWriteSomething [label = ""WriteFinished""] WaitingForWriteToComplete -> WaitingForRequestToWriteSomething [label = ""CancellationTokenActivated""] WaitingForRequestToWriteSomething -> ServiceFaulted [label = ""ExceptionCaught""] WaitingForWriteToComplete ->ServiceFaulted [label = ""ExceptionCaught""] WaitingForRequestToWriteSomething ->ShutdownStarted [label = ""CancellationTokenActivated""] WaitingForRequestToWriteSomething ->ShutdownStarted [label = ""StopAsyncActivated""] WaitingForWriteToComplete ->ShutdownStarted [label = ""StopAsyncActivated""] ShutdownStarted ->ShutdownComplete [label = ""ShutdownCompleted""] " ); #endregion var s1 = new List <string>() { @"StateMachine.Configure(State.WaitingForInitialization)", //$" .OnEntry(() => {{ if (OnWaitingForInitializationEntry!= null) OnWaitingForInitializationEntry(); }})", //$" .OnExit(() => {{ if (OnWaitingForInitializationExit!= null) OnWaitingForInitializationExit(); }})", $" .Permit(Trigger.InitializationCompleteReceived, State.WaitingForRequestToWriteSomething)", $";", @"StateMachine.Configure(State.WaitingForRequestToWriteSomething)", //$" .OnEntry(() => {{ if (OnWaitingForInitializationEntry!= null) OnWaitingForInitializationEntry(); }})", // $" .OnExit(() => {{ if (OnWaitingForInitializationExit!= null) OnWaitingForInitializationExit(); }})", $" .Permit(Trigger.WriteStarted, State.WaitingForWriteToComplete)", $" .Permit(Trigger.StopAsyncActivated, State.ShutdownStarted)", // $" .PermitReentryIf(Trigger.InitializationCompleteReceived, State.WaitingForRequestToWriteSomething, () => {{ if (GuardClauseFroWaitingForInitializationToWaitingForRequestToWriteSomethingUsingTriggerInitializationCompleteReceived!= null) return GuardClauseFroWaitingForInitializationToWaitingForRequestToWriteSomethingUsingTriggerInitializationCompleteReceived(); return true; }})", $";", @"StateMachine.Configure(State.WaitingForWriteToComplete)", $" .OnEntry((string mesg) => {{Console.Write(mesg);}})", // $" .OnExit(() => {{ if (OnWaitingForInitializationExit!= null) OnWaitingForInitializationExit(); }})", $" .Permit(Trigger.WriteFinished, State.WaitingForRequestToWriteSomething)", $" .Permit(Trigger.StopAsyncActivated, State.ShutdownStarted)", // $" .PermitReentryIf(Trigger.InitializationCompleteReceived, State.WaitingForRequestToWriteSomething, () => {{ if (GuardClauseFroWaitingForInitializationToWaitingForRequestToWriteSomethingUsingTriggerInitializationCompleteReceived!= null) return GuardClauseFroWaitingForInitializationToWaitingForRequestToWriteSomethingUsingTriggerInitializationCompleteReceived(); return true; }})", $";", @"StateMachine.Configure(State.ShutdownStarted)", //$" .OnEntry(() => {{ if (OnWaitingForInitializationEntry!= null) OnWaitingForInitializationEntry(); }})", // $" .OnExit(() => {{ if (OnWaitingForInitializationExit!= null) OnWaitingForInitializationExit(); }})", $" .Permit(Trigger.ShutdownCompleted, State.ShutdownComplete)", // $" .PermitReentryIf(Trigger.InitializationCompleteReceived, State.WaitingForRequestToWriteSomething, () => {{ if (GuardClauseFroWaitingForInitializationToWaitingForRequestToWriteSomethingUsingTriggerInitializationCompleteReceived!= null) return GuardClauseFroWaitingForInitializationToWaitingForRequestToWriteSomethingUsingTriggerInitializationCompleteReceived(); return true; }})", $";", @"StateMachine.Configure(State.ShutdownComplete);", }; #region Add UsingGroups to the Titular Derived and Titular Base CompilationUnits #region Add UsingGroups common to both the Titular Derived and Titular Base CompilationUnits #endregion #region Add UsingGroups specific to the Titular Base CompilationUnit #endregion #endregion #region Injected PropertyGroup For ConsoleSinkAndConsoleSource #endregion #region Additional Properties needed by the Base class var lclPropertyGroup = new GPropertyGroup($"Private Properties part of {mCreateAssemblyGroupResult.GClassBase.GName}"); var mesgProperty = new GProperty(gName: "Mesg", gType: "string", gVisibility: "private"); lclPropertyGroup.GPropertys.Add(mesgProperty.Philote, mesgProperty); mCreateAssemblyGroupResult.GClassBase.GPropertyGroups.Add(lclPropertyGroup.Philote, lclPropertyGroup); #endregion #region Add the MethodGroup containing new methods provided by this library to the Titular Base CompilationUnit var gMethodGroup = new GMethodGroup( gName: $"MethodGroup specific to {mCreateAssemblyGroupResult.GClassBase.GName}"); foreach (var gMethod in MCreateWriteMethodInConsoleSink()) { gMethodGroup.GMethods.Add(gMethod.Philote, gMethod); } mCreateAssemblyGroupResult.GClassBase.AddMethodGroup(gMethodGroup); #endregion #region Add additional classes provided by this library to the Titular Base CompilationUnit #endregion #region Add References used by the Titular Derived and Titular Base CompilationUnits to the ProjectUnit #region Add References used by both the Titular Derived and Titular Base CompilationUnits #endregion #region Add References unique to the Titular Base CompilationUnit #endregion #endregion /*******************************************************************************/ #region Update the Interface Assembly for this service #region Add UsingGroups for the Titular Derived Interface and Titular Base Interface #region Add UsingGroups common to both the Titular Derived Interface and the Titular Base Interface #endregion #region Add UsingGroups specific to the Titular Base Interface #endregion #endregion #region Add References for the Titular Interface ProjectUnit #region Add References common to both the Titular Derived Interface and Titular Base Interface #endregion #region Add References unique to the Titular Base Interface CompilationUnit #endregion #endregion #endregion #region Finalize the GHHS GAssemblyGroupGHHSFinalizer(mCreateAssemblyGroupResult); #endregion #region Populate the ConfigureStateMachine method mCreateAssemblyGroupResult.GClassBase.CombinedMethods() .Where(x => x.GDeclaration.GName == "ConfigureStateMachine").First().GBody.GStatements.AddRange(s1); // mCreateAssemblyGroupResult.GPrimaryConstructorBase.GBody.GStatements.AddRange(s1); #endregion return(mCreateAssemblyGroupResult.GAssemblyGroup); }
//#region Titular Base Class (IHostedService) // GClass gClass = new GClass(gCompilationUnitName, gVisibility: "public", // gInheritance: "BackgroundService", // gImplements: new List<string> { "IDisposable" }, // gDisposesOf: new List<string> { "SubscriptionToConsoleReadLineAsyncAsObservableDisposeHandle" }); // #region specific methods for BackgroundService // gClass.AddMethod(MCreateExecuteAsyncMethod(gAccessModifier: "override async")); // gClass.AddMethodGroup(MCreateStartStopAsyncMethods(gAccessModifier: "override async")); // #endregion // #region Constructors // gConstructor = new GMethod(new GMethodDeclaration(gCompilationUnitName, isConstructor: true, // gVisibility: "public")); // gClass.GMethods.Add(gConstructor.Philote,gConstructor); // #endregion public static void MAssemblyGroupCommonConstructorForGHHSAndGHBSPart2( IGAssemblyGroupBasicConstructorResult mCreateAssemblyGroupResult) { #region Add a StateMachine for the service #region Declare and populate the initial initialDiGraphList, which handles basic states for a GHS List <string> initialDiGraphList = new List <string>() { @"WaitingForInitialization ->ServiceFaulted [label = ""AnyException""]", @"WaitingForInitialization ->ShutdownStarted [label = ""StopAsyncActivated""]", @"ServiceFaulted ->ShutdownStarted [label = ""CancellationTokenActivated""]", @"ServiceFaulted ->ShutdownStarted [label = ""StopAsyncActivated""]", @"ShutdownStarted->ShutDownComplete [label = ""AllShutDownStepsCompleted""]", }; #endregion MStateMachineConstructor(mCreateAssemblyGroupResult.GTitularBaseCompilationUnit, mCreateAssemblyGroupResult.GNamespaceBase, mCreateAssemblyGroupResult.GClassBase, mCreateAssemblyGroupResult.GPrimaryConstructorBase, initialDiGraphList); #endregion #region ResourceUnits GResourceUnit gResourceUnit; GResourceItem gResourceItem; Dictionary <IPhilote <IGResourceItem>, IGResourceItem> gResourceItems; GPatternReplacement gExceptionMessagesResourcePatternReplacement = new GPatternReplacement( gDictionary: new Dictionary <Regex, string>() { { new Regex("ExceptionMessagesResourceUnitNameReplacementPattern"), "AssemblyUnitNameReplacementPattern" } }); gExceptionMessagesResourcePatternReplacement.GDictionary.AddRange(mCreateAssemblyGroupResult.GTitularAssemblyUnitPatternReplacement.GDictionary); gResourceItem = new GResourceItem(gName: "ExceptionMessage1", gValue: "text for exception {0}", gComment: "{0} is the exception something?"); gResourceItems = new Dictionary <IPhilote <IGResourceItem>, IGResourceItem> { [gResourceItem.Philote] = gResourceItem }; gResourceUnit = new GResourceUnit("ExceptionMessages", gRelativePath: "Resources", gResourceItems: gResourceItems, gPatternReplacement: gExceptionMessagesResourcePatternReplacement); mCreateAssemblyGroupResult.GTitularAssemblyUnit.GResourceUnits.Add(gResourceUnit.Philote, gResourceUnit); mCreateAssemblyGroupResult.GTitularAssemblyUnit.GProjectUnit.GResourceUnits.Add(gResourceUnit.Philote, gResourceUnit); GPatternReplacement gUIMessagesResourcePatternReplacement = new GPatternReplacement( gDictionary: new Dictionary <Regex, string>() { { new Regex("ExceptionMessagesResourceUnitNameReplacementPattern"), "AssemblyUnitNameReplacementPattern" } }); gUIMessagesResourcePatternReplacement.GDictionary.AddRange(mCreateAssemblyGroupResult.GTitularAssemblyUnitPatternReplacement.GDictionary); gResourceItem = new GResourceItem(gName: "Enter Selection>", gValue: "Enter Selection>", gComment: "Enter Selection prompt for Console UI"); gResourceItems = new Dictionary <IPhilote <IGResourceItem>, IGResourceItem> { [gResourceItem.Philote] = gResourceItem }; gResourceUnit = new GResourceUnit("UIMessages", gRelativePath: "Resources", gResourceItems: gResourceItems, gPatternReplacement: gUIMessagesResourcePatternReplacement); mCreateAssemblyGroupResult.GTitularAssemblyUnit.GResourceUnits.Add(gResourceUnit.Philote, gResourceUnit); mCreateAssemblyGroupResult.GTitularAssemblyUnit.GProjectUnit.GResourceUnits.Add(gResourceUnit.Philote, gResourceUnit); #endregion //#region StringConstants Base CompilationUnit //mCreateAssemblyGroupResult.GTitularBaseCompilationUnitPatternReplacement = new GPatternReplacement( // gDictionary: new Dictionary<Regex, string>() { // {new Regex("CompilationUnitNameReplacementPattern"), "AssemblyUnitNameReplacementPattern"} // }); //foreach (var kvp in mCreateAssemblyGroupResult.gAssemblyUnitPatternReplacement.GDictionary) { // mCreateAssemblyGroupResult.GTitularBaseCompilationUnitPatternReplacement.GDictionary.Add(kvp.Key, kvp.Value); //} #region DefaultConfiguration CompilationUnit #region GPatternReplacement for the DefaultConfiguration CompilationUnit var gTitularAssemblyUnitDefaultConfigurationPatternReplacement = new GPatternReplacement(gName: "gTitularAssemblyUnitDefaultConfigurationPatternReplacement"); gTitularAssemblyUnitDefaultConfigurationPatternReplacement.GDictionary.AddRange( mCreateAssemblyGroupResult.GTitularAssemblyUnitPatternReplacement.GDictionary); #endregion #region Additional DefaultConfiguration items var gAdditionalStatements = new List <string>() { "{dummyConfigKeyRoot,dummyConfigDefaultString}" }; #endregion var gCompilationUnit = CompilationUnitDefaultConfigurationConstructor(gNamespaceName: mCreateAssemblyGroupResult.GNamespaceDerived.GName, gRelativePath: mCreateAssemblyGroupResult.SubDirectoryForGeneratedFiles, gAdditionalStatements: gAdditionalStatements, gPatternReplacement: gTitularAssemblyUnitDefaultConfigurationPatternReplacement); mCreateAssemblyGroupResult.GTitularAssemblyUnit.GCompilationUnits.Add(gCompilationUnit.Philote, gCompilationUnit); #endregion #region Settings File(s) for Configuration #endregion #region Upate the ProjectUnit in the Titular AssemblyUnit #region ItemGroups for the ProjectUnit var gItemGroupInProjectUnitList = MGenericHostServiceCommonItemGroupInProjectUnitList(); gItemGroupInProjectUnitList.ForEach(o => mCreateAssemblyGroupResult.GTitularAssemblyUnit.GProjectUnit.GItemGroupInProjectUnits.Add(o.Philote, o)); //_projectReferences.ForEach(o => // gAssemblyUnit.GProjectUnit.GItemGroupInProjectUnits.Add(o.Philote, o)); //_packageReferences.ForEach(o => // gAssemblyUnit.GProjectUnit.GItemGroupInProjectUnits.Add(o.Philote, o)); #endregion #endregion // GAssemblyGroup.GAssemblyUnits.Add(gAssemblyUnit.Philote, gAssemblyUnit); /* ************************************************************************************ */ //#region Interfaces //#region Pattern Replacements for AssemblyUnit //gAssemblyUnitPatternReplacement = new GPatternReplacement(gDictionary: new Dictionary<Regex, string>() { // {new Regex("AssemblyUnitNameReplacementPattern"), $"{GAssemblyGroupName}"} //}); //foreach (var kvp in gAssemblyGroupPatternReplacement.GDictionary) { // gAssemblyUnitPatternReplacement.GDictionary.Add(kvp.Key, kvp.Value); //} //#endregion //#region Create AssemblyUnit for Interfaces //gAssemblyUnitName = $"{GAssemblyGroupName}.Interfaces"; //gAssemblyUnit = new GAssemblyUnit($"{gAssemblyUnitName}", // gRelativePath: $"{gAssemblyUnitName}", // gProjectUnit: new GProjectUnit($"{gAssemblyUnitName}", // gPatternReplacement: gAssemblyUnitPatternReplacement), gPatternReplacement: gAssemblyUnitPatternReplacement); //#endregion //#region Pattern Replacements for CompilationUnit //gCompilationUnitPatternReplacement = new GPatternReplacement(gDictionary: new Dictionary<Regex, string>() { // {new Regex("CompilationUnitNameReplacementPattern"), "AssemblyUnitNameReplacementPattern"} //}); //foreach (var kvp in gAssemblyUnitPatternReplacement.GDictionary) { // gCompilationUnitPatternReplacement.GDictionary.Add(kvp.Key, kvp.Value); //} //#endregion //#region Create CompilationUnit for Titular Base Interface CompilationUnit //var compilationUnitName = $"I{baseCompilationUnitName}"; //gCompilationUnit = new GCompilationUnit($"{compilationUnitName}", gFileSuffix: ".cs", // gRelativePath: SubDirectoryForGeneratedFiles, gPatternReplacement: gCompilationUnitPatternReplacement); //gAssemblyUnit.GCompilationUnits.Add(gCompilationUnit.Philote, gCompilationUnit); #region Usings For Titular Base Interface CompilationUnit var gUsingGroup = MUsingGroupForMicrosoftGenericHostInGHHSAndGHBS(); mCreateAssemblyGroupResult.GTitularInterfaceBaseCompilationUnit.GUsingGroups.Add(gUsingGroup.Philote, gUsingGroup); gUsingGroup = MUsingGroupForSystemGenericHostInGHHSAndGHBS(); mCreateAssemblyGroupResult.GTitularInterfaceBaseCompilationUnit.GUsingGroups.Add(gUsingGroup.Philote, gUsingGroup); #endregion //#region Namespace For Titular Base Interface CompilationUnit //gNamespace = new GNamespace($"{BaseNamespaceName}.{GAssemblyGroupName}"); //gCompilationUnit.GNamespaces.Add(gNamespace.Philote, gNamespace); //#endregion //#region Create Interface for Titular Base Interface CompilationUnit (IHostedService) //var baseInterfaceName = $"I{baseCompilationUnitName}"; //var gInterface = new GInterface(baseInterfaceName, "public"); //gNamespace.GInterfaces.Add(gInterface.Philote, gInterface); //#endregion //#endregion #region Create CompilationUnit for Titular Interface CompilationUnit //compilationUnitName = $"I{GAssemblyGroupName}"; //gCompilationUnit = new GCompilationUnit($"{compilationUnitName}", gFileSuffix: ".cs", // gRelativePath: SubDirectoryForGeneratedFiles, gPatternReplacement: gCompilationUnitPatternReplacement); //gAssemblyUnit.GCompilationUnits.Add(gCompilationUnit.Philote, gCompilationUnit); #region Usings For Titular Interface CompilationUnit gUsingGroup = MUsingGroupForSystemGenericHostInGHHSAndGHBS(); mCreateAssemblyGroupResult.GTitularInterfaceDerivedCompilationUnit.GUsingGroups.Add(gUsingGroup.Philote, gUsingGroup); #endregion //#region Namespace For Titular Interface CompilationUnit //gNamespace = new GNamespace($"{BaseNamespaceName}.{GAssemblyGroupName}"); //gCompilationUnit.GNamespaces.Add(gNamespace.Philote, gNamespace); //#endregion //#region Create Interface for Titular Interface CompilationUnit (IHostedService) //var titularInterfaceName = $"I{GAssemblyGroupName}"; //gInterface = new GInterface(titularInterfaceName, "public", // gImplements: new List<string>() {$"{baseInterfaceName}"}); //gNamespace.GInterfaces.Add(gInterface.Philote, gInterface); //#endregion #endregion #region Upate the ProjectUnit in the Interfaces AssemblyUnit //#region PropertyGroups for the ProjectUnit in the Interfaces AssemblyUnit //var gPropertyGroupInProjectUnit = PropertyGroupInProjectUnitForProjectUnitIsLibrary(); //gAssemblyUnit.GProjectUnit.GPropertyGroupInProjectUnits[gPropertyGroupInProjectUnit.Philote] = // gPropertyGroupInProjectUnit; //gPropertyGroupInProjectUnit = PropertyGroupInProjectUnitForPackableOnBuild(); //gAssemblyUnit.GProjectUnit.GPropertyGroupInProjectUnits[gPropertyGroupInProjectUnit.Philote] = // gPropertyGroupInProjectUnit; //gPropertyGroupInProjectUnit = PropertyGroupInProjectUnitForLifecycleStage(); //gAssemblyUnit.GProjectUnit.GPropertyGroupInProjectUnits[gPropertyGroupInProjectUnit.Philote] = // gPropertyGroupInProjectUnit; //gPropertyGroupInProjectUnit = PropertyGroupInProjectUnitForBuildConfigurations(); //gAssemblyUnit.GProjectUnit.GPropertyGroupInProjectUnits[gPropertyGroupInProjectUnit.Philote] = // gPropertyGroupInProjectUnit; //gPropertyGroupInProjectUnit = PropertyGroupInProjectUnitForVersion(); //gAssemblyUnit.GProjectUnit.GPropertyGroupInProjectUnits[gPropertyGroupInProjectUnit.Philote] = // gPropertyGroupInProjectUnit; //#endregion #region ItemGroups for the ProjectUnit in the Interfaces AssemblyUnit new List <IGItemGroupInProjectUnit>() { NetCoreGenericHostReferencesItemGroupInProjectUnit(), }.ForEach(o => mCreateAssemblyGroupResult.gTitularInterfaceAssemblyUnit.GProjectUnit.GItemGroupInProjectUnits.Add(o.Philote, o)); #endregion #endregion //GAssemblyGroup.GAssemblyUnits.Add(gAssemblyUnit.Philote, gAssemblyUnit); //#endregion //return GAssemblyGroup; }
public static IGAssemblyGroup MConsoleSourceGHS(string gAssemblyGroupName, string subDirectoryForGeneratedFiles = default, string baseNamespaceName = default, bool hasInterfaces = true, GPatternReplacement gPatternReplacement = default) { GPatternReplacement _gPatternReplacement = gPatternReplacement == default ? new GPatternReplacement() : gPatternReplacement; var mCreateAssemblyGroupResult = MAssemblyGroupGHHSConstructor(gAssemblyGroupName, subDirectoryForGeneratedFiles, baseNamespaceName, hasInterfaces, _gPatternReplacement); #region Initial StateMachine Configuration mCreateAssemblyGroupResult.GPrimaryConstructorBase.GStateConfiguration.GDOTGraphStatements.Add( @" WaitingForInitialization ->BlockingOnConsoleInReadLineAsync [label = ""InitializationCompleteReceived""] BlockingOnConsoleInReadLineAsync -> ServiceFaulted [label = ""ExceptionCaught""] BlockingOnConsoleInReadLineAsync -> ShutdownStarted [label = ""CancellationTokenActivated""] " ); #endregion #region Add UsingGroups to the Titular Derived and Titular Base CompilationUnits #region Add UsingGroups common to both the Titular Derived and Titular Base CompilationUnits #endregion #region Add UsingGroups specific to the Titular Base CompilationUnit var gUsingGroup = new GUsingGroup( $"UsingGroup specific to {mCreateAssemblyGroupResult.GTitularBaseCompilationUnit.GName}"); foreach (var gName in new List <string>() { "System.Reactive.Linq", "System.Reactive.Concurrency", }) { var gUsing = new GUsing(gName); gUsingGroup.GUsings.Add(gUsing.Philote, gUsing); } mCreateAssemblyGroupResult.GTitularBaseCompilationUnit.GUsingGroups .Add(gUsingGroup.Philote, gUsingGroup); #endregion #endregion #region Injected PropertyGroup For ConsoleSinkAndConsoleSource #endregion #region Add the MethodGroup containing new methods provided by this library to the Titular Base CompilationUnit var gMethodGroup = new GMethodGroup( gName: $"MethodGroup specific to {mCreateAssemblyGroupResult.GClassBase.GName}"); IGMethod gMethod; gMethod = CreateConsoleReadLineAsyncAsObservableMethod(); gMethodGroup.GMethods.Add(gMethod.Philote, gMethod); mCreateAssemblyGroupResult.GClassBase.AddMethodGroup(gMethodGroup); #endregion #region Add additional classes provided by this library to the Titular Base CompilationUnit #endregion #region Add References used by the Titular Derived and Titular Base CompilationUnits to the ProjectUnit #region Add References used by both the Titular Derived and Titular Base CompilationUnits foreach (var o in new List <IGItemGroupInProjectUnit>() { ReactiveUtilitiesReferencesItemGroupInProjectUnit(), } ) { mCreateAssemblyGroupResult.GTitularAssemblyUnit.GProjectUnit.GItemGroupInProjectUnits .Add(o.Philote, o); } #endregion #region Add References unique to the Titular Base CompilationUnit #endregion #endregion /*******************************************************************************/ #region Update the Interface Assembly for this service #region Add UsingGroups for the Titular Derived Interface and Titular Base Interface #region Add UsingGroups common to both the Titular Derived Interface and the Titular Base Interface #endregion #region Add UsingGroups specific to the Titular Base Interface #endregion #endregion #region Add References for the Titular Interface ProjectUnit #region Add References common to both the Titular Derived Interface and Titular Base Interface foreach (var o in new List <IGItemGroupInProjectUnit>() { ReactiveUtilitiesReferencesItemGroupInProjectUnit() } ) { mCreateAssemblyGroupResult.gTitularInterfaceAssemblyUnit.GProjectUnit.GItemGroupInProjectUnits .Add(o.Philote, o); } #endregion #region Add References unique to the Titular Base Interface CompilationUnit #endregion #endregion #endregion #region Finalize the GHHS GAssemblyGroupGHHSFinalizer(mCreateAssemblyGroupResult); #endregion return(mCreateAssemblyGroupResult.GAssemblyGroup); }
public static IGAssemblyGroup MTimerGHS(string gAssemblyGroupName, string subDirectoryForGeneratedFiles = default, string baseNamespaceName = default, bool hasInterfaces = true, GPatternReplacement gPatternReplacement = default) { GPatternReplacement _gPatternReplacement = gPatternReplacement == default ? new GPatternReplacement() : gPatternReplacement; var mCreateAssemblyGroupResult = MAssemblyGroupGHHSConstructor(gAssemblyGroupName, subDirectoryForGeneratedFiles, baseNamespaceName, hasInterfaces, _gPatternReplacement); #region Initial StateMachine Configuration mCreateAssemblyGroupResult.GPrimaryConstructorBase.GStateConfiguration.GDOTGraphStatements.Add( @" WaitingForInitialization -> WaitingForARequestForATimer [label = ""InitializationCompleteReceived""] WaitingForARequestForATimer -> RespondingToARequestForATimer [label = ""TimerRequested""] RespondingToARequestForATimer -> WaitingForARequestForATimer [label = ""TimerAllocatedAndSent""] RespondingToARequestForATimer -> WaitingForARequestForATimer [label = ""CancellationTokenActivated""] WaitingForARequestForATimer -> ServiceFaulted [label = ""ExceptionCaught""] RespondingToARequestForATimer ->ServiceFaulted [label = ""ExceptionCaught""] WaitingForARequestForATimer ->ShutdownStarted [label = ""CancellationTokenActivated""] RespondingToARequestForATimer ->ShutdownStarted [label = ""StopAsyncActivated""] " ); #endregion #region Add UsingGroups to the Titular Derived and Titular Base CompilationUnits #region Add UsingGroups common to both the Titular Derived and Titular Base CompilationUnits #endregion #region Add UsingGroups specific to the Titular Base CompilationUnit #endregion #endregion #region Injected PropertyGroup For ConsoleSinkAndConsoleSource #endregion #region Add the MethodGroup for this service var gMethodGroup = new GMethodGroup( gName: $"MethodGroup specific to {mCreateAssemblyGroupResult.GClassBase.GName}"); IGMethod gMethod; gMethod = MCreateRequestATimer(); gMethodGroup.GMethods.Add(gMethod.Philote, gMethod); mCreateAssemblyGroupResult.GClassBase.AddMethodGroup(gMethodGroup); #endregion #region Add References used by the Titular Derived and Titular Base CompilationUnits to the ProjectUnit #region Add References used by both the Titular Derived and Titular Base CompilationUnits #endregion #region Add References unique to the Titular Base CompilationUnit #endregion #endregion /*******************************************************************************/ #region Update the Interface Assembly for this service #region Add UsingGroups for the Titular Derived Interface and Titular Base Interface #region Add UsingGroups common to both the Titular Derived Interface and the Titular Base Interface #endregion #region Add UsingGroups specific to the Titular Base Interface #endregion #endregion #region Add References for the Titular Interface ProjectUnit #region Add References common to both the Titular Derived Interface and Titular Base Interface #endregion #region Add References unique to the Titular Base Interface CompilationUnit #endregion #endregion #endregion #region Finalize the GHHS GAssemblyGroupGHHSFinalizer(mCreateAssemblyGroupResult); #endregion return(mCreateAssemblyGroupResult.GAssemblyGroup); }