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)); }
/// <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)); }
/// <summary> /// Maps the specified feature record data object into corresponding feature. /// </summary> /// <param name="featureData">The reference to the feature record data object /// to be mapped.</param> /// <returns>A reference to a new feature record with the specified data.</returns> /// <exception cref="System.ArgumentNullException"><paramref name="featureData"/> is a /// null reference.</exception> public TFeatureRecord MapObject(FeatureRecordData featureData) { if (featureData == null) { throw new ArgumentNullException("featureData"); } var feature = new TFeatureRecord(); var objectID = featureData.Attributes.TryGet <long>(_layerDescription.ObjectIDField); if (objectID.HasValue) { feature.ObjectID = objectID.Value; } var featureGeometry = featureData.Geometry; if (_locationProperty != null && featureGeometry != null) { var geometry = default(object); var gpGeometry = featureGeometry; if (gpGeometry is GPPoint) { geometry = GPObjectHelper.GPPointToPoint((GPPoint)gpGeometry); } else if (gpGeometry is GPPolyline) { geometry = GPObjectHelper.GPPolylineToPolyline((GPPolyline)gpGeometry); } else if (gpGeometry is GPPolygon) { geometry = GPObjectHelper.GPPolygonToPolygon((GPPolygon)gpGeometry); } _locationProperty.SetValue(feature, geometry); } var knownAttributes = featureData.Attributes .Where(item => _properties.ContainsKey(item.Key)); foreach (var item in knownAttributes) { var property = _properties[item.Key]; _ExtractValue(item.Value, property.PropertyType) .Do(value => property.SetValue(feature, value)); } return(feature); }
/// <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()); }
/// <summary> /// Method collects information from solve request data for planned date and /// builds request object. /// </summary> /// <param name="data">Required data to get information from.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="data"/> is null reference.</exception> /// <returns>Request object with filled information for request.</returns> public SubmitDiscoveryRequest BuildRequest(DiscoveryRequestData data) { // Validate inputs. if (data == null) { throw new ArgumentNullException("data"); } // Build request object. SubmitDiscoveryRequest req = new SubmitDiscoveryRequest(); if (data.RegionPoint != null) { int wkid = data.MapExtent.SpatialReference.WKID; // Get depot point converted with correct spatial reference. Point depotPoint = (Point)data.RegionPoint; Point wmPoint = WebMercatorUtil.ProjectPointToWebMercator(depotPoint, wkid); GPPoint gpPoint = GPObjectHelper.PointToGPPoint(wmPoint); gpPoint.SpatialReference = new GPSpatialReference(wkid); // Fill required options. req.Geometry = gpPoint; req.GeometryType = NAGeometryType.esriGeometryPoint; req.SpatialReference = wkid; req.ResponseFormat = NAOutputFormat.JSON; req.Layers = NAIdentifyOperationLayers.AllLayers; req.Tolerance = DEFAULT_TOLERANCE; req.ImageDisplay = _GetImageDisplayParameter(data.MapExtent); req.MapExtent = string.Format(MAP_EXTENT_PARAMETER_FORMAT, data.MapExtent.XMin, data.MapExtent.YMin, data.MapExtent.XMax, data.MapExtent.YMax); // Do not return geometry to optimize request. req.ReturnGeometry = false; req.ReturnZ = false; req.ReturnM = false; // Fill non-required options. req.LayerDefinitions = string.Empty; req.Time = string.Empty; req.LayerTimeOptions = string.Empty; req.MaxAllowableOffset = string.Empty; req.DynamicLayers = string.Empty; } return(req); }
/// <summary> /// Convert Point Barrier into GPFeature. /// </summary> /// <param name="barrier">Barrier to convert</param> /// <returns>Point barrier GPFeature</returns> private GPFeature _ConvertToPointFeature(Barrier barrier) { Debug.Assert(barrier != null); GPFeature feature = new GPFeature(); feature.Geometry = new GeometryHolder(); // Convert geometry. feature.Geometry.Value = GPObjectHelper.PointToGPPoint((Point)barrier.Geometry); // Fill attributes. feature.Attributes = _GetAttributes(barrier, BarrierGeometryType.Point); return(feature); }
/// <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>()); }
/// <summary> /// Converts the specified geometry object to corresponding GP Geometry object. /// </summary> /// <param name="geometry">A reference to the geometry object to be converted.</param> /// <returns>A new <see cref="GeometryHolder"/> with corresponding GP Geometry object /// or null reference if <paramref name="geometry"/> is null.</returns> private static GPGeometry _ConvertGeometryToGPGeometry(object geometry) { if (geometry == null) { return(null); } var gpGeometry = new GPGeometry(); if (geometry.GetType().IsAssignableFrom(typeof(Point))) { gpGeometry = GPObjectHelper.PointToGPPoint((Point)geometry); } else if (geometry.GetType().IsAssignableFrom(typeof(Polyline))) { gpGeometry = GPObjectHelper.PolylineToGPPolyline((Polyline)geometry); } else if (geometry.GetType().IsAssignableFrom(typeof(Polygon))) { gpGeometry = GPObjectHelper.PolygonToGPPolygon((Polygon)geometry); } return(gpGeometry); }
/// <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)); }
/// <summary> /// Method gets stops date from route. /// </summary> /// <param name="route">Route to get information.</param> /// <returns>Collection of stops data.</returns> private List <StopData> _GetStops(Route route) { Debug.Assert(route != null); IDataObjectCollection <Stop> stops = route.Stops; int stopsCount = stops.Count; var stopDatas = new List <StopData>(stopsCount); for (int index = 0; index < stopsCount; ++index) { Stop stop = stops[index]; StopData sd = new StopData(); sd.SequenceNumber = stop.SequenceNumber; sd.Distance = stop.Distance; sd.WaitTime = stop.WaitTime; sd.TimeAtStop = stop.TimeAtStop; sd.TravelTime = stop.TravelTime; sd.ArriveTime = (DateTime)stop.ArriveTime; if (stop.StopType == StopType.Lunch) { // Break. // ToDo - need update logic - now find only first TWBreak. var twBreaks = from currBreak in route.Breaks where currBreak is TimeWindowBreak select currBreak; TimeWindowBreak rtBreak = twBreaks.FirstOrDefault() as TimeWindowBreak; if (rtBreak != null && rtBreak.Duration > 0.0) { // TODO Break //// Time window. //DateTime? twStart = null; //DateTime? twEnd = null; //if (rtBreak.TimeWindow != null) // _ConvertTW(rtBreak.TimeWindow, out twStart, out twEnd); sd.TimeWindowStart1 = _TSToDate(rtBreak.From); sd.TimeWindowEnd1 = _TSToDate(rtBreak.To); } } else { Debug.Assert(stop.AssociatedObject != null); // Associated object id. sd.AssociatedObject = stop.AssociatedObject; // Geometry. Point pt = _GetStopPoint(stop); sd.Geometry = GPObjectHelper.PointToGPPoint(pt); // Time windows. DateTime?twStart1 = null; DateTime?twStart2 = null; DateTime?twEnd1 = null; DateTime?twEnd2 = null; // Type-specific data. if (stop.StopType == StopType.Order) { Order order = stop.AssociatedObject as Order; Debug.Assert(order != null); // Curbapproach. sd.NACurbApproach = CurbApproachConverter.ToNACurbApproach( _context.SolverSettings.GetDepotCurbApproach()); // Time window 1. if (order.TimeWindow != null) { _ConvertTW(order.TimeWindow, out twStart1, out twEnd1); } // Time window 2. if (order.TimeWindow2 != null) { _ConvertTW(order.TimeWindow2, out twStart2, out twEnd2); } } else if (stop.StopType == StopType.Location) { Location loc = stop.AssociatedObject as Location; Debug.Assert(loc != null); // Time window. if (loc.TimeWindow != null) { _ConvertTW(loc.TimeWindow, out twStart1, out twEnd1); } } sd.TimeWindowStart1 = twStart1; sd.TimeWindowStart2 = twStart2; sd.TimeWindowEnd1 = twEnd1; sd.TimeWindowEnd2 = twEnd2; } sd.RouteId = route.Id; sd.StopType = stop.StopType; stopDatas.Add(sd); } SolveHelper.ConsiderArrivalDelayInStops( _context.SolverSettings.ArriveDepartDelay, stopDatas); return(stopDatas); }
/// <summary> /// Deserializes <see cref="System.DateTime"/> values. /// </summary> /// <param name="value">The number of milliseconds to be converted to /// <see cref="System.DateTime"/> value.</param> /// <returns>Deserialized <see cref="System.DateTime"/> object.</returns> private static object _DeserializeDateTime(object value) { return(GPObjectHelper.GPDateTimeToDateTime(Convert.ToInt64(value))); }