|
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.
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.