Example #1
0
        private void _UpdateBarriers <TBarrier>(
            IFeatureLayer <TBarrier> barriersLayer,
            DateTime plannedDate,
            IEnumerable <TBarrier> barriers)
            where TBarrier : BarrierBase, new()
        {
            Debug.Assert(barriersLayer != null);
            Debug.Assert(barriers != null && barriers.All(barrier => barrier != null));

            // Retrieve IDs of existing barriers for planned date.
            var whereClause = string.Format(
                QUERY_FORMATTER,
                NON_DELETED_OBJECTS_FOR_DATE_QUERY_WHERE_CLAUSE,
                GPObjectHelper.DateTimeToGPDateTime(plannedDate));
            var existingIDs     = barriersLayer.QueryObjectIDs(whereClause);
            var deletedBarriers = _PrepareDeletion <TBarrier>(existingIDs);

            var newBarriers = barriers.ToList();

            _PrepareAddition(newBarriers);

            foreach (var barrier in newBarriers)
            {
                barrier.PlannedDate = plannedDate;
            }

            // Delete current barriers and add new ones in a single transaction.
            barriersLayer.ApplyEdits(
                newBarriers,
                deletedBarriers,
                Enumerable.Empty <long>());
        }
        /// <summary>
        /// Updates the specified objects at the feature layer.
        /// </summary>
        /// <typeparam name="T">The type of objects in the feature layer.</typeparam>
        /// <param name="featureLayer">The reference to feature layer to update objects
        /// at.</param>
        /// <param name="updatedObjects">The reference to the collection of objects
        /// to be updated.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="featureLayer"/> or
        /// <paramref name="updatedObjects"/> argument or any of it's elements is a null
        /// reference.</exception>
        /// <exception cref="ESRI.ArcLogistics.Tracking.TrackingService.TrackingServiceException">
        /// Failed to update objects at the feature layer.</exception>
        /// <exception cref="ESRI.ArcLogistics.CommunicationException">Failed
        /// to communicate with the remote service.</exception>
        public static void UpdateObjects <T>(
            this IFeatureLayer <T> featureLayer,
            IEnumerable <T> updatedObjects)
            where T : DataRecordBase, new()
        {
            if (featureLayer == null)
            {
                throw new ArgumentNullException("featureLayer");
            }

            if (updatedObjects == null || updatedObjects.Any(obj => obj == null))
            {
                throw new ArgumentNullException("updatedObjects");
            }

            featureLayer.ApplyEdits(
                Enumerable.Empty <T>(),
                updatedObjects,
                Enumerable.Empty <long>());
        }
        /// <summary>
        /// Adds specified objects to the feature layer.
        /// </summary>
        /// <typeparam name="T">The type of objects in the feature layer.</typeparam>
        /// <param name="featureLayer">The reference to feature layer to add objects to.</param>
        /// <param name="newObjects">The reference to the collection of objects to be added to
        /// the feature layer.</param>
        /// <returns>The reference to the collection of object IDs identifying added
        /// objects.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="featureLayer"/> or
        /// <paramref name="newObjects"/> argument or any of it's elements is a null
        /// reference.</exception>
        /// <exception cref="ESRI.ArcLogistics.Tracking.TrackingService.TrackingServiceException">
        /// Failed to add objects to the feature layer.</exception>
        /// <exception cref="ESRI.ArcLogistics.CommunicationException">Failed
        /// to communicate with the remote service.</exception>
        public static IEnumerable <long> AddObjects <T>(
            this IFeatureLayer <T> featureLayer,
            IEnumerable <T> newObjects)
            where T : DataRecordBase, new()
        {
            if (featureLayer == null)
            {
                throw new ArgumentNullException("featureLayer");
            }

            if (newObjects == null || newObjects.Any(obj => obj == null))
            {
                throw new ArgumentNullException("newObjects");
            }

            return(featureLayer.ApplyEdits(
                       newObjects,
                       Enumerable.Empty <T>(),
                       Enumerable.Empty <long>()));
        }