OSDN Git Service

TweenMain.http を削除, HttpConnection.GlobalHttpClient をなるべく使用する
authorKimura Youichi <kim.upsilon@bucyou.net>
Sat, 28 Jun 2014 21:45:07 +0000 (06:45 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Mon, 30 Jun 2014 10:27:22 +0000 (19:27 +0900)
12 files changed:
OpenTween/Bing.cs
OpenTween/ImageCache.cs
OpenTween/Resources/ChangeLog.txt
OpenTween/Thumbnail/Services/FoursquareCheckin.cs
OpenTween/Thumbnail/Services/ImgAzyobuziNet.cs
OpenTween/Thumbnail/Services/MetaThumbnailService.cs
OpenTween/Thumbnail/Services/Pixiv.cs
OpenTween/Thumbnail/Services/Tinami.cs
OpenTween/Thumbnail/Services/ViaMe.cs
OpenTween/Thumbnail/Services/Vimeo.cs
OpenTween/Thumbnail/ThumbnailGenerator.cs
OpenTween/Tween.cs

index 559cbfe..377ce58 100644 (file)
@@ -168,11 +168,20 @@ namespace OpenTween
         private static readonly string TranslateUri =
             "https://api.datamarket.azure.com/Data.ashx/Bing/MicrosoftTranslator/v1/Translate";
 
-        private readonly HttpClient http;
+        protected HttpClient http
+        {
+            get { return this.localHttpClient ?? HttpConnection.GlobalHttpClient; }
+        }
+        private readonly HttpClient localHttpClient;
+
+        public Bing()
+            : this(null)
+        {
+        }
 
         public Bing(HttpClient http)
         {
-            this.http = http;
+            this.localHttpClient = http;
         }
 
         /// <summary>
index 806e53f..1fa3c70 100644 (file)
@@ -34,11 +34,6 @@ namespace OpenTween
     public class ImageCache : IDisposable
     {
         /// <summary>
-        /// 画像の取得に使用する HttpClient インスタンス
-        /// </summary>
-        private readonly HttpClient http;
-
-        /// <summary>
         /// キャッシュとして URL と取得した画像を対に保持する辞書
         /// </summary>
         internal LRUCacheDictionary<string, Task<MemoryImage>> innerDictionary;
@@ -58,10 +53,8 @@ namespace OpenTween
         /// </summary>
         private bool disposed = false;
 
-        public ImageCache(HttpClient http)
+        public ImageCache()
         {
-            this.http = http;
-
             this.innerDictionary = new LRUCacheDictionary<string, Task<MemoryImage>>(trimLimit: 300, autoTrimCount: 100);
             this.innerDictionary.CacheRemoved += (s, e) => {
                 // まだ参照されている場合もあるのでDisposeはファイナライザ任せ
@@ -129,7 +122,7 @@ namespace OpenTween
 
         private async Task<MemoryImage> FetchImageAsync(string uri, CancellationToken cancelToken)
         {
-            using (var response = await this.http.GetAsync(uri, cancelToken).ConfigureAwait(false))
+            using (var response = await HttpConnection.GlobalHttpClient.GetAsync(uri, cancelToken).ConfigureAwait(false))
             {
                 var imageStream = await response.Content.ReadAsStreamAsync()
                     .ConfigureAwait(false);
index 1900338..0bc14be 100644 (file)
@@ -9,6 +9,7 @@
  * CHG: 発言詳細部の更新時のパフォーマンスを改善
  * FIX: 一部クライアントから投稿されたツイートの読み込み時にエラーが発生する問題の修正
  * FIX: 短縮URL生成時のエラーが適切に処理されない問題を修正
+ * FIX: プロキシ設定が一部の機能 (アイコンの読み込み, 短縮URLの展開等) で適用されない問題を修正
 
 ==== Ver 1.2.1(2014/05/26)
  * NEW: 5月28日(太平洋夏時間, UTC-7)から追加される予定の pic.twitter.com の複数枚画像表示に対応しました
index 22476ee..bd105cc 100644 (file)
@@ -40,11 +40,20 @@ namespace OpenTween.Thumbnail.Services
 
         public static readonly string ApiBase = "https://api.foursquare.com/v2";
 
-        protected readonly HttpClient http;
+        protected HttpClient http
+        {
+            get { return this.localHttpClient ?? HttpConnection.GlobalHttpClient; }
+        }
+        private readonly HttpClient localHttpClient;
+
+        public FoursquareCheckin()
+            : this(null)
+        {
+        }
 
         public FoursquareCheckin(HttpClient http)
         {
-            this.http = http;
+            this.localHttpClient = http;
         }
 
         public override async Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
index 02a7b36..03fab2f 100644 (file)
@@ -43,10 +43,19 @@ namespace OpenTween.Thumbnail.Services
         protected IEnumerable<Regex> UrlRegex = null;
         protected Timer UpdateTimer;
 
-        protected readonly HttpClient http;
+        protected HttpClient http
+        {
+            get { return this.localHttpClient ?? HttpConnection.GlobalHttpClient; }
+        }
+        private readonly HttpClient localHttpClient;
 
         private object LockObj = new object();
 
+        public ImgAzyobuziNet(bool autoupdate)
+            : this(null, autoupdate)
+        {
+        }
+
         public ImgAzyobuziNet(HttpClient http)
             : this(http, autoupdate: false)
         {
@@ -60,7 +69,7 @@ namespace OpenTween.Thumbnail.Services
             this.Enabled = true;
             this.DisabledInDM = true;
 
-            this.http = http;
+            this.localHttpClient = http;
         }
 
         public bool AutoUpdate
index b801147..ff4b1a7 100644 (file)
@@ -39,12 +39,22 @@ namespace OpenTween.Thumbnail.Services
         protected static Regex metaPattern = new Regex("<meta (name|property)=[\"'](?<name>.+?)[\"'] (content|value)=[\"'](?<content>.+?)[\"']");
         protected static string[] propertyNames = { "twitter:image", "og:image" };
 
-        protected readonly HttpClient http;
+        protected HttpClient http
+        {
+            get { return this.localHttpClient ?? HttpConnection.GlobalHttpClient; }
+        }
+        private readonly HttpClient localHttpClient;
+
         protected readonly Regex regex;
 
+        public MetaThumbnailService(string urlPattern)
+            : this(null, urlPattern)
+        {
+        }
+
         public MetaThumbnailService(HttpClient http, string urlPattern)
         {
-            this.http = http;
+            this.localHttpClient = http;
             this.regex = new Regex(urlPattern);
         }
 
index 09aa622..9716a1b 100644 (file)
@@ -36,6 +36,11 @@ namespace OpenTween.Thumbnail.Services
         public static readonly string UrlPattern =
             @"^http://www\.pixiv\.net/(member_illust|index)\.php\?(?=.*mode=(medium|big))(?=.*illust_id=(?<illustId>[0-9]+)).*$";
 
+        public Pixiv()
+            : base(Pixiv.UrlPattern)
+        {
+        }
+
         public Pixiv(HttpClient http)
             : base(http, Pixiv.UrlPattern)
         {
index df7c569..e5bd1b3 100644 (file)
@@ -38,11 +38,20 @@ namespace OpenTween.Thumbnail.Services
         public static readonly Regex UrlPatternRegex =
             new Regex(@"^http://www\.tinami\.com/view/(?<ContentId>\d+)$");
 
-        protected readonly HttpClient http;
+        protected HttpClient http
+        {
+            get { return this.localHttpClient ?? HttpConnection.GlobalHttpClient; }
+        }
+        private readonly HttpClient localHttpClient;
+
+        public Tinami()
+            : this(null)
+        {
+        }
 
         public Tinami(HttpClient http)
         {
-            this.http = http;
+            this.localHttpClient = http;
         }
 
         public override async Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
index e22ac8b..08f26cd 100644 (file)
@@ -40,11 +40,20 @@ namespace OpenTween.Thumbnail.Services
         public static readonly Regex UrlPatternRegex =
             new Regex(@"^https?://via\.me/-(\w+)$");
 
-        protected readonly HttpClient http;
+        protected HttpClient http
+        {
+            get { return this.localHttpClient ?? HttpConnection.GlobalHttpClient; }
+        }
+        private readonly HttpClient localHttpClient;
+
+        public ViaMe()
+            : this(null)
+        {
+        }
 
         public ViaMe(HttpClient http)
         {
-            this.http = http;
+            this.localHttpClient = http;
         }
 
         public override async Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
index 8224ae0..b1a40ca 100644 (file)
@@ -40,11 +40,20 @@ namespace OpenTween.Thumbnail.Services
         public static readonly Regex UrlPatternRegex =
             new Regex(@"http://vimeo\.com/(?<postID>[0-9]+)");
 
-        protected readonly HttpClient http;
+        protected HttpClient http
+        {
+            get { return this.localHttpClient ?? HttpConnection.GlobalHttpClient; }
+        }
+        private readonly HttpClient localHttpClient;
+
+        public Vimeo()
+            : this(null)
+        {
+        }
 
         public Vimeo(HttpClient http)
         {
-            this.http = http;
+            this.localHttpClient = http;
         }
 
         public override async Task<ThumbnailInfo> GetThumbnailInfoAsync(string url, PostClass post, CancellationToken token)
index 7f20a95..48f6a50 100644 (file)
@@ -42,9 +42,9 @@ namespace OpenTween.Thumbnail
             ThumbnailGenerator.Services = new List<IThumbnailService>();
         }
 
-        public static void InitializeGenerator(HttpClient http)
+        public static void InitializeGenerator()
         {
-            ImgAzyobuziNetInstance = new ImgAzyobuziNet(http, autoupdate: true);
+            ImgAzyobuziNetInstance = new ImgAzyobuziNet(autoupdate: true);
 
             ThumbnailGenerator.Services = new List<IThumbnailService>()
             {
@@ -125,10 +125,10 @@ namespace OpenTween.Thumbnail
                     "http://lohas.nicoseiga.jp/thumb/${id}l?"),
 
                 // pixiv
-                new Pixiv(http),
+                new Pixiv(),
 
                 // flickr
-                new MetaThumbnailService(http, @"^https?://www\.flickr\.com/.+$"),
+                new MetaThumbnailService(@"^https?://www\.flickr\.com/.+$"),
 
                 // フォト蔵
                 new SimpleThumbnailService(
@@ -137,7 +137,7 @@ namespace OpenTween.Thumbnail
                     "http://photozou.jp/p/img/${photoId}"),
 
                 // Piapro
-                new MetaThumbnailService(http, @"^http://piapro\.jp/(?:content/[0-9a-z]+|t/[0-9a-zA-Z_\-]+)$"),
+                new MetaThumbnailService(@"^http://piapro\.jp/(?:content/[0-9a-z]+|t/[0-9a-zA-Z_\-]+)$"),
 
                 // Tumblr
                 new Tumblr(),
@@ -152,7 +152,7 @@ namespace OpenTween.Thumbnail
                 new SimpleThumbnailService(@"^http://ow\.ly/i/(\w+)$", "http://static.ow.ly/photos/thumb/${1}.jpg"),
 
                 // vimeo
-                new Vimeo(http),
+                new Vimeo(),
 
                 // cloudfiles
                 new SimpleThumbnailService(@"^http://c[0-9]+\.cdn[0-9]+\.cloudfiles\.rackspacecloud\.com/[a-z_0-9]+", "${0}"),
@@ -170,10 +170,10 @@ namespace OpenTween.Thumbnail
                     "http://pikubo.me/l/${1}"),
 
                 // Foursquare
-                new FoursquareCheckin(http),
+                new FoursquareCheckin(),
 
                 // TINAMI
-                new Tinami(http),
+                new Tinami(),
 
                 // pic.twitter.com
                 new SimpleThumbnailService(
@@ -194,13 +194,13 @@ namespace OpenTween.Thumbnail
                     "${0}.jpg"),
 
                 // via.me
-                new ViaMe(http),
+                new ViaMe(),
 
                 // tuna.be
                 new SimpleThumbnailService(@"^http://tuna\.be/t/(?<entryId>[a-zA-Z0-9\.\-_]+)$", "http://tuna.be/show/thumb/${entryId}"),
 
                 // Path (path.com)
-                new MetaThumbnailService(http, @"^https?://path.com/p/\w+$"),
+                new MetaThumbnailService(@"^https?://path.com/p/\w+$"),
 
                 // GIFMAGAZINE
                 new SimpleThumbnailService(@"^http://gifmagazine\.net/post_images/(\d+)", "http://img.gifmagazine.net/gifmagazine/images/${1}/original.gif"),
index 88f9162..f2ceadb 100644 (file)
@@ -53,8 +53,6 @@ namespace OpenTween
 {
     public partial class TweenMain : OTBaseForm
     {
-        private HttpClient http;
-
         //各種設定
         private Size _mySize;           //画面サイズ
         private Point _myLoc;           //画面位置
@@ -362,8 +360,6 @@ namespace OpenTween
                 this.IconCache.Dispose();
             }
 
-            this.http.Dispose();
-
             // 終了時にRemoveHandlerしておかないとメモリリークする
             // http://msdn.microsoft.com/ja-jp/library/microsoft.win32.systemevents.powermodechanged.aspx
             Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
@@ -664,7 +660,7 @@ namespace OpenTween
             ////設定読み出し
             LoadConfig();
 
-            ThumbnailGenerator.InitializeGenerator(this.http);
+            ThumbnailGenerator.InitializeGenerator();
 
             var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
             imgazyobizinet.Enabled = this._cfgCommon.EnableImgAzyobuziNet;
@@ -919,7 +915,7 @@ namespace OpenTween
             _initial = true;
 
             //アイコンリスト作成
-            this.IconCache = new ImageCache(this.http);
+            this.IconCache = new ImageCache();
 
             bool saveRequired = false;
             bool firstRun = false;
@@ -5918,7 +5914,7 @@ namespace OpenTween
             var versionInfoUrl = new Uri(ApplicationSettings.VersionInfoUrl + "?" +
                 DateTime.Now.ToString("yyMMddHHmmss") + Environment.TickCount);
 
-            var responseText = await this.http.GetStringAsync(versionInfoUrl)
+            var responseText = await HttpConnection.GlobalHttpClient.GetStringAsync(versionInfoUrl)
                 .ConfigureAwait(false);
 
             // 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
@@ -12289,14 +12285,6 @@ namespace OpenTween
         private HookGlobalHotkey _hookGlobalHotkey;
         public TweenMain()
         {
-            this.http = HttpConnection.CreateHttpClient(new HttpClientHandler());
-            HttpConnection.WebProxyChanged += (o, e) =>
-            {
-                var newClient = HttpConnection.CreateHttpClient(new HttpClientHandler());
-                var oldClient = Interlocked.Exchange(ref this.http, newClient);
-                oldClient.Dispose();
-            };
-
             _hookGlobalHotkey = new HookGlobalHotkey(this);
 
             // この呼び出しは、Windows フォーム デザイナで必要です。
@@ -12978,7 +12966,7 @@ namespace OpenTween
             if (string.IsNullOrEmpty(str))
                 return;
 
-            var bing = new Bing(this.http);
+            var bing = new Bing();
             try
             {
                 var translatedText = await bing.TranslateAsync(str,