/// <summary> /// set up the file watcher for detecting changes /// </summary> protected void InitSite() { if (_host != null && _host.WebSite != null && !String.IsNullOrEmpty(_host.WebSite.Path)) { prefUtility = new PrefUtility() { ExtensionName = "OrangeBits", SitePath = _host.WebSite.Path, SitePreferences = _host.WebSite.SitePreferences }; // by default, do not do anything to node_modules var path = Path.Combine(_host.WebSite.Path, "node_modules"); var isSet = prefUtility.PathHasValue(path); if (!isSet) { var props = typeof(OptionViewModel).GetProperties().Where(x => Attribute.IsDefined(x, typeof(DefaultValueAttribute))); OptionViewModel vm = new OptionViewModel() { Paths = new string[] { path } }; foreach (var prop in props) { if (prop.PropertyType == typeof(bool?)) { prop.SetValue(vm, false, null); } } prefUtility.SaveOptions(vm); } _siteFileWatcher.RegisterForSiteNotifications(WatcherChangeTypes.Changed | WatcherChangeTypes.Created, new FileSystemEventHandler(SourceFileChanged), null); } else { _siteFileWatcher.DeregisterForSiteNotifications(WatcherChangeTypes.Changed | WatcherChangeTypes.Created, new FileSystemEventHandler(SourceFileChanged), null); } }
/// <summary> /// set up the file watcher for detecting changes /// </summary> protected void InitSite() { if (_host != null && _host.WebSite != null && !String.IsNullOrEmpty(_host.WebSite.Path)) { prefUtility = new PrefUtility() { ExtensionName = "OrangeBits", SitePath = _host.WebSite.Path, SitePreferences = _host.WebSite.SitePreferences }; // by default, do not do anything to node_modules var path = Path.Combine(_host.WebSite.Path, "node_modules"); var isSet = prefUtility.PathHasValue(path); if (!isSet) { var props = typeof(OptionViewModel).GetProperties().Where(x => Attribute.IsDefined(x, typeof(DefaultValueAttribute))); OptionViewModel vm = new OptionViewModel() { Paths = new string[] { path } }; foreach (var prop in props) { if (prop.PropertyType == typeof(bool?)) prop.SetValue(vm, false, null); } prefUtility.SaveOptions(vm); } _siteFileWatcher.RegisterForSiteNotifications(WatcherChangeTypes.Changed | WatcherChangeTypes.Created, new FileSystemEventHandler(SourceFileChanged), null); } else { _siteFileWatcher.DeregisterForSiteNotifications(WatcherChangeTypes.Changed | WatcherChangeTypes.Created, new FileSystemEventHandler(SourceFileChanged), null); } }