예제 #1
0
            public override Task<MemoryImage> LoadThumbnailImageAsync(CancellationToken token)
            {
                return Task.Factory.StartNew(() =>
                {
                    var oauth = new HttpOAuthApiProxy();
                    TonTwitterCom.InitializeOAuthToken(oauth);

                    Stream response = null;
                    var statusCode = oauth.GetContent("GET", new Uri(this.ThumbnailUrl), null, ref response, MyCommon.GetUserAgentString());

                    using (response)
                    {
                        if (statusCode == HttpStatusCode.OK)
                            return MemoryImage.CopyFromStream(response);
                        else
                            throw new WebException(statusCode.ToString(), WebExceptionStatus.ProtocolError);
                    }
                },
                token, TaskCreationOptions.None, TaskScheduler.Default); // 明示しないと TaskScheduler.Current になり UI スレッド上で実行されてしまう
            }
예제 #2
0
            public override Task<MemoryImage> LoadThumbnailImageAsync(HttpClient http, CancellationToken cancellationToken)
            {
                // TODO: HttpClient を使用したコードに置き換えたい
                return Task.Run(() =>
                {
                    var oauth = new HttpOAuthApiProxy();
                    TonTwitterCom.InitializeOAuthToken(oauth);

                    Stream response = null;
                    var statusCode = oauth.GetContent("GET", new Uri(this.ThumbnailUrl), null, ref response, MyCommon.GetUserAgentString());

                    using (response)
                    {
                        if (statusCode == HttpStatusCode.OK)
                            return MemoryImage.CopyFromStreamAsync(response);
                        else
                            throw new WebException(statusCode.ToString(), WebExceptionStatus.ProtocolError);
                    }
                }, cancellationToken);
            }
예제 #3
0
            public override Task <MemoryImage> LoadThumbnailImageAsync(HttpClient http, CancellationToken cancellationToken)
            {
                // TODO: HttpClient を使用したコードに置き換えたい
                return(Task.Run(async() =>
                {
                    var oauth = new HttpOAuthApiProxy();
                    TonTwitterCom.InitializeOAuthToken(oauth);

                    Stream response = null;
                    var statusCode = oauth.GetContent("GET", new Uri(this.ThumbnailUrl), null, ref response, Networking.GetUserAgentString());

                    using (response)
                    {
                        if (statusCode != HttpStatusCode.OK)
                        {
                            throw new WebException(statusCode.ToString(), WebExceptionStatus.ProtocolError);
                        }

                        return await MemoryImage.CopyFromStreamAsync(response)
                        .ConfigureAwait(false);
                    }
                }, cancellationToken));
            }