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>
public class ImageCache : IDisposable
{
/// <summary>
- /// 画像の取得に使用する HttpClient インスタンス
- /// </summary>
- private readonly HttpClient http;
-
- /// <summary>
/// キャッシュとして URL と取得した画像を対に保持する辞書
/// </summary>
internal LRUCacheDictionary<string, Task<MemoryImage>> innerDictionary;
/// </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はファイナライザ任せ
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);
* CHG: 発言詳細部の更新時のパフォーマンスを改善
* FIX: 一部クライアントから投稿されたツイートの読み込み時にエラーが発生する問題の修正
* FIX: 短縮URL生成時のエラーが適切に処理されない問題を修正
+ * FIX: プロキシ設定が一部の機能 (アイコンの読み込み, 短縮URLの展開等) で適用されない問題を修正
==== Ver 1.2.1(2014/05/26)
* NEW: 5月28日(太平洋夏時間, UTC-7)から追加される予定の pic.twitter.com の複数枚画像表示に対応しました
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)
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)
{
this.Enabled = true;
this.DisabledInDM = true;
- this.http = http;
+ this.localHttpClient = http;
}
public bool AutoUpdate
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);
}
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)
{
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)
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)
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)
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>()
{
"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(
"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(),
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}"),
"http://pikubo.me/l/${1}"),
// Foursquare
- new FoursquareCheckin(http),
+ new FoursquareCheckin(),
// TINAMI
- new Tinami(http),
+ new Tinami(),
// pic.twitter.com
new SimpleThumbnailService(
"${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"),
{
public partial class TweenMain : OTBaseForm
{
- private HttpClient http;
-
//各種設定
private Size _mySize; //画面サイズ
private Point _myLoc; //画面位置
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;
////設定読み出し
LoadConfig();
- ThumbnailGenerator.InitializeGenerator(this.http);
+ ThumbnailGenerator.InitializeGenerator();
var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
imgazyobizinet.Enabled = this._cfgCommon.EnableImgAzyobuziNet;
_initial = true;
//アイコンリスト作成
- this.IconCache = new ImageCache(this.http);
+ this.IconCache = new ImageCache();
bool saveRequired = false;
bool firstRun = false;
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つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
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 フォーム デザイナで必要です。
if (string.IsNullOrEmpty(str))
return;
- var bing = new Bing(this.http);
+ var bing = new Bing();
try
{
var translatedText = await bing.TranslateAsync(str,