Пример #1
0
        public PicasaPictureCollection GetPictures()
        {
            string download_link = GDataApi.GetAlbumFeedById(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 feed = doc.SelectSingleNode("atom:feed", nsmgr);
            PicasaPictureCollection coll = new PicasaPictureCollection();

            foreach (XmlNode item in feed.SelectNodes("atom:entry", nsmgr))
            {
                coll.Add(new PicasaPicture(conn, this, item, nsmgr));
            }
            coll.SetReadOnly();
            return(coll);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
0
        public void AddTag(string tag)
        {
            if (tag == null)
            {
                throw new ArgumentNullException("title");
            }

            string op_string = GetXmlForTagging(tag);

            byte []        op_bytes = Encoding.UTF8.GetBytes(op_string);
            string         url      = GDataApi.GetPictureFeed(conn.User, album.UniqueID, UniqueID);
            HttpWebRequest request  = conn.AuthenticatedRequest(url);

            request.ContentType = "application/atom+xml; charset=UTF-8";
            request.Method      = "POST";
            Stream output_stream = request.GetRequestStream();

            output_stream.Write(op_bytes, 0, op_bytes.Length);
            output_stream.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (Stream stream = response.GetResponseStream()) {
                StreamReader sr = new StreamReader(stream, Encoding.UTF8);
                sr.ReadToEnd();
            }
            response.Close();
        }
Пример #5
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);
        }
Пример #6
0
        public PicasaAlbum CreateAlbum(string title, string description, AlbumAccess access, DateTime pubDate)
        {
            if (title == null)
            {
                throw new ArgumentNullException("title");
            }

            if (description == null)
            {
                description = "";
            }

            if (access != AlbumAccess.Public && access != AlbumAccess.Private)
            {
                throw new ArgumentException("Invalid value.", "access");
            }

            // Check if pubDate can be in the past
            string url = GDataApi.GetPostURL(conn.User);

            if (url == null)
            {
                throw new UnauthorizedAccessException("You are not authorized to create albums.");
            }
            string op_string = GetXmlForCreate(title, description, pubDate, access);

            byte []        op_bytes = Encoding.UTF8.GetBytes(op_string);
            HttpWebRequest request  = conn.AuthenticatedRequest(url);

            request.ContentType = "application/atom+xml; charset=UTF-8";
            request.Method      = "POST";
            Stream output_stream = request.GetRequestStream();

            output_stream.Write(op_bytes, 0, op_bytes.Length);
            output_stream.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string          received = "";

            using (Stream stream = response.GetResponseStream()) {
                StreamReader sr = new StreamReader(stream, Encoding.UTF8);
                received = sr.ReadToEnd();
            }
            response.Close();

            XmlDocument doc = new XmlDocument();

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

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

            return(new PicasaAlbum(conn, null, entry, nsmgr));
        }
Пример #7
0
        public PicasaAlbumCollection GetAlbums()
        {
            string gallery_link = GDataApi.GetGalleryFeed(user);
            string received     = conn.DownloadString(gallery_link);

            XmlDocument doc = new XmlDocument();

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

            XmlUtil.AddDefaultNamespaces(nsmgr);
            XmlNode feed = doc.SelectSingleNode("atom:feed", nsmgr);
            PicasaAlbumCollection coll = new PicasaAlbumCollection();

            foreach (XmlNode item in feed.SelectNodes("atom:entry", nsmgr))
            {
                coll.Add(new PicasaAlbum(conn, user, item, nsmgr));
            }
            coll.SetReadOnly();
            return(coll);
        }
Пример #8
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);
        }
Пример #9
0
        public PicasaPicture UploadPicture(string title, string description, string mime_type, Stream input)
        {
            if (title == null)
            {
                throw new ArgumentNullException("title");
            }

            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (!input.CanRead)
            {
                throw new ArgumentException("Cannot read from stream", "input");
            }

            string url = GDataApi.GetURLForUpload(conn.User, id);

            if (url == null)
            {
                throw new UnauthorizedAccessException("You are not authorized to upload to this album.");
            }

            MultipartRequest request = new MultipartRequest(conn, url);
            MemoryStream     ms      = null;

            if (UploadProgress != null)
            {
                // We do 'manual' buffering
                request.Request.AllowWriteStreamBuffering = false;
                ms = new MemoryStream();
                request.OutputStream = ms;
            }

            request.BeginPart(true);
            request.AddHeader("Content-Type: application/atom+xml; \r\n", true);
            string upload = GetXmlForUpload(title, description);

            request.WriteContent(upload);
            request.EndPart(false);
            request.BeginPart();
            request.AddHeader("Content-Type: " + mime_type + "\r\n", true);

            byte [] data = new byte [8192];
            int     nread;

            while ((nread = input.Read(data, 0, data.Length)) > 0)
            {
                request.WritePartialContent(data, 0, nread);
            }
            request.EndPartialContent();
            request.EndPart(true);              // It won't call Close() on the MemoryStream

            if (UploadProgress != null)
            {
                int req_length = (int)ms.Length;
                request.Request.ContentLength = req_length;
                DoUploadProgress(title, 0, req_length);
                using (Stream req_stream = request.Request.GetRequestStream()) {
                    byte [] buffer = ms.GetBuffer();
                    int     nwrite = 0;
                    int     offset;
                    for (offset = 0; offset < req_length; offset += nwrite)
                    {
                        nwrite = System.Math.Min(16384, req_length - offset);
                        req_stream.Write(buffer, offset, nwrite);
                        // The progress uses the actual request size, not file size.
                        DoUploadProgress(title, offset, req_length);
                    }
                    DoUploadProgress(title, offset, req_length);
                }
            }

            string      received = request.GetResponseAsString();
            XmlDocument doc      = new XmlDocument();

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

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

            return(new PicasaPicture(conn, this, entry, nsmgr));
        }