Author: thomasvm
Date: 2007-04-27 02:01:25 -0400 (Fri, 27 Apr 2007)
New Revision: 76369

Added:
   trunk/facebook-sharp/examples/InfiniteSession.cs
Modified:
   trunk/facebook-sharp/ChangeLog
   trunk/facebook-sharp/examples/Makefile.am
   trunk/facebook-sharp/src/Mono.Facebook/FacebookSession.cs
   trunk/facebook-sharp/src/Mono.Facebook/Responses.cs
Log:
2007-04-27 Thomas Van Machelen <[EMAIL PROTECTED]>
        * src/Mono.Facebook/FacebookSession:
                add an extra constructor to restart an infinite session and
                return the SessionInfo on GetSession if it's an infinite one
        * src/Mono.Facebook/Responses:
                add the expires attribute on SessionInfo so we can check for
                infinite sessions and add an extra constructor to restore the
                infinite session
        * examples/Makefile.am:
        * examples/InfiniteSession.cs:
                a new example to demonstrate the use of infinite sessions



Modified: trunk/facebook-sharp/ChangeLog
===================================================================
--- trunk/facebook-sharp/ChangeLog      2007-04-27 04:36:27 UTC (rev 76368)
+++ trunk/facebook-sharp/ChangeLog      2007-04-27 06:01:25 UTC (rev 76369)
@@ -1,3 +1,15 @@
+2007-04-27 Thomas Van Machelen <[EMAIL PROTECTED]>
+       * src/Mono.Facebook/FacebookSession:
+               add an extra constructor to restart an infinite session and
+               return the SessionInfo on GetSession if it's an infinite one
+       * src/Mono.Facebook/Responses:
+               add the expires attribute on SessionInfo so we can check for
+               infinite sessions and add an extra constructor to restore the
+               infinite session
+       * examples/Makefile.am:
+       * examples/InfiniteSession.cs:
+               a new example to demonstrate the use of infinite sessions
+
 2007-04-09 George Talusan <[EMAIL PROTECTED]>
        * src/Mono.Facebook/User.cs: 
                cover user information better

Added: trunk/facebook-sharp/examples/InfiniteSession.cs
===================================================================
--- trunk/facebook-sharp/examples/InfiniteSession.cs    2007-04-27 04:36:27 UTC 
(rev 76368)
+++ trunk/facebook-sharp/examples/InfiniteSession.cs    2007-04-27 06:01:25 UTC 
(rev 76369)
@@ -0,0 +1,41 @@
+using System;
+using Mono.Facebook;
+
+namespace Mono.Facebook.Test
+{
+       class GetAlbums
+       {
+               static void Main(string[] args)
+               {
+                       // create session
+                       FacebookSession session = new 
FacebookSession("ca9511b32569d823f1d3a942b31c6c84", 
"61f4712317fb7a2d12581f523c01fe71");
+
+                       // create token and login with it
+                       Uri login = session.CreateToken();
+                       System.Diagnostics.Process.Start("firefox", 
login.AbsoluteUri);
+                       Console.WriteLine ("Press enter after you've logged 
in.");
+                       Console.ReadLine ();
+
+                       // get session key
+                       SessionInfo old_info = session.GetSession();
+
+                       // check for infinite
+                       if (old_info == null) {
+                               Console.WriteLine ("Not an infinite session... 
quitting.");
+                               return;
+                       }
+
+                       Console.WriteLine ("Infinite Session: session key {0} 
secret {1}", 
+                               old_info.SessionKey, old_info.Secret);
+
+                       Console.WriteLine ("Press enter after you've logged 
out.");
+                       Console.ReadLine ();
+
+                       SessionInfo new_info = new SessionInfo 
(old_info.SessionKey, old_info.UId, old_info.Secret);
+                       session = new FacebookSession 
("ca9511b32569d823f1d3a942b31c6c84", new_info);
+
+                       foreach (Album a in session.GetAlbums ())
+                               Console.WriteLine (a.Name);
+               }
+       }
+}

Modified: trunk/facebook-sharp/examples/Makefile.am
===================================================================
--- trunk/facebook-sharp/examples/Makefile.am   2007-04-27 04:36:27 UTC (rev 
76368)
+++ trunk/facebook-sharp/examples/Makefile.am   2007-04-27 06:01:25 UTC (rev 
76369)
@@ -1,4 +1,4 @@
-SAMPLES=GetAlbums.cs GetFriends.cs GetEvents.cs
+SAMPLES=GetAlbums.cs GetFriends.cs GetEvents.cs InfiniteSession.cs
 MCSFLAGS= -debug -nologo -r:Mono.Facebook.dll
 
 EXTRA_DIST=$(SAMPLES)

Modified: trunk/facebook-sharp/src/Mono.Facebook/FacebookSession.cs
===================================================================
--- trunk/facebook-sharp/src/Mono.Facebook/FacebookSession.cs   2007-04-27 
04:36:27 UTC (rev 76368)
+++ trunk/facebook-sharp/src/Mono.Facebook/FacebookSession.cs   2007-04-27 
06:01:25 UTC (rev 76369)
@@ -52,11 +52,19 @@
                        get { return session_info.SessionKey; }
                }
 
+               // use this for plain sessions
                public FacebookSession (string api_key, string shared_secret)
                {
                        util = new Util (api_key, shared_secret);
                }
 
+               // use this if you want to re-start an infinite session
+               public FacebookSession (string api_key, SessionInfo 
session_info)
+                       : this (api_key, session_info.Secret)
+               {
+                       this.session_info = session_info;
+               }
+
                public Uri CreateToken ()
                {
                        XmlDocument doc = util.GetResponse 
("facebook.auth.createToken");
@@ -65,12 +73,15 @@
                        return new Uri (string.Format 
("http://www.facebook.com/login.php?api_key={0}&v=1.0&auth_token={1}";, 
util.ApiKey, auth_token));
                }
 
-               public void GetSession ()
+               public SessionInfo GetSession ()
                {
                        this.session_info = util.GetResponse<SessionInfo> 
("facebook.auth.getSession", 
                                FacebookParam.Create ("auth_token", 
auth_token));
                        this.util.SharedSecret = session_info.Secret;
+
                        this.auth_token = string.Empty;
+
+                       return session_info.IsInfinite ? session_info : null;
                }
 
                public Album[] GetAlbums ()

Modified: trunk/facebook-sharp/src/Mono.Facebook/Responses.cs
===================================================================
--- trunk/facebook-sharp/src/Mono.Facebook/Responses.cs 2007-04-27 04:36:27 UTC 
(rev 76368)
+++ trunk/facebook-sharp/src/Mono.Facebook/Responses.cs 2007-04-27 06:01:25 UTC 
(rev 76369)
@@ -42,6 +42,28 @@
 
                [XmlElement ("secret")]
                public string Secret;
+
+               [XmlElement ("expires")]
+               public long Expires;
+
+               [XmlIgnore ()]
+               public bool IsInfinite
+               {
+                       get { return Expires == 0; }
+               }       
+               
+               public SessionInfo ()
+               {}
+
+               // use this if you want to create a session based on infinite 
session
+               // credentials
+               public SessionInfo (string session_key, long uid, string secret)
+               {
+                       this.SessionKey = session_key;
+                       this.UId = uid;
+                       this.Secret = secret;
+                       this.Expires = 0;
+               }
        }
 
        [XmlRoot ("photos_getAlbums_response", Namespace = 
"http://api.facebook.com/1.0/";, IsNullable = false)]

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to