Exemplo n.º 1
0
        /// <summary>
        /// Reads the contents of a text file.
        /// </summary>
        /// <param name="filename">The name of the file to read.</param>
        /// <returns>Reads the contents of a text file as a string.</returns>
        private string ReadFile(string filename)
        {
            try
            {
                using (var sr = new StreamReader(filename, CharacterEncoding, true))
                {
                    return(sr.ReadToEnd());
                }
            }
            catch (FileNotFoundException)
            {
                if (!BadFiles.Contains(filename))
                {
                    BadFiles.Add(filename);
                }
                if (FileVariableErrors == VariableError.ThrowException)
                {
                    throw;
                }
            }
            catch (IOException)
            {
                if (!BadFiles.Contains(filename))
                {
                    BadFiles.Add(filename);
                }
                if (FileVariableErrors == VariableError.ThrowException)
                {
                    throw;
                }
            }
            catch (UnauthorizedAccessException)
            {
                if (!BadFiles.Contains(filename))
                {
                    BadFiles.Add(filename);
                }
                if (FileVariableErrors == VariableError.ThrowException)
                {
                    throw;
                }
            }

            // returning null indicates an IO error
            return(null);
        }
Exemplo n.º 2
0
        private void finalizeFile(object obj)
        {
            if (!(obj is FileHolder holder))
            {
                return;
            }

            Files.Remove(holder);

            if (holder.IsDirty)
            {
                BadFiles.Add(holder);
            }
            else
            {
                GoodFiles.Add(holder);
            }
        }