DataSetController.cs :  » Persistence-Frameworks » NEO » SQLToNeo » Controller » 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 » NEO 
NEO » SQLToNeo » Controller » DataSetController.cs
/* $Id: DataSetController.cs,v 1.8 2004/10/27 14:09:20 larsbm Exp $
 * Copyright (c) 2004 Engine EAR GmbH & Co. KG
 * Developed by: Lars Behrmann, lb@engine.de
 */

using System;
using System.Data;
using System.IO;
using System.Windows.Forms;
using SQLToNeo.Model;

namespace SQLToNeo.Controller{
  /// <summary>
  /// Zusammenfassung fr DataSetController.
  /// </summary>
  public class DataSetController
  {
    public string _path;

    private bool _generateJavaName;

    #region Property get set CurrentDataSet
    private DataSet _currentDataSet;
    public DataSet CurrentDataSet
    {
      get { return this._currentDataSet; }
      set { this._currentDataSet = value; }
    }
    #endregion

    #region Property get set EmptyDataSet
    private DataSet _emptyDataSet;
    public DataSet EmptyDataSet
    {
      get { return this._emptyDataSet; }
      set { this._emptyDataSet = value; }
    }
    #endregion
    
    #region Property get set GenerateJavaName
    public bool GenerateJavaName
    {
      get
      {
        return _generateJavaName;
      }
      set
      {
        _generateJavaName = value;
      }
    }
    #endregion

    #region Property get set Databasename
    private string _databasename;
    public string Databasename
    {
      get { return this._databasename; }
      set { this._databasename = value; }
    }
    #endregion

    #region Property get set IsNew
    private bool _isnew;
    public bool IsNew
    {
      get { return this._isnew; }
      set { this._isnew = value; }
    }
    #endregion

    public DataSetController()
    {
      CurrentDataSet = new DataSet("CurrentDataSet");
      EmptyDataSet = new DataSet("OnlineDataSet");
      _path = Application.StartupPath +@"\"+ System.Configuration.ConfigurationManager.AppSettings["projectfolder"] +@"\";
    }

    public DataSetController(bool generateJavaName)
    {
      this._generateJavaName = generateJavaName;
      CurrentDataSet = new DataSet("CurrentDataSet");
      EmptyDataSet = new DataSet("OnlineDataSet");
      _path = Application.StartupPath +@"\"+ System.Configuration.ConfigurationManager.AppSettings["projectfolder"] +@"\";
    }

    public bool LoadData(string databasename)
    {
      CreateEmptyDataSet();
      Databasename = _path + databasename+".xml";
      if(File.Exists(Databasename))
      {
        if(LoadExisting())
          return true;
        else
          return false;
      }
      else
        CreateNewSchema();
      
      return true;
    }

    public void SpecialMerge()
    {
      MergeSpecial ms = new MergeSpecial();
      ms.GenerateJavaName = _generateJavaName;
      DataSet dsTemp = ms.Merge(CurrentDataSet, EmptyDataSet);
      CurrentDataSet = dsTemp;
    }

    private bool LoadExisting()
    {
      try
      {
        CurrentDataSet.ReadXml(Databasename,XmlReadMode.ReadSchema);
        CreateNeoSpecificRow();
        return true;
      }
      catch(Exception ex)
      {
        Console.WriteLine("Error while reading existing DataSet from xml file");
        Console.WriteLine("Error Message:\n {0}", ex.Message);
        return false;
      }
    }

    public void SaveCurrentDataSet()
    {
      CurrentDataSet.WriteXml(Databasename,XmlWriteMode.WriteSchema);
      //CurrentDataSet.WriteXml(@"D:\temp\nunit.xml",XmlWriteMode.WriteSchema);
    }

