Пример #1
0
        /// <summary>
        /// Processes the supplied text in a way that all text variables
        /// are replaced by the values of the current data item.
        /// </summary>
        /// <param name="text">The text with text variables to be processed.</param>
        /// <param name="clearBadVarsAndFiles">If true, BadFiles and BadVariable lists will be cleared before the process, else not.</param>
        /// <returns>Returns the text with all text variables replaced by the values of the current data item.</returns>
        public StringBuilder Process(StringBuilder text, bool clearBadVarsAndFiles)
        {
            if (clearBadVarsAndFiles)
            {
                BadFiles.Clear();
                BadVariables.Clear();
            }

            return(ReplaceTextVariablesWithValues(text, SearchTextVariables(text)));
        }
Пример #2
0
 private void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             // Dispose managed resources.
             BadFiles.Clear();
             BadVariables.Clear();
         }
     }
     _disposed = true;
 }
Пример #3
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);
        }
Пример #4
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);
            }
        }