MPropertyGroupAndConstructorDeclarationAndInitializationForInjectedPropertyInFileSystemToObjectGraphBaseAssembly(
            IGClass gClass,
            IGMethod gConstructor)
        {
            var gPropertyGroup = new GPropertyGroup("Injected Propertys specific to the FileSystemToObjectGraph");

            gClass.AddPropertyGroups(gPropertyGroup);
            // foreach (var o in new List<string>() { "ConsoleMonitor" }) {
            // gClass.AddTConstructorAutoPropertyGroup(gConstructor.Philote, o, gPropertyGroupId: gPropertyGroup.Philote);
            // }
        }
Exemplo n.º 2
0
 public static IR1Top RMethod(this IR1Top r1Top, IGMethod gMethod)
 {
     r1Top.RComment(gMethod.GComment);
     r1Top.RMethodDeclaration(gMethod.GDeclaration);
     if (!gMethod.IsForInterface)
     {
         r1Top.Indent.Append(r1Top.IndentDelta);
         r1Top.RBody(gMethod.GBody);
         r1Top.Indent.ReplaceFirst(r1Top.IndentDelta, "");
         r1Top.Sb.Append($"{r1Top.Indent}}}{r1Top.Eol}");
     }
     return(r1Top);
 }
        public static IGMethodGroup MCreateHostApplicationLifetimeEventHandlerMethods()
        {
            GMethodGroup newgMethodGroup =
                new GMethodGroup(gName: "OnStarted, OnStopping, and OnStopped Event Handler Methods for HostApplicationLifetime events");
            IGMethod gMethod = MCreateOnStartedMethod();

            newgMethodGroup.GMethods[gMethod.Philote] = gMethod;
            gMethod = MCreateOnStoppingMethod();
            newgMethodGroup.GMethods[gMethod.Philote] = gMethod;
            gMethod = MCreateOnStoppedMethod();
            newgMethodGroup.GMethods[gMethod.Philote] = gMethod;
            return(newgMethodGroup);
        }
Exemplo n.º 4
0
        public static IGMethod ConvertMethodToInterfaceMethod(IGMethod gMethod)
        {
            GMethod gInterfaceMethod = default;

            if (!gMethod.GDeclaration.IsConstructor && gMethod.GDeclaration.GVisibility == "public")
            {
                var gAccessModifier     = gMethod.GDeclaration.GAccessModifier;
                var accessModifierRegex = new Regex("(?:override|async|virtual)");
                gAccessModifier  = accessModifierRegex.Replace(gAccessModifier, "");
                gInterfaceMethod = new GMethod(
                    new GMethodDeclaration(gMethod.GDeclaration.GName, gMethod.GDeclaration.GType, "", gAccessModifier,
                                           gMethod.GDeclaration.IsStatic, false, gMethod.GDeclaration.GArguments, isForInterface: true),
                    gComment: gMethod.GComment, isForInterface: true);
            }
            return(gInterfaceMethod);
        }
Exemplo n.º 5
0
        public static IGClass AddTConstructorAutoPropertyGroup(this IGClass gClass, IPhilote <IGMethod> gMethodId, string gAutoPropertyName, string gType, IPhilote <IGPropertyGroup> gPropertyGroupId = default, string?gAccessors = "{ get;}", string?gVisibility = default)
        {
            var gProperty = new GProperty(gAutoPropertyName.ToUpperFirstChar(), gType, gAccessors, gVisibility);

            if (gClass.GPropertyGroups != null && gClass.GPropertyGroups.ContainsKey(gPropertyGroupId))
            {
                gClass.GPropertyGroups[gPropertyGroupId].GPropertys[gProperty.Philote] = gProperty;
            }
            else
            {
                throw new Exception(string.Format("{0} not found in the PropertyGroups of {1}", gPropertyGroupId.ID.ToString(), gClass.GName));
            }
            IGMethod gMethod = default;

            if (gClass.GMethods != null && gClass.GMethods.ContainsKey(gMethodId))
            {
                gMethod = gClass.GMethods[gMethodId];
            }
            else if (gClass.GMethodGroups != null)
            {
                foreach (var kvp in gClass.GMethodGroups)
                {
                    if (kvp.Value.GMethods.ContainsKey(gMethodId))
                    {
                        var gMethodGroup = kvp.Value;
                        gMethod = gMethodGroup.GMethods[gMethodId];
                    }
                }
            }

            if (gMethod == null)
            {
                throw new Exception(string.Format("{0} not found in the Methods or MethodGroups of {1}", gMethodId.ID.ToString(), gClass.GName));
            }

            GArgument gArgument = new GArgument(gAutoPropertyName.ToLowerFirstChar(), gType);

            gMethod.GDeclaration.GArguments[gArgument.Philote] = gArgument;

            gMethod.GBody.GStatements.Add($"{gAutoPropertyName.ToUpperFirstChar()} = {gAutoPropertyName.ToLowerFirstChar()} ?? throw new ArgumentNullException(nameof({gAutoPropertyName.ToLowerFirstChar()}));");
            return(gClass);
        }
        public static IGClass AddTLocalizerConstructorAutoPropertyGroup(this IGClass gClass, IPhilote <IGMethod> gMethodId, string gAutoPropertyName, string assemblyUnitName, IPhilote <IGPropertyGroup> gPropertyGroupId = default, string?gAccessors = "{ get; }", string?gVisibility = default)
        {
            IGMethod gMethod = default;

            if (gClass.GMethods != null && gClass.GMethods.ContainsKey(gMethodId))
            {
                gMethod = gClass.GMethods[gMethodId];
            }
            else if (gClass.GMethodGroups != null)
            {
                foreach (var kvp in gClass.GMethodGroups)
                {
                    if (kvp.Value.GMethods.ContainsKey(gMethodId))
                    {
                        //GMethodGroup gMethodGroup = kvp.Value;
                        gMethod = kvp.Value.GMethods[gMethodId];
                    }
                }
            }
            if (gMethod == null)
            {
                throw new Exception(string.Format("{0} not found in the Constructors, Methods or MethodGroups of {1}", gMethodId.ID.ToString(), gClass.GName));
            }

            var       gMethodDeclaration = gMethod.GDeclaration;
            string    gName     = gMethodDeclaration.GName;
            GProperty gProperty = new GProperty(gName: $"{gAutoPropertyName}", gType: $"IStringLocalizer", gAccessors: gAccessors);

            if (gClass.GPropertyGroups != null && gClass.GPropertyGroups.ContainsKey(gPropertyGroupId))
            {
                gClass.GPropertyGroups[gPropertyGroupId].GPropertys[gProperty.Philote] = gProperty;
            }
            else
            {
                throw new Exception(string.Format("{0} not found in the PropertyGroups of {1}", gPropertyGroupId.ID.ToString(), gClass.GName));
            }

            //gMethod.GBody.StatementList.Add($"{gAutoPropertyName} = StringLocalizerFactory.Create(nameof({assemblyUnitName}.Resources), \"{assemblyUnitName}\");");
            gMethod.GBody.GStatements.Add($"{gAutoPropertyName} = StringLocalizerFactory.Create(nameof(Resources), \"{assemblyUnitName}\");");
            return(gClass);
        }
