//------------------------------------------------------------------------------- /// <summary> /// URLを短縮します。 /// </summary> /// <param name="url">短縮するURL</param> /// <returns>短縮URL</returns> public static string Shorten(string url, URLShortenType type) { return SHORTEN_DIC[type].Shorten(url); }
//------------------------------------------------------------------------------- /// <summary> /// テキストボックス内のURLを短縮 /// </summary> /// <param name="type">短縮タイプ</param> private void TextURLShorten(URLShortenType type) { this.Invoke((Action)(() => rtxtTwit.Enabled = btnTwit.Enabled = false)); try { btnURLShorten.Enabled = false; string[] urls = Utilization.ExtractURL(rtxtTwit.Text) .Distinct() .Where((url) => !URLShortener.IsShortenURL(url)) .ToArray(); List<Tuple<string, string>> valList = new List<Tuple<string, string>>(); Utilization.InvokeTransactionDoingEvents( () => { foreach (string url in urls) { string shorturl = URLShortener.Shorten(url, type); valList.Add(new Tuple<string, string>(url, shorturl)); } } ); string text = rtxtTwit.Text; foreach (var tuple in valList) { text = text.Replace(tuple.Item1, tuple.Item2); } rtxtTwit.Text = text; } finally { this.Invoke((Action)(() => rtxtTwit.Enabled = btnTwit.Enabled = true)); } }