/// <summary> /// If the user attempts to <see cref="IDisposable.Dispose"/> an /// <see cref="IntelChannel"/> this function will be part of the /// <see cref="IComponent"/> tear-down process. /// </summary> /// <param name="channel"> /// The instance of <see cref="IntelChannel"/> being removed. /// </param> protected virtual void OnRemoveChannel(IntelChannel channel) { // Called when the channel is being disposed if (this.status != IntelStatus.Disposing) { lock (this.syncRoot) { var count = this.channels.RemoveAll(x => x == channel); if (count > 0) { this.OnPropertyChanged(new PropertyChangedEventArgs("Channels")); } } } }
/// <summary> /// Initializes a new instance of the <see cref="ChannelSite"/> class. /// </summary> /// <param name="container">The container.</param> /// <param name="component">The component.</param> /// <param name="name">The name.</param> internal ChannelSite(IntelChannelContainer container, IntelChannel component, string name) { Contract.Requires(container != null); Contract.Requires(component != null); Contract.Requires(!String.IsNullOrEmpty(name)); this.container = container; this.component = component; this.name = name; }
/// <summary> /// Creates an instance of <see cref="IntelChannel" /> to manage /// the monitoring of an intel channel log file. /// </summary> /// <param name="channelName">The base file name of the intel channel to monitor.</param> /// <returns> /// An instance of <see cref="IntelChannel" /> to use when /// monitoring the log file. /// </returns> /// <remarks> /// Classes derived from <see cref="IntelChannelContainer" /> are /// free to override <see cref="CreateChannel" /> and completely /// replace the logic without calling the base implementation. /// In this case, the derivative class must register handlers to /// call <see cref="OnUpdateStatus" /> and <see cref="OnIntelReported" /> /// under the appropriate circumstances. The /// <see cref="IComponent.Site" /> must be initialzied to a proper /// linking instance of <see cref="ISite" />. /// </remarks> protected virtual IntelChannel CreateChannel(string channelName) { Contract.Requires<ArgumentException>(!String.IsNullOrEmpty(channelName)); Contract.Ensures(Contract.Result<IntelChannel>() != null); Contract.Ensures(Contract.Result<IntelChannel>().Site != null); Contract.Ensures(Contract.Result<IntelChannel>().Site.Container == this); Contract.Ensures(Contract.Result<IntelChannel>().Name == channelName); var channel = new IntelChannel(); channel.Site = new ChannelSite(this, channel, channelName); if (this.logDirectory != null) { channel.Path = this.logDirectory; } channel.IntelReported += channel_IntelReported; channel.PropertyChanged += channel_PropertyChanged; return channel; }