private bool Unregister()
        {
            //Careful here - events have to be unregistered on the same
            //thread they were registered on...hence the use of the
            //Queued Task
            QueuedTask.Run(() =>
            {
                //One kvp per layer....of which there is only one in the sample
                //out of the box but you can add others and register for events
                foreach (var kvp in _rowevents)
                {
                    RowCreatedEvent.Unsubscribe(kvp.Value[0]);
                    RowChangedEvent.Unsubscribe(kvp.Value[1]);
                    RowDeletedEvent.Unsubscribe(kvp.Value[2]);
                    kvp.Value.Clear();
                }
                _rowevents.Clear();

                //Editing and Edit Completed.
                RowDeletedEvent.Unsubscribe(_editevents[0]);
                RowDeletedEvent.Unsubscribe(_editevents[1]);
                _editevents.Clear();
            });

            return(false);
        }
コード例 #2
0
        public static void StopADelete()
        {
            // subscribe to the RowDeletedEvent for the appropriate table
            Table table = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault().GetTable();

            RowDeletedEvent.Subscribe(OnRowDeletedEvent, table);
        }
コード例 #3
0
        private void onProjectOpened(ProjectEventArgs obj)
        {
            //subscribe to edit completed event
            //this is across all maps and layers in the project
            EditCompletedEvent.Subscribe(onEditCompleted);

            //subscribe to row events for a certain layer in a certain map
            //look for a map named 'Layers' in the project
            var mapProjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name == "Layers");

            if (mapProjItem == null)
            {
                return;
            }

            //run on MCT
            QueuedTask.Run(() =>
            {
                var theMap = mapProjItem.GetMap();

                //look for a layer named 'Parcels' in the map
                var featLayer = theMap.FindLayers("Parcels").FirstOrDefault() as FeatureLayer;
                if (featLayer == null)
                {
                    return;
                }
                var layerTable = featLayer.GetTable();

                //setup row events
                _rowCreateToken  = RowCreatedEvent.Subscribe(onRowCreateEvent, layerTable);
                _rowDeleteToken  = RowDeletedEvent.Subscribe(onRowDeleteEvent, layerTable);
                _rowChangedToken = RowChangedEvent.Subscribe(onRowChangedEvent, layerTable);
            });
        }
コード例 #4
0
        protected override void OnClick()
        {
            QueuedTask.Run(async() =>
            {
                //find layer and derive geodatabase
                var cpLayer = MapView.Active.Map.FindLayers("CrowdPlanning").FirstOrDefault() as FeatureLayer;

                if (cpLayer == null)
                {
                    return;
                }
                var geodatabase = cpLayer.GetFeatureClass().GetDatastore() as Geodatabase;

                //Advise if the project has edits. Need to clear edits to make schema changes.
                if (Project.Current.HasEdits)
                {
                    MessageBox.Show("Please save or discard edits", "Pending Edits");
                    return;
                }

                //Delete and Create the editlog table
                //For the purpose of this sample, start with a fresh table
                var mva = Geoprocessing.MakeValueArray(geodatabase.GetPath().AbsolutePath, "EditLog");
                var cts = new System.Threading.CancellationTokenSource();
                await Geoprocessing.ExecuteToolAsync("CreateTable_management", mva);

                //add fields to editlog
                var tablePath = geodatabase.GetPath().AbsolutePath + @"\EditLog";
                mva           = Geoprocessing.MakeValueArray(tablePath, "Layer", "STRING");
                await Geoprocessing.ExecuteToolAsync("AddField_management", mva);
                mva = Geoprocessing.MakeValueArray(tablePath, "OID", "LONG");
                await Geoprocessing.ExecuteToolAsync("AddField_management", mva);
                mva = Geoprocessing.MakeValueArray(tablePath, "Date", "DATE");
                await Geoprocessing.ExecuteToolAsync("AddField_management", mva);
                mva = Geoprocessing.MakeValueArray(tablePath, "EditType", "STRING");
                await Geoprocessing.ExecuteToolAsync("AddField_management", mva);

                _ehTable = MapView.Active.Map.FindStandaloneTables("EditLog").FirstOrDefault();

                //setup row events for layer
                if (_rowChangedToken == null)
                {
                    _rowChangedToken = RowChangedEvent.Subscribe(OnRowEvent, cpLayer.GetTable());
                }
                if (_rowCreatedToken == null)
                {
                    _rowCreatedToken = RowCreatedEvent.Subscribe(OnRowEvent, cpLayer.GetTable());
                }
                if (_rowDeletedToken == null)
                {
                    _rowDeletedToken = RowDeletedEvent.Subscribe(OnRowEvent, cpLayer.GetTable());
                }
            });
        }
