コード例 #1
0
ファイル: TwitterClient.cs プロジェクト: KAN-RYU/FavoImgs
        private static void DownloadFile(string tempFilePath, string realFilePath, long tweetId, Uri uri)
        {
            try
            {
                WebClient wc = new WebClient();

                ConsoleHelper.WriteColoredLine(ConsoleColor.DarkCyan, " - {0}", uri);
                wc.DownloadFile(uri, tempFilePath);

                // 확장자가 붙지 않았을 경우, Content-Type으로 추론
                if (!Path.HasExtension(tempFilePath))
                {
                    string extension   = MimeHelper.GetFileExtension(wc.ResponseHeaders["Content-Type"]);
                    string newFilePath = String.Format("{0}{1}", tempFilePath, extension);

                    File.Move(tempFilePath, newFilePath);
                    tempFilePath = newFilePath;
                    realFilePath = String.Format("{0}{1}", realFilePath, extension);
                }


                // 탐색기 섬네일 캐시 문제로 인하여 임시 폴더에서 파일을 받은 다음, 해당 폴더로 이동
                File.Move(tempFilePath, realFilePath);

                TweetCache.Add(tweetId, uri.ToString());

                Statistics.Current.DownloadedCount += 1;
            }
            catch (Exception ex)
            {
                ConsoleHelper.WriteException(ex);
                logger.InfoException(String.Format("{0} - {1}", ex.Message, uri.ToString()), ex);

                if (File.Exists(tempFilePath))
                {
                    File.Delete(tempFilePath);
                }
            }
        }
コード例 #2
0
        public void MimeHelperTest()
        {
            string actual = MimeHelper.GetFileExtension("image/jpeg");

            Assert.AreEqual(".jpg", actual);
        }