public bool RegisterWatcher(ServiceProfile profile, string host, IServiceContext serviceContext)
 {
     lock (locker)
     {
         IRPCWatcher watcher = watchers.Find(w => w.HostInfo.Node.Equals(host, StringComparison.OrdinalIgnoreCase));
         if (watcher == null)
         {
             this.logger.LogDebug($@"setting up an Remote fs watcher for {host}...");
             var currentHostInfo = new RPCHostInfo(host, profile.GetNodeServiceNetLocation(host));
             this.logger.LogDebug($@"targeting {currentHostInfo.WatchDir} on server {host}...");
             using (var subContainer = this.factoryContainer.GetNestedContainer())
             {
                 subContainer.Inject <IRPCHostInfo>(currentHostInfo);
                 watcher = subContainer.GetInstance <IRPCWatcher>();
                 watcher.OrchWatcherErrorEventHandler += HandleWatcherFailure;
                 this.logger.LogDebug($@"{host} watchdog setup ok ");
                 var result = watcher.StartWatching();
                 if (result)
                 {
                     this.logger.LogDebug($@"{host} watchdog working...");
                     watchers.Add(watcher);
                 }
                 else
                 {
                     this.logger.LogError($@"{host} watchdog setup ok but failed to start");
                     return(false);
                 }
             }
         }
         watcher.OrchFileChangeEventHandler += serviceContext.OnProcessFinishRequest;
         return(true);
     }
 }
        private void HandleWatcherFailure(object sender, ErrorEventArgs args)
        {
            IRPCWatcher watcher = sender as IRPCWatcher;

            if (watcher != null)
            {
                logger.LogWarning($@"Restart watcher on {watcher.WatchingDir}");
                PushToRestart(watcher);
            }
        }