Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                SetLoggerSettings();
                logger.Info("qlik-engineapi-generator");
                logger.Info("Load options...");
                var config = GetConfig();
                if (!File.Exists(config.SourceFile))
                {
                    logger.Warn("No source file found. Please check the args.");
                    return;
                }

                var origJsonObject = GetJsonObject(config.SourceFile);
                var workDir        = Path.GetDirectoryName(config.SourceFile);
                if (string.IsNullOrEmpty(config.OutputFolder))
                {
                    config.OutputFolder = workDir;
                }
                Directory.CreateDirectory(config.OutputFolder);

                var files          = Directory.GetFiles(workDir, "*.json", SearchOption.TopDirectoryOnly);
                var changeJsonFile = config.GetChangeFile();
                if (File.Exists(changeJsonFile))
                {
                    var changeJsonObject = GetJsonObject(changeJsonFile);
                    origJsonObject.Merge(changeJsonObject);

                    var parameters = origJsonObject.SelectTokens("$...parameters").ToList();
                    var jArray     = new JArray();
                    for (int i = 0; i < parameters.Count; i++)
                    {
                        jArray = parameters[i].ToObject <JArray>();
                        parameters[i].Replace(origJsonObject.MergeArray(jArray));
                    }

                    var responses = origJsonObject.SelectTokens("$...responses").ToList();
                    for (int i = 0; i < responses.Count; i++)
                    {
                        jArray = responses[i].ToObject <JArray>();
                        responses[i].Replace(origJsonObject.MergeArray(jArray));
                    }
                }

                logger.Info("Start parsing...");
                var qlikApiGenerator = new QlikApiGenerator(config, ScriptLanguage.CSharp);
                var engineObjects    = qlikApiGenerator.ReadJson(origJsonObject);
                WriteCSharp(engineObjects, config, qlikApiGenerator);

                qlikApiGenerator = new QlikApiGenerator(config, ScriptLanguage.TypeScript);
                engineObjects    = qlikApiGenerator.ReadJson(origJsonObject);
                WriteTypeScript(engineObjects, config, qlikApiGenerator);

                Environment.ExitCode = 0;
                logger.Info("Finish");
                logger.Factory.Flush();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "The Application has an Error.");
                logger.Factory.Flush();
                Environment.ExitCode = 1;
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            try
            {
                SetLoggerSettings();
                logger.Info("qlik-engineapi-generator");
                logger.Info("Load options...");
                var config = GetConfig();
                if (!File.Exists(config.SourceFile))
                {
                    logger.Warn("No source file found. Please check the args.");
                    return;
                }

                var origJsonObject = GetJsonObject(config.SourceFile);
                var workDir        = Path.GetDirectoryName(config.SourceFile);
                if (string.IsNullOrEmpty(config.OutputFolder))
                {
                    config.OutputFolder = workDir;
                }
                Directory.CreateDirectory(config.OutputFolder);

                var files          = Directory.GetFiles(workDir, "*.json", SearchOption.TopDirectoryOnly);
                var changeJsonFile = config.GetChangeFile();
                if (File.Exists(changeJsonFile))
                {
                    var changeJsonObject = GetJsonObject(changeJsonFile);
                    origJsonObject.Merge(changeJsonObject);
                    var keyNames = new List <string>()
                    {
                        "qMode", "qType", "qFieldSelectionMode", "qState", "qGrouping", "qSortIndicator",
                        "qDimensionType", "qExportState", "qReductionMode", "qMatchingFieldMode",
                        "qGroup"
                    };
                    var parameters = origJsonObject.SelectTokens("$...parameters").ToList();
                    var jArray     = new JArray();
                    for (int i = 0; i < parameters.Count; i++)
                    {
                        jArray = parameters[i].ToObject <JArray>();
                        parameters[i].Replace(origJsonObject.MergeArray(jArray, keyNames));
                    }
                    keyNames = new List <string>()
                    {
                        "qReturn"
                    };
                    var responses = origJsonObject.SelectTokens("$...responses").ToList();
                    for (int i = 0; i < responses.Count; i++)
                    {
                        jArray = responses[i].ToObject <JArray>();
                        responses[i].Replace(origJsonObject.MergeArray(jArray, keyNames));
                    }
                }

                logger.Info("Start parsing...");
                var qlikApiGenerator = new QlikApiGenerator(config);
                var engineObjects    = qlikApiGenerator.ReadJson(origJsonObject);

                logger.Info("Write Enums...");
                var objectResults = engineObjects.Where(o => o.EngType == EngineType.ENUM).ToList();
                var savePath      = Path.Combine(config.OutputFolder, "Enums.cs");
                qlikApiGenerator.SaveToCSharp(config, objectResults, savePath);

                logger.Info("Write Interfaces...");
                objectResults = engineObjects.Where(o => o.EngType == EngineType.INTERFACE).ToList();
                savePath      = Path.Combine(config.OutputFolder, "Interfaces.cs");
                qlikApiGenerator.SaveToCSharp(config, objectResults, savePath);

                logger.Info("Write Classes...");
                objectResults = engineObjects.Where(o => o.EngType == EngineType.CLASS).ToList();
                foreach (var classResult in objectResults)
                {
                    savePath = Path.Combine(config.OutputFolder, $"{classResult.Name}.cs");
                    qlikApiGenerator.SaveToCSharp(config, new List <IEngineObject>()
                    {
                        classResult
                    }, savePath);
                }

                Environment.ExitCode = 0;
                logger.Info("Finish");
                logger.Factory.Flush();
            }
            catch (Exception ex)
            {
                logger.Error(ex, "The Application has an Error.");
                logger.Factory.Flush();
                Environment.ExitCode = 1;
            }
        }