public static bool UnregisterViewController(IHotReloadableController controller) { string contentFile = controller.ContentFilePath; if (string.IsNullOrEmpty(contentFile)) { #if HRVC_DEBUG Logger.log.Critical($"Skipping registration for {controller.GetInstanceID()}:{controller.Name}, it has not content file defined."); #endif return(false); } bool successful = false; string contentDirectory = Path.GetDirectoryName(contentFile); if (WatcherDictionary.TryGetValue(contentDirectory, out WatcherGroup watcherGroup)) { successful = watcherGroup.UnbindController(controller); } #if HRVC_DEBUG else { Logger.log.Warn($"Unable to get WatcherGroup for {contentDirectory}"); } if (successful) { Logger.log.Info($"Successfully unregistered {controller.GetInstanceID()}:{controller.Name}"); } else { Logger.log.Warn($"Failed to Unregister {controller.GetInstanceID()}:{controller.Name}"); } #endif return(successful); }
public static bool RegisterViewController(IHotReloadableController controller) { string contentFile = controller.ContentFilePath; if (string.IsNullOrEmpty(contentFile)) { return(false); } string contentDirectory = Path.GetDirectoryName(contentFile); if (!Directory.Exists(contentDirectory)) { return(false); } WatcherGroup watcherGroup; if (!WatcherDictionary.TryGetValue(contentDirectory, out watcherGroup)) { watcherGroup = new WatcherGroup(contentDirectory); WatcherDictionary.Add(contentDirectory, watcherGroup); } watcherGroup.BindController(controller); return(true); }
internal bool UnbindController(IHotReloadableController controller) { if (controller == null) { #if HRVC_DEBUG Logger.log.Critical($"Unable to unbind controller, it is null."); #endif return(false); } return(UnbindController(controller.GetInstanceID())); }
internal bool BindController(IHotReloadableController controller) { if (BoundControllers.ContainsKey(controller.GetInstanceID())) { #if HRVC_DEBUG Logger.log.Critical($"Failed to register controller, already exists. {controller.GetInstanceID()}:{controller.Name}"); #endif return(false); } BoundControllers.Add(controller.GetInstanceID(), new WeakReference <IHotReloadableController>(controller)); CreateWatcher(); Watcher.EnableRaisingEvents = true; #if HRVC_DEBUG Logger.log.Info($"Registering controller {controller.GetInstanceID()}:{controller.Name}"); #endif return(true); }