예제 #1
0
        public PicasaPicture(GoogleConnection conn, string aid, string pid)
        {
            if (conn == null)
            {
                throw new ArgumentNullException("conn");
            }
            if (conn.User == null)
            {
                throw new ArgumentException("Need authentication before being used.", "conn");
            }
            this.conn = conn;

            if (aid == null || aid == String.Empty)
            {
                throw new ArgumentNullException("aid");
            }
            this.album = new PicasaAlbum(conn, aid);

            if (pid == null || pid == String.Empty)
            {
                throw new ArgumentNullException("pid");
            }

            string      received = conn.DownloadString(GDataApi.GetPictureEntry(conn.User, aid, pid));
            XmlDocument doc      = new XmlDocument();

            doc.LoadXml(received);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            XmlUtil.AddDefaultNamespaces(nsmgr);
            XmlNode entry = doc.SelectSingleNode("atom:entry", nsmgr);

            ParsePicture(entry, nsmgr);
        }
예제 #2
0
        public PicasaWeb(GoogleConnection conn, string username)
        {
            if (conn == null)
            {
                throw new ArgumentNullException("conn");
            }

            if (conn.User == null && username == null)
            {
                throw new ArgumentException("The connection should be authenticated OR you should call this constructor with a non-null username argument");
            }

            this.conn = conn;
            this.user = username ?? conn.User;

            string      received = conn.DownloadString(GDataApi.GetGalleryEntry(user));
            XmlDocument doc      = new XmlDocument();

            doc.LoadXml(received);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            XmlUtil.AddDefaultNamespaces(nsmgr);
            XmlNode entry = doc.SelectSingleNode("atom:entry", nsmgr);

            ParseGallery(entry, nsmgr);
        }
예제 #3
0
        public PicasaAlbum(GoogleConnection conn, string user, string aid, string authkey)
            : this(conn)
        {
            if (user == null || user == String.Empty)
                throw new ArgumentNullException ("user");

            if (aid == null || aid == String.Empty)
                throw new ArgumentNullException ("aid");

            this.user = user;
            this.id = aid;
            this.authkey = authkey;

            string download_link = GDataApi.GetAlbumEntryById (user, id);
            if (authkey != null && authkey != "")
                download_link += "&authkey=" + authkey;
            string received = conn.DownloadString (download_link);

            XmlDocument doc = new XmlDocument ();
            doc.LoadXml (received);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager (doc.NameTable);
            XmlUtil.AddDefaultNamespaces (nsmgr);
            XmlNode entry = doc.SelectSingleNode ("atom:entry", nsmgr);
            ParseAlbum (entry, nsmgr);
        }
예제 #4
0
        protected void Connect <T>(string name, string token) where T : AccountConnection
        {
            var a = this._context.Current;
            var c = this._accountConnectionService.GetConnection <T>(name);

            if (this._context.Current == null ||
                (c != null && c.AccountId == a.ID))
            {
                return;
            }
            if (c != null && c.AccountId != a.ID)
            {
                throw new CooperknownException(string.Format(this.Lang().sorry_already_connect_another, name));
            }

            if (typeof(T) == typeof(GoogleConnection))
            {
                this._accountConnectionService.Create(c = new GoogleConnection(name, token, a));
            }
            else if (typeof(T) == typeof(GitHubConnection))
            {
                this._accountConnectionService.Create(c = new GitHubConnection(name, token, a));
            }
            //HACK:连接账号时自动关联一切可以关联的信息
            this.AssociateEverything(c);
        }
예제 #5
0
        public PicasaAlbum(GoogleConnection conn, string user, string aid, string authkey) : this(conn)
        {
            if (user == null || user == String.Empty)
            {
                throw new ArgumentNullException("user");
            }

            if (aid == null || aid == String.Empty)
            {
                throw new ArgumentNullException("aid");
            }

            this.user    = user;
            this.id      = aid;
            this.authkey = authkey;

            string download_link = GDataApi.GetAlbumEntryById(user, id);
            if (authkey != null && authkey != "")
            {
                download_link += "&authkey=" + authkey;
            }
            string received = conn.DownloadString(download_link);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(received);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            XmlUtil.AddDefaultNamespaces(nsmgr);
            XmlNode entry = doc.SelectSingleNode("atom:entry", nsmgr);
            ParseAlbum(entry, nsmgr);
        }
