ErrorManager.cs :  » Persistence-Frameworks » FileHelpers-Library » FileHelpers » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » FileHelpers Library 
FileHelpers Library » FileHelpers » ErrorManager.cs
#region "   Copyright 2005-07 to Marcos Meli - http://www.marcosmeli.com.ar" 

// Errors, suggestions, contributions, send a mail to: marcos@filehelpers.com.

#endregion

using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;

namespace FileHelpers{
  /// <summary>This is the class that handles the errors of the engines process.</summary>
  /// <remarks>All the engines and DataStorages contains a ErrorManager.</remarks>
#if NET_2_0
    [DebuggerDisplay("{ErrorsDescription()}. ErrorMode: {ErrorMode.ToString()}")]
#endif
    public sealed class ErrorManager
  {
    /// <summary>Initializes a new instance of the <see cref="ErrorManager"/> class.</summary>
    public ErrorManager()
    {
    }

    /// <summary>Initializes a new instance of the <see cref="ErrorManager"/> class. with the specified <see cref="ErrorMode"/>.</summary>
    /// <param name="mode">Indicates the error behavior of the class.</param>
    public ErrorManager(ErrorMode mode)
    {
      mErrorMode = mode;
    }


#if NET_2_0
        private string ErrorsDescription()
        {
            if (ErrorCount == 1)
                return ErrorCount.ToString() + " Error";
            else if (ErrorCount == 0)
                return "No Errors";
            else
                return ErrorCount.ToString() + " Errors";
        }

        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
        ArrayList mErrorsArray = new ArrayList();

    /// <summary>Is an array of <see cref="ErrorInfo"/> that contains the errors of the last operation in this class.</summary>
#if NET_2_0
        [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
#endif
        public ErrorInfo[] Errors
    {
      get { return (ErrorInfo[]) mErrorsArray.ToArray(typeof (ErrorInfo)); }
    }

#if NET_2_0
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
#endif
        private ErrorMode mErrorMode = ErrorMode.ThrowException;
    

    /// <summary>Indicates the behavior of the <see cref="FileHelperEngine"/> when it found an error.</summary>
    public ErrorMode ErrorMode
    {
      get { return mErrorMode; }
      set { mErrorMode = value; }
    }


    /// <summary>Number of contained errors.</summary>
    public int ErrorCount
    {
      get { return mErrorsArray.Count; }
    }

    /// <summary>Indicates if contains one or more errors.</summary>
    public bool HasErrors
    {
      get { return mErrorsArray.Count > 0; }
    }

    /// <summary>Clears the error collection.</summary>
    public void ClearErrors()
    {
      mErrorsArray.Clear();
    }

    /// <summary>Add the specified ErrorInfo to the contained collection.</summary>
    /// <param name="error"></param>
    internal void AddError(ErrorInfo error)
    {
      mErrorsArray.Add(error);
    }

    /// <summary>Add the specified ErrorInfo to the contained collection.</summary>
    internal void AddErrors(ErrorManager errors)
    {
      mErrorsArray.AddRange(errors.mErrorsArray);
    }

//    public void ProcessError(Exception ex, string line)
//    {
//    }


    /// <summary>Saves the contained errors to the specified file.</summary>
    /// <param name="fileName">The file that contains the errors.</param>
    public void SaveErrors(string fileName)
    {
      string header;
      if (ErrorCount > 0)
        header = "FileHelpers - Errors Saved ";
      else
        header = "FileHelpers - NO Errors Found ";

      header += "at " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
      header += StringHelper.NewLine + "LineNumber | LineString |ErrorDescription";

      SaveErrors(fileName, header);
    }

    /// <summary>Saves the contained errors to the specified file.</summary>
    /// <param name="fileName">The file that contains the errors.</param>
    /// <param name="header">The header line of the errors file.</param>
    public void SaveErrors(string fileName, string header)
    {
      FileHelperEngine engine = new FileHelperEngine(typeof (ErrorInfo));

      if (header.IndexOf(StringHelper.NewLine) == header.LastIndexOf(StringHelper.NewLine))
        header +=  StringHelper.NewLine;

      engine.HeaderText = header;
      engine.WriteFile(fileName, Errors);

    }

    /// <summary>Load errors from a file.</summary>
    /// <param name="fileName">The file that contains the errors.</param>
    public static ErrorInfo[] LoadErrors(string fileName)
    {
      FileHelperEngine engine = new FileHelperEngine(typeof (ErrorInfo));
      return (ErrorInfo[]) engine.ReadFile(fileName);
    }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.