public UploadFormDataRequest(UserToken token, UploadParameters parameters)
 {
     _token = token;
     _parameters = parameters;
     _boundary = string.Format("---------------------------{0}",
         DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture).Substring(0, 12));
 }
 public UploadFormDataRequest(UserToken token, UploadParameters parameters)
 {
     _token      = token;
     _parameters = parameters;
     _boundary   = string.Format("---------------------------{0}",
                                 DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture).Substring(0, 12));
 }
        /// <summary>
        /// Upload an item to the server.
        /// </summary>
        /// <param name="token">The <see cref="UserToken"/> for the ArcGIS Server Manager user.</param>
        /// <param name="parameters">The parameters of the item to upload.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">token cannot be null.</exception>
        /// <exception cref="ArgumentNullException">parameters cannot be null.</exception>
        public Task <UploadResult> UploadItemAsync(UserToken token, UploadParameters parameters)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var taskCompletionSource = new TaskCompletionSource <UploadResult>();
            var uploader             = new UploadFormDataRequest(token, parameters);

            uploader.UploadAsync(_serverUrl,
                                 result => taskCompletionSource.SetResult(JsonConvert.DeserializeObject <UploadResult>(result)));
            return(taskCompletionSource.Task);
        }