示例#1
0
        public async Task <CloudChangeResult> GetChanges(CloudChangesRequest parameters = null)
        {
            const string path = "changes";

            try
            {
                var url      = CreateMetaUrl(path);
                var postData = parameters == null || parameters.IsEmpty() ? "" : this.SerializeObject(parameters);
                var message  = await PostMessage(url, new StringContent(postData, Encoding.UTF8, "text/json"));

                var stream = await message.Content.ReadAsStreamAsync();

                var gZip   = new GZipStream(stream, CompressionMode.Decompress);
                var result = new CloudChangeResult
                {
                    HasMore = true,
                };
                Task.Run(() => ReadChanges(gZip, result));
                return(result);
            }
            catch (Exception ex)
            {
                return(new CloudChangeResult
                {
                    Error = ex.ToString(),
                    ErrorDescription = ex.Message.ToString(),
                });
            }
        }
示例#2
0
        public async Task <CloudChangesResult> GetChanges(CloudChangesRequest parameters = null)
        {
            const string path = "changes";

            try{
                var url      = CreateMetaUrl(path);
                var postData = parameters == null || parameters.IsEmpty() ? "" : this.SerializeObject(parameters);
                var message  = await PostMessage(url, new StringContent (postData, Encoding.UTF8, "text/json"));

                var data = await message.Content.ReadAsStringAsync();

                bool hasMore = false;

                //Amazon sends horribly ugly/bad json format. It's actually 2 sets of json...
                //To properly deseralize the data, you need to remove the bad data.
                if (data.EndsWith("{\"end\":true}"))
                {
                    data    = data.Replace("{\"end\":true}", "");
                    hasMore = false;
                }
                else if (data.EndsWith("{\"end\":false}"))
                {
                    data    = data.Replace("{\"end\":false}", "");
                    hasMore = true;
                }
                var result = Deserialize <CloudChangesResult> (data);
                return(result);
            }
            catch (Exception ex) {
                return(new CloudChangesResult {
                    Error = ex.ToString(),
                    ErrorDescription = ex.Message.ToString(),
                });
            }
        }
		public async Task<CloudChangesResult> GetChanges(CloudChangesRequest parameters = null)
		{
			const string path = "changes";
			try{
				var url = CreateMetaUrl (path);
				var postData = parameters == null || parameters.IsEmpty () ? "" : this.SerializeObject (parameters);
				var message = await PostMessage (url, new StringContent (postData, Encoding.UTF8, "text/json"));
				var data = await message.Content.ReadAsStringAsync ();
				bool hasMore = false;

				//Amazon sends horribly ugly/bad json format. It's actually 2 sets of json...
				//To properly deseralize the data, you need to remove the bad data.
				if (data.EndsWith ("{\"end\":true}")) {
					data = data.Replace ("{\"end\":true}", "");
					hasMore = false;
				} else if (data.EndsWith ("{\"end\":false}")) {
					data = data.Replace ("{\"end\":false}", "");
					hasMore = true;
				}
				var result = Deserialize<CloudChangesResult> (data);
				return result;
			}
			catch(Exception ex) {
				return new CloudChangesResult {
					Error = ex.ToString(),
					ErrorDescription = ex.Message.ToString(),
				};
			}
				
		}