public static FacebookItem ConvertResponseToItem(dynamic post, AccountFacebook ReceivingAccount) { try { FacebookItem item = new FacebookItem(); item.Account = ReceivingAccount; item.fullId = post.id as string; string[] ids = item.fullId.Split(new Char[] { '_' }, StringSplitOptions.RemoveEmptyEntries); if (ids.Length < 2) { return(null); } try { item.Id = Convert.ToDecimal(ids[1]); } catch { return(null); } #region Messagetypes if (post.type != null) { string postType = post.type; switch (postType) { case "photo": item.MessageType = MessageTypes.Photo; break; case "link": item.MessageType = MessageTypes.Link; break; case "event": item.MessageType = MessageTypes.Event; break; case "checkin": item.MessageType = MessageTypes.CheckIn; break; case "status": item.MessageType = MessageTypes.StatusMessage; break; case "video": item.MessageType = MessageTypes.Video; break; case "note": item.MessageType = MessageTypes.Note; break; } } #endregion item.To.FullName = null; if (post.to != null) { if (post.to.data != null) { foreach (dynamic receiver in post.to.data) { item.To = FacebookUser.CreateFromDynamic(receiver, ReceivingAccount); item.To.ReceivingAccount = ReceivingAccount; // only one receiver for now - should be a collection later on of course break; } } } DateTime createdDate; DateTime.TryParse(post.created_time as string, out createdDate); item.CreatedAt = createdDate; DateTime updatedDate; DateTime.TryParse(post.updated_time as string, out updatedDate); item.UpdatedAt = updatedDate; //item.User.Id = post.from.id; //item.User.FullName = post.from.name; item.User = FacebookUser.CreateFromDynamic(post.from, item.Account); if (item.User == null) { AppController.Current.Logger.writeToLogfile("Null user on item retrieval"); return(null); } if (post.comments != null) { AppController.Current.Logger.writeToLogfile("Facebook item has comments"); if (post.comments.data != null) { AppController.Current.Logger.writeToLogfile("Facebook item has comments/data"); foreach (dynamic fbcomment in post.comments.data) { AppController.Current.Logger.writeToLogfile("Reading comment"); FacebookComment comment = new FacebookComment(fbcomment); comment.Account = item.Account; if (comment.Id == ReceivingAccount.Id.ToString()) { item.isCommented = true; } item.Comments.Add(comment); } } } if (post.application != null) { item.Application.Name = post.application.name; item.Application.Link = post.application.link; item.Application.Id = post.application.id; } if (post.likes != null) { if (post.likes.count != null) { item.LikesCount = Convert.ToInt32(post.likes.count); } if (post.likes.data != null) { AppController.Current.Logger.writeToLogfile("Facebook item has likes/data"); foreach (dynamic fbLike in post.likes.data) { AppController.Current.Logger.writeToLogfile("Reading like"); FacebookUser user = FacebookUser.CreateFromDynamic(fbLike, item.Account); user.ReceivingAccount = item.Account; if (user != null) { item.Likes.Add(user); if (user.FullName == item.Account.FullName) { item.isLiked = true; } } } } } if (post.picture != null) { FacebookPicture picture = new FacebookPicture(); picture.ThumbnailPath = post.picture; picture.Link = post.link; picture.Caption = post.caption; item.Picture = picture.ThumbnailPath; item.PictureLink = picture.Link; item.Images.Add(picture); } item.Description = post.description; item.Message = post.message; item.Name = post.name; item.Caption = post.caption; item.Link = post.link; // ganz zum Schluss, das in der Textbox auf diese Aenderung getriggert wird item.Text = item.Message; return(item); } catch (Exception exp) { AppController.Current.Logger.writeToLogfile(exp); return(null); } }
public static FacebookUser CreateFromDynamic(dynamic data, AccountFacebook ReceivingAccount) { if (data != null) { FacebookUser user = new FacebookUser(); user.Id = data.id; user.FullName = data.name; if (data.username == null && data.first_name == null && ReceivingAccount != null) { data = (IDictionary <string, object>)ReceivingAccount.facebookClient.Get(user.Id); } user.FirstName = data.first_name; user.LastName = data.last_name; user.MiddleName = data.middle_name; if (data.gender != null) { if (data.gender == "female") { user.Gender = Genders.Female; } } user.Locale = data.locale; user.ProfileLink = data.link; user.Username = data.username; user.ThirdPartyId = data.third_party_id; if (data.timezone != null) { try { user.Timezone = data.timezone; } catch { user.Timezone = 0; } } DateTime tempUpdated; DateTime.TryParse(data.updated_time, out tempUpdated); user.UpdatedTime = tempUpdated; bool tempVerified = false; try { if (data.verified != null) { string verifyString = data.verified as string; if (verifyString != null) { if (verifyString.ToLower() == "true") { user.Verified = true; } } } // Boolean.TryParse(data.verified, out tempVerified); // much better code - but throws to many exception } catch { } user.Verified = tempVerified; user.Bio = data.bio; DateTime tempBirthday; DateTime.TryParse(data.birthday, out tempBirthday); user.Birthday = tempBirthday; user.Email = data.email; // this.HomeTown = data.hometown; user.Political = data.political; user.Quotes = data.quotes; user.RelationshipStatus = data.releationship_status; user.Religion = data.religion; user.Website = data.website; return(user); } else { return(null); } }