/// <summary> /// 新しい検索チケットを作成する。 /// </summary> /// <param name="ticket_id">作成する検索チケットのID。</param> /// <param name="option">検索条件。</param> /// <returns>検索チケットを作成した場合はtrue、指定されたチケットIDを持つ検索チケットが既にある場合はfalse。</returns> public static bool CreateNewTicket(string ticket_id, SearchingTagOption option) { string ticket_directory = GetTicketDirectory(ticket_id); if (Directory.Exists(ticket_directory)) { return(false); } string option_file = GetTicketOptionFile(ticket_id); Directory.CreateDirectory(ticket_directory); string option_text = SerializeSearchingOption(option); IJFile.WriteUTF8(option_file, option_text); return(true); }
/// <summary> /// 検索条件を表す<see cref="SearchingTagOption"/>を、ファイル保存用に文字列に変換する。 /// </summary> /// <param name="option">変換する検索条件。</param> /// <returns>ファイル保存用に文字列に変換された検索条件。</returns> public static string SerializeSearchingOption(SearchingTagOption option) { StringBuilder option_text = new StringBuilder(); using (TextWriter writer = new StringWriter(option_text)) { for (int i = 0; i < option.searching_tag_list.Count; i++) { string searching_tag = option.searching_tag_list[i]; writer.WriteLine("searching_tag={0}", searching_tag); } writer.WriteLine("is_searching_kind_tag={0}", option.is_searching_kind_tag.ToString() ?? string.Empty); writer.WriteLine("is_detail_getting={0}", option.is_detail_getting.ToString()); writer.WriteLine("detail_info_lower={0}", option.detail_info_lower.ToString()); writer.WriteLine("sort_kind_num={0}", option.sort_kind_num.ToString()); writer.WriteLine("is_page_all={0}", option.is_page_all.ToString()); writer.WriteLine("page_start={0}", option.page_start.ToString()); writer.WriteLine("page_end={0}", option.page_end.ToString()); writer.WriteLine("is_using_condition={0}", option.is_using_condition.ToString()); writer.WriteLine("date_from={0},{1}", option.date_from.Ticks.ToString(), option.date_from.Kind.ToString()); writer.WriteLine("date_to={0},{1}", option.date_to.Ticks.ToString(), option.date_to.Kind.ToString()); writer.WriteLine("condition_lower={0}", option.condition_lower.ToString()); writer.WriteLine("condition_upper={0}", option.condition_upper.ToString()); writer.WriteLine("searching_interval={0}", option.searching_interval ?? string.Empty); writer.WriteLine("getting_detail_interval={0}", option.getting_detail_interval ?? string.Empty); writer.WriteLine("redundant_seatching_method={0}", option.redundant_seatching_method.ToString()); writer.WriteLine("save_html_dir={0}", option.save_html_dir); writer.WriteLine("is_sending_user_session={0}", option.is_sending_user_session); } return(option_text.ToString()); }
/// <summary> /// 検索条件を表す文字列を<see cref="SearchingTagOption"/>に変換する。 /// </summary> /// <param name="ticket_id">検索条件に設定する検索チケットID。</param> /// <param name="option_text">検索条件を表す文字列。</param> /// <returns>検索条件。</returns> public static SearchingTagOption DeserializeSearchingOption(string ticket_id, string option_text) { SearchingTagOption option = new SearchingTagOption(); option.searching_tag_list = new List <string>(); option.ticket_id = ticket_id; option.is_create_ticket = false; using (TextReader reader = new StringReader(option_text)) { string line; while ((line = reader.ReadLine()) != null) { Match match = Regex.Match(line, "^(?<name>[^=]+)=(?<value>.+)$"); if (!match.Success) { continue; } string name = match.Groups["name"].Value; string value = match.Groups["value"].Value; try { switch (name) { case "searching_tag": option.searching_tag_list.Add(value); break; case "is_searching_kind_tag": option.is_searching_kind_tag = bool.Parse(value); break; case "is_detail_getting": option.is_detail_getting = bool.Parse(value); break; case "detail_info_lower": option.detail_info_lower = int.Parse(value); break; case "sort_kind_num": option.sort_kind_num = int.Parse(value); break; case "is_page_all": option.is_page_all = bool.Parse(value); break; case "page_start": option.page_start = int.Parse(value); break; case "page_end": option.page_end = int.Parse(value); break; case "is_using_condition": option.is_using_condition = bool.Parse(value); break; case "date_from": string[] ticks_kind_from = value.Split(','); if (ticks_kind_from.Length < 2) { throw new FormatException(); } long ticks_from = long.Parse(ticks_kind_from[0]); DateTimeKind kind_from = (DateTimeKind)Enum.Parse(typeof(DateTimeKind), ticks_kind_from[1]); option.date_from = new DateTime(ticks_from, kind_from); break; case "date_to": string[] ticks_kind_to = value.Split(','); if (ticks_kind_to.Length < 2) { throw new FormatException(); } long ticks_to = long.Parse(ticks_kind_to[0]); DateTimeKind kind_to = (DateTimeKind)Enum.Parse(typeof(DateTimeKind), ticks_kind_to[1]); option.date_to = new DateTime(ticks_to, kind_to); break; case "condition_lower": option.condition_lower = int.Parse(value); break; case "condition_upper": option.condition_upper = int.Parse(value); break; case "searching_interval": option.searching_interval = value; break; case "getting_detail_interval": option.getting_detail_interval = value; break; case "redundant_seatching_method": option.redundant_seatching_method = (RedundantSearchingMethod)Enum.Parse(typeof(RedundantSearchingMethod), value); break; case "save_html_dir": option.save_html_dir = value; break; case "is_sending_user_session": option.is_sending_user_session = bool.Parse(value); break; default: break; } } catch (OverflowException e) { throw new FormatException(null, e); } catch (ArgumentException e) { throw new FormatException(null, e); } } } return(option); }