Exemplo n.º 7
0
        public static IDictionary <IGMethodGroupId <TValue>, IGMethodGroup <TValue> > ConvertToInterfaceMethodGroups(this IGClass gClass)
        {
            var           gInterfaceMethodGroups = new Dictionary <IGMethodGroupId <TValue>, IGMethodGroup <TValue> >();
            IGMethodGroup gInterfaceMethodGroup;
            IGMethod      gInterfaceMethod = default;

            foreach (var kvp in gClass.GMethodGroups)
            {
                gInterfaceMethodGroup = new GMethodGroup(gName: kvp.Value.GName);
                foreach (var mkvp in kvp.Value.GMethods)
                {
                    gInterfaceMethod = ConvertMethodToInterfaceMethod(mkvp.Value);
                    if (gInterfaceMethod != default)
                    {
                        gInterfaceMethodGroup.GMethods.Add(gInterfaceMethod.Id, gInterfaceMethod);
                    }
                }
                gInterfaceMethodGroups.Add(gInterfaceMethodGroup.Id, gInterfaceMethodGroup);
            }
            return(gInterfaceMethodGroups);
        }
        public static IGClass AddTLoggerConstructorAutoPropertyGroup(this IGClass gClass, IPhilote <IGMethod> gMethodId, IPhilote <IGPropertyGroup> gPropertyGroupId = default, string?gAccessors = "{ get; }", string?gVisibility = default)
        {
            IGMethod gMethod = default;

            if (gClass.GMethods != null && gClass.GMethods.ContainsKey(gMethodId))
            {
                gMethod = gClass.GMethods[gMethodId];
            }
            else if (gClass.GMethodGroups != null)
            {
                foreach (var kvp in gClass.GMethodGroups)
                {
                    if (kvp.Value.GMethods.ContainsKey(gMethodId))
                    {
                        var gMethodGroup = kvp.Value;
                        gMethod = gMethodGroup.GMethods[gMethodId];
                    }
                }
            }
            if (gMethod == null)
            {
                throw new Exception(string.Format("{0} not found in the Constructors, Methods or MethodGroups of {1}", gMethodId.ID.ToString(), gClass.GName));
            }

            var       gMethodDeclaration = gMethod.GDeclaration;
            string    gName     = gMethodDeclaration.GName;
            GProperty gProperty = new GProperty(gName: $"Logger", gType: $"ILogger<{gName}>", gAccessors: gAccessors);

            if (gClass.GPropertyGroups != null && gClass.GPropertyGroups.ContainsKey(gPropertyGroupId))
            {
                gClass.GPropertyGroups[gPropertyGroupId].GPropertys[gProperty.Philote] = gProperty;
            }
            else
            {
                throw new Exception(string.Format("{0} not found in the PropertyGroups of {1}", gPropertyGroupId.ID.ToString(), gClass.GName));
            }

            gMethod.GBody.GStatements.Add($"Logger = LoggerFactory.CreateLogger<{gName}>();");
            return(gClass);
        }
 public static IGInterface AddMethod(this IGInterface gInterface, IGMethod gMethod)
 {
     gInterface.GMethods[gMethod.Id] = gMethod;
     return(gInterface);
 }
        public static void MStateMachineConstructor(
            IGCompilationUnit gCompilationUnit = default, IGNamespace gNamespace = default, IGClass gClass = default,
            IGMethod gConstructor = default, IList <string> initialDiGraphList   = default)
        {
            #region UsingGroup
            var gUsingGroup = MUsingGroupForStatelessStateMachine();
            gCompilationUnit.GUsingGroups.Add(gUsingGroup.Philote, gUsingGroup);
            #endregion
            #region Delegates
            var gDelegates = new Dictionary <IPhilote <IGDelegate>, IGDelegate>();
            var UnhandledTriggerDelegateArguments = new Dictionary <IPhilote <IGArgument>, IGArgument>();
            foreach (var o in new List <IGArgument>()
            {
                new GArgument("state", "State"), new GArgument("trigger", "Trigger"),
            })
            {
                UnhandledTriggerDelegateArguments.Add(o.Philote, o);
            }
            foreach (var o in new List <IGDelegate>()
            {
                new GDelegate(new GDelegateDeclaration("UnHandledTriggerDelegate", gType: "void", gVisibility: "public",
                                                       gArguments: UnhandledTriggerDelegateArguments)),
                new GDelegate(new GDelegateDeclaration(gName: "EntryExitDelegate", gType: "void", gVisibility: "public")),
                new GDelegate(new GDelegateDeclaration(gName: "GuardClauseDelegate", gType: "void", gVisibility: "public")),
            })
            {
                gDelegates.Add(o.Philote, o);
            }
            gNamespace.AddDelegate(gDelegates);
            #endregion

            #region StateMachine GPropertyGroup and its properties
            var gPropertyGroup = new GPropertyGroup(gName: "StateMachine Properties");
            // StateMachine Property
            var gProperty = new GProperty(gName: "StateMachine", gType: "StateMachine<State,Trigger>", gAccessors: "{get;}");
            gPropertyGroup.GPropertys.Add(gProperty.Philote, gProperty);
            // StateConfigurations property
            //gProperty = new GProperty(gName: "StateConfigurations", gType: "List<StateConfiguration>", gAccessors: "{get;}");
            //gPropertyGroup.GPropertys.Add(gProperty.Philote, gProperty);
            // Add the PropertyGroup to the gClass
            gClass.GPropertyGroups.Add(gPropertyGroup.Philote, gPropertyGroup);
            #endregion

            // Add initialization statements for the properties in the the StateMachine Properties Property Group to the constructor body
            gConstructor.GBody.GStatements.AddRange(new List <string>()
            {
                "StateMachine = new StateMachine<State, Trigger>(State.WaitingForInitialization);",
                "//StateConfigurations = stateConfigurations;",
                "ConfigureStateMachine();",
            });

            //// StateConfiguration Class for the provided namespace
            //// Define the properties for the StateConfiguration class
            //// ToDo: Move this type into ATAP.Utilities.StateMachine
            //var gPropertys = new Dictionary<IPhilote<IGProperty>, GIProperty>();
            //gProperty = new GProperty("State", "State", gAccessors: "{get;}", gVisibility: "public");
            //gPropertys.Add(gProperty.Philote, gProperty);
            //gProperty = new GProperty("Trigger", "Trigger", gAccessors: "{get;}", gVisibility: "public");
            //gPropertys.Add(gProperty.Philote, gProperty);
            //gProperty = new GProperty("NextState", "State", gAccessors: "{get;}", gVisibility: "public");
            //gPropertys.Add(gProperty.Philote, gProperty);
            //var stateConfigurationClass = new GClass(gName: "StateConfiguration", gPropertys: gPropertys);

            //var gMethodArguments = new Dictionary<IPhilote<IGArgument>, IGArgument>();
            //foreach (var o in new List<IGArgument>() {
            //  new GArgument("state", "State"), new GArgument("trigger", "Trigger"), new GArgument("nextState", "State"),
            //}) {
            //  gMethodArguments.Add(o.Philote, o);
            //}

            //gConstructor = new GMethod(
            //  new GMethodDeclaration(gName: "StateConfiguration", isConstructor: true, gType: "IDisposable",
            //    gVisibility: "public", gAccessModifier: "",
            //    gArguments: gMethodArguments),
            //  gBody:
            //  new GBody(new List<string>() {"State=state;", "Trigger=trigger;", "NextState=nextState;",}),
            //  new GComment(new List<string>() {
            //    "/// <summary>", "/// builds one state instance", "/// </summary>", "/// <returns></returns>",
            //  }));
            //stateConfigurationClass.GMethods.Add(gConstructor.Philote, gConstructor);
            //gNamespace.GClasss.Add(stateConfigurationClass.Philote, stateConfigurationClass);
        }
Exemplo n.º 11
0
 public static IGClass AddMethod(this IGClass gClass, IGMethod gMethod)
 {
     gClass.GMethods[gMethod.Id] = gMethod;
     return(gClass);
 }