Ejemplo n.º 1
0
        //private void GetServices(IArcGISServerCatalog catalog, Action<IArcGISService[]> callback)
        //{
        //    Throw.IfArgumentNull(catalog, "catalog");
        //    Throw.IfArgumentNull(callback, "callback");
        //    string template = catalog.RootUrl + "/{0}/{1}";
        //    ReturnServicesToAction returnServices = new ReturnServicesToAction(ReturnServices);
        //    foreach (ArcGISServiceInfo info in catalog.ServiceInfos)
        //    {
        //        switch (info.Type)
        //        {
        //            case serviceType.FeatureServer:
        //            case serviceType.GeodataServer:
        //            case serviceType.GeometryServer:
        //                this.rest.HydrateAsync<GeometryServer>(
        //                    string.Format(template, info.Name, info.Type.ToString())+ "?" + JSON, cb =>
        //                    {
        //                        returnServices(cb, template, info, callback);
        //                    });
        //                break;
        //            case serviceType.GPServer:
        //                this.rest.HydrateAsync<GeoprocessingServer>(
        //                    string.Format(template, info.Name, info.Type.ToString()) + "?" + JSON, cb =>
        //                    {
        //                        returnServices(cb, template, info, callback);
        //                    });
        //                break;
        //            case serviceType.GeocodeServer:
        //                this.rest.HydrateAsync<GeocodeServer>(
        //                    string.Format(template, info.Name, info.Type.ToString()) + "?" + JSON, cb =>
        //                    {
        //                        returnServices(cb, template, info, callback);
        //                    });
        //                break;
        //            case serviceType.MapServer:
        //                this.rest.HydrateAsync<MapServer>(
        //                    string.Format(template, info.Name, info.Type.ToString()) + "?" + JSON, cb =>
        //                    {
        //                        returnServices(cb, template, info, callback);
        //                    });
        //                break;
        //        }

        //    }
        //}

        /// <summary>
        /// Returns the service.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="url">The URL.</param>
        /// <param name="type">The type.</param>
        /// <param name="version">The ArcGIS Server version.</param>
        /// <returns>
        /// Returns an instance of <see cref="IArcGISService"/>.
        /// </returns>
        private IArcGISService ReturnService(ArcGISService service, string url, serviceType type, double?version)
        {
            Throw.IfArgumentNull(service, "service");
            var token = this.ParseTokenFromUrl(url);

            url = url.Contains("?") ? url.Substring(0, url.IndexOf("?")) : url;
            if (url.EndsWith("/"))
            {
                url = url.Substring(0, url.LastIndexOf("/"));
            }
            string name = url.Substring(0, url.LastIndexOf("/"));

            name                   = name.Substring(name.LastIndexOf("/") + 1);
            service.Name           = name;
            service.RestHelper     = new RestHelper();
            service.Url            = url;
            service.CurrentVersion = version;
            service.ProxyUrl       = this.ProxyUrl;
            service.ServiceType    = type;
            service.Token          = token;
            if (type == serviceType.GPServer)
            {
                PopuplateGPTasks(service);
            }
            return((IArcGISService)service);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Popuplates the GP tasks.
        /// </summary>
        /// <param name="service">The service.</param>
        private void PopuplateGPTasks(ArcGISService service)
        {
            if (!(service is GeoprocessingServer))
            {
                return;
            }
            GeoprocessingServer gpserver = (GeoprocessingServer)service;

            gpserver.Tasks = new List <IGeoprocessingTask>();
            string url = service.Url.EndsWith("/") ? service.Url + "{0}" : service.Url + "/{0}";

            foreach (string task in gpserver.TaskNames)
            {
                string taskurl  = string.Format(url, Uri.EscapeDataString(task));
                string proxyurl = !string.IsNullOrEmpty(this.ProxyUrl)
                    ? this.ProxyUrl + "?" + taskurl + "?" + JSON : taskurl + "?" + JSON;
                GeoprocessingTask gptask = this.rest.Hydrate <GeoprocessingTask>(proxyurl + "&token=" + service.Token);
                if (gptask != null)
                {
                    gptask.Url        = taskurl;
                    gptask.RestHelper = rest;
                }
                gpserver.Tasks.Add(gptask);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Determines whether the service's existing token is valid. If no token exists the method will return
 /// true to indicate that the service can be accessed as-is.
 /// </summary>
 /// <returns>
 /// Whether the existing token is still valid or not.
 /// </returns>
 public bool IsTokenValid()
 {
     if (string.IsNullOrEmpty(this.Token))
     {
         return(true);
     }
     else
     {
         try
         {
             ArcGISService service = null;
             var           url     = string.Format("{0}?token={1}", Url, this.Token);
             if (Url.Contains(Enum.GetName(typeof(serviceType), serviceType.MapServer)))
             {
                 service = Geocrest.Model.RestHelper.HydrateObject <MapServer>(url);
             }
             if (Url.Contains(Enum.GetName(typeof(serviceType), serviceType.GeocodeServer)))
             {
                 service = Geocrest.Model.RestHelper.HydrateObject <GeocodeServer>(url);
             }
             if (Url.Contains(Enum.GetName(typeof(serviceType), serviceType.GPServer)))
             {
                 service = Geocrest.Model.RestHelper.HydrateObject <GeoprocessingServer>(url);
             }
             if (Url.Contains(Enum.GetName(typeof(serviceType), serviceType.GeometryServer)))
             {
                 service = Geocrest.Model.RestHelper.HydrateObject <GeometryServer>(url);
             }
             if (Url.Contains(Enum.GetName(typeof(serviceType), serviceType.FeatureServer)))
             {
                 service = Geocrest.Model.RestHelper.HydrateObject <FeatureServer>(url);
             }
             if (Url.Contains(Enum.GetName(typeof(serviceType), serviceType.MobileServer)))
             {
                 service = Geocrest.Model.RestHelper.HydrateObject <MobileServer>(url);
             }
             return(service != null);
         }
         catch (HttpException ex)
         {
             int code = ex.GetHttpCode();
             return(!(code == 498 || code == 499));
         }
     }
 }