コード例 #5
0
        private void onProjectClosed(ProjectEventArgs obj)
        {
            //Unsubscribe from events
            EditCompletedEvent.Unsubscribe(onEditCompleted);

            QueuedTask.Run(() =>
            {
                RowCreatedEvent.Unsubscribe(_rowCreateToken);
                RowDeletedEvent.Unsubscribe(_rowDeleteToken);
                RowChangedEvent.Unsubscribe(_rowChangedToken);
            });
        }
コード例 #6
0
        protected void subRowEvent()
        {
            QueuedTask.Run(() =>
            {
                //Listen for row events on a layer
                var featLayer  = MapView.Active.GetSelectedLayers().First() as FeatureLayer;
                var layerTable = featLayer.GetTable();

                //subscribe to row events
                var rowCreateToken = RowCreatedEvent.Subscribe(onRowEvent, layerTable);
                var rowChangeToken = RowChangedEvent.Subscribe(onRowEvent, layerTable);
                var rowDeleteToken = RowDeletedEvent.Subscribe(onRowEvent, layerTable);
            });
        }
コード例 #7
0
        protected void SetupEvents()
        {
            QueuedTask.Run(() =>
            {
                var featLayer  = MapView.Active.GetSelectedLayers().First() as FeatureLayer;
                var layerTable = featLayer.GetTable();

                //subscribe to row events for a layer
                var rowCreateToken = RowCreatedEvent.Subscribe(onRowEvent, layerTable);
                var rowChangeToken = RowChangedEvent.Subscribe(onRowEvent, layerTable);
                var rowDeleteToken = RowDeletedEvent.Subscribe(onRowEvent, layerTable);
            });

            //subscribe to editevents
            var editComplete = EditCompletedEvent.Subscribe(onEditComplete);
        }
        private bool Register()
        {
            var layers = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>();

            QueuedTask.Run(() => {
                foreach (var fl in layers)
                {
                    var fc     = fl.GetFeatureClass();
                    var tokens = new List <SubscriptionToken>();
                    //These events are fired once ~per feature~,
                    //per table
                    tokens.Add(RowCreatedEvent.Subscribe((rc) => RowEventHandler(rc), fc));
                    tokens.Add(RowChangedEvent.Subscribe((rc) => RowEventHandler(rc), fc));
                    tokens.Add(RowDeletedEvent.Subscribe((rc) => RowEventHandler(rc), fc));
                    _rowevents[fl.Name] = tokens;
                }

                //This event is fired once per edit execute
                //Note: This event won't fire if the edits were cancelled
                _editevents.Add(EditCompletingEvent.Subscribe((ec) =>
                {
                    RecordEvent("EditCompletingEvent", "");
                    //can also cancel edit in the completing event...
                    //cancels everything (that is cancealable)
                    //
                    //you'll need to modify the RowEventHandler() to prevent if
                    //from doing the cancel or this will never get called
                    if (_cancelEdit)
                    {
                        ec.CancelEdit($"EditCompletingEvent, edit cancelled");
                        AddEntry("*** edits cancelled");
                        AddEntry("---------------------------------");
                    }
                }));
                //This event is fired after all the edits are completed (and on
                //save, discard, undo, redo) and is fired once
                _editevents.Add(EditCompletedEvent.Subscribe((ec) => {
                    HandleEditCompletedEvent(ec);
                    return(Task.FromResult(0));
                }));
            });
            return(true);
        }
コード例 #9
0
        public async Task <bool> InitializeEventsAsync()
        {
            bool result = (Layer.ConnectionStatus == ConnectionStatus.Connected);

            if (result)
            {
                MapSelectionChangedEvent.Subscribe(OnMapSelectionChanged);
                DrawCompleteEvent.Subscribe(OnDrawCompleted);

                await QueuedTask.Run(() =>
                {
                    var table   = Layer.GetTable();
                    _rowChanged = RowChangedEvent.Subscribe(OnRowChanged, table);
                    _rowDeleted = RowDeletedEvent.Subscribe(OnRowDeleted, table);
                    _rowCreated = RowCreatedEvent.Subscribe(OnRowCreated, table);
                });
            }

            await LoadMeasurementsAsync();

            return(result);
        }
コード例 #10
0
        public async Task DisposeAsync()
        {
            await QueuedTask.Run(() =>
            {
                if (_rowChanged != null)
                {
                    RowChangedEvent.Unsubscribe(_rowChanged);
                }

                if (_rowDeleted != null)
                {
                    RowDeletedEvent.Unsubscribe(_rowDeleted);
                }

                if (_rowCreated != null)
                {
                    RowCreatedEvent.Unsubscribe(_rowCreated);
                }
            });

            MapSelectionChangedEvent.Unsubscribe(OnMapSelectionChanged);
            DrawCompleteEvent.Unsubscribe(OnDrawCompleted);
        }
コード例 #11
0
 public Task Handle(RowDeletedEvent <OutboxChangedEvent> message, IMessageHandlerContext context)
 {
     return(Task.CompletedTask);
 }