public ControlWatcher(AssemblyConfiguration configuration) { _configuration = configuration; _waitingControl = new MessageControl(); Content = _waitingControl; _host = new AppDomainedControlHost(_configuration); _host.StatusChanged += HandleHostChanged; _host.Reload(); }
private void WatchClicked(object sender, RoutedEventArgs e) { var pathToAssembly = PathToAssembly.Text; if (!File.Exists(pathToAssembly)) { return; } Reset(); try { // TODO update this so that it doesn't keep ALL configurations AssemblyConfiguration configuration; if (!_configurations.TryGetValue(pathToAssembly, out configuration)) { configuration = new AssemblyConfiguration() { PathToAssembly = pathToAssembly }; _configurations[configuration.PathToAssembly] = configuration; } Environment.CurrentDirectory = Path.GetDirectoryName(pathToAssembly); _watcher = new ControlWatcher(configuration); } catch (Exception exception) { MessageBox.Show($"Error Loading Assembly:\r\n {pathToAssembly}\r\n > {exception.Message}\r\n\r\nLoading has been canceled", "Error Loading Assembly", MessageBoxButton.OK, MessageBoxImage.Error); return; } LoadAssemblyInput.Visibility = Visibility.Collapsed; HostedControl.Visibility = Visibility.Visible; Host.Content = _watcher; SaveSettings(); }
public AppDomainedControlHost(AssemblyConfiguration configuration) { _configuration = configuration; _rootDictionary = Path.GetDirectoryName(_configuration.PathToAssembly); _assemblyToObserve = new AssemblyNameHelper().GetAssemblyNameOf(_configuration.PathToAssembly); _watcher = new FileSystemWatcher { Path = _rootDictionary, IncludeSubdirectories = false, Filter = Path.GetFileName(_configuration.PathToAssembly) }; var dispatcher = Dispatcher.CurrentDispatcher; FileSystemEventHandler callback = delegate { dispatcher.InvokeAsync(() => _timer.Start()); }; _watcher.Created += callback; _watcher.Changed += callback; _watcher.Deleted += callback; _watcher.EnableRaisingEvents = true; _timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1), IsEnabled = false }; _timer.Tick += delegate { _timer.Stop(); Reload(); }; }