Ejemplo n.º 1
0
        public JsonAddItemResponse AddItem(AddItemParameters addItemParams, string folderId, string token)
        {
            try
            {
                if (folderId != String.Empty) folderId += "/";
                //TODO: figure out how to generate the URL //01a1484edcb14e0d99cb5b1266e9657b
                Uri url = new Uri(string.Format("http://www.arcgis.com/sharing/content/users/{0}/{1}addItem?f=json&token={2}", userCredentials.Username, folderId, token));
                HttpPostRequest request = new HttpPostRequest(url);

                if (addItemParams.File != String.Empty)
                {
                    request.AddFile("file", addItemParams.File, addItemParams.Filename);
                }
                request.AddFields(addItemParams.GetParameters());

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

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

                return jsonAddItemResponse;

            }

            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 2
0
        public JsonArcGISServerResponse QueryArcGISServer(string server, string folder)
        {
            //get the information from the AGS
            if (folder != String.Empty && !folder.EndsWith("/"))
            {
                folder += "/";
            }
            Uri url = new Uri(string.Format("{0}/{1}?f=json", server, folder));
            HttpPostRequest request = new HttpPostRequest(url);

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

            return agsResponse;
        }
Ejemplo n.º 3
0
        public JsonFolderResponse CreateFolder(CreateFolderParameters createFolderParams, string token)
        {
            //TODO: figure out how to generate the URL
            Uri url = new Uri(string.Format("http://www.arcgis.com/sharing/content/users/{0}/createFolder?f=json&token={1}", userCredentials.Username, token));
            HttpPostRequest request = new HttpPostRequest(url);

            request.AddFields(createFolderParams.GetParameters());

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

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

            return jsonCreateFolderResponse;
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
0
        public bool IsServiceNameAvailable(ServiceNameParameters serviceNameParams)
        {
            //TODO: config this URL
            Uri url = new Uri("https://www.arcgis.com/sharing/generateToken?f=json");
            HttpPostRequest request = new HttpPostRequest(url);
            request.AddFields(serviceNameParams.GetParameters());

            HttpWebResponse response = request.PostData();
            string available = JsonParser.ParseJson("available", response);
            bool result = false;
            bool success = bool.TryParse(available, out result);

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

            return result;
        }
Ejemplo n.º 6
0
        public string GenerateToken(TokenParameters tokenParams)
        {
            //TODO: config this URL
            Uri url = new Uri("https://www.arcgis.com/sharing/generateToken?f=json");
            HttpPostRequest request = new HttpPostRequest(url);
            request.AddFields(tokenParams.GetParameters());

            HttpWebResponse response = request.PostData();
            string token = JsonParser.ParseJson("token", response);

            //TODO: do this error-checking better
            if (String.IsNullOrWhiteSpace(token))
            {
                throw new Exception();
            }

            return token;
        }