static void Main(string[] args) { var map = new Dictionary<string, string>(StringComparer.Ordinal); var key = (string)null; foreach (var item in args) { if (item.Length == 0) continue; if (item.StartsWith('-')) key = item; else if (key != null) map[key] = $"{(map.TryGetValue(key, out var value) ? value + " " : string.Empty)}{item.Trim(' ', '\'', '\"')}"; } if (!map.TryGetValue("-p", out var path) && !map.TryGetValue("--path", out path)) { throw new ArgumentException("Path missing, expect -p|--path path1 path2"); } if (!map.TryGetValue("-o", out var output) && !map.TryGetValue("--out", out output)) { throw new ArgumentException("Out missing, expect -o|--out path1 path2"); } if (!map.TryGetValue("-n", out var nameSpace) && !map.TryGetValue("--namespace", out nameSpace)) { //throw new ArgumentException("Namespace missing, expect -n|--namespace name space definition"); } if (!map.TryGetValue("-r", out var references) && !map.TryGetValue("--references", out references)) { //throw new ArgumentException("References missing, expect -r|--references paths to project or library"); } var generator = new ClientGenerator(path, output, nameSpace ?? "DataWF.Web.Client", references); generator.Generate(); generator.GetUnits(true); }
static void Main(string[] args) { var map = new Dictionary<string, string>(); var key = (string)null; foreach (var item in args) { if (item.Length == 0) continue; if (item.StartsWith('-')) key = item; else if (key != null) map[key] = $"{(map.TryGetValue(key, out var value) ? value + " " : string.Empty)}{item.Trim(' ', '\'', '\"')}"; } if (!map.TryGetValue("-p", out var path) && !map.TryGetValue("--path", out path)) { throw new ArgumentException("Path missing, expect -p|--path path1 path2"); } if (!map.TryGetValue("-o", out var output) && !map.TryGetValue("--out", out output)) { throw new ArgumentException("Out missing, expect -o|--out path1 path2"); } if (!map.TryGetValue("-n", out var nameSpace) && !map.TryGetValue("--namespace", out nameSpace)) { //throw new ArgumentException("Nmaespace missing, expect -n|--namespace Name.Space"); } var generator = new ClientGenerator(path, output, nameSpace); generator.Generate(); generator.GetUnits(true); }
static int Main(String[] args) { // These are the parameters that are parsed out of the command line. String inputFilePath = String.Empty; String outputFileName = String.Empty; String targetNamespace = "DefaultNamespace"; try { // The command line parser is driven by different states that are triggered by the flags read. Unless a flag has been parsed, the command line // parser assumes that it's reading the file name from the command line. ArgumentState argumentState = ArgumentState.InputFileName; // Parse the command line for arguments. foreach (String argument in args) { // Use the dictionary to transition from one state to the next based on the input parameters. ArgumentState nextArgumentState; if (ClientCompiler.argumentStates.TryGetValue(argument, out nextArgumentState)) { argumentState = nextArgumentState; continue; } // The parsing state will determine which variable is read next. switch (argumentState) { case ArgumentState.InputFileName: // Expand the environment variables so that paths don't need to be absolute. inputFilePath = Environment.ExpandEnvironmentVariables(argument); // The output name defaults to the input file name with a new extension. outputFileName = String.Format("{0}.cs", Path.GetFileNameWithoutExtension(inputFilePath)); break; case ArgumentState.OutputFileName: // Expand the environment variables so that paths don't need to be absolute. outputFileName = Environment.ExpandEnvironmentVariables(argument); break; case ArgumentState.TargetNamespace: // This is the namespace that is used to create the target data model. targetNamespace = argument; break; } // The default state is to look for the input file name on the command line. argumentState = ArgumentState.InputFileName; } // This will read the input XML schema into a large buffer. String fileContents; using (StreamReader streamReader = new StreamReader(inputFilePath)) fileContents = streamReader.ReadToEnd(); // This next step simulates the calling convension used by a custom tool, which is to say it uses unmanaged code. The progress indicator is used // to provide feedback, to either the IDE or the command line, about how far along the compilation is. Note that the calling interface is from // unmanaged-code to managed code, the way you would expect the IDE to call the generator, so we create an unmanaged buffer pointer for the results. IntPtr[] buffer = new IntPtr[1]; UInt32 bufferSize; ClientGenerator clientGenerator = new ClientGenerator(); clientGenerator.Generate(inputFilePath, fileContents, targetNamespace, buffer, out bufferSize, new ProgressIndicator()); // Once the buffer of source code is generated, it is copied back out of the unmanaged buffers and written to the output file. Byte[] outputBuffer = new byte[bufferSize]; Marshal.Copy(buffer[0], outputBuffer, 0, Convert.ToInt32(bufferSize)); using (StreamWriter streamWriter = new StreamWriter(outputFileName)) streamWriter.Write(Encoding.UTF8.GetString(outputBuffer)); } catch (Exception exception) { // This will catch any generic errors and dump them to the console. Console.WriteLine(exception.Message); } // The execution at this point was a success. return(0); }