Esempio n. 1
0
        /// <summary>
        /// Extract first child path, i.e. text before first separator.
        /// </summary>
        /// <param name="path">The inital path.</param>
        /// <param name="remainder">The remainder of the path after extraction.</param>
        /// <returns>The text before the first separator.</returns>
        public static FacebookObjectId ExtractFirstChildPath(string path, out string remainder)
        {
            string childPath = path;

            remainder = String.Empty;
            if (!string.IsNullOrEmpty(path))
            {
                int separatorIndex = path.IndexOf("/", StringComparison.Ordinal);
                if (separatorIndex >= 0 && separatorIndex < path.Length)
                {
                    // Separator was found, remainder of the path is passed to the matching child for further lookup
                    childPath = path.Substring(0, separatorIndex);
                    if (separatorIndex + 1 < path.Length)
                    {
                        remainder = path.Substring(separatorIndex + 1, path.Length - (separatorIndex + 1));
                    }
                }
            }

            if (!string.IsNullOrEmpty(childPath))
            {
                childPath = Uri.UnescapeDataString(childPath);
            }

            return(FacebookObjectId.Create(childPath));
        }
Esempio n. 2
0
        public Navigator GetNavigatorFromPath(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            string searchPrefix = Uri.EscapeDataString("[search]");

            if (path.StartsWith(searchPrefix))
            {
                path = path.Substring(searchPrefix.Length);
                path = Uri.UnescapeDataString(path);
                return(new SearchNavigator(_viewManager.DoSearch(path)));
            }

            string           childPath;
            FacebookObjectId guid = Navigator.ExtractFirstChildPath(path, out childPath);

            foreach (var topNav in _children)
            {
                if (guid == topNav.Guid)
                {
                    if (string.IsNullOrEmpty(childPath))
                    {
                        return(topNav);
                    }

                    return(topNav.FindChildNavigatorFromPath(childPath));
                }
            }

            return(null);
        }
Esempio n. 3
0
        public Navigator FindChildNavigatorFromPath(string path)
        {
            Verify.IsNeitherNullNorEmpty(path, "path");

            // Extract the first guid in the path and match it to a child navigator. If there is no child separator,
            // treat the entire path as the child's guid
            string           remainder;
            FacebookObjectId childGuid = ExtractFirstChildPath(path, out remainder);

            Assert.IsTrue(FacebookObjectId.IsValid(childGuid));

            Navigator childNavigator = GetChildNavigatorWithGuid(childGuid);

            if (childNavigator == null)
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(remainder))
            {
                return(childNavigator.FindChildNavigatorFromPath(remainder));
            }

            return(childNavigator);
        }
Esempio n. 4
0
        public Navigator GetPhotoWithId(FacebookObjectId ownerId, FacebookObjectId photoId)
        {
            Verify.IsTrue(FacebookObjectId.IsValid(ownerId), "Invalid ownerId");
            Verify.IsTrue(FacebookObjectId.IsValid(photoId), "Invalid photoId");
            _albums.VerifyAccess();

            for (int index = 0; index < _albums.Count; ++index)
            {
                if (_albums[index].Owner.UserId.Equals(ownerId))
                {
                    for (int index2 = 0; index2 < _albums[index].Photos.Count; ++index2)
                    {
                        if (_albums[index].Photos[index2].PhotoId.Equals(photoId))
                        {
                            return(new PhotoNavigator(
                                       _albums[index].Photos[index2],
                                       new PhotoAlbumNavigator(_albums[index], this)
                            {
                                ParentIndex = index,
                            })
                            {
                                ParentIndex = index2,
                            });
                        }
                    }
                }
            }
            return(null);
        }
