/// <summary> /// Load an Assembly /// </summary> /// <param name="apiPath"></param> /// <param name="server"></param> private static void LoadApi(IWebServer server, string apiPath) { try { var fullPath = Path.GetFullPath(apiPath); if (Path.GetExtension(apiPath).Equals(".dll")) { var assembly = Assembly.LoadFile(fullPath); server.LoadApiControllers(assembly).LoadWebSockets(assembly); } else { var files = Directory.GetFiles(fullPath, "*.dll"); foreach (var file in files) { var assembly = Assembly.LoadFile(file); server.LoadApiControllers(assembly).LoadWebSockets(assembly); } } } catch (FileNotFoundException fileEx) { $"Assembly FileNotFoundException {fileEx.Message}".Debug(nameof(Program)); } catch (Exception ex) { $"Assembly Exception {ex.Message}".Debug(nameof(Program)); ex.Log(nameof(Program)); } }
/// <summary> /// Add WebApiModule to WebServer. /// </summary> /// <param name="webserver">The webserver instance.</param> /// <param name="assembly">The assembly to load WebApi Controllers from. Leave null to avoid autoloading.</param> /// <param name="responseJsonException">if set to <c>true</c> [response json exception].</param> /// <returns> /// An instance of webserver. /// </returns> /// <exception cref="ArgumentNullException">webserver.</exception> public static IWebServer WithWebApi(this IWebServer webserver, Assembly assembly = null, bool responseJsonException = false) { if (webserver == null) { throw new ArgumentNullException(nameof(webserver)); } webserver.RegisterModule(new WebApiModule()); return(assembly != null?webserver.LoadApiControllers(assembly, responseJsonException) : webserver); }