Beispiel #1
0
        static private string GetFileImports(EEntityFile eEntityFile)
        {
            try {
                string           imports          = "";
                List <EEnumFile> restInPeaceEnums = CSharpEnumReader.fileList;
                foreach (EEntityProperty eEntityProperty in eEntityFile.propertyList)
                {
                    if (eEntityProperty.typescriptTypeName == "string" ||
                        eEntityProperty.typescriptTypeName == "number" ||
                        eEntityProperty.typescriptTypeName == "boolean" ||
                        eEntityProperty.typescriptTypeName == "object" ||
                        eEntityProperty.typescriptTypeName == "Date")
                    {
                        continue;
                    }

                    if (eEntityProperty.typescriptTypeName.Contains("TimeSpan"))
                    {
                        if (!imports.Contains("TimeSpan"))
                        {
                            imports += "\nimport {TimeSpan} from 'typescript-dotnet-amd/System/Time/TimeSpan';";
                        }
                        continue;
                    }
                    else
                    {
                        Logger.LogInfo("entidade:" + eEntityProperty.csharpTypeName);
                        if (eEntityProperty.csharpTypeName.ToLower() == "entitytype")
                        {
                        }
                        string import = "";
                        if (restInPeaceEnums.Any(x => String.Equals(x.enumName, eEntityProperty.csharpTypeName, StringComparison.CurrentCultureIgnoreCase)))
                        {
                            import += "\nimport { " + eEntityProperty.csharpTypeName + " } from '../../enums/restinpeace/" + eEntityProperty.csharpTypeName.ToLower() + "';";
                        }
                        else
                        {
                            import = "\nimport {" + eEntityProperty.csharpTypeName + "} from './" + eEntityProperty.csharpTypeName.ToLower() + "';";
                        }
                        if (!imports.Contains(import))
                        {
                            imports += import;
                        }
                    }
                }
                if (!string.IsNullOrEmpty(imports))
                {
                    imports += "\n";
                }
                return(imports);
            } catch (Exception e) {
                Logger.LogError(e);
            }
            return("");
        }
Beispiel #2
0
 static private bool AnalyseFile(string path)
 {
     try {
         if (!File.Exists(path))
         {
             return(true);
         }
         FileInfo             fileInfo    = new FileInfo(path);
         string               fullContent = File.ReadAllText(path);
         IEnumerable <string> linesList   = fullContent.Split('\n');
         EEntityFile          eEntityFile = new EEntityFile();
         eEntityFile.className    = fileInfo.Name.Replace(".cs", String.Empty);
         eEntityFile.propertyList = new List <EEntityProperty>();
         if (fullContent.Contains("[RestInPeaceEntity]") || fullContent.Contains("[RestInPeaceEntityImport]"))
         {
             Logger.LogInfoIfDebugLevel(DebugLevels.Files | DebugLevels.All, "\t" + eEntityFile.className);
         }
         for (int l = 0; l < linesList.Count(); l++)
         {
             string lineContent = linesList.ElementAt(l);
             if (lineContent.Contains("[RestInPeaceEntityImport]")) //significa que nao vamos compiar o conteudo do entity. Apenas vamos adicionar o import no Angular service onde ele é usado
             {
                 fileList.Add(eEntityFile);
                 eEntityFile.onlyImport = true;
                 return(true);
             }
             if (!lineContent.Contains("[RestInPeaceEntity]"))
             {
                 continue;
             }
             if (!AnalyseEntity(ref eEntityFile, fullContent))
             {
                 return(false);
             }
             if (!AnalyseListsInEntity(ref eEntityFile, fullContent))
             {
                 return(false);
             }
             //por enquanto suporta só um entity por arquivo
             break;
         }
         if (eEntityFile.propertyList.Count > 0)
         {
             fileList.Add(eEntityFile);
         }
         return(true);
     } catch (Exception e) {
         Logger.LogError(e);
     }
     return(false);
 }
Beispiel #3
0
 static private bool WriteTypescriptEntityFile(EEntityFile eEntityFile, string entityDirectory)
 {
     try {
         string typescriptFileName         = eEntityFile.className.ToLower() + ".ts";
         string completeTypescriptFilePath = entityDirectory + "/" + typescriptFileName;
         Logger.LogInfo("Writing " + typescriptFileName);
         StringBuilder newFileContent = new StringBuilder();
         string        imports        = GetFileImports(eEntityFile);
         if (!string.IsNullOrEmpty(imports))
         {
             newFileContent.Append(imports);
         }
         newFileContent.Append("\nexport class " + eEntityFile.className + "{");
         foreach (EEntityProperty eEntityProperty in eEntityFile.propertyList)
         {
             if (!eEntityProperty.isList)
             {
                 newFileContent.Append("\n\t" + eEntityProperty.typescriptPropName + ":" + eEntityProperty.typescriptTypeName + ";");
             }
             else
             {
                 newFileContent.Append("\n\t" + eEntityProperty.typescriptPropName + ":" + eEntityProperty.typescriptTypeName + "[];");
             }
         }
         newFileContent.Append("\n}");
         //Logger.LogInfo(newFileContent.ToString());
         string oldContent = "";
         if (File.Exists(completeTypescriptFilePath))
         {
             oldContent = File.ReadAllText(completeTypescriptFilePath);
         }
         if (newFileContent.ToString() != oldContent)
         {
             File.WriteAllText(completeTypescriptFilePath, newFileContent.ToString());
         }
         return(true);
     } catch (Exception e) {
         Logger.LogError(e);
     }
     return(false);
 }
