Bloom.Api.EnhancedImageServer.CheckForSampleTextChanges C# (CSharp) Method

CheckForSampleTextChanges() private method

private CheckForSampleTextChanges ( IRequestInfo info ) : bool
info IRequestInfo
return bool
        private bool CheckForSampleTextChanges(IRequestInfo info)
        {
            lock (SyncObj)
            {
                if (_sampleTextsWatcher == null)
                {
                    var path = Path.Combine(Path.GetDirectoryName(CurrentCollectionSettings.SettingsFilePath), "Sample Texts");
                    if (!Directory.Exists(path))
                        Directory.CreateDirectory(path);

                    _sampleTextsWatcher = new FileSystemWatcher { Path = path };
                    _sampleTextsWatcher.Created += SampleTextsOnChange;
                    _sampleTextsWatcher.Changed += SampleTextsOnChange;
                    _sampleTextsWatcher.Renamed += SampleTextsOnChange;
                    _sampleTextsWatcher.Deleted += SampleTextsOnChange;
                    _sampleTextsWatcher.EnableRaisingEvents = true;
                }
            }

            lock (_sampleTextsWatcher)
            {
                var hasChanged = _sampleTextsChanged;

                // Reset the changed flag.
                // NOTE: we are only resetting the flag if it was "true" when we checked in case the FileSystemWatcher detects a change
                // after we check the flag but we reset it to false before we check again.
                if (hasChanged)
                    _sampleTextsChanged = false;

                info.ContentType = "text/plain";
                info.WriteCompleteOutput(hasChanged ? "yes" : "no");

                return true;
            }
        }