YouTube | Facebook | X(Twitter) | RSS

編集情報の記録

2016/9/1 (木)

//読み込み
var featurelayer = ArcMap.Document.FocusMap.get_Layer(0) as IFeatureLayer;
var gputil = new GPUtilitiesClass();
var defeaturelayer = gputil.MakeGPLayerFromLayer(featurelayer) as IGPFeatureLayer;
var editortracking = defeaturelayer.DEFeatureClass as IDEEditorTracking;
 
System.Diagnostics.Debug.WriteLine(editortracking.EditorTrackingEnabled);
System.Diagnostics.Debug.WriteLine(editortracking.CreatedAtFieldName);
System.Diagnostics.Debug.WriteLine(editortracking.CreatorFieldName);
 
 
//書き込み
http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#//000100000p7r000000
 
Enabling editor tracking
Enable editor tracking on a dataset by setting at least one of the IClassSchemaEdit4 field properties to the name of an existing field.
The following code example enables editor tracking for a feature class or table by setting the following four field properties: 
CreatorFieldName
CreatedAtFieldName
EditorFieldName
EditedAtFieldName
 
 
 
//[C#]
private static void EnableEditorTracking(IDataset dataset, String sCreatorField,
    String sCreatedField, String sEditorField, String sEditedField, Boolean
    isTimeUTC)
{
    //Get the fields collection.
    IFields fields = null;
    if (dataset.Type == esriDatasetType.esriDTFeatureClass)
    {
        IFeatureClass featureClass = (IFeatureClass)dataset;
        fields = featureClass.Fields;
    }
    else
    {
        ITable table = (ITable)dataset;
        fields = table.Fields;
    }
 
    //Get the individual fields.
    int fieldIndex = fields.FindField(sCreatorField);
    IField creatorField = fields.get_Field(fieldIndex);
    fieldIndex = fields.FindField(sCreatedField);
    IField createdField = fields.get_Field(fieldIndex);
    fieldIndex = fields.FindField(sEditorField);
    IField editorField = fields.get_Field(fieldIndex);
    fieldIndex = fields.FindField(sEditedField);
    IField editedField = fields.get_Field(fieldIndex);
 
    //Enable editor tracking.
    IObjectClass oc = (IObjectClass)dataset;
    IClassSchemaEdit4 se4 = (IClassSchemaEdit4)oc;
    se4.CreatorFieldName = creatorField.Name;
    se4.CreatedAtFieldName = createdField.Name;
    se4.EditorFieldName = editorField.Name;
    se4.EditedAtFieldName = editedField.Name;
    se4.IsTimeInUTC = isTimeUTC;
}
 
 
 
'[VB.NET]
Public Sub EnableEditorTracking(dataset As IDataset, sCreatorField As [String], sCreatedField As [String], sEditorField As [String], sEditedField As [String], isTimeUTC As [Boolean])
    'Get the fields collection.
    Dim fields As IFields = Nothing
    If dataset.Type = esriDatasetType.esriDTFeatureClass Then
        Dim featureClass As IFeatureClass = DirectCast(dataset, IFeatureClass)
        fields = featureClass.Fields
    Else
        Dim table As ITable = DirectCast(dataset, ITable)
        fields = table.Fields
    End If
     
    'Get the individual fields.
    Dim fieldIndex As Integer = fields.FindField(sCreatorField)
    Dim creatorField As IField = fields.get_Field(fieldIndex)
    fieldIndex = fields.FindField(sCreatedField)
    Dim createdField As IField = fields.get_Field(fieldIndex)
    fieldIndex = fields.FindField(sEditorField)
    Dim editorField As IField = fields.get_Field(fieldIndex)
    fieldIndex = fields.FindField(sEditedField)
    Dim editedField As IField = fields.get_Field(fieldIndex)
     
    'Enable editor tracking.
    Dim oc As IObjectClass = DirectCast(dataset, IObjectClass)
    Dim se4 As IClassSchemaEdit4 = DirectCast(oc, IClassSchemaEdit4)
    se4.CreatorFieldName = creatorField.Name
    se4.CreatedAtFieldName = createdField.Name
    se4.EditorFieldName = editorField.Name
    se4.EditedAtFieldName = editedField.Name
    se4.IsTimeInUTC = isTimeUTC
