static void Main(string[] args) { if (args.Length <= 0) { Console.WriteLine(GetHelp); return; } ArgumentResult argumentResult = new ArgumentResult(args); if (argumentResult.ErrMsg.GetCountByArguments("ERR") > 0) { Console.WriteLine(argumentResult.ErrMsg["ERR"]); return; } bool isHaveBaseController = argumentResult.BaseController.GetCountByArguments("-B", "--BaseController") > 0; bool isHaveHttpGet = argumentResult.BaseController.GetCountByArguments("-G", "--HttpGet") > 0; bool isShowUI = argumentResult.ShowUI.GetCountByArguments("-ui", "--ShowUI") > 0; string apiFileName = argumentResult.APIControllerFileName["api"]; if (!File.Exists(apiFileName)) { Console.WriteLine($"檔案 {apiFileName} 不存在!請確認。"); return; } string originalContent = FileHelper.ReadTextFileToEnd(apiFileName); if (isShowUI) { frmConvertWebAPI contextForm = new frmConvertWebAPI(originalContent); CSharpFile cs = ParseApiController(apiFileName); contextForm.SetTargetCsSource(cs.ToString()); DialogResult result = contextForm.ShowDialog(); if (result == DialogResult.OK) { FileHelper.WriteTextToFile(apiFileName, cs.ToString()); Console.WriteLine($"寫入 {apiFileName} Ok!"); } else { Console.WriteLine("使用者取消..."); } } else { CSharpFile cs = ParseApiController(apiFileName); FileHelper.WriteTextToFile(apiFileName, cs.ToString()); } //Console.ReadLine(); }
/// <summary> /// Converts a CSharpFile into a TextFile. /// </summary> /// <param name="cSharpFile">The CSharpFile</param> /// <returns>The generated TextFile.</returns> public static TextFile ToTextFile(this CSharpFile cSharpFile) { if (cSharpFile == null) { throw new ArgumentNullException(nameof(cSharpFile)); } // Generate the output string fileContents = cSharpFile.ToString(); // Create the TextFile object which will be sent back to Vipr TextFile textFile = new TextFile(cSharpFile.RelativeFilePath, fileContents); return(textFile); }
/// <summary> /// Generates the transmitter class. /// </summary> /// <param name="contract">The contract for which to generate the transmitter class.</param> /// <param name="implementationName">The name of the ouput class. This will also be the name of the output file before appending the extension.</param> /// <param name="namespace">The namespace in which to put the generated classes.</param> /// <param name="accessLevel">The access level of the generated classes.</param> public string Run( ContractDefinition contract, string implementationName, string @namespace, CSharpAccessModifier accessLevel = CSharpAccessModifier.Public) { if (contract == null) { throw new ArgumentNullException(nameof(contract)); } if (implementationName == null) { throw new ArgumentNullException(nameof(implementationName)); } if (!CSharpNamingUtils.IsValidIdentifier(implementationName)) { throw new ArgumentException($"Implementation name must be a valid class name: {implementationName}", nameof(implementationName)); } if (@namespace == null) { throw new ArgumentNullException(nameof(@namespace)); } foreach (string namespacePart in @namespace.Split('.')) { if (!CSharpNamingUtils.IsValidIdentifier(namespacePart)) { throw new ArgumentException($"The provided namespace is invalid because the part '{namespacePart}' is not a valid C# identifier: {@namespace}", nameof(@namespace)); } } // Validate the contract this.ValidateContract(contract); // Generate the code CSharpFile file = this.GenerateCode(contract, implementationName, @namespace, accessLevel); string result = file.ToString(); return(result); }