Beispiel #1
0
        private static void WriteCSharp(List <IEngineObject> engineObjects, QlikApiConfig config, QlikApiGenerator qlikApiGenerator)
        {
            //pragmas for compiler warnings
            var pragmas = new List <string>()
            {
                "#pragma warning disable IDE1006",
                "#pragma warning disable CS1591"
            };

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

            qlikApiGenerator.SaveTo(config, objectResults, savePath, pragmas);

            logger.Info("Write Interfaces...");
            objectResults = engineObjects.Where(o => o.EngType == EngineType.INTERFACE).ToList();
            savePath      = Path.Combine(config.OutputFolder, "Interfaces.cs");
            qlikApiGenerator.SaveTo(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.SaveTo(config, new List <IEngineObject>()
                {
                    classResult
                }, savePath);
            }
        }
Beispiel #2
0
        private static void WriteTypeScript(List <IEngineObject> engineObjects, QlikApiConfig config, QlikApiGenerator qlikApiGenerator)
        {
            logger.Info("Write Enums...");
            var objectResults = engineObjects.Where(o => o.EngType == EngineType.ENUM).ToList();
            var enumFile      = Path.Combine(config.TypeScriptFolder, "Enums.d.ts");

            qlikApiGenerator.SaveTo(config, objectResults, enumFile, null);

            logger.Info("Write Interfaces...");
            objectResults = engineObjects.Where(o => o.EngType == EngineType.INTERFACE).ToList();
            var interfaceFile = Path.Combine(config.TypeScriptFolder, "Interfaces.d.ts");

            qlikApiGenerator.SaveTo(config, objectResults, interfaceFile, null);

            logger.Info("Write Classes...");
            objectResults = engineObjects.Where(o => o.EngType == EngineType.CLASS).ToList();
            var classFile = Path.Combine(config.TypeScriptFolder, $"Class.d.ts");

            qlikApiGenerator.SaveTo(config, objectResults, classFile, null);

            logger.Info("Write Index file...");
            var indexBuilder = new StringBuilder();

            indexBuilder.AppendLine("// Type definitions for qlik-engineapi 12.67");
            indexBuilder.AppendLine("// Project: https://help.qlik.com/en-US/sense-developer/February2019/Subsystems/EngineAPI/Content/Sense_EngineAPI/introducing-engine-API.htm");
            indexBuilder.AppendLine("// Definitions by: Konrad Mattheis <https://github.com/konne>");
            indexBuilder.AppendLine("// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped");
            indexBuilder.AppendLine();
            indexBuilder.Append($"declare namespace {config.NamespaceName.Replace("Qlik.","")} {{");
            var content = File.ReadAllText(enumFile);

            indexBuilder.AppendLine($"\n    {content}");
            content = File.ReadAllText(interfaceFile);
            indexBuilder.AppendLine($"\n    {content}");
            content = File.ReadAllText(classFile);
            indexBuilder.AppendLine($"\n    {content}");
            indexBuilder.AppendLine("}");

            indexBuilder.AppendLine("");
            indexBuilder.AppendLine("declare namespace enigmaJS {");
            indexBuilder.AppendLine("    interface IGeneratedAPI {");
            indexBuilder.AppendLine("    }");
            indexBuilder.AppendLine("}");

            File.WriteAllText(Path.Combine(config.TypeScriptFolder, "index.d.ts"), indexBuilder.ToString());

            File.Delete(enumFile);
            File.Delete(interfaceFile);
            File.Delete(classFile);
        }