/// <summary> /// Converts a <see cref="CompilerErrorCollection"/> to a collection of <see cref="BindingExpressionCompilationError"/> objects. /// </summary> private static List <BindingExpressionCompilationError> CreateBindingExpressionCompilationErrors(LegacyExpressionCompilerState state, IEnumerable <DataSourceWrapperInfo> models, CompilerErrorCollection errors) { var result = new List <BindingExpressionCompilationError>(); var workingDirectory = state.GetWorkingDirectory(); var errorsByFile = errors.Cast <CompilerError>() .Where(x => !x.IsWarning).GroupBy(x => Path.GetFileName(x.FileName)).ToDictionary(x => x.Key, x => x.ToList()); foreach (var model in models) { var dataSourceWrapperFilename = Path.GetFileName(state.GetWorkingFileForDataSourceWrapper(model)); var dataSourceErrors = default(List <CompilerError>); if (errorsByFile.TryGetValue(dataSourceWrapperFilename, out dataSourceErrors)) { foreach (var dataSourceError in dataSourceErrors) { var fullPathToFile = model.DataSourceWrapperName; if (state.WriteErrorsToFile) { fullPathToFile = Path.GetFullPath(Path.Combine(workingDirectory, Path.ChangeExtension(model.DataSourceWrapperName, "cs"))); } result.Add(new BindingExpressionCompilationError(fullPathToFile, dataSourceError.Line, dataSourceError.Column, dataSourceError.ErrorNumber, dataSourceError.ErrorText)); } } } return(result); }
/// <summary> /// Writes any compiler errors to the working directory. /// </summary> private static void WriteErrorsToWorkingDirectory(LegacyExpressionCompilerState state, IEnumerable <DataSourceWrapperInfo> models, CompilerResults results) { var logpath = Path.Combine(state.GetWorkingDirectory(), "Compilation Errors.txt"); try { File.Delete(logpath); } catch (DirectoryNotFoundException) { } var logdir = Path.GetDirectoryName(logpath); Directory.CreateDirectory(logdir); // NOTE: Under Mono we seem to get warnings even when "Treat Warnings as Errors" is turned off. var trueErrors = results.Errors.Cast <CompilerError>().Where(x => !x.IsWarning).ToList(); if (trueErrors.Count > 0) { var filesWithErrors = trueErrors.Select(x => x.FileName).Where(x => !String.IsNullOrEmpty(x)).Distinct(); var filesWithErrorsPretty = new Dictionary <String, String> { { String.Empty, String.Empty } }; foreach (var fileWithErrors in filesWithErrors) { var modelNameForFile = models.Where(x => x.UniqueID.ToString() == Path.GetFileNameWithoutExtension(fileWithErrors)) .Select(x => x.DataSourceWrapperName).SingleOrDefault(); var prettyFileName = Path.ChangeExtension(modelNameForFile, "cs"); filesWithErrorsPretty[fileWithErrors] = prettyFileName; var fileWithErrorsSrc = Path.GetFullPath(fileWithErrors); var fileWithErrorsDst = Path.Combine(state.GetWorkingDirectory(), prettyFileName); File.Copy(fileWithErrorsSrc, fileWithErrorsDst, true); } var errorStrings = trueErrors.Select(x => String.Format("{0}\t{1}\t{2}\t{3}", x.ErrorNumber, x.ErrorText, filesWithErrorsPretty[x.FileName ?? String.Empty], x.Line)); File.WriteAllLines(logpath, Enumerable.Union(new[] { "Code\tDescription\tFile\tLine" }, errorStrings)); } }
/// <summary> /// Writes the source code of the specified collection of wrappers to the working directory. /// </summary> private static void WriteCompiledFilesToWorkingDirectory(LegacyExpressionCompilerState state, IEnumerable <DataSourceWrapperInfo> models) { var workingDirectory = state.GetWorkingDirectory(); Directory.CreateDirectory(workingDirectory); foreach (var model in models) { var path = Path.ChangeExtension(Path.Combine(workingDirectory, model.DataSourceWrapperName), "cs"); File.WriteAllText(path, model.DataSourceWrapperSourceCode); } }