/// <inheritdoc/> public BindingExpressionCompilationResult CompileSingleView(UltravioletContext uv, BindingExpressionCompilerOptions options) { Contract.Require(options, "options"); if (String.IsNullOrEmpty(options.Input)) throw new ArgumentException(PresentationStrings.InvalidCompilerOptions); var definition = CreateDataSourceDefinitionFromXml(options.RequestedViewModelNamespace, options.RequestedViewModelName, options.Input); if (definition == null) return BindingExpressionCompilationResult.CreateSucceeded(); var state = CreateCompilerState(uv, options); var dataSourceWrapperInfo = GetDataSourceWrapperInfo(state, definition.Value); var dataSourceWrapperInfos = new[] { dataSourceWrapperInfo }; var result = CompileViewModels(state, dataSourceWrapperInfos, null); if (result.Succeeded) { options.Output = dataSourceWrapperInfos[0].DataSourceWrapperSourceCode; } else { DeleteWorkingDirectory(state); } return result; }
/// <inheritdoc/> public BindingExpressionCompilationResult Compile(UltravioletContext uv, BindingExpressionCompilerOptions options) { Contract.Require(uv, "uv"); Contract.Require(options, "options"); if (String.IsNullOrEmpty(options.Input) || String.IsNullOrEmpty(options.Output)) throw new ArgumentException(PresentationStrings.InvalidCompilerOptions); var state = CreateCompilerState(uv, options); var dataSourceWrapperInfos = GetDataSourceWrapperInfos(state, uv, options.Input); var cacheFile = Path.ChangeExtension(options.Output, "cache"); var cacheNew = CompilerCache.FromDataSourceWrappers(dataSourceWrapperInfos); if (File.Exists(options.Output)) { var cacheOld = CompilerCache.TryFromFile(cacheFile); if (cacheOld != null && !options.IgnoreCache && !cacheOld.IsDifferentFrom(cacheNew)) return BindingExpressionCompilationResult.CreateSucceeded(); } var result = CompileViewModels(state, dataSourceWrapperInfos, options.Output); if (result.Succeeded) { cacheNew.Save(cacheFile); if (!options.WriteCompiledFilesToWorkingDirectory && !options.WorkInTemporaryDirectory) DeleteWorkingDirectory(state); } if (options.WriteCompiledFilesToWorkingDirectory && !options.WorkInTemporaryDirectory) WriteCompiledFilesToWorkingDirectory(state, dataSourceWrapperInfos); return result; }
/// <inheritdoc/> public BindingExpressionCompilationResult Compile(UltravioletContext uv, BindingExpressionCompilerOptions options) { Contract.Require(uv, nameof(uv)); Contract.Require(options, nameof(options)); if (String.IsNullOrEmpty(options.Input) || String.IsNullOrEmpty(options.Output)) { throw new ArgumentException(PresentationStrings.InvalidCompilerOptions); } var compiler = CreateCodeProvider(); var state = new LegacyExpressionCompilerState(uv, compiler) { GenerateInMemory = options.GenerateInMemory, WorkInTemporaryDirectory = options.WorkInTemporaryDirectory, WriteErrorsToFile = options.WriteErrorsToFile }; var dataSourceWrapperInfos = DataSourceLoader.GetDataSourceWrapperInfos(state, options.Input); var cacheFile = Path.ChangeExtension(options.Output, "cache"); var cacheNew = CompilerCache.FromDataSourceWrappers(this, dataSourceWrapperInfos); if (File.Exists(options.Output)) { var cacheOld = CompilerCache.TryFromFile(cacheFile); if (cacheOld != null && !options.IgnoreCache && !cacheOld.IsDifferentFrom(cacheNew)) { return(BindingExpressionCompilationResult.CreateSucceeded()); } } var result = CompileViewModels(state, dataSourceWrapperInfos, options.Output, options.GenerateDebugAssembly); if (result.Succeeded) { if (!options.GenerateInMemory) { cacheNew.Save(cacheFile); } if (!options.WriteCompiledFilesToWorkingDirectory && !options.WorkInTemporaryDirectory) { state.DeleteWorkingDirectory(); } } if (options.WriteCompiledFilesToWorkingDirectory && !options.WorkInTemporaryDirectory) { WriteCompiledFilesToWorkingDirectory(state, dataSourceWrapperInfos); } return(result); }
/// <inheritdoc/> public BindingExpressionCompilationResult CompileSingleView(UltravioletContext uv, BindingExpressionCompilerOptions options) { Contract.Require(options, nameof(options)); if (String.IsNullOrEmpty(options.Input)) { throw new ArgumentException(PresentationStrings.InvalidCompilerOptions); } var definition = DataSourceLoader.CreateDataSourceDefinitionFromXml(options.RequestedViewModelNamespace, options.RequestedViewModelName, options.Input); if (definition == null) { return(BindingExpressionCompilationResult.CreateSucceeded()); } var state = new RoslynExpressionCompilerState(uv) { GenerateInMemory = options.GenerateInMemory, WorkInTemporaryDirectory = options.WorkInTemporaryDirectory, WriteErrorsToFile = options.WriteErrorsToFile }; var dataSourceWrapperInfo = DataSourceLoader.GetDataSourceWrapperInfo(state, definition.Value); var dataSourceWrapperInfos = new[] { dataSourceWrapperInfo }; var result = CompileViewModels(state, dataSourceWrapperInfos, null, options.GenerateDebugAssembly); if (result.Succeeded) { options.Output = dataSourceWrapperInfos[0].DataSourceWrapperSourceCode; } else { state.DeleteWorkingDirectory(); } return(result); }
/// <summary> /// Creates a new instance of <see cref="ExpressionCompilerState"/> from the specified set of compiler options. /// </summary> private ExpressionCompilerState CreateCompilerState(UltravioletContext uv, BindingExpressionCompilerOptions options) { var compiler = CreateCodeProvider(); var state = new ExpressionCompilerState(uv, compiler); state.WorkInTemporaryDirectory = options.WorkInTemporaryDirectory; state.WriteErrorsToFile = options.WriteErrorsToFile; return state; }