Пример #1
0
		public FullImagesTimedResponse GetFullImagesOfUser(int userId, DateTime since)
		{
			FullImagesTimedResponse fullImagesTimed = null;
			List<ImageResponse> images = null;
			
			var we = new ManualResetEvent(false);
			
			string uri = string.Format("http://storage.21offserver.com/json/syncreply/FullImages?WhereUserId={0}&Since={1}&Count={2}", 
					userId, since.Ticks, 5);
			
			JsonUtility.Launch(uri, false, s =>
	        {
				try
				{
					fullImagesTimed = new FullImagesTimedResponse();
					images = new List<ImageResponse>();
					fullImagesTimed.Images = images;
					
					var json = JsonArray.Load (s);
					if (json.ContainsKey("Time"))
					{
						DateTime? time = ActivitiesService.JsonToTime((JsonValue)json["Time"]);
						fullImagesTimed.Time = time;
					}
					foreach (JsonObject obj in json["Images"])
					{		
						try
						{
							JsonObject imgJson = (JsonObject)obj["Image"];							
							int likesCount = Convert.ToInt32(obj["LikesCount"].ToString());							
							
							var keywords = new List<Keyword>();
							foreach (JsonObject jsonObj in obj["Keywords"])
							{
								keywords.Add(KeywordsService.JsonToKeyword(jsonObj));
							}
							
							var comments = new List<CommentResponse>();
							foreach (JsonObject jsonObj in obj["Comments"])
							{
								JsonObject comm = (JsonObject)jsonObj["Comment"];
								JsonObject user = (JsonObject)jsonObj["User"];
								
								var cresp = new CommentResponse()
								{
									Comment = CommentsService.JsonToComment(comm),
									User = UsersService.JsonToUser(user),
								};
								comments.Add(cresp);
							}
							
							var imgResp = new ImageResponse()
							{
								Comments = comments,
								Image = JsonToImage(imgJson),
								LikesCount = likesCount,
								Keywords = keywords,
							};
							images.Add(imgResp);
						}
						catch (Exception ex)
						{
							Util.LogException("GetFullImagesOfUser", ex);
						}
					}
				}
				catch (Exception ex)
				{
					Util.LogException("GetaImagesOfUser", ex);
				}
				we.Set();
			});
			
			we.WaitOne(5000);			
			
			return fullImagesTimed;			
		}
Пример #2
0
		public ImageResponse GetFullImage(int id)
		{
			var images = new List<ImageResponse>();				
			
			var we = new ManualResetEvent(false);
			string uri = string.Format("http://storage.21offserver.com/json/syncreply/FullImages?ImageId={0}", id);
			
			JsonUtility.Launch(uri, false, s =>
	        {
				try
				{
					var json = JsonArray.Load (s);
					foreach (JsonObject obj in json["Images"])
					{		
						try
						{
							JsonObject imgJson = (JsonObject)obj["Image"];							
							int likesCount = Convert.ToInt32(obj["LikesCount"].ToString());							
							
							var keywords = new List<Keyword>();
							foreach (JsonObject jsonObj in obj["Keywords"])
							{
								keywords.Add(KeywordsService.JsonToKeyword(jsonObj));
							}
							
							var comments = new List<CommentResponse>();
							foreach (JsonObject jsonObj in obj["Comments"])
							{
								JsonObject comm = (JsonObject)jsonObj["Comment"];
								JsonObject user = (JsonObject)jsonObj["User"];
								
								var cresp = new CommentResponse()
								{
									Comment = CommentsService.JsonToComment(comm),
									User = UsersService.JsonToUser(user),
								};
								comments.Add(cresp);
							}
							
							var imgResp = new ImageResponse()
							{
								Comments = comments,
								Image = JsonToImage(imgJson),
								LikesCount = likesCount,
								Keywords = keywords,
							};
							images.Add(imgResp);
						}
						catch (Exception ex)
						{
							Util.LogException("GetFullImagesOfUser", ex);
						}
					}
				}
				catch (Exception ex)
				{
					Util.LogException("GetaImagesOfUser", ex);
				}
				we.Set();
			});
			
			we.WaitOne();
			
			return images.FirstOrDefault();
		}