namespace Johnssk.example.media {
using System;
using System.IO;
using com.matisse.reflect;
using com.matisse.Data;
using com.matisse;
// A class generated by Matisse
/// <summary>
/// Photo is a schema class generated by Matisse.
/// </summary>
public class Photo : MtObject {
// Generated field, do not modify
/// <summary>
/// Class 'Photo' Cache ID
/// </summary>
private static int CID = MtDatabase.AllocCID(new MtClass.Loader("Photo"));
// Generated field, do not modify
/// <summary>
/// Dictionary 'PhotoTitle' Cache ID
/// </summary>
private static int photoTitleDictionaryCID = MtDatabase.AllocCID(new MtEntryPointDictionary.Loader("PhotoTitle"));
// Generated field, do not modify
/// <summary>
/// Attribute 'Title' Cache ID
/// </summary>
private static int titleAttributeCID = MtDatabase.AllocCID(new MtAttribute.Loader("Title", CID));
// Generated field, do not modify
/// <summary>
/// Attribute 'Description' Cache ID
/// </summary>
private static int descriptionAttributeCID = MtDatabase.AllocCID(new MtAttribute.Loader("Description", CID));
// Generated field, do not modify
/// <summary>
/// Attribute 'LargeImage' Cache ID
/// </summary>
private static int largeImageAttributeCID = MtDatabase.AllocCID(new MtAttribute.Loader("LargeImage", CID));
// Generated field, do not modify
/// <summary>
/// Attribute 'Thumbnail' Cache ID
/// </summary>
private static int thumbnailAttributeCID = MtDatabase.AllocCID(new MtAttribute.Loader("Thumbnail", CID));
// Generated constructor, do not modify
/// <summary>
/// The factory constructor
/// </summary>
/// <param name="db">a database</param>
/// <param name="mtOid">an existing object ID in the db</param>
public Photo(MtDatabase db, int mtOid) :
base(db, mtOid) {
}
// Generated constructor, do not modify
/// <summary>
/// Cascaded constructor, used by subclasses to create a new object in the database
/// </summary>
/// <param name="clazz">the class descriptor of the class to instantiate</param>
protected Photo(MtClass clazz) :
base(clazz) {
}
// Generated property, do not modify
/// <summary>
/// Property for attribute 'Title'
/// </summary>
public string Title {
get {
return GetString(GetTitleAttribute(Database));
}
set {
SetString(GetTitleAttribute(Database), value);
}
}
// Generated property, do not modify
/// <summary>
/// Property for attribute 'Description'
/// </summary>
public string Description {
get {
return GetString(GetDescriptionAttribute(Database));
}
set {
SetString(GetDescriptionAttribute(Database), value);
}
}
// Generated property, do not modify
/// <summary>
/// Property for attribute 'LargeImage'
/// </summary>
public System.Byte[] LargeImage {
get {
return GetImages(GetLargeImageAttribute(Database));
}
set {
SetImages(GetLargeImageAttribute(Database), value);
}
}
// Generated property, do not modify
/// <summary>
/// Read only property 'LargeImageSize': the number of elements in the list
/// </summary>
public long LargeImageSize {
get {
return GetListSize(GetLargeImageAttribute(Database));
}
}
// Generated property, do not modify
/// <summary>
/// Property for attribute 'Thumbnail'
/// </summary>
public System.Byte[] Thumbnail {
get {
return GetImages(GetThumbnailAttribute(Database));
}
set {
SetImages(GetThumbnailAttribute(Database), value);
}
}
// Generated property, do not modify
/// <summary>
/// Read only property 'ThumbnailSize': the number of elements in the list
/// </summary>
public long ThumbnailSize {
get {
return GetListSize(GetThumbnailAttribute(Database));
}
}
// Generated method, do not modify
/// <summary>
/// Gets the 'Photo' class descriptor
/// </summary>
public new static MtClass GetClass(MtDatabase db) {
return ((MtClass)(db.GetCachedObject(CID)));
}
// Generated method, do not modify
/// <summary>
/// Create an enumerator on all instances of this class (and its subclasses)
/// </summary>
/// <param name="db">a database</param>
/// <return>returns the total number of instances</return>
public new static long GetInstanceNumber(MtDatabase db) {
return GetClass(db).GetInstanceNumber();
}
// Generated method, do not modify
/// <summary>
/// Create an enumerator on all instances of this class (and its subclasses)
/// </summary>
/// <param name="db">a database</param>
/// <return>returns an object enumerator</return>
public new static MtObjectEnumerator InstanceEnumerator(MtDatabase db) {
return GetClass(db).InstanceEnumerator();
}
// Generated method, do not modify
/// <summary>
/// Gets the 'PhotoTitle' Dictionary descriptor
/// </summary>
/// <param name="db">the database containing the Dictionary</param>
/// <return>returns the Dictionary descriptor object</return>
public static MtEntryPointDictionary GetPhotoTitleDictionary(MtDatabase db) {
return ((MtEntryPointDictionary)(db.GetCachedObject(photoTitleDictionaryCID)));
}
// Generated method, do not modify
/// <summary>
/// Performs an entry point lookup on the 'PhotoTitle' dictionary(single match)
/// </summary>
/// <param name="db">a database</param>
/// <param name="ep">the search string</param>
/// <return>returns the matching Photo or null if non was found</return>
public static Photo LookupPhotoTitle(MtDatabase db, string ep) {
return ((Photo)(GetPhotoTitleDictionary(db).Lookup(ep, GetClass(db))));
}
// Generated method, do not modify
/// <summary>
/// Performs an entry point lookup on the 'PhotoTitle' dictionary(multiple match)
/// </summary>
/// <param name="db">a database</param>
/// <param name="ep">the search string</param>
/// <return>returns an object enumerator</return>
public static MtObjectEnumerator PhotoTitleEnumerator(MtDatabase db, string ep) {
return GetPhotoTitleDictionary(db).Enumerator(ep, GetClass(db));
}
// Generated method, do not modify
/// <summary>
/// Create an enumerator on all 'Photo' objects where 'title' matches this value. Use this method to restrict the enumerator to members of a subclass of this class or to set a maxium number of objects
/// </summary>
/// <param name="db">a database</param>
/// <param name="ep">the search string</param>
/// <param name="filterClass">return only instances (direct/indirect) of this class</param>
/// <param name="numObjPerBuffer">maxinum number of objects to include in the enumerator</param>
/// <return>returns an object enumerator</return>
public static MtObjectEnumerator PhotoTitleEnumerator(MtDatabase db, string ep, MtClass filterClass, int numObjPerBuffer) {
return GetPhotoTitleDictionary(db).Enumerator(ep, filterClass, numObjPerBuffer);
}
// Generated method, do not modify
/// <summary>
/// Gets the 'Title' Attribute descriptor
/// </summary>
/// <param name="db">the database containing the Attribute</param>
/// <return>returns the Attribute descriptor object</return>
public static MtAttribute GetTitleAttribute(MtDatabase db) {
return ((MtAttribute)(db.GetCachedObject(titleAttributeCID)));
}
// Generated method, do not modify
/// <summary>
/// Removes the 'Title' attribute value. Falls back to the default value if there is one
/// </summary>
public void RemoveTitle() {
RemoveValue(GetTitleAttribute(Database));
}
// Generated method, do not modify
/// <summary>
/// Gets the 'Description' Attribute descriptor
/// </summary>
/// <param name="db">the database containing the Attribute</param>
/// <return>returns the Attribute descriptor object</return>
public static MtAttribute GetDescriptionAttribute(MtDatabase db) {
return ((MtAttribute)(db.GetCachedObject(descriptionAttributeCID)));
}
// Generated method, do not modify
/// <summary>
/// Removes the 'Description' attribute value. Falls back to the default value if there is one
/// </summary>
public void RemoveDescription() {
RemoveValue(GetDescriptionAttribute(Database));
}
// Generated method, do not modify
/// <summary>
/// Gets the 'LargeImage' Attribute descriptor
/// </summary>
/// <param name="db">the database containing the Attribute</param>
/// <return>returns the Attribute descriptor object</return>
public static MtAttribute GetLargeImageAttribute(MtDatabase db) {
return ((MtAttribute)(db.GetCachedObject(largeImageAttributeCID)));
}
// Generated method, do not modify
/// <summary>
/// Removes the 'LargeImage' attribute value. Falls back to the default value if there is one
/// </summary>
public void RemoveLargeImage() {
RemoveValue(GetLargeImageAttribute(Database));
}
// Generated method, do not modify
/// <summary>
/// Reads 'LargeImage' attribute value elements into a portion of an array
/// </summary>
/// <param name="val">destination buffer</param>
/// <param name="offset">offset at which to start storing elements</param>
/// <param name="len">the maxinum number of elements to read</param>
/// <return>returns the number of elements read</return>
public int GetLargeImageElements(System.Byte[] val, long offset, int len) {
return GetImagesElements(GetLargeImageAttribute(Database), val, len, offset);
}
// Generated method, do not modify
/// <summary>
/// Writes a portion of an array of elements to the 'LargeImage' attribute value
/// </summary>
/// <param name="val">an array of elements</param>
/// <param name="offset">offset from which to start writing characters</param>
/// <param name="len">the number of characters to write</param>
/// <param name="discardAfter">truncate the remaining part of the attribute value</param>
public void SetLargeImageElements(System.Byte[] val, long offset, int len, bool discardAfter) {
SetImagesElements(GetLargeImageAttribute(Database), val, len, offset, discardAfter);
}
// Generated method, do not modify
/// <summary>
/// Gets the 'Thumbnail' Attribute descriptor
/// </summary>
/// <param name="db">the database containing the Attribute</param>
/// <return>returns the Attribute descriptor object</return>
public static MtAttribute GetThumbnailAttribute(MtDatabase db) {
return ((MtAttribute)(db.GetCachedObject(thumbnailAttributeCID)));
}
// Generated method, do not modify
/// <summary>
/// Removes the 'Thumbnail' attribute value. Falls back to the default value if there is one
/// </summary>
public void RemoveThumbnail() {
RemoveValue(GetThumbnailAttribute(Database));
}
// Generated method, do not modify
/// <summary>
/// Reads 'Thumbnail' attribute value elements into a portion of an array
/// </summary>
/// <param name="val">destination buffer</param>
/// <param name="offset">offset at which to start storing elements</param>
/// <param name="len">the maxinum number of elements to read</param>
/// <return>returns the number of elements read</return>
public int GetThumbnailElements(System.Byte[] val, long offset, int len) {
return GetImagesElements(GetThumbnailAttribute(Database), val, len, offset);
}
// Generated method, do not modify
/// <summary>
/// Writes a portion of an array of elements to the 'Thumbnail' attribute value
/// </summary>
/// <param name="val">an array of elements</param>
/// <param name="offset">offset from which to start writing characters</param>
/// <param name="len">the number of characters to write</param>
/// <param name="discardAfter">truncate the remaining part of the attribute value</param>
public void SetThumbnailElements(System.Byte[] val, long offset, int len, bool discardAfter) {
SetImagesElements(GetThumbnailAttribute(Database), val, len, offset, discardAfter);
}
// Generated constructor
/// <summary>
/// Default constructor provided as an example. You may modify or delete this constructor
/// </summary>
public Photo(MtDatabase db) :
base(GetClass(db)) {
}
public void ImportDataFromFile(FileInfo imageFile) {
FileInfo metadata = new FileInfo(imageFile.Directory.ToString() + "\\"
+ imageFile.Name + ".md");
// Read the meta data
if ( metadata.Exists ) {
StreamReader sr = metadata.OpenText();
this.Title = sr.ReadLine();
this.Description = sr.ReadLine();
sr.Close();
}
// Read the screenshot image data
if ( imageFile.Exists ) {
FileStream fs = imageFile.OpenRead();
int bufferSize = 32 * 1024; // 32K
byte[] buffer = new byte[bufferSize];
int offset = 0;
int bytesRead;
while ( (bytesRead = fs.Read(buffer, 0, bufferSize)) > 0 ) {
this.SetLargeImageElements(buffer, offset, bytesRead, false);
if ( bytesRead < bufferSize )
break;
offset += bytesRead;
}
fs.Close();
}
// Read the thumbnail image
FileInfo thumbfile = new FileInfo(imageFile.Directory.ToString() +
"\\tnails\\" + imageFile.Name);
if ( thumbfile.Exists ) {
FileStream fs = thumbfile.OpenRead();
int bufferSize = 32 * 1024; // 32K
byte[] buffer = new byte[bufferSize];
int offset = 0;
int bytesRead;
while ( (bytesRead = fs.Read(buffer, 0, bufferSize)) > 0 ) {
this.SetThumbnailElements(buffer, offset, bytesRead, false);
if ( bytesRead < bufferSize )
break;
offset += bytesRead;
}
fs.Close();
}
}
public override string ToString() {
return Title;
}
}
}