예제 #1
0
        public static void AddAdditionalMapping(ClientMapping mapping)
        {
            if (client_map.Version == mapping.Version)
            {
                foreach (TypeMapping type in mapping.Types)
                {
                    try
                    {
                        foreach (TypeMapping original in client_map.Types)
                        {
                            if (original.RefactoredName == type.RefactoredName)
                            {
                                List <MethodMapping> methods = new List <MethodMapping>();
                                if (original.Methods != null)
                                {
                                    methods.AddRange(original.Methods);
                                }
                                if (type.Methods != null)
                                {
                                    methods.AddRange(type.Methods);
                                }
                                original.Methods = methods.ToArray();

                                List <PropertyMapping> properties = new List <PropertyMapping>();
                                if (original.Properties != null)
                                {
                                    properties.AddRange(original.Properties);
                                }
                                if (type.Properties != null)
                                {
                                    properties.AddRange(type.Properties);
                                }
                                original.Properties = properties.ToArray();

                                List <EnumValueMapping> values = new List <EnumValueMapping>();
                                if (original.EnumValues != null)
                                {
                                    values.AddRange(original.EnumValues);
                                }
                                if (type.EnumValues != null)
                                {
                                    values.AddRange(type.EnumValues);
                                }
                                original.EnumValues = values.ToArray();
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
            SetupFormats();
        }
예제 #2
0
        private static void Main(string[] args)
        {
            if (args.Length != 3 && args.Length != 1)
            {
                System.Console.WriteLine("Usage: Parser.exe <client_map> <api_output_path> <unit_tests_output_path>");
                System.Console.ReadLine();
                return;
            }

            if (args.Length == 1)
            {
                args = new string[] { args[0], "Generated", "Tests" };
            }

            System.Console.WriteLine("Loading client map");
            ClientMapping src = JsonReader.Deserialize <ClientMapping>(File.ReadAllText(args[0]));

            System.Console.WriteLine("Client map loaded");

            Generator.SetClientMap(src);
            Generator.AddAdditionalMapping(JsonReader.Deserialize <ClientMapping>(File.ReadAllText("enums.json")));
            Generator.LoadTemplate("Class_Template.cs");
            Generator.LoadUTTemplate("UT_Template.cs");
            Generator.LoadEnumTeplate("Enum_Template.cs");

            System.Console.WriteLine("Templates loaded");

            var api_files = Generator.Generate();

            Utils.Empty(args[1]);

            foreach (var item in api_files)
            {
                File.WriteAllText(Path.Combine(args[1], item.Key), Utils.Beautify(item.Value));
            }

            System.Console.WriteLine("API Files generated and saved");

            var ut_files = Generator.GenerateUnitTests();

            Utils.Empty(args[2]);

            foreach (var item in ut_files)
            {
                File.WriteAllText(Path.Combine(args[2], item.Key), Utils.Beautify(item.Value));
            }

            System.Console.WriteLine("Unit tests generated and saved");
        }
예제 #3
0
        /// <summary>
        /// Sets client map as source for generating
        /// </summary>
        /// <param name="map">Map</param>
        public static void SetClientMap(ClientMapping map)
        {
            client_map = map;

            SetupFormats();
        }