End Sub
Setting a realm
If your data resides in an ArcSDE geodatabase and you connect through database authentication, you can choose to append a realm (for example, @esri.com) to the name of the user who makes the edit. For example, if you have a user named John in your Denver office and a user named John in your Seattle office, you can track their edits as John@denver and John@seattle, respectively, so that you can be certain which John made each edit.
To set the realm for an ArcSDE geodatabase, you must have administrator privileges on the database. Set the realm by setting IDatabaseConnectionInfo4.Realm to a string.
The following code example can be used to get a default realm for a workspace and set it as the realm:
 
[C#]
private static Boolean SetRealm(IWorkspace workspace)
{
    IDatabaseConnectionInfo4 dbConnectionInfo = workspace as
        IDatabaseConnectionInfo4;
    if (dbConnectionInfo != null)
    {
        string sRealm = string.Empty;
        sRealm = GetDefaultRealm(workspace);
        dbConnectionInfo.Realm = sRealm;
        if (dbConnectionInfo.Realm == string.Empty || dbConnectionInfo.Realm !=
            sRealm)
        {
            return false;
        }
        return true;
    }
    else
    {
        return false;
    }
}
 
private static String GetDefaultRealm(IWorkspace workspace)
{
    IDatabaseConnectionInfo4 dbConnectionInfo = workspace as
        IDatabaseConnectionInfo4;
    if (dbConnectionInfo != null)
    {
        return dbConnectionInfo.GenerateDefaultRealm().ToString();
    }
    else
    {
        return string.Empty;
    }
}
[VB.NET]
Private Shared Function SetRealm(workspace As IWorkspace) As [Boolean]
Dim dbConnectionInfo As IDatabaseConnectionInfo4 = TryCast(workspace, IDatabaseConnectionInfo4)
If dbConnectionInfo IsNot Nothing Then
    Dim sRealm As String = String.Empty
    sRealm = GetDefaultRealm(workspace)
    dbConnectionInfo.Realm = sRealm
    If dbConnectionInfo.Realm = String.Empty OrElse dbConnectionInfo.Realm <> sRealm Then
        Return False
    End If
    Return True
Else
    Return False
End If
End Function
 
Private Shared Function GetDefaultRealm(workspace As IWorkspace) As [String]
Dim dbConnectionInfo As IDatabaseConnectionInfo4 = TryCast(workspace, IDatabaseConnectionInfo4)
If dbConnectionInfo IsNot Nothing Then
    Return dbConnectionInfo.GenerateDefaultRealm().ToString()
Else
    Return String.Empty
End If
End Function
Disabling editor tracking
Disable editor tracking by setting each of the IClassSchemaEdit4 field properties to an empty string, as shown in the following code example:
[C#]
private static void DisableEditorTracking(IDataset dataset)
{
    //Disable editor tracking.
    IObjectClass oc = (IObjectClass)dataset;
    IClassSchemaEdit4 se4 = (IClassSchemaEdit4)oc;
    se4.CreatorFieldName = string.Empty;
    se4.CreatedAtFieldName = string.Empty;
    se4.EditorFieldName = string.Empty;
    se4.EditedAtFieldName = string.Empty;
}
[VB.NET]
Private Shared Sub DisableEditorTracking(dataset As IDataset)
'Disable editor tracking.
Dim oc As IObjectClass = DirectCast(dataset, IObjectClass)
Dim se4 As IClassSchemaEdit4 = DirectCast(oc, IClassSchemaEdit4)
se4.CreatorFieldName = String.Empty
se4.CreatedAtFieldName = String.Empty
se4.EditorFieldName = String.Empty
se4.EditedAtFieldName = String.Empty
End Sub
  • この記事を書いた人

羽田 康祐

伊達と酔狂のGISエンジニア。GIS上級技術者、Esri認定インストラクター、CompTIA CTT+ Classroom Trainer、潜水士、PADIダイブマスター、四アマ。WordPress は 2.1 からのユーザーで歴だけは長い。 代表著書『"地図リテラシー入門―地図の正しい読み方・描き方がわかる』 GIS を使った自己紹介はこちら。ESRIジャパン(株)所属、元青山学院大学非常勤講師を兼務。日本地図学会第31期常任委員。発言は個人の見解です。

-プログラミング, ArcGIS
-,