/// <summary> /// Initialize the Source Monitor as a Service Extension. /// </summary> /// <param name="config">configuration </param> /// <param name="serviceHost">service host which init the extension</param> public void Initialize(IConfiguration config, IServiceHost serviceHost) { if (config == null || serviceHost == null) { throw new InitializeParameterEmtyException("parameter can't be null for initialize"); } _configSetting = config; _serviceHost = serviceHost; WatchSourceCollection watchSourcese = this.ConfigurationSetting.GetConfiguationData <WatchSourceCollection>(""); List <ISourceWatcher> watchers = _serviceHost.GetFunctionExtensions <ISourceWatcher>(ExtensionCategory.WatchingExtension); foreach (WatchSource source in watchSourcese) { watchers.ForEach(delegate(ISourceWatcher watcher) { if (watcher.IsAcceptedSource(source)) { watcher.Watching(source); watcher.RegisterEvent(this.MonitorSourceChangedEventHandler); } }); } _serviceHost.RunInBackground(this); }