Exemplo n.º 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>
        /// Serializes <see cref="System.DateTime"/> values.
        /// </summary>
        /// <param name="value">The <see cref="System.DateTime"/> instance
        /// to be serialized.</param>
        /// <returns>Serialized <see cref="System.DateTime"/> object.</returns>
        private static object _SerializeDateTime(object value)
        {
            if (value == null)
            {
                return(null);
            }

            return(GPObjectHelper.DateTimeToGPDateTime((DateTime)value));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets all events for the specified mobile device at the specified dates range.
        /// </summary>
        /// <param name="deviceID">Object ID identifying mobile device to get events for.</param>
        /// <param name="fromTime">Starting date time to get events for.</param>
        /// <param name="toTime">Ending date time to get events for.</param>
        /// <returns>Collection of events for the specified mobile device the specified
        /// dates range.</returns>
        /// <exception cref="ESRI.ArcLogistics.Tracking.TrackingService.TrackingServiceException">
        /// Failed to retrieve events from the tracking service.</exception>
        /// <exception cref="ESRI.ArcLogistics.CommunicationException">Failed
        /// to communicate with the remote service.</exception>
        public IEnumerable <Event> GetEvents(long deviceID, DateTime fromTime, DateTime toTime)
        {
            var whereClause = string.Format(
                QUERY_FORMATTER,
                EVENTS_QUERY_WHERE_CLAUSE,
                GPObjectHelper.DateTimeToGPDateTime(fromTime),
                GPObjectHelper.DateTimeToGPDateTime(toTime),
                deviceID);

            var ids = _eventsLayer.QueryObjectIDs(whereClause);

            return(_eventsLayer.QueryObjectsByIDs(ids));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets list with all(either deleted or non deleted) stops for the mobile device
        /// with the specified object ID from the tracking service.
        /// </summary>
        /// <param name="mobileDeviceID">The object ID of the mobile device to get stops
        /// for.</param>
        /// <param name="plannedDate">The date/time to retrieve stops for.</param>
        /// <returns>Collection of stops for the mobile device with the specified
        /// object ID.</returns>
        /// <exception cref="ESRI.ArcLogistics.Tracking.TrackingService.TrackingServiceException">
        /// Failed to retrieve stops from the tracking service.</exception>
        /// <exception cref="ESRI.ArcLogistics.CommunicationException">Failed
        /// to communicate with the remote service.</exception>
        public IEnumerable <Stop> GetAllStops(long mobileDeviceID, DateTime plannedDate)
        {
            var whereClause = string.Format(
                QUERY_FORMATTER,
                STOPS_BY_DEVICE_QUERY_WHERE_CLAUSE,
                mobileDeviceID,
                GPObjectHelper.DateTimeToGPDateTime(plannedDate));
            var deviceStops = _stopsLayer.QueryData(
                whereClause,
                ALL_FIELDS,
                GeometryReturningPolicy.WithoutGeometry).ToList();

            return(deviceStops.ToList());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Updates route settings for the specified date.
        /// </summary>
        /// <param name="plannedDate">The date to update route settings for.</param>
        /// <param name="routeSettings">The reference to serialized route settings.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="routeSettings"/>
        /// argument is a null reference.</exception>
        /// <exception cref="ESRI.ArcLogistics.Tracking.TrackingService.TrackingServiceException">
        /// Failed to update route settings at the tracking service.</exception>
        /// <exception cref="ESRI.ArcLogistics.CommunicationException">Failed
        /// to communicate with the remote service.</exception>
        public void UpdateRouteSettings(DateTime plannedDate, string routeSettings)
        {
            if (routeSettings == null)
            {
                throw new ArgumentNullException("routeSettings");
            }

            plannedDate = plannedDate.Date;

            // Split route settings into multiple records due to feature service limitation.
            var parts    = routeSettings.SplitToChunks(MAX_STRING_SIZE);
            var settings = parts
                           .Select((part, index) =>
                                   new Setting
            {
                KeyID       = ROUTE_SETTINGS_KEY,
                PlannedDate = plannedDate,
                PartIndex   = index,
                Value       = new string(part.ToArray()),
            })
                           .ToList();

            _PrepareAddition(settings);

            // Retrieve IDs of existing route settings for planned date.
            var whereClause = string.Format(
                QUERY_FORMATTER,
                SETTINGS_QUERY_WHERE_CLAUSE,
                ROUTE_SETTINGS_KEY,
                GPObjectHelper.DateTimeToGPDateTime(plannedDate));
            var existingIDs     = _settingsLayer.QueryObjectIDs(whereClause);
            var deletedSettings = _PrepareDeletion <Setting>(existingIDs);

            // Delete current settings and add new ones in a single transaction.
            _settingsLayer.ApplyEdits(
                settings,
                deletedSettings,
                Enumerable.Empty <long>());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Format query which will return undeleted object for planned date with the
        /// specified mobile devices IDs from the tracking service.
        /// </summary>
        /// <param name="mobileDevicesIDs">List of mobile devices IDs.</param>
        /// <param name="plannedDate">The date/time to retrieve objects for.</param>
        /// <returns>Query string.</returns>
        private string _FormatUndeletedObjectsForPlannedDateQuery
            (IEnumerable <long> mobileDevicesIDs, DateTime plannedDate)
        {
            // Create query string for undeleted objects for specified date.
            var sb = new StringBuilder();

            sb.AppendFormat(
                QUERY_FORMATTER,
                NON_DELETED_OBJECTS_FOR_DATE_QUERY_WHERE_CLAUSE,
                GPObjectHelper.DateTimeToGPDateTime(plannedDate));

            // Add mobile devices IDs condition.
            sb.Append(AND_CLAUSE);
            sb.Append(OPEN_BRACKET);
            foreach (var deviceID in mobileDevicesIDs)
            {
                sb.AppendFormat(QUERY_FORMATTER, DEVICEID_OR_CLAUSE, deviceID);
            }
            // Remove last 'OR' from sb.
            sb.Remove(sb.Length - 1 - OR_LENGTH, OR_LENGTH);
            sb.Append(CLOSING_BRACKET);

            return(sb.ToString());
        }
        /// <summary>
        /// Sets time window attributes with specified names in the specified attributes dictionary.
        /// </summary>
        /// <param name="dictionary">The dictionary to set attributes for.</param>
        /// <param name="window">The time window to get attribute values from.</param>
        /// <param name="plannedDate">The date/time when time window should be applied.</param>
        /// <param name="timeWindowStartAttribute">The name of the time window start
        /// attribute.</param>
        /// <param name="timeWindowEndAttribute">The name of the time window end
        /// attribute.</param>
        public static void SetTimeWindow(
            this AttrDictionary dictionary,
            TimeWindow window,
            DateTime plannedDate,
            string timeWindowStartAttribute,
            string timeWindowEndAttribute)
        {
            Debug.Assert(dictionary != null);
            Debug.Assert(window != null);
            Debug.Assert(!string.IsNullOrEmpty(timeWindowStartAttribute));
            Debug.Assert(!string.IsNullOrEmpty(timeWindowEndAttribute));

            if (window.IsWideOpen)
            {
                dictionary.Set(timeWindowStartAttribute, null);
                dictionary.Set(timeWindowEndAttribute, null);

                return;
            }

            // Time window is not wide-open so we apply it to the specified planned date and
            // attribute values in the dictionary.
            var dates = window.ToDateTime(plannedDate);

            var from = dates.Item1.Value;

            dictionary.Add(
                timeWindowStartAttribute,
                GPObjectHelper.DateTimeToGPDateTime(from));

            var to = dates.Item2.Value;

            dictionary.Add(
                timeWindowEndAttribute,
                GPObjectHelper.DateTimeToGPDateTime(to));
        }