/// <summary>
        /// Converts an ODItem into a Json String
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static string JsonString(this ODDataModel item)
        {
            object jsonSource = item;

#if DEBUG
            // Pretty-print the JSON by round tripping through the JSON converter
            if (null != item.OriginalJson)
            {
                jsonSource = Newtonsoft.Json.JsonConvert.DeserializeObject(item.OriginalJson);
            }
#endif
            return(Newtonsoft.Json.JsonConvert.SerializeObject(jsonSource, Newtonsoft.Json.Formatting.Indented));
        }
Example #2
0
        /// <summary>
        /// Uploads a fragment to the UploadSession.UploadUrl end point. Returns either an ODUploadSession
        /// with the latest information about expected ranges, or an ODItem when the file is complete.
        /// </summary>
        /// <param name="startByte"></param>
        /// <param name="endByte"></param>
        /// <param name="fragment"></param>
        /// <returns></returns>
        private async Task <ODDataModel> ExecuteUploadFragment(long startByte, long endByte, byte[] fragment)
        {
            Uri serviceUri = new Uri(UploadSession.UploadUrl);

            if (endByte > DataSource.Length || startByte > DataSource.Length || endByte <= startByte)
            {
                throw new ArgumentException("range can't go past file length");
            }

            ODDataModel responseObject = await Connection.PutFileFragment(serviceUri, fragment, new ContentRange
            {
                FirstByteIndex   = startByte,
                LastByteIndex    = endByte,
                TotalLengthBytes = DataSource.Length
            });

            return(responseObject);
        }