Ejemplo n.º 1
0
            public override object Deserialize(LoadContext loadContext, System.Type objectType, System.IO.Stream stream)
            {
                XDocument doc = XDocument.Load(stream);

                AuthorizedUser user = (from u in doc.Descendants("user")
                                       select new AuthorizedUser
                {
                    LoadContext = loadContext,
                    Id = (string)u.Attribute("id"),
                    UserName = (string)u.Element("name"),
                    Link = (string)u.Element("link")
                }).FirstOrDefault();

                return(user);
            }
        public void AuthenticateUser(Action <AuthorizedUser> completed, Action <Exception> error)
        {
            EnsureIsAuthenticated();

            AuthorizedUser = DataManager.Current.LoadFromCache <AuthorizedUser>("authenticated_user");

            // LoadFromCache returns an object even if it didn't exist in the
            // cache so check one of its properties for existance vs. the object
            // itself.
            if (!String.IsNullOrEmpty(AuthorizedUser.Id))
            {
                if (completed != null)
                {
                    completed(AuthorizedUser);
                }
                return;
            }

            // Force a network request of the AuthorizedUser because the code
            // above has just confirmed it doesn't exist in the cache.  This
            // funky deconstruction of what a normal Load<>() does is so the
            // calling code can wait on getting a "real" instance vs. an
            // empty one that then pops with live data.
            DataManager.Current.Refresh <AuthorizedUser>(
                "authenticated_user",
                user =>
            {
                this.AuthorizedUser = user;
                if (completed != null)
                {
                    completed(AuthorizedUser);
                }
            },
                e =>
            {
                if (error != null)
                {
                    error(e);
                }
            });
        }