ArcObjects Library Reference  

TimestampClassDescription

About the Timestamper class extension Sample

[C#]

TimestampClassDescription.cs

using System;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using Timestamper.Properties;

namespace Timestamper
{
	/// <summary>
	/// A custom feature class description for use with the TimestampClassExtension. The properties return
	/// nearly the same values as the FeatureClassDescription class, with the exception of the Name
	/// ("Timestamped Class") and DefaultFields (returns three additional fields, Date fields for features'
	/// creation and modification dates and a text field for a user name).
	/// </summary>
	[Guid("2198329f-69ba-43fa-a3ed-85ee11237bf2")]
	[ClassInterface(ClassInterfaceType.None)]
	[ProgId("Timestamper.TimestampClassDescription")]
	[ComVisible(true)]
	public class TimestampedClassDescription : IObjectClassDescription, IFeatureClassDescription
	{
		#region IObjectClassDescription Members
		/// <summary>
		/// The alias of the described class.
		/// </summary>
		public String AliasName
		{
			get
			{
				return String.Empty;
			}
		}

		/// <summary>
		/// The described class' extension UID.
		/// </summary>
		public UID ClassExtensionCLSID
		{
			get
			{
				// Return the UID of TimestampClassExtension.
				UID uid = new UIDClass();
				uid.Value = "{31b0b791-3606-4c58-b4d9-940c157dca4c}";
				return uid;
			}
		}

		/// <summary>
		/// The described class' instance UID.
		/// </summary>
		public UID InstanceCLSID
		{
			get
			{
				// Return the UID of Feature.
				UID uid = new UIDClass();
				uid.Value = "{52353152-891A-11D0-BEC6-00805F7C4268}";
				return uid;
			}
		}

		/// <summary>
		/// The model name of the described class.
		/// </summary>
		public String ModelName
		{
			get
			{
				return String.Empty;
			}
		}

		/// <summary>
		/// Indicates if the model name of the described class is unique.
		/// </summary>
		public Boolean ModelNameUnique
		{
			get
			{
				return false;
			}
		}

		/// <summary>
		/// The name of the described class.
		/// </summary>
		public String Name
		{
			get
			{
				return Resources.TimestampedClassName;
			}
		}

		/// <summary>
		/// The set of required fields for the described class.
		/// </summary>
		public IFields RequiredFields
		{
			get
			{
				// Get the feature class required fields.
				IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
				IObjectClassDescription ocDescription = (IObjectClassDescription)fcDescription;
				IFields requiredFields = ocDescription.RequiredFields;
				IFieldsEdit requiredFieldsEdit = (IFieldsEdit)requiredFields;

				// Add a created date field.
				IField createdField = new FieldClass();
				IFieldEdit createdFieldEdit = (IFieldEdit)createdField;
				createdFieldEdit.Name_2 = Resources.DefaultCreatedField;
				createdFieldEdit.Required_2 = false;
				createdFieldEdit.IsNullable_2 = true;
				createdFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate;
				requiredFieldsEdit.AddField(createdField);

				// Add a modified date field.
				IField modifiedField = new FieldClass();
				IFieldEdit modifiedFieldEdit = (IFieldEdit)modifiedField;
				modifiedFieldEdit.Name_2 = Resources.DefaultModifiedField;
				modifiedFieldEdit.Required_2 = false;
				modifiedFieldEdit.IsNullable_2 = true;
				modifiedFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate;
				requiredFieldsEdit.AddField(modifiedField);

				// Add a user text field.
				IField userField = new FieldClass();
				IFieldEdit userFieldEdit = (IFieldEdit)userField;
				userFieldEdit.Name_2 = Resources.DefaultUserField;
				userFieldEdit.Required_2 = false;
				userFieldEdit.IsNullable_2 = true;
				userFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
				userFieldEdit.Length_2 = 100;
				requiredFieldsEdit.AddField(userField);

				return requiredFields;
			}
		}
		#endregion

		#region IFeatureClassDescription Members
		/// <summary>
		/// The esriFeatureType for the instances of the described class.
		/// </summary>
		public esriFeatureType FeatureType
		{
			get
			{
				return esriFeatureType.esriFTSimple;
			}
		}

		/// <summary>
		/// The name of the described class' geometry field.
		/// </summary>
		public String ShapeFieldName
		{
			get
			{
				// Use the feature class default.
				IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
				return fcDescription.ShapeFieldName;
			}
		}
		#endregion

		#region COM Registration Functions
		/// <summary>
		/// Registers the class description in the appropriate component category.
		/// </summary>
		/// <param name="registerType">The class description's type.</param>
		[ComRegisterFunction()]
		[ComVisible(false)]
		static void RegisterFunction(Type registerType)
		{
			String regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
			GeoObjectClassDescriptions.Register(regKey);
		}

		/// <summary>
		/// Removes the class description from the appropriate component category.
		/// </summary>
		/// <param name="registerType">The class description's type.</param>
		[ComUnregisterFunction()]
		[ComVisible(false)]
		static void UnregisterFunction(Type registerType)
		{
			String regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
			GeoObjectClassDescriptions.Unregister(regKey);
		}
		#endregion
	}
}

[Visual Basic .NET]

TimestampClassDescription.vb

Imports System
Imports System.Runtime.InteropServices
Imports ESRI.ArcGIS.ADF.CATIDs
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geodatabase
Imports Timestamper.My.Resources

''' <summary>
''' A custom feature class description for use with the TimestampClassExtension. The properties return
''' nearly the same values as the FeatureClassDescription class, with the exception of the Name
''' ("Timestamped Class") and DefaultFields (returns three additional fields, Date fields for features'
''' creation and modification dates and a text field for a user name).
''' </summary>
<Guid("858e76eb-18b0-47e1-b69b-288541fe1c96")> _
<ClassInterface(ClassInterfaceType.None)> _
<ProgId("Timestamper.TimestampClassDescription")> _
<ComVisible(True)> _
Public Class TimestampClassDescription
	Implements IObjectClassDescription
	Implements IFeatureClassDescription

#Region "IObjectClassDescription Members"
	''' <summary>
	''' The alias of the described class.
	''' </summary>
	Public ReadOnly Property AliasName() As String Implements IObjectClassDescription.AliasName
		Get
			AliasName = String.Empty
		End Get
	End Property

	''' <summary>
	''' The described class' extension UID.
	''' </summary>
	Public ReadOnly Property ClassExtensionCLSID() As ESRI.ArcGIS.esriSystem.UID Implements IObjectClassDescription.ClassExtensionCLSID
		Get
			' Return the UID of TimestampClassExtension.
			Dim uid As UID = New UIDClass()
			uid.Value = "{becd0269-32f2-4a21-9145-619a891e7862}"
			ClassExtensionCLSID = uid
		End Get
	End Property

	''' <summary>
	''' The described class' instance UID.
	''' </summary>
	Public ReadOnly Property InstanceCLSID() As ESRI.ArcGIS.esriSystem.UID Implements IObjectClassDescription.InstanceCLSID
		Get
			' Return the UID of Feature.
			Dim uid As UID = New UIDClass()
			uid.Value = "{52353152-891A-11D0-BEC6-00805F7C4268}"
			InstanceCLSID = uid
		End Get
	End Property

	''' <summary>
	''' The model name of the described class.
	''' </summary>
	Public ReadOnly Property ModelName() As String Implements IObjectClassDescription.ModelName
		Get
			ModelName = String.Empty
		End Get
	End Property

	''' <summary>
	''' Indicates if the model name of the described class is unique.
	''' </summary>
	Public ReadOnly Property ModelNameUnique() As Boolean Implements IObjectClassDescription.ModelNameUnique
		Get
			ModelNameUnique = False
		End Get
	End Property

	''' <summary>
	''' The name of the described class.
	''' </summary>
	Public ReadOnly Property Name() As String Implements IObjectClassDescription.Name
		Get
			Name = Resources.TimestampedClassName
		End Get
	End Property

	''' <summary>
	''' The set of required fields for the described class.
	''' </summary>
	Public ReadOnly Property RequiredFields() As IFields Implements IObjectClassDescription.RequiredFields
		Get
			' Get the feature class required fields.
			Dim fcDescription As IFeatureClassDescription = New FeatureClassDescriptionClass()
			Dim ocDescription As IObjectClassDescription = CType(fcDescription, IObjectClassDescription)
			Dim fcRequiredFields As IFields = ocDescription.RequiredFields
			Dim fcRequiredFieldsEdit As IFieldsEdit = CType(fcRequiredFields, IFieldsEdit)

			' Add a created date field.
			Dim createdField As IField = New FieldClass()
			Dim createdFieldEdit As IFieldEdit = CType(createdField, IFieldEdit)
			createdFieldEdit.Name_2 = Resources.DefaultCreatedField
			createdFieldEdit.Required_2 = False
			createdFieldEdit.IsNullable_2 = True
			createdFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate
			fcRequiredFieldsEdit.AddField(createdField)

			' Add a modified date field.
			Dim modifiedField As IField = New FieldClass()
			Dim modifiedFieldEdit As IFieldEdit = CType(modifiedField, IFieldEdit)
			modifiedFieldEdit.Name_2 = Resources.DefaultModifiedField
			modifiedFieldEdit.Required_2 = False
			modifiedFieldEdit.IsNullable_2 = True
			modifiedFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate
			fcRequiredFieldsEdit.AddField(modifiedField)

			' Add a user text field.
			Dim userField As IField = New FieldClass()
			Dim userFieldEdit As IFieldEdit = CType(userField, IFieldEdit)
			userFieldEdit.Name_2 = Resources.DefaultUserField
			userFieldEdit.Required_2 = False
			userFieldEdit.IsNullable_2 = True
			userFieldEdit.Type_2 = esriFieldType.esriFieldTypeString
			userFieldEdit.Length_2 = 100
			fcRequiredFieldsEdit.AddField(userField)

			RequiredFields = fcRequiredFields
		End Get
	End Property
#End Region

#Region "IFeatureClassDescription Members"
	''' <summary>
	''' The esriFeatureType for the instances of the described class.
	''' </summary>
	Public ReadOnly Property FeatureType() As esriFeatureType Implements IFeatureClassDescription.FeatureType
		Get
			FeatureType = esriFeatureType.esriFTSimple
		End Get
	End Property

	''' <summary>
	''' The name of the described class' geometry field.
	''' </summary>
	Public ReadOnly Property ShapeFieldName() As String Implements IFeatureClassDescription.ShapeFieldName
		Get
			' Use the feature class default.
			Dim fcDescription As IFeatureClassDescription = New FeatureClassDescriptionClass()
			ShapeFieldName = fcDescription.ShapeFieldName
		End Get
	End Property
#End Region

#Region "COM Registration Function(s)"
	<ComRegisterFunction(), ComVisibleAttribute(False)> _
	Public Shared Sub RegisterFunction(ByVal registerType As Type)
		Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
		GeoObjectClassDescriptions.Register(regKey)
	End Sub

	<ComUnregisterFunction(), ComVisibleAttribute(False)> _
	Public Shared Sub UnregisterFunction(ByVal registerType As Type)
		Dim regKey As String = String.Format("HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)
		GeoObjectClassDescriptions.Unregister(regKey)
	End Sub
#End Region
End Class