    private void CreateNewSchema()
    {
      CurrentDataSet.Tables.Add(TableBuilder.GetTableXML());
      CurrentDataSet.Tables.Add(TableBuilder.GetTableForeignKeys("iforeignkey"));
      CurrentDataSet.Tables.Add(TableBuilder.GetTableForeignKeys("foreignkey"));
      CurrentDataSet.Tables.Add(TableBuilder.GetTableTable());
      CurrentDataSet.Tables.Add(TableBuilder.GetTableColumns());

      DataRelation dl = new DataRelation("cols",CurrentDataSet.Tables["table"].Columns["id"],
        CurrentDataSet.Tables["column"].Columns["tableid"], true);      
      CurrentDataSet.Relations.Add(dl);
      dl = new DataRelation("foreignkeys",CurrentDataSet.Tables["table"].Columns["id"],
        CurrentDataSet.Tables["foreignkey"].Columns["tableid"], true);
      CurrentDataSet.Relations.Add(dl);
      dl = new DataRelation("iforeignkeys",CurrentDataSet.Tables["table"].Columns["id"],
        CurrentDataSet.Tables["iforeignkey"].Columns["tableid"], true);
      CurrentDataSet.Relations.Add(dl);

      foreach(DataRelation drl in CurrentDataSet.Relations)
        drl.Nested = true;

      CreateNeoSpecificRow();
    }

    private void CreateEmptyDataSet()
    {
      EmptyDataSet.Tables.Add(TableBuilder.GetTableXML());
      EmptyDataSet.Tables.Add(TableBuilder.GetTableForeignKeys("iforeignkey"));
      EmptyDataSet.Tables.Add(TableBuilder.GetTableForeignKeys("foreignkey"));
      EmptyDataSet.Tables.Add(TableBuilder.GetTableTable());
      EmptyDataSet.Tables.Add(TableBuilder.GetTableColumns());

      DataRelation dl = new DataRelation("cols",EmptyDataSet.Tables["table"].Columns["id"],
        EmptyDataSet.Tables["column"].Columns["tableid"], true);
      EmptyDataSet.Relations.Add(dl);
      dl = new DataRelation("foreignkeys",EmptyDataSet.Tables["table"].Columns["id"],
        EmptyDataSet.Tables["foreignkey"].Columns["tableid"], true);
      EmptyDataSet.Relations.Add(dl);
      dl = new DataRelation("iforeignkeys",EmptyDataSet.Tables["table"].Columns["id"],
        EmptyDataSet.Tables["iforeignkey"].Columns["tableid"], true);
      EmptyDataSet.Relations.Add(dl);

      foreach(DataRelation drl in EmptyDataSet.Relations)
        drl.Nested = true;
    }

    private void CreateNeoSpecificRow()
    {
      if(CurrentDataSet.Tables["xml"].Rows.Count==0)
      {
        DataRow dr = CurrentDataSet.Tables["xml"].NewRow();
        CurrentDataSet.Tables["xml"].Rows.Add(dr);
      }
    }
  }
}

/*
 * $Log: DataSetController.cs,v $
 * Revision 1.8  2004/10/27 14:09:20  larsbm
 * - Fixed bugs in tablebuilder, TablestyleCreator
 * - Working on the forms
 * - Finishing DBTypes
 * - Add IWriter & Writer, NeoXMLModelWriter as abstraction for writing the xml model
 *
 * Revision 1.7  2004/10/26 13:23:43  larsbm
 * - Fixed bugs in tablebuilder
 * - Working on the forms
 * - Finishing MergeSpecial
 * - Make app run with mergespecial
 * - start converter for sqldatatypes
 *
 * Revision 1.6  2004/10/25 13:47:15  larsbm
 * - Add new classes MergeSpecial and MergSpecialTest
 * - Merging the current local model with the current db schema on the server
 *
 * Revision 1.5  2004/10/21 15:39:26  larsbm
 * - Add Test for method SpecialMerge(), don't run!
 *
 * Revision 1.4  2004/10/18 14:13:52  larsbm
 * - Add columns, foreignkeys
 * - Bring Anaylzer, NewMainformController and DataSetController together
 * - Several bugfixes
 *
 * Revision 1.3  2004/10/13 08:53:54  larsbm
 * - Start to implement new anaylzer via bridge pattern
 * - Adding a test for the new analyzer
 *
 * 
 */
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.