/// <summary> /// Returns plugins that are registered for the given interface, sorted by dependencies (MefPovider.DependsOn). /// </summary> internal static IEnumerable <PluginInfo> FindPlugins(ContainerBuilder builder, Type pluginInterface) { lock (_pluginsLock) { if (_pluginsByExport == null) { var assemblies = ListAssemblies(); try { _pluginsByExport = LoadPlugins(assemblies); } catch (Exception ex) { string typeLoadReport = CsUtility.ReportTypeLoadException(ex, "Cannot load plugins.", assemblies); if (typeLoadReport != null) { throw new FrameworkException(typeLoadReport, ex); } else { ExceptionsUtility.Rethrow(ex); } } } return(_pluginsByExport.Get(pluginInterface.FullName)); } }
private void FailOnTypeLoadErrors(Assembly assembly, string assemblyPath) { try { assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { throw new FrameworkException(CsUtility.ReportTypeLoadException(ex, "Error while compiling " + assemblyPath + "."), ex); } }
public Assembly Generate(IAssemblySource assemblySource, CompilerParameters compilerParameters) { var stopwatch = Stopwatch.StartNew(); compilerParameters.ReferencedAssemblies.AddRange(assemblySource.RegisteredReferences.ToArray()); if (compilerParameters.WarningLevel == -1) { compilerParameters.WarningLevel = 4; } string sourceFile = null; CompilerResults results; if (compilerParameters.GenerateInMemory) { using (CSharpCodeProvider codeProvider = new CSharpCodeProvider()) results = codeProvider.CompileAssemblyFromSource(compilerParameters, assemblySource.GeneratedCode); } else { sourceFile = Path.GetFullPath(Path.ChangeExtension(compilerParameters.OutputAssembly, ".cs")); File.WriteAllText(sourceFile, assemblySource.GeneratedCode, Encoding.UTF8); using (CSharpCodeProvider codeProvider = new CSharpCodeProvider()) results = codeProvider.CompileAssemblyFromFile(compilerParameters, sourceFile); } _performanceLogger.Write(stopwatch, "CSharpCodeProvider.CompileAssemblyFromSource"); if (results.Errors.HasErrors) { throw new FrameworkException(ReportErrors(results, assemblySource.GeneratedCode, sourceFile)); } try { results.CompiledAssembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { throw new FrameworkException(CsUtility.ReportTypeLoadException(ex, "Error while compiling " + compilerParameters.OutputAssembly + "."), ex); } ReportWarnings(results, sourceFile); return(results.CompiledAssembly); }
public static int Main(string[] args) { var logProvider = new NLogProvider(); var logger = logProvider.GetLogger("DeployPackages"); var pauseOnError = false; logger.Info(() => "Logging configured."); try { if (!DeployPackagesArguments.ValidateArguments(args)) { return(1); } string rhetosAppRootPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..")); Build(args, logProvider, rhetosAppRootPath, out pauseOnError); DbUpdate(args, logProvider); logger.Info("Done."); } catch (Exception e) { logger.Error(e.ToString()); string typeLoadReport = CsUtility.ReportTypeLoadException(e); if (typeLoadReport != null) { logger.Error(typeLoadReport); } if (Environment.UserInteractive) { InteractiveExceptionInfo(e, pauseOnError); } return(1); } return(0); }
private void FailOnTypeLoadErrors(Assembly assembly, string outputAssemblyPath, IEnumerable <string> referencedAssembliesPaths) { try { assembly.GetTypes(); } catch (Exception ex) { string contextInfo = $"Error while compiling {Path.GetFileName(outputAssemblyPath)}."; string typeLoadReport = CsUtility.ReportTypeLoadException(ex, contextInfo, referencedAssembliesPaths); if (typeLoadReport != null) { throw new FrameworkException(typeLoadReport, ex); } else { ExceptionsUtility.Rethrow(ex); } } }
/// <summary> /// Returns plugins that are registered for the given interface, sorted by dependencies (MefPovider.DependsOn). /// </summary> internal static IEnumerable <PluginInfo> FindPlugins(ContainerBuilder builder, Type pluginInterface) { try { lock (_pluginsLock) { if (_pluginsByExport == null) { var assemblies = ListAssemblies(); _pluginsByExport = LoadPlugins(assemblies); } return(_pluginsByExport.Get(pluginInterface.FullName)); } } catch (ReflectionTypeLoadException ex) { throw new FrameworkException(CsUtility.ReportTypeLoadException(ex, "Cannot load plugins."), ex); } }
private int SafeExecuteCommand(Action action, string commandName, bool msBuildErrorFormat) { var logger = _logProvider.GetLogger("Rhetos " + commandName); logger.Info(() => $"Started in {AppDomain.CurrentDomain.BaseDirectory}"); try { action.Invoke(); logger.Info($"Done."); } catch (DslSyntaxException dslException) when(msBuildErrorFormat) { PrintCanonicalError(dslException); // Detailed exception info is logged as additional information, not as an error, to avoid duplicate error reporting. logger.Info(dslException.ToString()); return(1); } catch (Exception e) { logger.Error(e.ToString()); string typeLoadReport = CsUtility.ReportTypeLoadException(e); if (typeLoadReport != null) { logger.Error(typeLoadReport); } if (Environment.UserInteractive) { PrintErrorSummary(e); } return(1); } return(0); }
private MultiDictionary <string, PluginInfo> GetPluginsByExport(IEnumerable <string> pluginAssemblies) { List <string> assemblyPaths = pluginAssemblies.Select(path => Path.GetFullPath(path)).Distinct().ToList(); foreach (var assembly in assemblyPaths) { if (!File.Exists(assembly)) { throw new FrameworkException($"{nameof(PluginScanner)}: The given assembly file path does not exist: '{assembly}'."); } else { _logger.Trace(() => $"Searching for plugins in '{assembly}'"); } } MultiDictionary <string, PluginInfo> plugins = null; try { plugins = LoadPlugins(assemblyPaths); } catch (Exception ex) { string typeLoadReport = CsUtility.ReportTypeLoadException(ex, "Cannot load plugins.", assemblyPaths); if (typeLoadReport != null) { throw new FrameworkException(typeLoadReport, ex); } else { ExceptionsUtility.Rethrow(ex); } } return(plugins); }
private int ReportError(Action action, bool msBuildErrorFormat = false) { try { action.Invoke(); Logger.Info("Done."); } catch (DslSyntaxException dslException) when(msBuildErrorFormat) { DeploymentUtility.PrintCanonicalError(dslException); // Detailed exception info is logged as additional information, not as an error, to avoid duplicate error reporting. Logger.Info(dslException.ToString()); return(1); } catch (Exception e) { Logger.Error(e.ToString()); string typeLoadReport = CsUtility.ReportTypeLoadException(e); if (typeLoadReport != null) { Logger.Error(typeLoadReport); } if (Environment.UserInteractive) { DeploymentUtility.PrintErrorSummary(e); } return(1); } return(0); }
public static int Main(string[] args) { ILogger logger = new ConsoleLogger("DeployPackages"); // Using the simplest logger outside of try-catch block. string oldCurrentDirectory = null; DeployArguments arguments = null; try { logger = DeploymentUtility.InitializationLogProvider.GetLogger("DeployPackages"); // Setting the final log provider inside the try-catch block, so that the simple ConsoleLogger can be used (see above) in case of an initialization error. arguments = new DeployArguments(args); if (arguments.Help) return 1; if (arguments.StartPaused) { if (!Environment.UserInteractive) throw new Rhetos.UserException("DeployPackages parameter 'StartPaused' must not be set, because the application is executed in a non-interactive environment."); // Use for debugging (Attach to Process) Console.WriteLine("Press any key to continue . . ."); Console.ReadKey(true); } Paths.InitializeRhetosServerRootPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..")); oldCurrentDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); InitialCleanup(logger, arguments); DownloadPackages(logger, arguments); GenerateApplication(logger, arguments); InitializeGeneratedApplication(logger, arguments); logger.Trace("Done."); } catch (Exception ex) { logger.Error(ex.ToString()); string typeLoadReport = CsUtility.ReportTypeLoadException(ex); if (typeLoadReport != null) logger.Error(typeLoadReport); if (Environment.UserInteractive) { PrintSummary(ex); if (arguments != null && !arguments.NoPauseOnError) { Console.WriteLine("Press any key to continue . . . (use /NoPause switch to avoid pause on error)"); Console.ReadKey(true); } } return 1; } finally { if (oldCurrentDirectory != null && Directory.Exists(oldCurrentDirectory)) Directory.SetCurrentDirectory(oldCurrentDirectory); } return 0; }