Beispiel #1
0
        public VK.Audio[] Get(VK.UID page, bool needUserDigest, VK.AudioOwnerDigest userDigest, VK.AudioAlbum album = null, int offset = 0, int count = -1)
#endif
        {
            // Check
            HostSession.EnsureHasPermission(VK.SecurityFlag.Audios);

            if (!page.IsValid)
                throw new ArgumentException("Invalid page UID specified.");
            else if (album != null && album.ID.Page != page)
                throw new ArgumentException("Invalid 'album' specified, this album does not belong to the specified page.");
            else if (album != null && !album.IsValid)
                throw new ArgumentException("Album does not exists.");
            else if (offset < -1)
                throw new ArgumentOutOfRangeException("offset", "Invalid 'offset' value.");

            // Request
            var args = new NameValueCollection();
            if(page != HostSession.UserPage)
                args.Add("owner_id", page.Value.ToString());
            if (album != null)
                args.Add("album_id", album.ID.Ordinal.ToString());
            if (needUserDigest)
                args.Add("need_user", "1");
            if (offset != -1)
                args.Add("offset", offset.ToString());
            if (count != -1)
                args.Add("count", count.ToString());

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

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

            // Parse user digest
            if (needUserDigest && response["user"] != null)
                userDigest.Parse(response["user"]);

            // Parse audios
            VK.Audio[] audios = null;
            if (response.GetAttribute("list") == "true")    // Notice: maybe this is incorrect, but currently okay
            {
                audios = new VK.Audio[response.ChildNodes.Count];
                int iCount = 0;
                foreach (XmlElement node in response.ChildNodes)
                {
                    // Ensure it is audio
                    if (node.Name != "audio")
                        throw new VK.APIImplException(HostSession, "audio.get", "Unexpected server reply. "
                            + "Unexpected XML node; expected 'audio', got '" + node.Name + "'.");

                    audios[iCount] = new VK.Audio();
                    audios[iCount++].Parse(node);
                }
            }

            // Done
            return audios;
        }
Beispiel #2
0
        public void Restore(ref VK.Audio audio)
#endif
        {
            // Check
            HostSession.EnsureHasPermission(VK.SecurityFlag.Audios);

            if (!audio.ID.IsValid)
                throw new ArgumentException("Invalid Audio identfier specified.");

            // Request
            var args = new NameValueCollection();
            args.Add("owner_id", audio.ID.Page.Value.ToString());
            args.Add("audio_id", audio.ID.Ordinal.ToString());
#if NEWSTYLE
            XmlElement response = await HostSession.Network.AsyncXmlMethodCall("audio.restore", args);
#else
            XmlElement response = HostSession.Network.XmlMethodCall("audio.restore", args);
#endif

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

            // Parse
            audio.Parse(response["audio"]);
        }