static private bool WriteTypescriptFile(string completeTypescriptFilename, EFunctionFile eFile) { try { //string typescriptClassName = ""; //if (eFile.csharpFileName.StartsWith("S")) typescriptClassName = eFile.csharpFileName.Remove(0, 1); StringBuilder newFileContent = new StringBuilder(); newFileContent.Append("//author Bruno Tezine\n"); //let's insert all entity imports List <string> importList = new List <string>(); List <string> allFunctionArgTypes = GetFunctionArgumentTypeNames(eFile.functionList); List <string> allReturnTypes = GetAllReturnTypeNames(eFile.functionList); newFileContent.Append("//region imports\n"); foreach (string argType in allFunctionArgTypes) { string completeImportLine = ""; if (CSharpEntityReader.IsEntity(argType)) { completeImportLine = "import {" + argType + "} from \"./" + argType + "\";\n"; } else if (CSharpEnumReader.IsEnum(argType)) { completeImportLine = "import {" + argType + "} from \"./" + argType + "\";\n"; } else if (!Helper.isBasicDotnetType(argType)) { Logger.LogError($"Unknown arg type {argType} used in file {eFile.csharpFileName}!!!"); continue; } if (importList.Contains(completeImportLine)) { continue; } importList.Add(completeImportLine); } foreach (string returnType in allReturnTypes) { string completeImportLine = ""; if (CSharpEntityReader.IsEntity(returnType)) { completeImportLine = "import {" + returnType + "} from \"./" + returnType + "\";\n"; } else if (CSharpEnumReader.IsEnum(returnType)) { completeImportLine = "import {" + returnType + "} from \"./" + returnType + "\";\n"; } else if (!Helper.isBasicDotnetType(returnType)) { Logger.LogError($"Unknown return type {returnType} used in file {eFile.csharpFileName}!!!"); continue; } if (importList.Contains(completeImportLine)) { continue; } importList.Add(completeImportLine); } foreach (string importLine in importList) { newFileContent.Append(importLine); } // newFileContent.Append("import {MySimpleEvent} from \"@QtTyped/Codes/MySimpleEvent\";\n"); newFileContent.Append("import {MySimpleEvent} from \"./MySimpleEvent\";\n"); newFileContent.Append("//endregion\n\n"); //imports above foreach (EFunction eFunction in eFile.functionList) { GetTypeScriptFuctionReturnType(eFunction, out string userTypeName); if (string.IsNullOrEmpty(userTypeName)) { continue; } } newFileContent.Append("export declare class " + eFile.frontendClassName + " {\n"); newFileContent.Append("\n"); foreach (EFunction eFunction in eFile.functionList) { Logger.LogInfoIfDebugLevel(DebugLevels.Functions | DebugLevels.All, "\tFunction " + eFunction.functionName); string functionName = Char.ToLowerInvariant(eFunction.functionName[0]) + eFunction.functionName.Substring(1); newFileContent.Append("\tstatic " + functionName + "(" + GetTypeScriptFuctionArguments(eFunction) + ")" + GetTypeScriptFuctionReturnType(eFunction, out string userTypeName)); newFileContent.Append("\n"); } newFileContent.Append("}\n"); string oldContent = ""; if (File.Exists(completeTypescriptFilename)) { oldContent = File.ReadAllText(completeTypescriptFilename); } if (newFileContent.ToString() != oldContent) { File.WriteAllText(completeTypescriptFilename, newFileContent.ToString()); } return(true); } catch (Exception e) { Logger.LogError(e); } return(false); }
static private bool WriteFlutterFile(EFunctionFile eFile) { try { StringBuilder newFileContent = new StringBuilder(); newFileContent.Append("//region imports\n"); newFileContent.Append("//author Bruno Tezine\n"); newFileContent.Append("import \'dart:convert\';\n"); newFileContent.Append("import \'package:http/http.dart\' as http;\n"); newFileContent.Append("import \'package:flutter_base/codes/bool_helper.dart\';\n"); newFileContent.Append($"import \'package:{Globals.flutterPackageName}/codes/defines.dart\';\n"); //let's insert all entity imports List <string> importList = new List <string>(); List <string> allFunctionArgTypes = GetFunctionArgumentTypeNames(eFile.functionList); List <string> allReturnTypes = GetAllReturnTypeNames(eFile.functionList); foreach (string argType in allFunctionArgTypes) { string completeImportLine = ""; if (CSharpEntityReader.IsEntity(argType)) { completeImportLine = "import 'package:" + Globals.flutterPackageName + "/entities/restinpeace/" + argType.ToLower() + ".dart';\n"; } else if (CSharpEnumReader.IsEnum(argType)) { completeImportLine = "import 'package:" + Globals.flutterPackageName + "/enums/" + argType.ToLower() + ".dart';\n"; } else if (!Helper.isBasicDotnetType(argType)) { Logger.LogError($"Unknown arg type {argType} used in file {eFile.csharpFileName}!!!"); continue; } if (importList.Contains(completeImportLine)) { continue; } importList.Add(completeImportLine); } foreach (string returnType in allReturnTypes) { string completeImportLine = ""; if (CSharpEntityReader.IsEntity(returnType)) { completeImportLine = "import 'package:" + Globals.flutterPackageName + "/entities/restinpeace/" + returnType.ToLower() + ".dart';\n"; } else if (CSharpEnumReader.IsEnum(returnType)) { completeImportLine = "import 'package:" + Globals.flutterPackageName + "/enums/" + returnType.ToLower() + ".dart';\n"; } else if (!Helper.isBasicDotnetType(returnType)) { Logger.LogError($"Unknown return type {returnType} used in file {eFile.csharpFileName}!!!"); continue; } if (importList.Contains(completeImportLine)) { continue; } importList.Add(completeImportLine); } foreach (string importLine in importList) { newFileContent.Append(importLine); } newFileContent.Append("//endregion\n\n"); //imports above newFileContent.Append($"class {eFile.frontendClassName}" + "{\n"); // foreach (EFunction eFunction in eFile.functionList) { // string flutterTypeName=FlutterWatcher.GetFlutterType(eFunction.returnTypeName, out bool isAnotherEntityImport);//antes era GetFlutterFuctionReturnType // if (string.IsNullOrEmpty(flutterTypeName)) continue; // } newFileContent.Append("\n"); foreach (EFunction eFunction in eFile.functionList) { if (!WriteFunction(eFile, eFunction)) { Logger.LogError("unable get function " + eFunction.functionName + " from file " + eFile.csharpFileName); return(false); } newFileContent.Append(eFunction.frontendFunctionContent); newFileContent.Append("\n\n"); } newFileContent.Append("}\n"); string oldContent = ""; if (File.Exists(eFile.frontendFileName)) { oldContent = File.ReadAllText(eFile.frontendFileName); } if (newFileContent.ToString() != oldContent) { File.WriteAllText(eFile.frontendFileName, newFileContent.ToString()); } return(true); } catch (Exception e) { Logger.LogError(e); } return(false); }