Exemplo n.º 1
0
 public void CreateFromDynamic(dynamic data)
 {
     if (data != null)
     {
         this.Text = data.message;
         this.Id   = data.id;
         DateTime createdDate;
         DateTime.TryParse(data.created_time as string, out createdDate);
         this.CreatedAt = createdDate;
         this.User      = FacebookUser.CreateFromDynamic(data.from, this.Account);
         if (data.likes != null)
         {
             try
             {
                 this.LikesCount = Convert.ToInt32(data.likes);
             }
             catch (Exception exp) {
                 AppController.Current.Logger.writeToLogfile(exp);
             }
         }
         if (data.user_likes != null)
         {
             this.isLiked = true;
         }
     }
 }
Exemplo n.º 2
0
        public bool verifyCredentials()
        {
            try
            {
                IDictionary <string, object> loginParameters = new Dictionary <string, object>
                {
                    { "client_id", appId },
                    { "client_secret", appSecret },
                    { "grant_type", "fb_exchange_token" },
                    { "fb_exchange_token", AccessToken },
                };

                var updateAccessTokenClient = new FacebookClient();

                /* IDictionary<string, object> loginParameters = new Dictionary<string, object>
                 *                                             {
                 *                                                 { "client_id", appId },
                 *                                                 { "client_secret", appSecret },
                 *                                                 { "grant_type", "fb_exchange_token" },
                 *                                                 {"fb_exchange_token", AccessToken}
                 *                                             }; */


                dynamic updateTokenResult = updateAccessTokenClient.Get("oauth/access_token",
                                                                        loginParameters);

                AccessToken    = updateTokenResult.access_token;
                facebookClient = new FacebookClient(AccessToken);

                dynamic result = (IDictionary <string, object>)facebookClient.Get("me");

                if (result != null)
                {
                    LoginSuccessfull = true;
                    //_id = (decimal)result["id"];
                    _id       = result.id;
                    _username = result.username;
                    FullName  = result.name;
                    User      = FacebookUser.CreateFromDynamic(result, this);

                    AvailableNotificationClasses = new List <string>();
                    AvailableNotificationClasses.Add("Facebook " + FullName + " Status message");
                    AvailableNotificationClasses.Add("Facebook " + FullName + " Link");
                    AvailableNotificationClasses.Add("Facebook " + FullName + " Photo");
                    AvailableNotificationClasses.Add("Facebook " + FullName + " Video");
                    AvailableNotificationClasses.Add("Facebook " + FullName + " CheckIn");
                    AvailableNotificationClasses.Add("Facebook " + FullName + " Event");
                    AvailableNotificationClasses.Add("Facebook " + FullName + " Note");
                    AvailableNotificationClasses.Add("Facebook " + FullName + " Comment");
                    AvailableNotificationClasses.Add("Facebook " + FullName + " Comment (on message you didn't comment or like yourself)");
                    AvailableNotificationClasses.Add("Facebook " + FullName + " Like");
                    AvailableNotificationClasses.Add("Facebook " + FullName + " Like (on message you didn't comment or like yourself)");

                    foreach (string className in AvailableNotificationClasses)
                    {
                        AppController.Current.registerNotificationClass(className);
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (FacebookOAuthException oauthExp)
            {
                AppController.Current.Logger.writeToLogfile(oauthExp);
            }
            catch (Exception exp)
            {
                AppController.Current.Logger.writeToLogfile(exp);;
                return(false);
            }
            return(false);
        }
Exemplo n.º 3
0
        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);
            }
        }