Beispiel #4
0
        static private bool WriteDotnetEntityFile(EEntityFile eEntityFile, string entityDirectory)
        {
            try {
                string blazorEntityFileName = eEntityFile.className + ".cs";
                string completeFilePath     = entityDirectory + "/" + blazorEntityFileName;
                Logger.LogInfoIfDebugLevel(DebugLevels.Files | DebugLevels.Functions | DebugLevels.All, "\t" + blazorEntityFileName);
                StringBuilder fileContent = new StringBuilder();
                fileContent.Append("#region Imports\n");
                fileContent.Append("using System;\n");
                fileContent.Append("using DotnetBase.Codes;\n");
                fileContent.Append("#endregion;\n\n");
                fileContent.Append("namespace " + Globals.dotnetNamespace + ".Entities.RestInPeace {\n");

                fileContent.Append($"\tpublic class {eEntityFile.className}" + "{\n");
                foreach (EEntityProperty eEntityProperty in eEntityFile.propertyList)
                {
                    if (string.IsNullOrEmpty(eEntityProperty.name))
                    {
                        continue;
                    }
                    fileContent.Append($"\t\tpublic {eEntityProperty.csharpTypeName} {eEntityProperty.name} " + "{ get; set; }\n");
                }
                fileContent.Append("\t}\n");
                fileContent.Append("}\n");
                //Logger.LogInfo(newFileContent.ToString());
                string oldContent = "";
                if (File.Exists(completeFilePath))
                {
                    oldContent = File.ReadAllText(completeFilePath);
                }
                if (fileContent.ToString() != oldContent)
                {
                    File.WriteAllText(completeFilePath, fileContent.ToString());
                }
                return(true);
            } catch (Exception e) {
                Logger.LogError(e);
            }
            return(false);
        }
Beispiel #5
0
 static private bool WriteQMLEntityFile(EEntityFile eEntityFile, string entityDirectory)
 {
     try {
         Directory.CreateDirectory(entityDirectory);
         string qmlFileName         = eEntityFile.className + ".qml";
         string completeQMLFilePath = entityDirectory + "/" + qmlFileName;
         Logger.LogInfo("Writing " + qmlFileName);
         StringBuilder newFileContent = new StringBuilder();
         newFileContent.Append("import QtQuick 2.6\n");
         newFileContent.Append("import com.tezine.base 1.0\n\n");
         newFileContent.Append("//author Bruno Tezine\n");
         newFileContent.Append("//Se for tipo primitivo nullable, usar var\n");
         newFileContent.Append("QtObject {");
         foreach (EEntityProperty eEntityProperty in eEntityFile.propertyList)
         {
             string propertyLine = "";
             if (!GetPropertyLine(eEntityProperty, out propertyLine))
             {
                 Logger.LogError("unable to write property in file " + qmlFileName);
                 return(false);
             }
             newFileContent.Append(propertyLine);
         }
         newFileContent.Append("\n}");
         //Logger.LogInfo(newFileContent.ToString());
         string oldContent = "";
         if (File.Exists(completeQMLFilePath))
         {
             oldContent = File.ReadAllText(completeQMLFilePath);
         }
         if (newFileContent.ToString() != oldContent)
         {
             File.WriteAllText(completeQMLFilePath, newFileContent.ToString());
         }
         return(true);
     } catch (Exception e) {
         Logger.LogError(e);
     }
     return(false);
 }
 static private bool WriteTypescriptEntityFile(EEntityFile eEntityFile, string entityDirectory)
 {
     try {
         string typescriptEntityFileName = eEntityFile.className + ".d.ts";
         string completeFilePath         = entityDirectory + "/" + typescriptEntityFileName;
         Logger.LogInfoIfDebugLevel(DebugLevels.Files | DebugLevels.Functions | DebugLevels.All, "\t" + typescriptEntityFileName);
         StringBuilder fileContent = new StringBuilder();
         fileContent.Append("\n");
         fileContent.Append("export declare class " + eEntityFile.className + " {\n");
         foreach (EEntityProperty eEntityProperty in eEntityFile.propertyList)
         {
             if (string.IsNullOrEmpty(eEntityProperty.name))
             {
                 continue;
             }
             if (!WriteProperty(eEntityProperty, out string propertyLine))
             {
                 Logger.LogError("unable to write property in file " + typescriptEntityFileName);
                 return(false);
             }
             fileContent.Append(propertyLine);
         }
         fileContent.Append("}");
         //Logger.LogInfo(newFileContent.ToString());
         string oldContent = "";
         if (File.Exists(completeFilePath))
         {
             oldContent = File.ReadAllText(completeFilePath);
         }
         if (fileContent.ToString() != oldContent)
         {
             File.WriteAllText(completeFilePath, fileContent.ToString());
         }
         return(true);
     } catch (Exception e) {
         Logger.LogError(e);
     }
     return(false);
 }
