/// <summary>
 /// Adds the elements of a <see cref="FilterSetCollection"/> to the end of the collection.
 /// </summary>
 /// <param name="items">The <see cref="FilterSetCollection"/> to be added to the end of the collection.</param>
 public void AddRange(FilterSetCollection items)
 {
     for (int i = 0; (i < items.Count); i = (i + 1))
     {
         Add(items[i]);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Copies a file while replacing the tokens identified by the given
        /// <see cref="FilterSetCollection" />.
        /// </summary>
        /// <param name="sourceFileName">The file to copy.</param>
        /// <param name="destinationFileName">The name of the destination file.</param>
        /// <param name="encoding">The <see cref="Encoding" /> used when filter-copying the file.</param>
        /// <param name="filtersets">The collection of filtersets that should be applied to the file.</param>
        public static void CopyFile(string sourceFileName, string destinationFileName, Encoding encoding, FilterSetCollection filtersets) {
            if (filtersets.HasFilters()) {
                StreamReader reader = null;
                StreamWriter writer = null;

                try {
                    if (encoding == null) {
                        reader = new StreamReader(new BufferedStream(File.OpenRead(sourceFileName)));
                        writer = new StreamWriter(new BufferedStream(File.Create(destinationFileName)));
                    } else {
                        reader = new StreamReader(new BufferedStream(File.OpenRead(sourceFileName)), encoding);
                        writer = new StreamWriter(new BufferedStream(File.Create(destinationFileName)), encoding);
                    }

                    string line = reader.ReadLine();
                    while (line != null) {
                        if (line.Length == 0) {
                            writer.WriteLine();
                        } else {
                            writer.WriteLine(filtersets.ReplaceTokens(line));
                        }
                        line = reader.ReadLine();
                    }
                } finally {
                    if (writer != null) {
                        writer.Close();
                    }
                    if (reader != null) {
                        reader.Close();
                    }
                }
            } else {
                // copy the source file to the destination file 
                File.Copy(sourceFileName, destinationFileName, true);
            }
        }
 /// <summary>
 /// Adds the elements of a <see cref="FilterSetCollection"/> to the end of the collection.
 /// </summary>
 /// <param name="items">The <see cref="FilterSetCollection"/> to be added to the end of the collection.</param> 
 public void AddRange(FilterSetCollection items) {
     for (int i = 0; (i < items.Count); i = (i + 1)) {
         Add(items[i]);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FilterSetCollection"/> class
 /// with the specified <see cref="FilterSetCollection"/> instance.
 /// </summary>
 public FilterSetCollection(FilterSetCollection value) {
     AddRange(value);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FilterSetEnumerator"/> class
 /// with the specified <see cref="FilterSetCollection"/>.
 /// </summary>
 /// <param name="arguments">The collection that should be enumerated.</param>
 internal FilterSetEnumerator(FilterSetCollection arguments) {
     IEnumerable temp = (IEnumerable) (arguments);
     _baseEnumerator = temp.GetEnumerator();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FilterSetCollection"/> class
 /// with the specified <see cref="FilterSetCollection"/> instance.
 /// </summary>
 public FilterSetCollection(FilterSetCollection value)
 {
     AddRange(value);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="FilterSetEnumerator"/> class
        /// with the specified <see cref="FilterSetCollection"/>.
        /// </summary>
        /// <param name="arguments">The collection that should be enumerated.</param>
        internal FilterSetEnumerator(FilterSetCollection arguments)
        {
            IEnumerable temp = (IEnumerable)(arguments);

            _baseEnumerator = temp.GetEnumerator();
        }
Beispiel #8
0
        /// <summary>
        /// Moves a file while replacing the tokens identified by the given
        /// <see cref="FilterSetCollection" />.
        /// </summary>
        /// <param name="sourceFileName">The file to move.</param>
        /// <param name="destinationFileName">The name of the destination file.</param>
        /// <param name="encoding">The <see cref="Encoding" /> used when filter-copying the file.</param>
        /// <param name="filtersets">The collection of filtersets that should be applied to the file.</param>
        public static void MoveFile(string sourceFileName, string destinationFileName, Encoding encoding, FilterSetCollection filtersets) {
            if (filtersets.HasFilters()) {
                // copy the source file to the destination file and replace tokens
                FileUtils.CopyFile(sourceFileName, destinationFileName, encoding, filtersets); 

                // remove the source file
                File.Delete(sourceFileName);
            } else {
                // move the source file to destination file
                File.Move(sourceFileName, destinationFileName);
            }
        }