Exemplo n.º 1
0
 public ChangerData(string changerId, string changerName, string rootAutoId, List <string> comments, List <BranchData> branchs, FinallyBranchData finallyBranch)
 {
     this.changerId     = changerId;
     this.changerName   = changerName;
     this.rootAutoId    = rootAutoId;
     this.comments      = comments;
     this.branchs       = branchs;
     this.finallyBranch = finallyBranch;
 }
Exemplo n.º 2
0
        public static string Changer(string changerName, List <string> routingComments, List <BranchData> brancheSourcesList, FinallyBranchData finallyBranch)
        {
            var classCommentBase = new List <string> {
                changerName, "generated Changer by Automatine."
            };

            classCommentBase.AddRange(routingComments);

            var brancheSources = new List <ChangerBranchData>();

            foreach (var branch in brancheSourcesList)
            {
                brancheSources.Add(new ChangerBranchData(branch));
            }

            var classDesc = new NoConstructorClassDescriptor(
                new List <string> {
                "System", "Automatine"
            },
                classCommentBase,
                "public",
                string.Empty,
                AutomatineDefinitions.Changer.CLASS_HEADER + changerName + " : " + AutomatineDefinitions.Changer.INTERFACE_NAME,
                () =>
            {
                var source = new ChangerMethodDesc(changerName, brancheSources, finallyBranch);
                return(source.data);
            },
                () =>
            {
                var source = new ChangerShouldImplementMethodDesc(changerName, brancheSources, finallyBranch);
                return(source.data);
            }
                );

            return(classDesc.data);
        }
Exemplo n.º 3
0
        public ChangerShouldImplementMethodDesc(string changerName, List <ChangerBranchData> brancheSources, FinallyBranchData finallyBranch)
        {
            var str = new List <string> {
                // add empty line.
                string.Empty,
                "	public Func<Auto<InitialParamType, UpdateParamType>, int, InitialParamType, Auto<InitialParamType, UpdateParamType>> Changer<InitialParamType, UpdateParamType> () {",
                "		return delegate (Auto<InitialParamType, UpdateParamType> auto, int frame, InitialParamType fixedContext) {",
                "			return "+ changerName + "(auto, frame, fixedContext);",
                "		};",
                "	}",
                "",
                "	public string ChangerName () {",
                "		return \""+ changerName + "\";",
                "	}",
                string.Empty
            };


            /*
             *                  add Effective checker.
             */
            var effectiveCheckerBrancheDescs = ChangerMethodDesc.GenerateEffectiveCheckBranchDescs(brancheSources);

            str.Add(
                "	public bool IsEffective<InitialParamType, UpdateParamType> (Auto<InitialParamType, UpdateParamType> baseAuto) {"
                );

            // add branch condition.
            if (effectiveCheckerBrancheDescs.Any())
            {
                str.AddRange(
                    new List <string> {
                    "		var conditions = baseAuto.Conditions();",
                    "		"
                }
                    );

                foreach (var effectiveCheckerBrancheDesc in effectiveCheckerBrancheDescs)
                {
                    str.Add(effectiveCheckerBrancheDesc.data);
                }
            }

            if (finallyBranch.IsExists())
            {
                str.AddRange(
                    new List <string> {
                    "	   // finally is ON.",
                    "		return true;"
                }
                    );
            }
            else
            {
                str.Add(
                    "		return false;"
                    );
            }

            str.Add(
                "	}"
                );

            data = string.Join("\n", str.ToArray());
        }
Exemplo n.º 4
0
        public ChangerMethodDesc(string changerName, List <ChangerBranchData> brancheSources, FinallyBranchData finallyBranch)
        {
            var changerBranches = GenerateChangerBranchDescs(brancheSources);

            // add Changer method.
            var str = new List <string> {
                "	public static Auto<InitialParamType, UpdateParamType> ",
                "		"+ changerName,
                "		<InitialParamType, UpdateParamType>",
                "		(Auto<InitialParamType, UpdateParamType> baseAuto, int frame, InitialParamType fixedContext)",
                "	{"
            };

            if (changerBranches.Any())
            {
                str.AddRange(
                    new List <string> {
                    "		var conditions = baseAuto.Conditions();",
                    "		"
                }
                    );
            }

            var branchesDesc = changerBranches.Select(branch => branch.data).ToList();

            str.AddRange(branchesDesc);

            if (finallyBranch.IsExists())
            {
                var finallyAuto     = finallyBranch.finallyAutoId;
                var finallyInherits = finallyBranch.inheritTimelineConditions;

                str.AddRange(
                    new List <string> {
                    "		var finallyAuto = new ",
                    "			"+ finallyAuto,
                    "			<InitialParamType, UpdateParamType>(frame, fixedContext);"
                }
                    );

                if (finallyInherits.Any())
                {
                    var inheritsWithClass = finallyInherits.Select(inheritType => "typeof(AutoConditions." + inheritType + ")").ToArray();
                    var inheritConditions = string.Join(", ", inheritsWithClass);
                    str.AddRange(
                        new List <string> {
                        "			finallyAuto.InheritTimelines(baseAuto.ExportTimelines(new Type[] {",
                        "				"+ inheritConditions,
                        "			}));"
                    }
                        );
                }

                str.Add(
                    "		return finallyAuto;"
                    );
            }
            else
            {
                str.Add(
                    "		return baseAuto;"
                    );
            }

            str.Add(
                "	}"
                );


            // add empty line.
            str.Add(string.Empty);

            var effectiveCheckerBrancheDescs = GenerateEffectiveCheckBranchDescs(brancheSources);

            /*
             *                  add IsEffective method.
             */
            str.Add(
                "	public static bool IsEffectiveChanger<InitialParamType, UpdateParamType> (Auto<InitialParamType, UpdateParamType> baseAuto) {"
                );

            // add branch condition.
            if (effectiveCheckerBrancheDescs.Any())
            {
                str.AddRange(
                    new List <string> {
                    "		var conditions = baseAuto.Conditions();",
                    "		"
                }
                    );

                foreach (var effectiveCheckerBrancheDesc in effectiveCheckerBrancheDescs)
                {
                    str.Add(effectiveCheckerBrancheDesc.data);
                }
            }

            if (finallyBranch.IsExists())
            {
                str.AddRange(
                    new List <string> {
                    "	   // finally is ON.",
                    "		return true;"
                }
                    );
            }
            else
            {
                str.Add(
                    "		return false;"
                    );
            }

            str.Add(
                "	}"
                );

            data = string.Join("\n", str.ToArray());
        }