public Options(string[] args) { Arguments cmdLine = new Arguments(args); if (cmdLine.FileList.Count != 1) { return; } InputFile = Path.GetFullPath(cmdLine.FileList[0]); Nmspace = cmdLine["namespace"]; if (Nmspace != null && !ParserUtils.IsValidQualifiedName(Nmspace)) { IsValid = false; } ClassName = cmdLine["class"]; if (ClassName == null) { ClassName = new Regex("[^0-9a-zA-Z_]", RegexOptions.IgnoreCase).Replace(Path.GetFileNameWithoutExtension(InputFile), "_"); if (ClassName.Length == 0 || ClassName.IndexOfAny(new[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }) == 0) { ClassName = "_" + ClassName; } } else if (!ParserUtils.IsValidUnqualifiedName(ClassName)) { IsValid = false; } OutputFile = cmdLine["out"]; if (OutputFile == "") { return; } if (OutputFile == null) { OutputFile = Path.ChangeExtension(InputFile, ExecutablesCommon.GeneratedFileExtension); } ConfigFile = cmdLine["config"]; if (ConfigFile == "") { return; } else if (ConfigFile == null) { ConfigFile = ExecutablesCommon.FindConfigFilePath(InputFile); } IsValid = true; }
public override bool Execute() { var inputsGroupedByConfigFile = new Dictionary <string, List <WorkItem> >(); OutputFiles = new ITaskItem[InputFiles.Length]; for (int i = 0; i < InputFiles.Length; i++) { string infileLocal = InputFiles[i].ItemSpec; OutputFiles[i] = new TaskItem(Path.ChangeExtension(infileLocal, ExecutablesCommon.GeneratedFileExtension)); string infile = Path.GetFullPath(infileLocal); string outfile = Path.ChangeExtension(infile, ExecutablesCommon.GeneratedFileExtension); string configFile = ExecutablesCommon.FindConfigFilePath(infile) ?? ""; List <WorkItem> l; if (!inputsGroupedByConfigFile.TryGetValue(configFile, out l)) { inputsGroupedByConfigFile[configFile] = l = new List <WorkItem>(); } l.Add(new WorkItem() { InFile = infile, OutFile = outfile, Namespace = FindNamespace(InputFiles[i]) }); } bool success = true; foreach (var kvp in inputsGroupedByConfigFile) { ExecutablesCommon.ProcessWorkItemsInSeparateAppDomain(kvp.Key, kvp.Value, (item, ex) => { if (ex is TemplateErrorException) { Log.LogError(null, null, null, item.InFile, 0, 0, 0, 0, ex.Message); success = false; } else { Log.LogErrorFromException(ex, true, true, item.InFile); success = false; } return(true); }); } return(success); }
public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress) { string className = Path.GetFileNameWithoutExtension(wszInputFilePath); string result; try { string configPath = ExecutablesCommon.FindConfigFilePath(wszInputFilePath); result = ExecutablesCommon.ProcessContentInSeparateAppDomain(configPath, bstrInputFileContents, className, wszDefaultNamespace); } catch (Exception ex) { result = ex.ToString(); } byte[] bytes = Encoding.UTF8.GetBytes(result); rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(bytes.Length); Marshal.Copy(bytes, 0, rgbOutputFileContents[0], bytes.Length); pcbOutput = (uint)bytes.Length; return(VSConstants.S_OK); }