コード例 #1
0
ファイル: ArtistBrowse.cs プロジェクト: gladish/Spotify.NET
        public IList <Image> EndLoadPortraits(IAsyncResult result)
        {
            AsyncLoadPortraitsResult loadImageResult = ThrowHelper.DownCast <AsyncLoadPortraitsResult>(result, "result");

            loadImageResult.WaitForCallbackComplete();

            List <Exception> errors = null;

            foreach (Image img in loadImageResult.Closure)
            {
                if (img.Error != Error.Ok)
                {
                    if (errors == null)
                    {
                        errors = new List <Exception>();
                    }
                    errors.Add(new Spotify.Exception(img.Error));
                }
            }

            System.Exception ex = null;
            if (errors != null)
            {
                ex = new AggregateException(errors);
            }

            loadImageResult.SetCompleted(ex);
            loadImageResult.CheckPendingException();
            return(loadImageResult.Closure);
        }
コード例 #2
0
ファイル: ArtistBrowse.cs プロジェクト: gladish/Spotify.NET
        public IAsyncResult BeginLoadPortraits(Session session, AsyncCallback userCallback, object state)
        {
            ThrowHelper.ThrowIfNull(session, "session");

            int n = LibSpotify.sp_artistbrowse_num_portraits_r(Handle);
            AsyncLoadPortraitsResult result = new AsyncLoadPortraitsResult(n, userCallback, state);

            result.Closure = new List <Image>();

            for (int i = 0; i < n; ++i)
            {
                Image image = new Image(LibSpotify.sp_image_create_r(session.Handle, LibSpotify.sp_artistbrowse_portrait_r(Handle, i)));
                image.Loaded += result.HandleImageLoaded;
                result.Closure.Add(image);
            }

            if (result.CheckComplete())
            {
                result.CompletedSynchronously = true;
            }

            return(result);
        }