/// <summary> /// <para>Returns the <see cref="DateTime"/> of the last change of the information watched</para> /// <para>The information is retrieved using the watched file modification timestamp</para> /// </summary> /// <returns>The <see cref="DateTime"/> of the last modificaiton, or <code>DateTime.MinValue</code> if the information can't be retrieved</returns> protected override DateTime GetCurrentLastWriteTime() { lock (_padLock) { DateTime lastWriteTime; DateTime createdTime; ChoConfigurationChangeAction configurationChangeAction = ChoConfigurationChangeAction.Changed; if (File.Exists(_configFilePath)) { lastWriteTime = File.GetLastWriteTime(_configFilePath); createdTime = File.GetCreationTime(_configFilePath); } else { lastWriteTime = DateTime.MinValue; createdTime = DateTime.MinValue; } try { if (lastWriteTime == DateTime.MinValue) { if (_lastWriteTime == DateTime.MinValue) { } else { configurationChangeAction = ChoConfigurationChangeAction.Deleted; } } else { if (_lastWriteTime == DateTime.MinValue) { configurationChangeAction = ChoConfigurationChangeAction.Created; } else { if (_lastWriteTime != lastWriteTime) { configurationChangeAction = ChoConfigurationChangeAction.Changed; } } } } finally { if (_configurationChangeAction != configurationChangeAction) { _configurationChangeAction = configurationChangeAction; _configurationFileChangedEventArgs = new ChoConfigurationFileChangedEventArgs(this.SectionName, ChoPath.GetFullPath(_configFilePath), _configurationChangeAction, _lastWriteTime); } _lastWriteTime = lastWriteTime; _createdTime = createdTime; } return(_lastWriteTime); } }
/// <summary> /// <para>Initialize a new <see cref="ChoConfigurationChangeFileWatcher"/> class with the path to the configuration file and the name of the section</para> /// </summary> /// <param name="_configFilePath"> /// <para>The full path to the configuration file.</para> /// </param> /// <param name="_configurationSectionName"> /// <para>The name of the configuration section to watch.</para> /// </param> public ChoConfigurationChangeFileWatcher(string configurationSectionName, string configFilePath) : base(configurationSectionName) { if (string.IsNullOrEmpty(configFilePath)) { throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "configFilePath"); } this._configFilePath = configFilePath; _configurationFileChangedEventArgs = new ChoConfigurationFileChangedEventArgs(configurationSectionName, ChoPath.GetFullPath(_configFilePath), _configurationChangeAction, DateTime.MinValue); }