public string GenerateFile(string inputFilePath, string outputFilePath, Func <GeneratorServices> generatorServicesProvider, Func <string, string> inputFileContentProvider = null, Action <string, string> outputFileContentWriter = null) { outputFileContentWriter = outputFileContentWriter ?? File.WriteAllText; inputFileContentProvider = inputFileContentProvider ?? File.ReadAllText; GeneratorServices generatorServices; ProjectSettings projectSettings; CodeDomHelper codeDomHelper; try { generatorServices = generatorServicesProvider(); projectSettings = generatorServices.GetProjectSettings(); codeDomHelper = GenerationTargetLanguage.CreateCodeDomHelper(projectSettings.ProjectPlatformSettings.Language); } catch (Exception ex) { OnOtherError(ex); return(null); } string inputFileContent; try { inputFileContent = inputFileContentProvider(inputFilePath); } catch (Exception ex) { OnOtherError(ex); return(null); } string outputFileContent = Generate(inputFilePath, inputFileContent, generatorServices, codeDomHelper, projectSettings); try { if (outputFilePath == null) { outputFilePath = inputFilePath + GenerationTargetLanguage.GetExtension(projectSettings.ProjectPlatformSettings.Language); } outputFileContentWriter(outputFilePath, outputFileContent); return(outputFilePath); } catch (Exception ex) { OnOtherError(ex); return(null); } }
public string GenerateFile(string inputFilePath, string outputFilePath, Func <GeneratorServices> generatorServicesProvider, Func <string, string> inputFileContentProvider = null, Action <string, string> outputFileContentWriter = null) { outputFileContentWriter = outputFileContentWriter ?? File.WriteAllText; inputFileContentProvider = inputFileContentProvider ?? File.ReadAllText; GeneratorServices generatorServices; ProjectSettings projectSettings; CodeDomHelper codeDomHelper; try { generatorServices = generatorServicesProvider(); projectSettings = generatorServices.GetProjectSettings(); codeDomHelper = GenerationTargetLanguage.CreateCodeDomHelper(projectSettings.ProjectPlatformSettings.Language); if (outputFilePath == null) { outputFilePath = inputFilePath + GenerationTargetLanguage.GetExtension(projectSettings.ProjectPlatformSettings.Language); } if (_projectInfo.ReferencedSpecFlowVersion == null) { return(WriteNoSpecFlowVersionReferencedError(outputFilePath, outputFileContentWriter, codeDomHelper)); } var generatorVersion = generatorServices.GetGeneratorVersion(); if (generatorVersion.Major != _projectInfo.ReferencedSpecFlowVersion.Major || generatorVersion.Minor != _projectInfo.ReferencedSpecFlowVersion.Minor) { return(WriteSpecFlowVersionConflictError(outputFilePath, outputFileContentWriter, generatorVersion, codeDomHelper)); } } catch (Exception ex) { OnOtherError(ex); return(null); } string inputFileContent; try { inputFileContent = inputFileContentProvider(inputFilePath); } catch (Exception ex) { OnOtherError(ex); return(null); } string outputFileContent = Generate(inputFilePath, inputFileContent, generatorServices, codeDomHelper, projectSettings); try { outputFileContentWriter(outputFilePath, outputFileContent); return(outputFilePath); } catch (Exception ex) { OnOtherError(ex); return(null); } }