Exemplo n.º 1
0
        private static (GenerationProperties Properties, string Out, bool InSingleFile) PrepareGenerationProperties(string[] args)
        {
            var properties   = new GenerationProperties();
            var outDir       = string.Empty;
            var inSingleFile = false;

            for (var i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-schema":
                    properties.JsonSchema = LoadSchema(args[++i]);
                    break;

                case "-out":
                    outDir = args[++i];
                    break;

                case "-sealed":
                    properties.IsSealed = true;
                    break;

                case "-ns":
                    properties.NameSpace = args[++i];
                    break;

                case "-sf":
                    inSingleFile = true;
                    break;
                }
            }

            return(properties, outDir, inSingleFile);
        }
Exemplo n.º 2
0
        private IEnumerable <GenerationResult> GenerateCode(string schema, string nameSpace, string schemaName)
        {
            if (_packageOptions.RedefineNameSpace && string.IsNullOrWhiteSpace(_packageOptions.NameSpace))
            {
                VsShellUtilities.ShowMessageBox(
                    _serviceProvider,
                    "Redefined namespace should not be Empty",
                    "Generation Failed!",
                    OLEMSGICON.OLEMSGICON_INFO,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                return(Enumerable.Empty <GenerationResult>());
            }

            var properties = new GenerationProperties
            {
                JsonSchema = schema,
                IsSealed   = _packageOptions.IsSealed,
                NameSpace  = _packageOptions.RedefineNameSpace ? _packageOptions.NameSpace : nameSpace
            };

            try
            {
                if (_packageOptions.InSingleFile)
                {
                    var result = _generator.GenerateSingleItem(properties);
                    result.FileName = schemaName;

                    return(new[] { result });
                }
                else
                {
                    return(_generator.GenerateSeparateItems(properties));
                }
            }
            catch (CodeGeneratorFailException exception)
            {
                VsShellUtilities.ShowMessageBox(
                    _serviceProvider,
                    string.IsNullOrEmpty(exception.ObjectDefinitionSource) ? string.Empty : $"Root node of achema:\n{exception.ObjectDefinitionSource}",
                    $"Error: {exception.Message}",
                    OLEMSGICON.OLEMSGICON_INFO,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                return(Enumerable.Empty <GenerationResult>());
            }
            catch (Exception exception)
            {
                VsShellUtilities.ShowMessageBox(
                    _serviceProvider,
                    exception.Message,
                    $"Unhandled Exception!",
                    OLEMSGICON.OLEMSGICON_INFO,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                return(Enumerable.Empty <GenerationResult>());
            }
        }