Exemplo n.º 1
0
            private void CreateFileWatcher()
            {
                m_fileWatcher = new SafeFileWatcher(Path);
                m_fileWatcher.InternalBufferSize    = m_fileProcessor.InternalBufferSize;
                m_fileWatcher.IncludeSubdirectories = true;

                m_fileWatcher.Created += m_fileProcessor.Watcher_Created;
                m_fileWatcher.Changed += m_fileProcessor.Watcher_Changed;
                m_fileWatcher.Renamed += m_fileProcessor.Watcher_Renamed;
                m_fileWatcher.Deleted += m_fileProcessor.Watcher_Deleted;
                m_fileWatcher.Error   += m_fileProcessor.Watcher_Error;

                m_fileWatcher.EnableRaisingEvents = true;
            }
Exemplo n.º 2
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="InterprocessCache"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        if ((object)m_fileWatcher != null)
                        {
                            m_fileWatcher.Changed -= m_fileWatcher_Changed;
                            m_fileWatcher.Dispose();
                            m_fileWatcher = null;
                        }

                        if ((object)m_retryTimer != null)
                        {
                            m_retryTimer.Elapsed -= m_retryTimer_Elapsed;
                            m_retryTimer.Dispose();
                            m_retryTimer = null;
                        }

                        if ((object)m_loadIsReady != null)
                        {
                            m_loadIsReady.Dispose();
                            m_loadIsReady = null;
                        }

                        if ((object)m_saveIsReady != null)
                        {
                            m_saveIsReady.Dispose();
                            m_saveIsReady = null;
                        }

                        if ((object)m_fileLock != null)
                        {
                            m_fileLock.Dispose();
                            m_fileLock = null;
                        }

                        m_fileName = null;
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes the file.
        /// </summary>
        /// <remarks>
        /// <see cref="Initialize()"/> is to be called by user-code directly only if the file is not consumed through the designer surface of the IDE.
        /// </remarks>
        public void Initialize()
        {
            if (!m_initialized)
            {
                // Load settings from the config file.
                LoadSettings();

                // Watch for changes to the file content.
                if (m_reloadOnModify)
                {
                    m_fileWatcher          = new SafeFileWatcher();
                    m_fileWatcher.Path     = FilePath.GetDirectoryName(FilePath.GetAbsolutePath(m_fileName));
                    m_fileWatcher.Filter   = FilePath.GetFileName(m_fileName);
                    m_fileWatcher.Changed += m_fileWatcher_Changed;
                }

                m_recordBuffer = new byte[GetRecordSize()];     // Create buffer for reading records.
                m_initialized  = true;                          // Initialize only once.
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="OutageLog"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        LogFileWatcher = null;
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.

                    if ((object)Disposed != null)
                    {
                        Disposed(this, EventArgs.Empty);
                    }
                }
            }
        }