예제 #6
0
		private PicasaAlbum (GoogleConnection conn)
		{
			if (conn == null)
				throw new ArgumentNullException ("conn");

			this.conn = conn;
		}
예제 #7
0
        /// <summary>
        /// 刷新GoogleToken信息
        /// </summary>
        private void RefreshConnectionToken(GoogleConnection connection)
        {
            _token = _googleTokenService.DeserializeToken(connection.Token);
            _googleTokenService.RefreshToken(_token);

            connection.SetToken(_googleTokenService.SerializeToken(_token));
            _accountConnectionService.Update(connection);
        }
예제 #8
0
        private PicasaAlbum(GoogleConnection conn)
        {
            if (conn == null)
            {
                throw new ArgumentNullException("conn");
            }

            this.conn = conn;
        }
예제 #9
0
 public void login()
 {
     try {
         connection = new GoogleConnection(GoogleService.Picasa);
         //ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy();
         connection.Authenticate(this.username, this.password);
         web           = new PicasaWeb(connection);
         this.loggedIn = true;
     } catch (Exception) {
         this.loggedIn = false;
     }
 }
        public static IServer GetCalendarServer(CalendarTypes calendarTypes, string username = null, string password = null)
        {
            IServer server;

            if (calendarTypes == CalendarTypes.Outlook)
            {
                return(new OutlookServer());
            }
            else
            {
                IConnection connection;
                if (calendarTypes == CalendarTypes.Google)
                {
                    if (File.Exists("token"))
                    {
                        StreamReader sr = new StreamReader("token");
                        connection = new GoogleConnection(sr.ReadLine());
                        sr.Close();
                    }
                    else
                    {
                        connection = refreshGoogleToken();
                    }
                    server = null;
                }
                else
                {
                    connection = new BasicConnection(username, password);
                    server     = null;
                }
                if (server == null)
                {
                    try
                    {
                        server = new CalDav.Client.Server(urlFromCalendarType(calendarTypes), connection, username, password);
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message == "Authentication is required" && connection.GetType().Equals(new GoogleConnection("").GetType()))
                        {
                            connection = refreshGoogleToken();
                            server     = new CalDav.Client.Server(urlFromCalendarType(calendarTypes), connection, username, password);
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                }
                return(server);
            }
        }
        private static IConnection refreshGoogleToken()
        {
            IConnection     connection;
            GoogleOAuthForm form = new GoogleOAuthForm();

            form.ShowDialog();
            connection = new GoogleConnection(form.Result.Token);
            StreamWriter sw = new StreamWriter("token");

            sw.WriteLine(form.Result.Token);
            sw.Close();
            return(connection);
        }
예제 #12
0
        public void CreateGoole()
        {
            var u = this.RandomString();
            var c = new GoogleConnection(u, _token, this.CreateAccount());

            this._accountConnectionService.Create(c);
            Assert.Greater(c.ID, 0);

            var c2 = this._accountConnectionService.GetConnection <GoogleConnection>(u);

            Assert.IsNotNull(c2);
            Assert.AreEqual(c2.ID, c.ID);
            Assert.AreEqual(c2.Name, c.Name);
        }
예제 #13
0
		public PicasaAlbum (GoogleConnection conn, string aid) : this (conn)
		{
			if (conn.User == null)
				throw new ArgumentException ("Need authentication before being used.", "conn");

			if (aid == null || aid == String.Empty)
				throw new ArgumentNullException ("aid");

			this.user = conn.User;
			this.id = aid;

			string received = conn.DownloadString (GDataApi.GetAlbumEntryById (conn.User, aid));
			XmlDocument doc = new XmlDocument ();
			doc.LoadXml (received);
			XmlNamespaceManager nsmgr = new XmlNamespaceManager (doc.NameTable);
			XmlUtil.AddDefaultNamespaces (nsmgr);
			XmlNode entry = doc.SelectSingleNode ("atom:entry", nsmgr);
			ParseAlbum (entry, nsmgr);
		}
예제 #14
0
        public PicasaWeb(GoogleConnection conn, string username)
        {
            if (conn == null)
                throw new ArgumentNullException ("conn");

            if (conn.User == null && username == null)
                throw new ArgumentException ("The connection should be authenticated OR you should call this constructor with a non-null username argument");

            this.conn = conn;
            this.user = username ?? conn.User;

            string received = conn.DownloadString (GDataApi.GetGalleryEntry (user));
            XmlDocument doc = new XmlDocument ();
            doc.LoadXml (received);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager (doc.NameTable);
            XmlUtil.AddDefaultNamespaces (nsmgr);
            XmlNode entry = doc.SelectSingleNode ("atom:entry", nsmgr);
            ParseGallery (entry, nsmgr);
        }
예제 #15
0
        public PicasaWeb Connect()
        {
            System.Console.WriteLine("GoogleAccount.Connect()");
            GoogleConnection conn = new GoogleConnection(GoogleService.Picasa);

            ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy();
            if (unlock_captcha == null || token == null)
            {
                conn.Authenticate(username, password);
            }
            else
            {
                conn.Authenticate(username, password, token, unlock_captcha);
                token          = null;
                unlock_captcha = null;
            }
            connection = conn;
            PicasaWeb picasa = new PicasaWeb(conn);

            this.picasa = picasa;
            return(picasa);
        }
예제 #16
0
        public PicasaAlbum(GoogleConnection conn, string aid) : this(conn)
        {
            if (conn.User == null)
            {
                throw new ArgumentException("Need authentication before being used.", "conn");
            }

            if (aid == null || aid == String.Empty)
            {
                throw new ArgumentNullException("aid");
            }

            this.user = conn.User;
            this.id   = aid;

            string      received = conn.DownloadString(GDataApi.GetAlbumEntryById(conn.User, aid));
            XmlDocument doc      = new XmlDocument();
            doc.LoadXml(received);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            XmlUtil.AddDefaultNamespaces(nsmgr);
            XmlNode entry = doc.SelectSingleNode("atom:entry", nsmgr);
            ParseAlbum(entry, nsmgr);
        }
예제 #17
0
        public static IServer GetCalendarServer(CalendarTypes calendarTypes, string username = null, string password = null, string token = null)
        {
            IServer     server;
            IConnection connection;

            if (calendarTypes == CalendarTypes.Google)
            {
                connection = new GoogleConnection(token);
                server     = null;
            }
            else
            {
                connection = new BasicConnection(username, password);
                server     = null;
            }

            if (server == null)
            {
                try
                {
                    server = new CalDav.Client.Server(urlFromCalendarType(calendarTypes), connection, username, password);
                }
                catch (Exception ex)
                {
                    if (ex.Message == "Authentication is required" && connection.GetType().Equals(new GoogleConnection("").GetType()))
                    {
                        connection = refreshGoogleToken();
                        server     = new CalDav.Client.Server(urlFromCalendarType(calendarTypes), connection, username, password);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            return(server);
        }
예제 #18
0
 public PicasaWeb(GoogleConnection conn)
     : this(conn, null)
 {
 }
예제 #19
0
        internal PicasaAlbum(GoogleConnection conn, string user, XmlNode nodeitem, XmlNamespaceManager nsmgr)
            : this(conn)
        {
            this.user = user ?? conn.User;

            ParseAlbum (nodeitem, nsmgr);
        }
예제 #20
0
        internal PicasaAlbum(GoogleConnection conn, string user, XmlNode nodeitem, XmlNamespaceManager nsmgr) : this(conn)
        {
            this.user = user ?? conn.User;

            ParseAlbum(nodeitem, nsmgr);
        }
		internal PicasaPicture (GoogleConnection conn, PicasaAlbum album, XmlNode nodeitem, XmlNamespaceManager nsmgr)
		{
			this.conn = conn;
			this.album = album;
			ParsePicture (nodeitem, nsmgr);
		}
예제 #22
0
 public PicasaWeb(GoogleConnection conn) : this(conn, null)
 {
 }
예제 #23
0
 internal PicasaPicture(GoogleConnection conn, PicasaAlbum album, XmlNode nodeitem, XmlNamespaceManager nsmgr)
 {
     this.conn  = conn;
     this.album = album;
     ParsePicture(nodeitem, nsmgr);
 }
예제 #24
0
 private void MarkChanged()
 {
     connection = null;
 }
예제 #25
0
 PicasaAlbum(GoogleConnection conn)
 {
     Connection = conn ?? throw new ArgumentNullException("conn");
 }