static private bool AnalyseFile(string path, string fileContent) { try { FileInfo fileInfo = new FileInfo(path); if (fileInfo.Name.ToLower().Contains("respcreateuser")) { Debug.WriteLine("encontrou"); } string[] linesList = fileContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None); var regex = new Regex("(\\w+)\\s*(?:=\\s*(\\d+))?", RegexOptions.None | RegexOptions.Singleline, TimeSpan.FromMilliseconds(1000)); EEnumFile eEnumFile = new EEnumFile { enumName = fileInfo.Name.Replace(".cs", String.Empty), valueList = new List <EEnumValue>() }; Logger.LogInfoIfDebugLevel(DebugLevels.Files | DebugLevels.All, "\t" + eEnumFile.enumName); //let's find the internal start line int startLine = 0; for (int line = 0; line < linesList.Length; line++) { if (!linesList.ElementAt(line).Contains("public enum")) { continue; } startLine = line + 1; break; } //let's find the internal end line int endLine = 0; for (int line = startLine; line < linesList.Length; line++) { if (linesList.ElementAt(line).Contains("}")) { endLine = line - 1; break; } } for (int l = startLine; l <= endLine; l++) { string lineContent = linesList.ElementAt(l); Match match = regex.Match(lineContent); if (!match.Success) { continue; } EEnumValue eEnumValue = new EEnumValue { name = match.Groups[1].Value, value = match.Groups[2].Value }; eEnumFile.valueList.Add(eEnumValue); } if (eEnumFile.valueList.Count > 0) { fileList.Add(eEnumFile); } return(true); } catch (Exception e) { Logger.LogError(e); } return(false); }
static public bool WriteFlutterEnumFile(EEnumFile eEnumFile) { try { if (!eEnumFile.valueList.Any()) { return(true); } string enumFilename = eEnumFile.enumName.ToLower() + ".dart"; string completeFilePath = Globals.flutterEnumFolder + "/" + enumFilename; Logger.LogInfoIfDebugLevel(DebugLevels.Files | DebugLevels.Functions | DebugLevels.All, "\t" + enumFilename); StringBuilder fileContent = new StringBuilder(); fileContent.Append("\n"); //vamos ver se criamos como enum ou como class. Caso tenha valores, temos que criar como classe pq dart não suporta EnumValue=1 if (string.IsNullOrEmpty(eEnumFile.valueList.FirstOrDefault().value)) //criamos como enum em dart { fileContent.Append("enum " + eEnumFile.enumName + " {\n"); foreach (EEnumValue eEnumValue in eEnumFile.valueList) { if (string.IsNullOrEmpty(eEnumValue.name)) { continue; } string valueLine = $"\t{eEnumValue.name},\n"; fileContent.Append(valueLine); } } else //criamos como class em dart { fileContent.Append("class " + eEnumFile.enumName + " {\n"); foreach (EEnumValue eEnumValue in eEnumFile.valueList) { if (string.IsNullOrEmpty(eEnumValue.name)) { continue; } string valueLine = "\tstatic const " + eEnumValue.name + "= " + eEnumValue.value + ";\n"; fileContent.Append(valueLine); } } 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); }
static public bool WriteTypescriptEnumFile(EEnumFile eEnumFile, string frontendDirectory, bool export = true) { try { string typescriptEnumFilename = eEnumFile.enumName + ".ts"; string completeFilePath = frontendDirectory + "/" + typescriptEnumFilename; Logger.LogInfoIfDebugLevel(DebugLevels.Files | DebugLevels.Functions | DebugLevels.All, "\t" + typescriptEnumFilename); StringBuilder fileContent = new StringBuilder(); fileContent.Append("\n"); if (export) { fileContent.Append("export enum " + eEnumFile.enumName + " {\n"); } else { fileContent.Append("enum " + eEnumFile.enumName + " {\n"); } foreach (EEnumValue eEnumValue in eEnumFile.valueList) { if (string.IsNullOrEmpty(eEnumValue.name)) { continue; } if (!string.IsNullOrEmpty(eEnumValue.value)) { fileContent.Append("\t" + eEnumValue.name + "= " + eEnumValue.value + ",\n"); } else { fileContent.Append("\t" + eEnumValue.name + ",\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); }
static public bool WriteAngularEnumFile(EEnumFile eEnumFile) { try { if (!eEnumFile.valueList.Any()) { return(true); } string enumFilename = eEnumFile.enumName.ToLower() + ".ts"; string completeFilePath = Globals.angularEnumsFolder + "/" + enumFilename; Logger.LogInfoIfDebugLevel(DebugLevels.Files | DebugLevels.Functions | DebugLevels.All, "\t" + enumFilename); StringBuilder fileContent = new StringBuilder(); fileContent.Append("\n"); fileContent.Append("export enum " + eEnumFile.enumName + " {\n"); foreach (EEnumValue eEnumValue in eEnumFile.valueList) { if (string.IsNullOrEmpty(eEnumValue.name)) { continue; } if (!string.IsNullOrEmpty(eEnumValue.value)) { fileContent.Append("\t" + eEnumValue.name + "= " + eEnumValue.value + ",\n"); } else { fileContent.Append($"\t{eEnumValue.name},\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); }