Beispiel #7
0
 static private bool AnalyseEntity(ref EEntityFile eEntityFile, string fileContent)
 {
     try {
         var   regex = new Regex("public\\s+(\\w+\\?*)\\s+(\\w+)\\s+{\\s*get", RegexOptions.None, TimeSpan.FromMilliseconds(1000));
         Match match = regex.Match(fileContent);
         if (!match.Success)
         {
             return(true);
         }
         for (Int32 i = 0; match.Success; i++, match = match.NextMatch())
         {
             EEntityProperty eEntityProperty = new EEntityProperty();
             eEntityProperty.csharpTypeName = match.Groups[1].Value;
             eEntityProperty.name           = match.Groups[2].Value;
             eEntityFile.propertyList.Add(eEntityProperty);
         }
         return(true);
     } catch (Exception e) {
         Logger.LogError(e);
     }
     return(false);
 }
 static private bool WriteFlutterEntityFile(EEntityFile eEntityFile, string entityDirectory)
 {
     try {
         string flutterEntityFileName = eEntityFile.className.ToLower() + ".dart";
         string completeFilePath      = entityDirectory + "/" + flutterEntityFileName;
         Logger.LogInfoIfDebugLevel(DebugLevels.Files | DebugLevels.Functions | DebugLevels.All, "\t" + flutterEntityFileName);
         StringBuilder fileContent = new StringBuilder();
         fileContent.Append("//region imports\n");
         fileContent.Append("//author Bruno Tezine\n");
         fileContent.Append("import \'package:json_annotation/json_annotation.dart\';\n");
         //let's add all imports from other entities
         foreach (EEntityProperty eEntityProperty in eEntityFile.propertyList)
         {
             if (string.IsNullOrEmpty(eEntityProperty.name))
             {
                 continue;
             }
             FlutterWatcher.GetFlutterType(eEntityProperty.csharpTypeName, out bool isAnotherEntityImport);
             if (!isAnotherEntityImport)
             {
                 continue;
             }
             fileContent.Append("import \'package:" + Globals.flutterPackageName + "/entities/restinpeace/" + eEntityProperty.csharpTypeName.ToLower() + ".dart\';\n");
         }
         fileContent.Append("part '" + eEntityFile.className.ToLower() + ".g.dart\';\n");
         fileContent.Append("//endregion\n\n");
         fileContent.Append("@JsonSerializable(nullable: true)\n");
         fileContent.Append($"class {eEntityFile.className}" + "{\n");
         foreach (EEntityProperty eEntityProperty in eEntityFile.propertyList)
         {
             if (string.IsNullOrEmpty(eEntityProperty.name))
             {
                 continue;
             }
             if (!WriteProperty(eEntityProperty, out string propertyLine))
             {
                 Logger.LogError("unable to write property in file " + flutterEntityFileName);
                 return(false);
             }
             fileContent.Append(propertyLine);
         }
         fileContent.Append("\n\t" + eEntityFile.className + "({\n");
         for (int p = 0; p < eEntityFile.propertyList.Count; p++)
         {
             EEntityProperty eEntityProperty = eEntityFile.propertyList.ElementAt(p);
             fileContent.Append("\t\tthis." + eEntityProperty.name);
             if (p != (eEntityFile.propertyList.Count - 1))
             {
                 fileContent.Append(",\n");
             }
             else
             {
                 fileContent.Append("\n});\n");
             }
         }
         fileContent.Append($"\n\tfactory {eEntityFile.className}.fromJson(Map<String, dynamic> json) => _${eEntityFile.className}FromJson(json);\n");
         fileContent.Append($"\tMap<String, dynamic> toJson() => _${eEntityFile.className}ToJson(this);\n");
         fileContent.Append("}");
         //Logger.LogInfo(newFileContent.ToString());
         string oldContent = "";
         if (File.Exists(completeFilePath))
         {
             oldContent = File.ReadAllText(completeFilePath);
         }
         if (fileContent.ToString() != oldContent)
         {
             File.WriteAllText(completeFilePath, fileContent.ToString());
         }
         return(true);
     } catch (Exception e) {
         Logger.LogError(e);
     }
     return(false);
 }