Exemple #1
0
        CreateAlbum(VK.UID page, string albumTitle)
        {
            // Check
            HostSession.EnsureHasPermission(VK.SecurityFlag.Audios);

            if (!page.IsValid)
                throw new ArgumentException("Invalid page UID specified.");
           else  if (!page.IsCommunity && page != HostSession.UserPage)
                throw new ArgumentException("Cannot modify other's private page audios.");
            else if (albumTitle == null)
                throw new ArgumentNullException("albumTitle", "You have to specify audio album title.");

            // Request
            var args = new NameValueCollection();
            if (page != HostSession.UserPage)
                args.Add("group_id", page.AbsoluteValue.ToString());
            args.Add("title", albumTitle);

#if NEWSTYLE
            XmlElement response = await HostSession.Network.AsyncXmlMethodCall("audio.addAlbum", args);
#else
            XmlElement response = HostSession.Network.XmlMethodCall("audio.addAlbum", args);
#endif

            // Check
            if (response == null || response["album_id"] == null)
                throw new VK.APIImplException(HostSession, "audio.addAlbum", "Unexpected server reply.");

            // Parse
            var album = new VK.AudioAlbum();
            album.Title = albumTitle;
            album.ID = new VK.DualID(page, uint.Parse(response["album_id"].InnerText));

            // Done
            return album;
        }
Exemple #2
0
        GetAlbums(VK.UID page, int offset, uint count)
        {
            // Check
            HostSession.EnsureHasPermission(VK.SecurityFlag.Audios);

            if (!page.IsValid)
                throw new ArgumentException("Invalid page UID specified.");
            else if (count < 1 || count > 100)
                throw new ArgumentOutOfRangeException("count", "Count of albums to fetch per one request must be in range [1-100].");
            else if (offset < -1)
                throw new ArgumentOutOfRangeException("offset", "Invalid 'offset' value.");

            // Request
            var args = new NameValueCollection();
            args.Add("owner_id", page.ToString());
            if (offset != -1)
                args.Add("offset", offset.ToString());
            args.Add("count", count.ToString());
#if NEWSTYLE
            XmlElement response = await HostSession.Network.AsyncXmlMethodCall("audio.getAlbums", args);
#else
            XmlElement response = HostSession.Network.XmlMethodCall("audio.getAlbums", args);
#endif

            // Check
            if (response == null)
                throw new VK.APIImplException(HostSession, "audio.getAlbums", "Unexpected server reply.");

            uint totalCount = 0;

            // Parse
            VK.AudioAlbum[] albums = null;
            if (response.GetAttribute("list") == "true")    // Notice: maybe this is incorrect, but currently okay
            {
                int iCount = 0;
                foreach (XmlElement node in response.ChildNodes)
                {
                    // Ensure it is what we expect
                    if (iCount == 0 && node.Name == "count")
                    {
                        // We have totalCount
                        totalCount = uint.Parse(node.InnerText);
                        if (count <= 0 || count > totalCount)
                            count = totalCount;

                        albums = new VK.AudioAlbum[count];
                        continue;
                    }
                    else if (node.Name != "album")
                        throw new NotSupportedException("Unknown node in xml server reply; expected 'album', got '" + node.Name + "'.");

                    albums[iCount++].Parse(node);
                }
            }

            // Done
            return new ArraySegment<VK.AudioAlbum,uint>(albums, totalCount);
        }