Click here to Skip to main content
15,896,111 members
Articles / Web Development / ASP.NET

An Introduction to a Post-relational Database for .NET: Matisse - Part 6

Rate me:
Please Sign up or sign in to vote.
4.45/5 (21 votes)
2 May 20043 min read 65.9K   966   37  
ASP.NET programming with a post-relational database.
using System;
using System.IO;
using System.Windows.Forms;
using com.matisse;
using Johnssk.example.media;

namespace MediaDemo
{
	/// <summary>
	/// Summary description for DataLoader.
	/// </summary>
	public class DataLoader
	{
        private string folderPath;
        private string hostname;
        private string dbname;

		public DataLoader(string h, string db, string path)
		{
			folderPath = String.Copy(path);
            hostname = String.Copy(h);
            dbname = String.Copy(db);
		}

        public bool Load() {
            DirectoryInfo dinfo = new DirectoryInfo(folderPath);
            if ( ! dinfo.Exists ) {
                MessageBox.Show(dinfo.ToString() + " does not exist");
                return false;
            }

            MtDatabase db = null;
            try {
                db = new MtDatabase(hostname, dbname);
                db.Open();
                db.StartTransaction();

                // Load all the GIF images
                FileInfo[] finfos = dinfo.GetFiles("*.gif");
                foreach(FileInfo finfo in finfos) {
                    Photo photo = new Photo(db);
                    photo.ImportDataFromFile(finfo);
                }

                // Load all the JPEG images
                finfos = dinfo.GetFiles("*.jpeg");
                foreach(FileInfo finfo in finfos) {
                    Photo photo = new Photo(db);
                    photo.ImportDataFromFile(finfo);
                }

                db.Commit();
                db.Close();
            } catch (MtException ex) {
                MessageBox.Show(ex.Message);
                if ( db.IsTransactionInProgress() )
                    db.Rollback();
                if ( db.IsConnectionOpen() )
                    db.Close();

                return false;
            }
            return true;
        }
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
Web Developer
United States United States
John is a software consultant and currently working for a large .NET project. He has an extensive experience in object-oriented technologies for more than 15 years ranging from Smalltalk, C++, Java, .NET to databases.

Comments and Discussions