diff --git a/ArcGISRESTAdmin/AGSClient.cs b/ArcGISRESTAdmin/AGSClient.cs index c511deb..491e7b0 100644 --- a/ArcGISRESTAdmin/AGSClient.cs +++ b/ArcGISRESTAdmin/AGSClient.cs @@ -95,8 +95,7 @@ public async Task Authenticate() var data = new[] { new KeyValuePair("username", encryptedUsername), new KeyValuePair("password", encryptedPassword), new KeyValuePair("client", encryptedClient), - new KeyValuePair("encrypted", "true"), - new KeyValuePair("f", "json") }; + new KeyValuePair("encrypted", "true") }; var content = new FormUrlEncodedContent(data); var tokenInfo = await PostAsync(tokenEndpoint, content, addToken: false); @@ -193,7 +192,8 @@ public async Task PublishServiceDefinition(System.IO.FileInfo fi) // Publish Service Definition GP tool takes one required parameter in_sdp_id which specifies the ID of the uploaded .sd // simply omitting other optional parameters var parms = new[] { new KeyValuePair("in_sdp_id", uploadResponse.item.itemID) }; - + + // Publish Service Definition is a system published GP tool hosted outside the main ArcGIS for Server Admin REST API Uri publishEndpoint = new Uri(ServerUrl, "/arcgis/rest/services/System/PublishingTools/GPServer/Publish Service Definition/submitJob"); var publishResponse = await GetStringAsync(publishEndpoint, parms); @@ -224,9 +224,8 @@ public async Task UploadItem(System.IO.FileInfo fi, string descr fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream"); content.Add(fileContent); - // other parameters + // add description if provided if (!string.IsNullOrEmpty(description)) content.Add(new StringContent(description), "description"); - content.Add(new StringContent("json"), "f"); UploadResponse response = await PostAsync(uploadEndpoint, content); diff --git a/ArcGISRESTAdmin/Classes/JsonConverters.cs b/ArcGISRESTAdmin/Classes/JsonConverters.cs index af8c692..72dc32f 100644 --- a/ArcGISRESTAdmin/Classes/JsonConverters.cs +++ b/ArcGISRESTAdmin/Classes/JsonConverters.cs @@ -4,9 +4,6 @@ // All other rights reserved. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using Newtonsoft.Json; namespace ArcGISRESTAdmin.Classes diff --git a/ArcGISRESTAdmin/Classes/LogMessage.cs b/ArcGISRESTAdmin/Classes/LogMessage.cs index a2454a9..f597a39 100644 --- a/ArcGISRESTAdmin/Classes/LogMessage.cs +++ b/ArcGISRESTAdmin/Classes/LogMessage.cs @@ -4,10 +4,6 @@ // All other rights reserved. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Newtonsoft.Json; namespace ArcGISRESTAdmin.Classes diff --git a/ArcGISRESTAdmin/Classes/LogQueryResponse.cs b/ArcGISRESTAdmin/Classes/LogQueryResponse.cs index e594a41..9f95da6 100644 --- a/ArcGISRESTAdmin/Classes/LogQueryResponse.cs +++ b/ArcGISRESTAdmin/Classes/LogQueryResponse.cs @@ -4,10 +4,6 @@ // All other rights reserved. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Newtonsoft.Json; namespace ArcGISRESTAdmin.Classes diff --git a/ArcGISRESTAdmin/Classes/ServicesResponse.cs b/ArcGISRESTAdmin/Classes/ServicesResponse.cs index 18ada0a..5d44bed 100644 --- a/ArcGISRESTAdmin/Classes/ServicesResponse.cs +++ b/ArcGISRESTAdmin/Classes/ServicesResponse.cs @@ -3,12 +3,6 @@ // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. // All other rights reserved. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace ArcGISRESTAdmin.Classes { public class ServicesResponse diff --git a/ArcGISRESTAdmin/EncodingHelper.cs b/ArcGISRESTAdmin/EncodingHelper.cs index 6f6f2ef..00003e5 100644 --- a/ArcGISRESTAdmin/EncodingHelper.cs +++ b/ArcGISRESTAdmin/EncodingHelper.cs @@ -4,18 +4,22 @@ // All other rights reserved. using System; -using System.Collections.Generic; -using System.Linq; using System.Text; -using System.Threading.Tasks; namespace ArcGISRESTAdmin { + /// + /// A set of helper methods for converting to/from various encoding formats used by the ArcGIS for Server Admin REST API. + /// public static class EncodingHelper { - private static readonly DateTime UnixEpoch = - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + /// + /// Converts a hex-encoded string to the corresponding byte array. + /// + /// Hex-encoded string + /// Byte representation of the hex-encoded input public static byte[] HexToBytes(string hex) { int length = hex.Length; @@ -28,22 +32,35 @@ public static byte[] HexToBytes(string hex) byte[] bytes = new byte[length / 2]; for (int i = 0; i < length; i += 2) + { bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16); + } return bytes; } + /// + /// Hex-encodes a byte array. + /// + /// Byte array to encode + /// Hex-encoded string public static string BytesToHex(byte[] bytes) { - StringBuilder stringBuilder = new StringBuilder(bytes.Length * 2); + StringBuilder sb = new StringBuilder(bytes.Length * 2); + for (int i = 0; i < bytes.Length; i++) { - byte b = bytes[i]; - stringBuilder.AppendFormat("{0:x2}", b); + sb.AppendFormat("{0:x2}", bytes[i]); } - return stringBuilder.ToString(); + + return sb.ToString(); } + /// + /// Return the given DateTime as the count of milliseconds since the Unix epoch (1970-01-01). + /// + /// + /// public static long GetUnixTimestampMillis(DateTime dateTime) { dateTime = dateTime.ToUniversalTime(); @@ -51,24 +68,23 @@ public static long GetUnixTimestampMillis(DateTime dateTime) return (long)totalMs; } + /// + /// Return the current UTC date and time as the count of milliseconds since the Unix epoch (1970-01-01). + /// + /// public static long GetCurrentUnixTimestampMillis() { return (long)(DateTime.UtcNow - UnixEpoch).TotalMilliseconds; } + /// + /// Return a DateTime corresponding to the input Unix timestamp (in milliseconds). + /// + /// + /// public static DateTime DateTimeFromUnixTimestampMillis(long millis) { return UnixEpoch.AddMilliseconds(millis); } - - public static long GetCurrentUnixTimestampSeconds() - { - return (long)(DateTime.UtcNow - UnixEpoch).TotalSeconds; - } - - public static DateTime DateTimeFromUnixTimestampSeconds(long seconds) - { - return UnixEpoch.AddSeconds(seconds); - } } }