Beispiel #1
0
        protected override bool ExecuteIsolated()
#endif

        {
            Log.LogCommandLine($">> [{typeof(GeneratorTask).Namespace}] START");

#if !DEBUG
            try
            {
#endif
            #region Settings Map

            Settings.RouteToServiceProjectFolder = RouteToServiceProjectFolder;
            Settings.ClientInterfaceName         = ClientInterfaceName;
            Settings.RegisterName       = RegisterName;
            Settings.UseValueTask       = bool.Parse(UseValueTask ?? "false");
            Settings.UseInternalClients = bool.Parse(UseInternalClients ?? "false");
            Settings.ClientNamespace    = ClientNamespace;
            Settings.AllowedNamespaces  = AllowedNamespaces?.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            Settings.ExcludedNamespaces = ExcludedNamespaces?.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            #endregion


            Directory.SetCurrentDirectory(CurrentDirectory);

            Log.LogCommandLine($"Generating W/ CurrentPath : {CurrentDirectory}");

            if (string.IsNullOrWhiteSpace(CurrentDirectory))
            {
                Log.LogError("One of the settings is not filled out.");
                return(false);
            }

            //Start out by loading all relevent DLLS
            if (string.IsNullOrEmpty(Settings.RouteToServiceProjectFolder))
            {
                Log.LogWarning("Service project folder is not provided");
                return(false);
            }
            Log.LogCommandLine(Settings.RouteToServiceProjectFolder);

            //Start out by loading all cs files into memory

            var parsedFiles = Directory.EnumerateFiles($"{Environment.CurrentDirectory}/{Settings.RouteToServiceProjectFolder}", "*Controller.cs", SearchOption.AllDirectories)
                              .Where(x => !x.Contains("/obj/") && !x.Contains("\\obj\\") &&
                                     !x.Contains("/bin/") && !x.Contains("\\bin\\"))
                              .Select(cs => new ParsedFile(cs))
                              .ToList();

            ClassWriter.WriteClientsFile(parsedFiles);

            Log.LogCommandLine("Client Generation Successful!");
            Log.LogCommandLine($">> [{typeof(GeneratorTask).Namespace}] END");
            return(true);

#if !DEBUG
        }

        catch (Exception ex)
        {
            Log.LogError(ex.ToString());
            return(false);
        }
#endif
        }
Beispiel #2
0
        protected override bool ExecuteIsolated()
#endif
        {
            Log.LogCommandLine($">> [{typeof(GeneratorTask).Namespace}] START");

#if !DEBUG
            try
            {
#endif
            #region Settings Map

            Settings.RouteToServiceProjectFolder = RouteToServiceProjectFolder;
            Settings.ClientInterfaceName         = ClientInterfaceName;
            Settings.RegisterName = RegisterName;

            Settings.UseValueTask             = bool.Parse(UseValueTask ?? "false");
            Settings.UseInternalClients       = bool.Parse(UseInternalClients ?? "false");
            Settings.ClientRouteConstraints   = bool.Parse(ClientRouteConstraints ?? "false");
            Settings.ErrorOnUnhandledCallback = bool.Parse(ErrorOnUnhandledCallback ?? "false");
            Settings.MultipleFiles            = bool.Parse(MultipleFiles ?? "false");
            Settings.GenerateStaticRoutes     = bool.Parse(GenerateStaticRoutes ?? "false");

            Settings.GenerateClientRepository     = bool.Parse(GenerateClientRepository ?? "true");
            Settings.GenerateLazyClientRepository = bool.Parse(GenerateLazyClientRepository ?? "false");

            Settings.RoutesNamespace = RoutesNamespace;
            Settings.ClientNamespace = ClientNamespace;
            Settings.HubNamespace    = HubNamespace;

            Settings.AllowedNamespaces  = AllowedNamespaces?.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            Settings.ExcludedNamespaces = ExcludedNamespaces?.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            #endregion


            Directory.SetCurrentDirectory(CurrentDirectory);

            Log.LogCommandLine($"Generating W/ CurrentPath : {CurrentDirectory}");

            if (string.IsNullOrWhiteSpace(CurrentDirectory))
            {
                Log.LogError("One of the settings is not filled out.");
                return(false);
            }

            //Start out by loading all relevent DLLS
            if (string.IsNullOrEmpty(Settings.RouteToServiceProjectFolder))
            {
                Log.LogWarning("Service project folder is not provided");
                return(false);
            }
            Log.LogCommandLine(Settings.RouteToServiceProjectFolder);

            //Start out by loading all cs files into memory

            var parsedControllers = Directory.EnumerateFiles($"{Environment.CurrentDirectory}/{Settings.RouteToServiceProjectFolder}", "*.cs", SearchOption.AllDirectories)
                                    .Where(x => !x.Contains("/obj/") && !x.Contains("\\obj\\") &&
                                           !x.Contains("/bin/") && !x.Contains("\\bin\\"))
                                    .Select(cs => new HttpControllerCSharpFile(cs))
                                    .ToList();


            var parsedHubs = Directory.EnumerateFiles($"{Environment.CurrentDirectory}/{Settings.RouteToServiceProjectFolder}", "*.cs", SearchOption.AllDirectories)
                             .Where(x => !x.Contains("/obj/") && !x.Contains("\\obj\\") &&
                                    !x.Contains("/bin/") && !x.Contains("\\bin\\"))
                             .Select(cs => new HubCSharpFile(cs))
                             .ToList();

            var hostFile = Directory.EnumerateFiles($"{Environment.CurrentDirectory}/{Settings.RouteToServiceProjectFolder}", "host.json", SearchOption.AllDirectories)
                           .Where(x => !x.Contains("/obj/") && !x.Contains("\\obj\\") &&
                                  !x.Contains("/bin/") && !x.Contains("\\bin\\"))
                           .Select(jn => new HostJsonFile(jn))
                           .SingleOrDefault();

            var parsedFunctions = Directory.EnumerateFiles($"{Environment.CurrentDirectory}/{Settings.RouteToServiceProjectFolder}", "*.cs", SearchOption.AllDirectories)
                                  .Where(x => !x.Contains("/obj/") && !x.Contains("\\obj\\") &&
                                         !x.Contains("/bin/") && !x.Contains("\\bin\\"))
                                  .Select(cs => new FunctionsCSharpFile(cs, hostFile?.Data))
                                  .ToList();

            var context = new GenerationContext();
            foreach (var file in parsedControllers)
            {
                context = context.Merge(file.Context);
            }
            foreach (var file in parsedHubs)
            {
                context = context.Merge(file.Context);
            }
            foreach (var file in parsedFunctions)
            {
                context = context.Merge(file.Context);
            }
            context.MapRelatedInfo();
            context.Validate(Settings.AllowedNamespaces, Settings.ExcludedNamespaces);

            ClassWriter.WriteClientsFile(context);

            Log.LogCommandLine("Client Generation Successful!");
            Log.LogCommandLine($">> [{typeof(GeneratorTask).Namespace}] END");
            return(true);

#if !DEBUG
        }

        catch (Exception ex)
        {
            Log.LogError(ex.ToString());
            return(false);
        }
#endif
        }