Beispiel #1
0
        static void Main(string[] args)
        {
            var cmdArgs = new CommandlineArguments(args);

            if (!cmdArgs.IsParsed)
            {
                return;
            }

            // Generator Start...

            var sw = Stopwatch.StartNew();

            Console.WriteLine("Project Compilation Start:" + cmdArgs.InputPath);

            var collector = new MethodCollector(cmdArgs.InputPath, cmdArgs.ConditionalSymbols);

            Console.WriteLine("Project Compilation Complete:" + sw.Elapsed.ToString());
            Console.WriteLine();

            sw.Restart();
            Console.WriteLine("Method Collect Start");

            var definitions = collector.Visit();

            GenericSerializationInfo[] genericInfos;
            EnumSerializationInfo[]    enumInfos;
            ExtractResolverInfo(definitions, out genericInfos, out enumInfos);

            Console.WriteLine("Method Collect Complete:" + sw.Elapsed.ToString());

            Console.WriteLine("Output Generation Start");
            sw.Restart();

            var enumTemplates = enumInfos.GroupBy(x => x.Namespace)
                                .OrderBy(x => x.Key)
                                .Select(x => new EnumTemplate()
            {
                Namespace = x.Key,
                enumSerializationInfos = x.ToArray()
            })
                                .ToArray();

            var resolverTemplate = new ResolverTemplate()
            {
                Namespace          = cmdArgs.NamespaceRoot + ".Resolvers",
                FormatterNamespace = cmdArgs.NamespaceRoot + ".Formatters",
                ResolverName       = "MagicOnionResolver",
                registerInfos      = genericInfos.OrderBy(x => x.FullName).Cast <IResolverRegisterInfo>().Concat(enumInfos.OrderBy(x => x.FullName)).ToArray()
            };

            var texts = definitions
                        .GroupBy(x => x.Namespace)
                        .OrderBy(x => x.Key)
                        .Select(x => new CodeTemplate()
            {
                Namespace     = x.Key,
                isAsyncSuffix = cmdArgs.IsAsyncSuffix,
                Interfaces    = x.ToArray()
            })
                        .ToArray();

            var registerTemplate = new RegisterTemplate
            {
                Namespace           = cmdArgs.NamespaceRoot,
                Interfaces          = definitions.Where(x => x.IsServiceDifinition).ToArray(),
                UnuseUnityAttribute = cmdArgs.UnuseUnityAttr
            };

            var sb = new StringBuilder();

            sb.AppendLine(registerTemplate.TransformText());
            sb.AppendLine(resolverTemplate.TransformText());
            foreach (var item in enumTemplates)
            {
                sb.AppendLine(item.TransformText());
            }

            foreach (var item in texts)
            {
                sb.AppendLine(item.TransformText());
            }
            Output(cmdArgs.OutputPath, sb.ToString());

            Console.WriteLine("String Generation Complete:" + sw.Elapsed.ToString());
            Console.WriteLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var cmdArgs = new CommandlineArguments(args);

            if (!cmdArgs.IsParsed)
            {
                return;
            }

            // Generator Start...

            var sw = Stopwatch.StartNew();

            Console.WriteLine("Project Compilation Start:" + cmdArgs.InputPath);

            var collector = new MethodCollector(cmdArgs.InputPath, cmdArgs.ConditionalSymbols);

            Console.WriteLine("Project Compilation Complete:" + sw.Elapsed.ToString());
            Console.WriteLine();

            sw.Restart();
            Console.WriteLine("Method Collect Start");

            var definitions = collector.Visit();

            Console.WriteLine("Method Collect Complete:" + sw.Elapsed.ToString());

            Console.WriteLine("Output Generation Start");
            sw.Restart();

            var texts = definitions
                        .GroupBy(x => x.Namespace)
                        .Select(x => new CodeTemplate()
            {
                Namespace             = x.Key,
                ZeroFormatterResolver = cmdArgs.ResolverName,
                Interfaces            = x.ToArray()
            })
                        .ToArray();

            var registerTemplate = new RegisterTemplate
            {
                Namespace           = cmdArgs.NamespaceRoot,
                Interfaces          = definitions.Where(x => x.IsServiceDifinition).ToArray(),
                UnuseUnityAttribute = cmdArgs.UnuseUnityAttr
            };

            if (cmdArgs.IsSeparate)
            {
                var initializerPath = Path.Combine(cmdArgs.OutputPath, "MagicOnionInitializer.cs");
                Output(initializerPath, registerTemplate.TransformText());

                foreach (var item in texts)
                {
                    foreach (var interfaceDef in item.Interfaces)
                    {
                        var path      = Path.Combine(cmdArgs.OutputPath, interfaceDef.ToString().Replace(".", "\\") + ".cs");
                        var template2 = new CodeTemplate()
                        {
                            Namespace = interfaceDef.Namespace, ZeroFormatterResolver = cmdArgs.ResolverName, Interfaces = new[] { interfaceDef }
                        };
                        Output(path, template2.TransformText());
                    }
                }
            }
            else
            {
                var sb = new StringBuilder();
                sb.AppendLine(registerTemplate.TransformText());
                foreach (var item in texts)
                {
                    sb.AppendLine(item.TransformText());
                }
                Output(cmdArgs.OutputPath, sb.ToString());
            }

            Console.WriteLine("String Generation Complete:" + sw.Elapsed.ToString());
            Console.WriteLine();
        }