RowCreatedEvent with feature services

212
0
07-08-2019 04:16 PM
JarrettMiller
New Contributor

Hello,

Is there anyway to subscribe to rows created in a feature service? Ultimately, I'm wanting to populate the user's system name and datetime in the callback. Everything generates perfectly when I pass in a file GDB feature class, but no luck with a service layer. 

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Threading.Tasks;
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using ArcGIS.Desktop.Core.Events;
using ArcGIS.Desktop.Editing.Events;


namespace ProAppModule6
{
    internal class Module1 : Module
    {
        private static Module1 _this = null;
        /// <summary>
        /// Retrieve the singleton instance to this module here
        /// </summary>
        public static Module1 Current
        {
            get
            {
                return _this ?? (_this = (Module1)FrameworkApplication.FindModule("ProAppModule2_Module"));
            }
        }

        #region Overrides
        /// <summary>
        /// Called by Framework when ArcGIS Pro is closing
        /// </summary>
        /// <returns>False to prevent Pro from closing, otherwise True</returns>
        protected override bool Initialize()
        {
            ProjectOpenedEvent.Subscribe(ProjectStartup);
            return base.Initialize();
        }

        private void ProjectStartup(ProjectEventArgs args)
        {
            QueuedTask.Run(() =>
            {
                var mapProjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name == "Map");
                if (mapProjItem == null)
                    return;
                var theMap = mapProjItem.GetMap();
                var featLayer = theMap.FindLayers("Current_Requests").FirstOrDefault() as FeatureLayer;
                if (featLayer == null)
                    return;

                var layerTable = featLayer.GetTable();

                var _rowCreateToken = RowCreatedEvent.Subscribe(onRowCreateEvent, layerTable);
            });

        }
        private void onRowCreateEvent(RowChangedEventArgs args)
        {
            var row = args.Row;
            row["created_user"] = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            row["created_date"] = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss tt");
        }
    }
}
#endregion Overrides‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks,

Tags (1)
0 Kudos
0 Replies