Esempio n. 5
0
        private Navigator _TryGetNavigatorFromPhotoUri(Uri uri)
        {
            if (uri.LocalPath.ToLowerInvariant().Equals("/photo.php"))
            {
                string userId  = null;
                string photoId = null;
                string id      = null;

                foreach (string part in uri.Query.Split('?', '&'))
                {
                    if (part.ToLowerInvariant().StartsWith("id="))
                    {
                        userId = part.Substring("id=".Length);
                    }
                    else if (part.ToLowerInvariant().StartsWith("pid="))
                    {
                        photoId = part.Substring("pid=".Length);
                    }
                }

                if (userId != null && photoId != null)
                {
                    // Need to do additional parsing here.
                    // If id is 32 bits then PID = ((id << 32) | pid)
                    // If id is 64 bits then PID = id + " _ " + pid
                    ulong userIdLong;
                    if (ulong.TryParse(userId, out userIdLong))
                    {
                        if (userIdLong == (ulong)(uint)userIdLong)
                        {
                            uint photoIdInt;
                            if (uint.TryParse(photoId, out photoIdInt))
                            {
                                id = ((userIdLong << 32) | (ulong)photoIdInt).ToString();
                            }
                        }
                        else
                        {
                            id = userId + "_" + photoId;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(id))
                {
                    FacebookObjectId fbUserId  = FacebookObjectId.Create(userId);
                    FacebookObjectId fbPhotoId = FacebookObjectId.Create(id);
                    Navigator        nav       = ((PhotoAlbumCollectionNavigator)ViewManager.MasterNavigator.PhotoAlbumsNavigator).GetPhotoWithId(fbUserId, fbPhotoId);
                    if (nav != null)
                    {
                        return(nav);
                    }
                }
            }

            return(null);
        }
Esempio n. 6
0
        public MasterNavigator(ViewManager viewManager, FacebookService facebookService, ViewPage startupPage)
        {
            Verify.IsNotNull(viewManager, "viewManager");
            Verify.IsNotNull(facebookService, "facebookService");
            _viewManager = viewManager;

            HomeNavigator        = new HomePage().GetNavigator(null, facebookService.Dispatcher);
            PhotoAlbumsNavigator = new PhotoAlbumCollectionNavigator(facebookService.PhotoAlbums, FacebookObjectId.Create("Photo Albums"), null);
            FriendsNavigator     = new ContactCollectionNavigator(facebookService.Friends, FacebookObjectId.Create("Friends"), null);
            ProfileNavigator     = new ContactNavigator(facebookService.MeContact, FacebookObjectId.Create("Me"), null);

            _children = new[] { HomeNavigator, PhotoAlbumsNavigator, FriendsNavigator, ProfileNavigator };

            Navigator startupNavigator = null;

            switch (startupPage)
            {
            case ViewPage.Friends:
                startupNavigator   = FriendsNavigator;
                _startupCollection = facebookService.Friends;
                break;

            case ViewPage.Newsfeed:
                startupNavigator   = HomeNavigator;
                _startupCollection = facebookService.NewsFeed;
                break;

            case ViewPage.Photos:
                startupNavigator   = PhotoAlbumsNavigator;
                _startupCollection = facebookService.PhotoAlbums;
                break;

            case ViewPage.Profile:
                startupNavigator   = ProfileNavigator;
                _startupCollection = null;
                break;
            }

            _loadingPage = new LoadingPage(startupNavigator);
            if (_startupCollection != null)
            {
                _startupCollection.CollectionChanged += _SignalNewsfeedChanged;
            }
            else
            {
                _loadingPage.Signal();
            }

            _loginPage         = new LoginPage(facebookService.ApplicationId, facebookService.ApplicationKey, _loadingPage.GetNavigator());
            LoginPageNavigator = _loginPage.Navigator;
        }
Esempio n. 7
0
        private Navigator _TryGetNavigatorFromProfileUri(Uri uri)
        {
            FacebookObjectId fbId = default(FacebookObjectId);

            // Maybe this is a straight-up profile.php?id=####
            if (uri.LocalPath.ToLowerInvariant().Equals("/profile.php"))
            {
                string id     = null;
                string idPart = null;
                foreach (string part in new[] { "?id=", "&id=" })
                {
                    if (uri.Query.ToLowerInvariant().Contains(part))
                    {
                        idPart = part;
                        break;
                    }
                }

                if (idPart != null)
                {
                    id = uri.Query.ToLower();
                    id = uri.Query.Substring(id.IndexOf(idPart) + idPart.Length);
                    // Strip out the rest of the query
                    id = id.Split('&')[0];

                    fbId = FacebookObjectId.Create(id);
                }

                if (FacebookObjectId.IsValid(fbId))
                {
                    var me = (FacebookContact)ViewManager.MasterNavigator.ProfileNavigator.Content;
                    if (me.UserId.Equals(fbId))
                    {
                        return(ViewManager.MasterNavigator.ProfileNavigator);
                    }

                    Navigator nav = ((ContactCollectionNavigator)ViewManager.MasterNavigator.FriendsNavigator).GetContactWithId(fbId);
                    if (nav != null)
                    {
                        return(nav);
                    }
                }
            }

            return(null);
        }
Esempio n. 8
0
        protected Navigator(object content, FacebookObjectId guid, Navigator parent)
        {
            Verify.IsNotNull(content, "content");
            Verify.IsTrue(FacebookObjectId.IsValid(guid), "Invalid guid");
            Content = content;

            Guid = guid;
            if (parent != null)
            {
                Parent = parent;
                Path   = Parent.Path + "/" + Uri.EscapeDataString(Guid.ToString());
            }
            else
            {
                Path = Uri.EscapeDataString(Guid.ToString());
            }
        }
Esempio n. 9
0
        public Navigator GetContactWithId(FacebookObjectId id)
        {
            _contacts.VerifyAccess();

            for (int index = 0; index < _contacts.Count; ++index)
            {
                if (_contacts[index].UserId == id)
                {
                    var navigator = new ContactNavigator(_contacts[index], this)
                    {
                        ParentIndex = index,
                    };
                    return(navigator);
                }
            }

            return(null);
        }
Esempio n. 10
0
        protected override Navigator GetChildNavigatorWithGuid(FacebookObjectId guid)
        {
            Verify.IsTrue(FacebookObjectId.IsValid(guid), "Invalid guid");
            _album.VerifyAccess();

            for (int index = 0; index < _album.Photos.Count; ++index)
            {
                if (_album.Photos[index].PhotoId == guid)
                {
                    var navigator = new PhotoNavigator(_album.Photos[index], this)
                    {
                        ParentIndex = index,
                    };
                    return(navigator);
                }
            }

            return(null);
        }
Esempio n. 11
0
        public static void GoOnline(string sessionKey, string sessionSecret, FacebookObjectId userId)
        {
            Verify.IsNeitherNullNorEmpty(sessionKey, "sessionKey");
            Verify.IsNeitherNullNorEmpty(sessionSecret, "sessionSecret");
            Verify.IsTrue(FacebookObjectId.IsValid(userId), "invalid userId");

            if (FacebookService.IsOnline)
            {
                throw new InvalidOperationException();
            }

            FacebookService.RecoverSession(sessionKey, sessionSecret, userId);

            var handler = GoneOnline;

            if (handler != null)
            {
                handler(FacebookService, new EventArgs());
            }
        }
Esempio n. 12
0
 public ContactNavigator(FacebookContact contact, FacebookObjectId guid, Navigator parent)
     : base(contact, guid, parent)
 {
 }
Esempio n. 13
0
 public _Navigator(LoginPage page, Dispatcher dispatcher)
     : base(page, FacebookObjectId.Create("[Login Page]"), null)
 {
 }
Esempio n. 14
0
 public SearchNavigator(SearchResults searchResults)
     : base(searchResults, FacebookObjectId.Create("[search]" + searchResults.SearchText), null)
 {
 }
Esempio n. 15
0
 public ContactCollectionNavigator(FacebookContactCollection contacts, FacebookObjectId guid, Navigator parent)
     : base(contacts, guid, parent)
 {
     _contacts = contacts;
 }
Esempio n. 16
0
 public PhotoAlbumCollectionNavigator(FacebookPhotoAlbumCollection albumCollection, FacebookObjectId guid, Navigator parent)
     : base(albumCollection, guid, parent)
 {
     _albums = albumCollection;
 }
Esempio n. 17
0
 protected virtual Navigator GetChildNavigatorWithGuid(FacebookObjectId guid)
 {
     return(null);
 }
Esempio n. 18
0
 public _Navigator(Navigator parent, HomePage page, Dispatcher dispatcher)
     : base(page, FacebookObjectId.Create("[homepage]"), parent)
 {
 }