コード例 #1
0
        /// <summary>
        /// Updates the user-interface with the values from the new hosts-file content.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">An <see cref="FileSystemEventArgs"/> that contains the event data.</param>    
        private void HostsFileContentChanged(object sender, FileSystemEventArgs e)
        {
            if (string.IsNullOrEmpty(e.FullPath) || File.Exists(e.FullPath) == false)
            {
                return;
            }

            HostFile newHostsFile = HostfileManager.Current.GetHostsFile(e.FullPath);
            if (newHostsFile != null)
            {
                /* attach new data-model */
                this.HostFileInstance = newHostsFile;
            }
        }
コード例 #2
0
        /// <summary>
        /// Loads the specified <see cref="HostsFileProfile"/>.
        /// </summary>
        /// <param name="sourceProfile">A <see cref="HostsFileProfile"/> object.</param>
        /// <returns>True if the specified <paramref name="sourceProfile"/> was loaded successfully; otherwise false.</returns>
        public bool LoadProfile(HostsFileProfile sourceProfile)
        {
            if (this.HostFileInstance != null)
            {
                HostFile hf = HostfileManager.Current.GetProfile(sourceProfile.ProfilePath);
                if (hf != null)
                {
                    this.HostFileInstance = hf;
                    return true;
                }
            }

            return false;
        }
コード例 #3
0
        /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
        /// <param name="disposing">A flag indicating whether this object is currently disposing.</param>
        protected override void Dispose(bool disposing)
        {
            if (this.disposed == false)
            {
                if (disposing)
                {
                    this.hostFileInstance = null;
                    HostfileManager.Current.Dispose();
                }

                // Free your own state (unmanaged objects).
                // Set large fields to null.
                this.disposed = true;
            }

            base.Dispose(disposing);
        }
コード例 #4
0
        /// <summary>Loads the hosts file with specified <paramref name="filePath"/>.</summary>
        /// <param name="filePath">The file path to a hosts file or a hosts file profile.</param>
        /// <returns>True if the specified <paramref name="filePath"/> was loaded successfully; otherwise false.</returns>
        public bool LoadFile(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            if (this.HostFileInstance != null)
            {
                HostFile hf = HostfileManager.Current.GetHostsFile(filePath);
                if (hf != null)
                {
                    this.HostFileInstance = hf;
                    return true;
                }
            }

            return false;
        }