Esempio n. 1
0
        private static void CheckStatusCompletedEventHandler(object sender, StatusCompletedEventArgs e)
        {
            //  "status": "partial | processing | failed | completed"
            if (e.Response.status == "completed")
            {
                AGOLClient client = new AGOLClient(userCreds);

                Console.WriteLine("Publishing Feature Service");
                PublishItemParameters publishParams = new PublishItemParameters("shapefile");
                publishParams.ItemId = e.Response.itemId;
                (publishParams.PublishParameters as PublishParametersShapefile).name = "Myservicetest";
                (publishParams.PublishParameters as PublishParametersShapefile).description = "My service description";
                JsonPublishResponse publishResponse = client.Publish(publishParams, token);

                foreach (JsonServiceResponse serviceResponse in publishResponse.services)
                {
                    Console.WriteLine(string.Format("{0} published", serviceResponse.type));
                    Console.WriteLine(string.Format("{0}", serviceResponse.serviceItemId));
                    Console.WriteLine(string.Format("{0}\n", serviceResponse.serviceurl));
                }

                if (publishResponse.services.Length == 0)
                {
                    Console.WriteLine(string.Format("Service publishing failed\n"));
                }
            }

            Console.WriteLine("\nPress Esc to quit");
        }
Esempio n. 2
0
        public JsonPublishResponse Publish(PublishItemParameters publishParams, string token)
        {
            try
            {
                //TODO: figure out how to generate the URL
                Uri url = new Uri(string.Format("http://www.arcgis.com/sharing/content/users/{0}/publish?f=json&token={1}", userCredentials.Username, token));
                HttpPostRequest request = new HttpPostRequest(url);

                request.AddFields(publishParams.GetParameters());

                HttpWebResponse response = request.PostData();
                StreamReader sr = new StreamReader(response.GetResponseStream());
                JsonPublishResponse jsonPublishResponse = JsonConvert.DeserializeObject<JsonPublishResponse>(sr.ReadToEnd());

                bool result = false;
                bool parseSuccess = true; //TODO!! bool.TryParse(jsonPublishResponse.type, out result);

                //TODO: do this error-checking better
                if (!parseSuccess)
                {
                    throw new Exception();
                }

                return jsonPublishResponse;

            }

            catch (Exception e)
            {
                throw e;
            }
        }