public string ShowAndGetResultMenu(IEdmTerm term) { int maxRetry = 3; int retry = 1; string[] types = { "xml", "json", "yaml" }; while (true) { Console.Clear(); Console.WriteLine($"\nSelect output format for \"{term.FullName()}\":\n"); for (int i = 1; i <= types.Length; i++) { Console.WriteLine($"\t[{i}]: {types[i - 1]}"); } Console.Write("\nPlease select the output index or [Q/q] for quit:"); string input = Console.ReadLine().Trim(); if (input == "q" || input == "Q") { // Exit Environment.Exit(0); } bool bOk = Int32.TryParse(input, out int index); if (bOk) { if (index >= 1 && index <= types.Length) { return(types[index - 1]); } } ConsoleColor foreColor = Console.ForegroundColor; if (retry > maxRetry) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("[Error:] Max try reach, Close now. 88"); Console.ForegroundColor = foreColor; Environment.Exit(0); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"[Error:] Wrong input, do you want to retry {retry}/{maxRetry} [y]?"); Console.ForegroundColor = foreColor; input = Console.ReadLine(); if (input == "Y" || input == "y") { retry++; } else { Environment.Exit(0); } } }
private void ValidateExpressionType(IEdmTerm term, IEdmExpression expr, Position position) { var errors = new ErrorList(); if (!(CheckType(term.Type, expr, ref errors) && errors.IsEmpty)) { logger.LogError("annotation value invalid for annotation {0} of type '{1}' ({2}){3}", term.FullName(), term.Type.FullName(), position, errors); } }
public string Run(IEdmTerm term, IEdmModel model) { if (term == null) { Console.WriteLine($"Cannot find the term {term.FullName()}"); return(null); } WriteTermStart(term.FullName()); IEdmType termType = term.Type.Definition; ProcessType(termType, false); WriteTermEnd(); stream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(stream); // Removing xml header to make the baseline's more compact and focused on the test at hand. return(reader.ReadToEnd()); }
static int Main(string[] args) { IEdmModel model; if (args.Length == 1) { // string csdlName = ""; // empty means use the built-in vacabulary model = LoadEdmModel(args[0]); } else { model = new EdmModel(); } if (model == null) { return(-1); } /* * IEdmTerm term = model.FindTerm(termName); * if (term == null) * { * Console.WriteLine($"Cannot find the term {termName}"); * return 1; * } * * Console.WriteLine("\n======> xml\n"); * TermGenerator g = GeneartorFactor.Create("xml"); * string result = g.Run(termName, model); * Console.WriteLine(result); * * Console.WriteLine("\n======> json\n"); * g = GeneartorFactor.Create("json"); * result = g.Run(termName, model); * Console.WriteLine(result); * * Console.WriteLine("\n======> yaml\n"); * g = GeneartorFactor.Create("yaml"); * result = g.Run(termName, model); * Console.WriteLine(result); */ while (true) { // ShowTerms(model); ModelProcesser processer = new ModelProcesser(model); string selected = processer.ShowAndGetNamespaceMenu(); IEdmTerm term = processer.ShowAndGetTermMenu(selected); string format = processer.ShowAndGetResultMenu(term); TermGenerator g = GeneartorFactor.Create(format); string result = g.Run(term, model); Console.Clear(); Console.WriteLine($"\n ==> Term '{term.FullName()}' has the following '{format}' template:\n"); ConsoleColor foreColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(result); Console.ForegroundColor = foreColor; Console.WriteLine(); Console.Write("\nPress any key do it again for other term. Or input [Q/q] for exit..."); string input = Console.ReadLine().Trim(); if (input == "q" || input == "Q") { // Exit Environment.Exit(0); } } }
private void ValidateAppliesTo(IEdmTerm term, IEdmVocabularyAnnotatable annotatable, Position position) { // https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_Applicability if (string.IsNullOrWhiteSpace(term.AppliesTo)) { // If no list is supplied, the term is not intended to be restricted in its application return; } var appliesTo = (term.AppliesTo.Split(' ') ?? Array.Empty <string>()).ToHashSet(); bool Check <T>(string kind, string edmName) where T : IEdmNamedElement { if (annotatable is T instance) { if (!appliesTo.Contains(kind)) { logger.LogError("annotation {0} can not be applied to {1} '{2}' ({3})", term.FullName(), edmName, instance.Name, position); } return(true); } return(false); } if (Check <IEdmProperty>("Property", "property")) { return; } if (Check <IEdmEntityType>("EntityType", "type")) { return; } if (Check <IEdmComplexType>("ComplexType", "type")) { return; } if (Check <IEdmEnumType>("EnumType", "enum")) { return; } if (Check <IEdmAction>("Action", "function")) { return; } if (Check <IEdmFunction>("EntityType", "function")) { return; } }