public void Start() { _shelfMaker = new ShelfMaker(); _shelfMaker.MakeShelf("TopShelf.DirectoryWatcher", typeof(DirectoryMonitorBootstrapper)); string serviceDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Services"); Directory.GetDirectories(serviceDir) .ToList() .ConvertAll(Path.GetFileName) .ForEach(dir => _shelfMaker.MakeShelf(dir)); }
public void Can_start_up_new_service_in_ShelfMaker_from_filesystem_event() { using (var dwStarted = new ManualResetEvent(false)) using (var bobStaring = new ManualResetEvent(false)) using (var sm = new ShelfMaker()) { sm.OnShelfStateChanged += (sender, args) => { if (args.ShelfName == "bob" && args.CurrentShelfState == ShelfState.Starting) bobStaring.Set(); if (args.ShelfName == "TopShelf.DirectoryWatcher" && args.CurrentShelfState == ShelfState.Started) dwStarted.Set(); }; // this needs to happen before we attach the file watcher string srvDir = Path.Combine(".", "Services"); Directory.CreateDirectory(srvDir); //Console.WriteLine("Starting TopShelf.DirectoryWatcher"); sm.MakeShelf("TopShelf.DirectoryWatcher", typeof(DirectoryMonitorBootstrapper)); dwStarted.WaitOne(20.Seconds()); sm.GetState("TopShelf.DirectoryWatcher").ShouldEqual(ShelfState.Started); //Console.WriteLine("TopShelf.DirectoryWatcher started"); // This isn't in setup, because we want the events to fire off to generate the shelf //Console.WriteLine("Copying files..."); string bobDir = Path.Combine(srvDir, "bob"); Directory.CreateDirectory(bobDir); CopyFileToDir("TopShelf.dll", bobDir); CopyFileToDir("TopShelf.Specs.dll", bobDir); CopyFileToDir("Magnum.dll", bobDir); CopyFileToDir("log4net.dll", bobDir); File.Copy("service.config", Path.Combine(bobDir, "bob.config")); //Console.WriteLine("Files copied, waiting for bob to start."); // let the service automagically start; using 'Starting' to speed up test bobStaring.WaitOne(20.Seconds()); (sm.GetState("bob") == ShelfState.Starting || sm.GetState("bob") == ShelfState.Started).ShouldBeTrue(); } }
public void Start() { _shelfMaker = new ShelfMaker(); _shelfMaker.MakeShelf("TopShelf.DirectoryWatcher", typeof(DirectoryMonitorBootstrapper)); }