private ActivityResponse ActivityTransform(Activity el, Database dbCmd) { try { var actResp = new ActivityResponse { Activity = el }; if (el.IdOwner != null) actResp.User = dbCmd.Get<User>(el.IdOwner); if (el.IdComment != null) actResp.Comment = dbCmd.Get<Comment>(el.IdComment); if (el.IdPhoto != null) actResp.Image = dbCmd.Get<Image>(el.IdPhoto); return actResp; } catch (Exception ex) { Util.LogException("ActivityTransform", ex); return null; } }
public static Activity JsonToActivity(JsonObject obj) { /* <Id>2</Id> <IdComment i:nil="true"/> <IdOwner>1</IdOwner> <IdPhoto>5</IdPhoto> <Time>2011-07-26T18:12:01.5371093+02:00</Time> <Type>0</Type> <UserId>2</UserId> */ var act = new Activity() { Id = Convert.ToInt32(obj["Id"].ToString()), UserId = Convert.ToInt32(obj["UserId"].ToString()), Type = Convert.ToInt32(obj["Type"].ToString()), //Time = DateTime.ParseExact (obj ["Time"], "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture), }; DateTime? time = JsonToTime(obj["Time"]); if (time.HasValue) { act.Time = time.Value; } int id; if (obj.ContainsKey("IdComment")) { if (int.TryParse(obj["IdComment"].ToString(), out id)) act.IdComment = id; } if (obj.ContainsKey("IdOwner")) { if (int.TryParse(obj["IdOwner"].ToString(), out id)) act.IdOwner = id; } if (obj.ContainsKey("IdPhoto")) { if (int.TryParse(obj["IdPhoto"].ToString(), out id)) act.IdPhoto = id; } if (obj.ContainsKey("IdShare")) { if (int.TryParse(obj["IdShare"].ToString(), out id)) act.IdShare = id; } return act; }
void DownloadTweets () { try { bool isMyPost = AppDelegateIPhone.AIphone.GetMainUserId() == _photo.UserId; var fullLikes = AppDelegateIPhone.AIphone.LikesServ.GetFullLikesOfImage(_photo.Id); if (fullLikes == null) { this.BeginInvokeOnMainThread (delegate { ReloadComplete (); }); return; } fullLikes = fullLikes.OrderByDescending(c => c.Like.Time); this.BeginInvokeOnMainThread (delegate { while (Root[0].Count > 0) Root[0].Remove (0); NSTimer.CreateScheduledTimer (0.1, delegate { int i = 0; foreach (FullLike like in fullLikes) { Activity dbAct = new Activity() { Id = i, IdPhoto = _photo.Id, UserId = like.Like.UserId, Time = like.Like.Time, }; var activity = new UIActivity() { Id = i, DbActivity = dbAct, User = like.User, Image = _photo, Type = ActivityType.PhotoLiker, Text = string.Format(" liked {0} post", isMyPost ? "your" : "the"), }; Root[0].Add(new ActivityElement(activity, null, null)); i++; } // Notify the dialog view controller that we are done // this will hide the progress info this.BeginInvokeOnMainThread (delegate { ReloadComplete (); }); }); }); } catch (Exception ex) { this.BeginInvokeOnMainThread (delegate { ReloadComplete (); }); Util.LogException("Download photo likers", ex); } }