/// <summary> /// AgFx will call this method when it wants to load the new value - /// even though it's just the values we got off of the OAuth process. /// </summary> /// <param name="result"></param> public override void Execute(Action <LoadRequestResult> result) { // Grab the values off of the LoadContext. // FacebookLoginLoadContext context = (FacebookLoginLoadContext)LoadContext; string access_token = context.AccessToken; DateTime expiration_time = context.Expiration; // Make sure we have a token. if (access_token != null) { // write the values into a stream and return that. MemoryStream ms = new MemoryStream(); StreamWriter sw = new StreamWriter(ms); sw.WriteLine(access_token); sw.WriteLine(expiration_time); sw.Flush(); ms.Seek(0, SeekOrigin.Begin); LoadRequestResult r = new LoadRequestResult(ms); result(r); } else { result(new LoadRequestResult(new UnauthorizedAccessException())); } }
/// <summary> /// Actually do the login, given a token and expiration time. /// </summary> /// <param name="accessToken"></param> /// <param name="expirationTimeUtc"></param> public static void Login(string accessToken, DateTime expirationTimeUtc) { FacebookLoginLoadContext defaultContext = (FacebookLoginLoadContext)FacebookLoginModel.Current.LoadContext; defaultContext.AccessToken = accessToken; defaultContext.Expiration = expirationTimeUtc; DataManager.Current.Refresh <FacebookLoginModel>(defaultContext, (lm) => { if (lm.IsLoggedIn) { lm.RaiseLogin(); } }, null); }