DataStorage.cs :  » Persistence-Frameworks » FileHelpers-Library » FileHelpers » DataLink » 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 » DataLink » DataStorage.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.ComponentModel;
using System.Data;

namespace FileHelpers.DataLink{
  /// <summary>Base class for all the Storage classes of the library or the custom Storage classes.</summary>
  public abstract class DataStorage
  {

    /// <summary>For internal Use.</summary>
    /// <param name="handler"></param>
    /// <param name="mode"></param>
    /// <param name="current"></param>
    /// <param name="total"></param>
    [EditorBrowsable(EditorBrowsableState.Never)]
    protected void Notify(ProgressChangeHandler handler, ProgressMode mode, int current, int total)
    {
      ProgressHelper.Notify(handler, mode, current, total);
    }

    /// <summary>Indicates the way to notify the progress.</summary>
    protected ProgressMode mProgressMode = ProgressMode.DontNotify;

    /// <summary>You method handler used to notify progress.</summary>
    protected ProgressChangeHandler mNotifyHandler = null;

    /// <summary>Set the handler to the engine used to notify progress into the operations.</summary>
    /// <param name="handler">The <see cref="ProgressChangeHandler"/></param>
    public void SetProgressHandler(ProgressChangeHandler handler)
    {
      SetProgressHandler(handler, ProgressMode.NotifyRecords);
    }

    /// <summary>Set the handler to the engine used to notify progress into the operations.</summary>
    /// <param name="handler">Your <see cref="ProgressChangeHandler"/> method.</param>
    /// <param name="mode">The <see cref="ProgressMode"/> to use.</param>
    public void SetProgressHandler(ProgressChangeHandler handler, ProgressMode mode)
    {
      mNotifyHandler = handler;

      if (mode == ProgressMode.NotifyBytes)
        throw new NotImplementedException("Not implemented yet. Planed for version 1.5.0");

      mProgressMode = mode;
    }

    private Type mRecordType;
    internal RecordInfo mRecordInfo;
    
    /// <summary>Returns the class that represent the records in the file.</summary>
    public Type RecordType
    {
      get
      {
        return mRecordType;
      }
    }

    /// <summary>Must Return the records from the DataSource (DB, Excel, etc)</summary>
    /// <returns>The extracted records.</returns>
    public abstract object[] ExtractRecords();

    /// <summary>Must Return the records from the DataSource (DB, Excel, etc)</summary>
    /// <returns>The extracted records.</returns>
    public DataTable ExtractRecordsAsDT()
    {
      RecordInfo ri = new RecordInfo(RecordType);
      return ri.RecordsToDataTable(ExtractRecords());
    }

    /// <summary>Must Insert the records in a DataSource (DB, Excel, etc)</summary>
    /// <param name="records">The records to insert.</param>
    public abstract void InsertRecords(object[] records);


    /// <summary>The Object responsable for manage the errors.</summary>
    protected ErrorManager mErrorManager = new ErrorManager();

    /// <summary>The Object responsable for manage the errors.</summary>
    public ErrorManager ErrorManager
    {
      get { return mErrorManager; }
    }

    /// <summary>Add an error to the ErrorCollection.</summary>
    /// <param name="lineNumber">The line when the error occurs.</param>
    /// <param name="ex">The exception throwed, can be null.</param>
    /// <param name="recordLine">The record values</param>
    protected void AddError(int lineNumber, Exception ex, string recordLine)
    {
      ErrorInfo e = new ErrorInfo();
      e.mLineNumber = lineNumber;
//      e.mColumnNumber = colNum;
      e.mExceptionInfo = ex;
      e.mRecordString = recordLine;

      mErrorManager.AddError(e);
    }

    /// <summary>Creates an instance of this class.</summary>
    protected DataStorage(Type recordClass)
    {
      mRecordType = recordClass;
      mRecordInfo = new RecordInfo(recordClass);
      
    }
    

    #region "  Values <-> Record Convertions "

    /// <summary>Returns a record created from an Array of values</summary>
    /// <param name="values">The values used to created the record.</param>
    /// <returns>The just created record.</returns>
    protected object ValuesToRecord(object[] values)
    {
      return mRecordInfo.ValuesToRecord(values);
    }

    /// <summary>Returns an array of value based on a record.</summary>
    /// <param name="record">The source record.</param>
    /// <returns>An array with the values of each field</returns>
    protected object[] RecordToValues(object record)
    {
      return mRecordInfo.RecordToValues(record);
    }

    #endregion

    /// <summary>The number of fields in the record class.</summary>
    protected int RecordFieldCount
    {
      get
      {
        return mRecordInfo.mFieldCount;
      }
    }



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