Exemplo n.º 1
0
        /// <summary>
        /// Gets full map extent from discovery service.
        /// </summary>
        /// <param name="knownTypes">Collection of known types to parse result.</param>
        /// <returns>Full map extent.</returns>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="knownTypes"/> is null reference.</exception>
        public GPEnvelope GetFullMapExtent(IEnumerable <Type> knownTypes)
        {
            // Validate input.
            if (knownTypes == null)
            {
                throw new ArgumentNullException("knownTypes");
            }

            var context = new RequestContext(_server.OpenConnection(), knownTypes);

            // Get appropriate query to discovery service.
            string query = RestHelper.BuildQueryString(new RequestBase(),
                                                       DiscoveryRequestBuilder.JsonTypes, false);

            // Get response from service.
            var response = _client.GetDiscoveryServiceInfo(query, context);

            if (response == null || response.FullExtent == null)
            {
                throw new RouteException(
                          Properties.Messages.Error_GetDiscoveryServiceConfigFailed);
            }

            return(response.FullExtent);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves collection of object IDs for the specified where clause.
        /// </summary>
        /// <param name="whereClause">The where clause specifying feature records to get IDs
        /// for.</param>
        /// <returns>A reference to the collection of object IDs for feature records satisfying
        /// the specified where clause.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="whereClause"/> is a null
        /// reference.</exception>
        /// <exception cref="ESRI.ArcLogistics.Tracking.TrackingService.TrackingServiceException">
        /// Failed to apply query ids from the feature layer.</exception>
        /// <exception cref="ESRI.ArcLogistics.CommunicationException">failed
        /// to communicate with the REST service.</exception>
        public IEnumerable <long> QueryObjectIDs(string whereClause)
        {
            if (whereClause == null)
            {
                throw new ArgumentNullException("whereClause");
            }

            var request = new QueryRequest
            {
                WhereClause   = whereClause,
                ReturnIDsOnly = true,
            };

            var query   = RestHelper.BuildQueryString(request, Enumerable.Empty <Type>(), true);
            var url     = string.Format(QUERY_URL_FORMAT, _uri.AbsoluteUri);
            var options = new HttpRequestOptions
            {
                Method          = HttpMethod.Post,
                UseGZipEncoding = true,
            };

            var response = _requestSender.SendRequest <ObjectIDsResponse>(url, query, options);

            // If result is null - return empty collection.
            var result = response.ObjectIDs;

            if (result == null)
            {
                result = new List <long>();
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Filters collection of object IDs by removing inexistent ones.
        /// </summary>
        /// <param name="objectIDs">The reference to the collection of object IDs
        /// to be filtered.</param>
        /// <returns>A reference to the collection of object IDs for feature records which exists
        /// at the feature service.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="objectIDs"/> is a null
        /// reference.</exception>
        /// <exception cref="ESRI.ArcLogistics.Routing.RestException">error was
        /// returned by the REST API.</exception>
        /// <exception cref="ESRI.ArcLogistics.CommunicationException">failed
        /// to communicate with the REST service.</exception>
        public IEnumerable <long> FilterObjectIDs(IEnumerable <long> objectIDs)
        {
            if (objectIDs == null)
            {
                throw new ArgumentNullException("objectIDs");
            }

            var request = new QueryRequest
            {
                ObjectIDs     = string.Join(",", objectIDs),
                ReturnIDsOnly = true,
            };

            var query   = RestHelper.BuildQueryString(request, Enumerable.Empty <Type>(), true);
            var url     = string.Format(QUERY_URL_FORMAT, _uri.AbsoluteUri);
            var options = new HttpRequestOptions
            {
                Method          = HttpMethod.Post,
                UseGZipEncoding = true,
            };

            var response = _requestSender.SendRequest <ObjectIDsResponse>(url, query, options);

            return(response.ObjectIDs);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets geographic region name.
        /// </summary>
        /// <param name="request">Discovery request.</param>
        /// <param name="knownTypes">Collection of known types to parse result.</param>
        /// <returns>Region name if successfully found.</returns>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="request"/> or <paramref name="knownTypes"/> is null reference.
        /// </exception>
        /// <exception cref="T:ESRI.ArcLogistics.Routing.RouteException">
        /// Result region name is null or empty string.</exception>
        public string GetRegionName(SubmitDiscoveryRequest request, IEnumerable <Type> knownTypes)
        {
            // Validate inputs.
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (knownTypes == null)
            {
                throw new ArgumentNullException("knownTypes");
            }

            // Create appropriate service client to make requests.
            string baseUrl = UriHelper.Concat(_discoveryServiceConfig.RestUrl,
                                              QUERY_OBJ_IDENTIFY);
            var client = new DiscoveryClient(baseUrl, _server.OpenConnection());

            // Get query and context.
            string query = RestHelper.BuildQueryString(request,
                                                       DiscoveryRequestBuilder.JsonTypes, false);
            var context = new RequestContext(_server.OpenConnection(), knownTypes);

            // Get response from service.
            var response = client.GetRegionName(query, context);

            // Try to get region name from response.
            string regionName = string.Empty;

            if (response != null && response.Results != null)
            {
                // Get any first description object from the collection.
                var parameterObject = response.Results.FirstOrDefault();

                if (parameterObject != null && parameterObject.Attributes != null)
                {
                    // Get region name from anyone attributes collection.
                    parameterObject.Attributes.TryGet(REGION_MEMBER_NAME, out regionName);
                }
            }

            if (string.IsNullOrEmpty(regionName))
            {
                throw new RouteException(Properties.Messages.Error_InvalidRegionInformation);
            }

            return(regionName);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Retrieves collection of feature records for the specified request.
        /// </summary>
        /// <param name="request">The request specifying objects to be retrieved.</param>
        /// <returns>A collection of feature records satisfying the specified request.</returns>
        /// <exception cref="ESRI.ArcLogistics.Routing.RestException">error was
        /// returned by the REST API.</exception>
        /// <exception cref="ESRI.ArcLogistics.CommunicationException">failed
        /// to communicate with the REST service.</exception>
        private IEnumerable <TFeatureRecord> _QueryData(QueryRequest request)
        {
            Debug.Assert(request != null);

            var query   = RestHelper.BuildQueryString(request, Enumerable.Empty <Type>(), true);
            var url     = string.Format(QUERY_URL_FORMAT, _uri.AbsoluteUri);
            var options = new HttpRequestOptions
            {
                Method          = HttpMethod.Post,
                UseGZipEncoding = true,
            };

            var response = _requestSender.SendRequest <FeatureRecordSetLayer>(url, query, options);
            var data     = response.Features.Select(_mapper.MapObject).ToList();

            return(data);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Loads feature layer description from the specified URL.
        /// </summary>
        /// <param name="featureLayerUrl">The URL of the feature layer to load
        /// description for.</param>
        /// <returns>A reference to the feature layer description obtained at the
        /// specified URL.</returns>
        private LayerDescription _LoadLayerDescription(Uri featureLayerUrl)
        {
            Debug.Assert(featureLayerUrl != null);

            var request = new ESRI.ArcLogistics.Tracking.TrackingService.Requests.RequestBase();
            var query   = RestHelper.BuildQueryString(request, Enumerable.Empty <Type>(), true);
            var options = new HttpRequestOptions
            {
                Method          = HttpMethod.Get,
                UseGZipEncoding = true,
            };

            var layerDescription = _requestSender.SendRequest <LayerDescription>(
                featureLayerUrl.AbsoluteUri,
                query,
                options);

            return(layerDescription);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a new instance of the <see cref="FeatureService"/> class with the specified
        /// url.
        /// </summary>
        /// <param name="serviceUrl">The URL of the feature service to be created.</param>
        /// <param name="server">The reference to the feature services server object.</param>
        /// <returns>A reference to the feature service object for the specified URL.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="serviceUrl"/>
        /// argument is a null reference.</exception>
        public static IFeatureService Create(Uri serviceUrl, AgsServer server)
        {
            if (serviceUrl == null)
            {
                throw new ArgumentNullException("serviceUrl");
            }

            var requestSender = new FeatureServiceRequestSender(server);

            var serviceQueryUri = string.Format(SERVICE_QUERY_FORMAT, serviceUrl.AbsoluteUri);
            var options         = new HttpRequestOptions
            {
                Method          = HttpMethod.Get,
                UseGZipEncoding = true,
            };

            var request = new ESRI.ArcLogistics.Tracking.TrackingService.Requests.RequestBase();
            var query   = RestHelper.BuildQueryString(request, Enumerable.Empty <Type>(), true);

            var info = requestSender.SendRequest <ServiceInfo>(serviceQueryUri, query, options);

            return(new FeatureService(new Uri(serviceQueryUri), info, requestSender));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Applies specified edits to the feature layer.
        /// </summary>
        /// <param name="newObjects">The reference to the collection of feature records to
        /// be added to the layer. Values of object ID field will be ignored.</param>
        /// <param name="updatedObjects">The reference to the collection of feature records
        /// to be updated.</param>
        /// <param name="deletedObjectIDs">The reference to the collection of object IDs of
        /// feature records to be deleted.</param>
        /// <returns>A reference to the collection of object IDs of added feature
        /// records.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="newObjects"/>,
        /// <paramref name="updatedObjects"/>, <paramref name="deletedObjectIDs"/> or any element
        /// in the <paramref name="newObjects"/> or <paramref name="updatedObjects"/> is a null
        /// reference.</exception>
        /// <exception cref="ESRI.ArcLogistics.Tracking.TrackingService.TrackingServiceException">
        /// Failed to apply edits to the feature layer.</exception>
        /// <exception cref="ESRI.ArcLogistics.CommunicationException">failed
        /// to communicate with the REST service.</exception>
        public IEnumerable <long> ApplyEdits(
            IEnumerable <TFeatureRecord> newObjects,
            IEnumerable <TFeatureRecord> updatedObjects,
            IEnumerable <long> deletedObjectIDs)
        {
            if (newObjects == null || newObjects.Any(obj => obj == null))
            {
                throw new ArgumentNullException("newObjects");
            }

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

            if (deletedObjectIDs == null)
            {
                throw new ArgumentNullException("deletedObjectIDs");
            }

            if (!newObjects.Any() && !updatedObjects.Any() && !deletedObjectIDs.Any())
            {
                return(Enumerable.Empty <long>());
            }

            var itemsToDelete = updatedObjects.Where(
                item => item.Deleted == DeletionStatus.Deleted);

            if (typeof(TFeatureRecord) == typeof(Device) && itemsToDelete.Any())
            {
                var itemsMessages = JsonSerializeHelper.Serialize(
                    itemsToDelete.Select(_mapper.MapObject).ToArray());
                var messageBuilder = new StringBuilder();
                messageBuilder.AppendFormat(
                    "Executing deletion for {0} records:\n",
                    typeof(TFeatureRecord));
                messageBuilder.Append(string.Join("\n", itemsMessages));

                Logger.Info(messageBuilder.ToString());
            }

            var request = new ApplyEditsRequest
            {
                Adds = JsonProcHelper.DoPostProcessing(JsonSerializeHelper.Serialize(newObjects
                                                                                     .Select(_mapper.MapObject)
                                                                                     .ToArray(),
                                                                                     VrpRequestBuilder.JsonTypes)),
                Updates = JsonProcHelper.DoPostProcessing(JsonSerializeHelper.Serialize(updatedObjects
                                                                                        .Select(_mapper.MapObject)
                                                                                        .ToArray(),
                                                                                        VrpRequestBuilder.JsonTypes)),
                Deletes = string.Join(",", deletedObjectIDs),
            };

            var query   = RestHelper.BuildQueryString(request, Enumerable.Empty <Type>(), true);
            var url     = string.Format(APPLY_EDITS_URL_FORMAT, _uri.AbsoluteUri);
            var options = new HttpRequestOptions
            {
                Method          = HttpMethod.Post,
                UseGZipEncoding = true,
            };

            var response = _requestSender.SendRequest <ApplyEditsResponse>(url, query, options);

            var failures = response
                           .AddResults
                           .Concat(response.UpdateResults)
                           .Concat(response.DeleteResults)
                           .Where(editResult => !editResult.Succeeded)
                           .Select(editResult => editResult.Error)
                           .Distinct()
                           .Select(error => error == null ? null : new TrackingServiceError(
                                       error.Code,
                                       error.Description));

            if (failures.Any())
            {
                var msg = string.Format(
                    Properties.Messages.Error_FeatureLayerCannotApplyEdits,
                    _layerDescription.Name ?? string.Empty);
                throw new TrackingServiceException(msg, failures);
            }

            var ids = response.AddResults
                      .Select(addResult => addResult.ObjectID)
                      .ToList();

            return(ids);
        }