public void DownloadRankingTest() { string temp_directory_path = TestUtility.TestData[TestUtility.KEY_TEMP_DIRECTORY]; TestUtility.EnsureLogin(network_); DirectoryInfo temp_directory = new DirectoryInfo(temp_directory_path); DownloadKind kind = new DownloadKind(); kind.SetDuration(true, false, false, false, false); CategoryItem categoryItem = new CategoryItem(); categoryItem.id = "music"; categoryItem.short_name = "mus"; categoryItem.name = "音楽"; categoryItem.page = new int[] { 3, 1, 1, 1, 0 }; List <CategoryItem> categoryList = new List <CategoryItem>(); categoryList.Add(categoryItem); kind.CategoryList = categoryList; kind.SetTarget(true, true, true); kind.SetFormat(DownloadKind.FormatKind.Html); bool completed = false; msgout_.OnWrite = delegate(string str) { if (str == "すべてのランキングのDLが完了しました。\r\n") { completed = true; } }; Assert.That(TestUtility.InitDirectory(temp_directory), Is.True, "DownloadRankingTest1"); TestUtility.Message("Running DownloadRankingTest - Download HTML"); network_manager_.DownloadRanking(kind, temp_directory_path); Assert.That(completed, Is.True, "DownloadRankingTest2-1"); int html_count = Directory.GetFiles(temp_directory_path, "*.html", SearchOption.AllDirectories).Length; Assert.That(html_count, Is.EqualTo(9), "DownloadRankingTest2-2"); Assert.That(TestUtility.InitDirectory(temp_directory), Is.True, "DownloadRankingTest3"); kind.SetFormatRss(); TestUtility.Message("Running DownloadRankingTest - Download RSS"); network_manager_.DownloadRanking(kind, temp_directory_path); Assert.That(completed, Is.True, "DownloadRankingTest4-1"); html_count = Directory.GetFiles(temp_directory_path, "*.xml", SearchOption.AllDirectories).Length; Assert.That(html_count, Is.EqualTo(9), "DownloadRankingTest4-2"); }
// スレッドを使うため引数なし関数を用意する public void DownloadRanking() { string rank_dl_dir = nico_download_.DownloadRanking((DownloadKind)param_[0], path_mgr_.GetRankDlDir()); msg_receiver_.UpdateSavedRankDir(rank_dl_dir); }
static void Main(string[] args) { try { if (args.Length <= 1) { ShowUsage(); System.Environment.Exit(1); } Receiver receiver = new Receiver(); CancelObject cancel_object = new CancelObject(); NicoNetwork network = new NicoNetwork(); NicoNetworkManager network_mgr = new NicoNetworkManager(network, receiver, cancel_object); NicoMylist nico_mylist = new NicoMylist(network, receiver, cancel_object); for (int i = 2; i < args.Length; ++i) { switch (args[i]) { case "-i": if (i < args.Length - 1) { input_rank_file_ = Dequote(args[i + 1]); if (!File.Exists(input_rank_file_)) { System.Console.WriteLine("入力ランクファイルが存在しません。"); System.Environment.Exit(1); } ++i; } else { System.Console.WriteLine("入力ランクファイルを指定してください。"); System.Environment.Exit(1); } break; case "-o": if (i < args.Length - 1) { output_rank_file_ = Dequote(args[i + 1]); ++i; } break; case "-c": if (i < args.Length - 1) { config_file_ = Dequote(args[i + 1]); ++i; } break; } } if (string.IsNullOrEmpty(config_file_)) // config ファイル指定なしの場合 { config_file_ = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "config.txt"); if (!File.Exists(config_file_)) { System.Console.WriteLine("最初に nicorank.exe を起動してオプションを指定してください。"); System.Environment.Exit(1); } } else { if (!File.Exists(config_file_)) { System.Console.WriteLine("config ファイルが見つかりません。"); System.Environment.Exit(1); } } ParseConfig(IJFile.Read(config_file_)); InputOutputOption iooption = new InputOutputOption(!string.IsNullOrEmpty(input_rank_file_), !string.IsNullOrEmpty(output_rank_file_)); if (string.IsNullOrEmpty(input_rank_file_)) // 標準入力から { iooption.SetInputFromStdin(); } else { iooption.SetInputPath(input_rank_file_); } if (string.IsNullOrEmpty(output_rank_file_)) // 標準出力へ { iooption.SetOutputRankFileDelegate(delegate(string s) { System.Console.Write(s); }); } else { iooption.SetOutputPath(output_rank_file_); } switch (args[0]) { case "download": switch (args[1]) { case "ranking": CategoryManager category_manager = new CategoryManager(); category_manager.SetString(option_["dlrank_category"]); category_manager.ParseCategoryFile(); network_mgr.DownloadRanking(GetDownloadKind(category_manager), option_["textBoxRankDlDir"]); break; case "video": LoadCookie(network); network_mgr.DownloadFlv(iooption, option_["textBoxDlInterval"], MakeDirectoryPath(option_["textBoxFlvDlDir"]), bool.Parse(option_["checkBoxIsFixFlvDlExtension"])); break; default: ShowInvalidAndUsage(args[1]); System.Environment.Exit(1); break; } break; case "list": switch (args[1]) { case "searchtag": network_mgr.MakeListAndWriteBySearchTag(iooption, MakeSearchingTagOption(), MakeRankingMethod()); break; default: ShowInvalidAndUsage(args[1]); System.Environment.Exit(1); break; } break; case "mylist": switch (args[1]) { case "add": LoadCookie(network); nico_mylist.AddMylist(iooption, option_["textBoxMylistId"]); break; default: ShowInvalidAndUsage(args[1]); System.Environment.Exit(1); break; } break; default: ShowInvalidAndUsage(args[0]); System.Environment.Exit(1); break; } } catch (KeyNotFoundException e) { System.Console.WriteLine("エラーが発生しました。"); System.Console.WriteLine("キーが存在しません: " + e.Data.ToString()); } catch (Exception e) { System.Console.WriteLine("エラーが発生しました。"); System.Console.WriteLine("エラー\r\n---メッセージ\r\n" + e.Message + "\r\n---ソース\r\n" + e.Source + "\r\n---スタックトレース\r\n" + e.StackTrace + "\r\n---ターゲット\r\n" + e.TargetSite + "\r\n---文字列\r\n" + e.ToString()); } }