private static kcsapi_questlist Serialize(Session session) { string s_tab_id = HttpUtility.ParseQueryString(session.Request.BodyAsString)["api_tab_id"]; int tab_id; if (!int.TryParse(s_tab_id, out tab_id)) { return(null); } /* * if (!KanColleClient.Current.Settings.QuestOnAnyTabs && tab_id != 0) * return null; */ Quests.cur_tab_id = tab_id; try { var djson = DynamicJson.Parse(session.GetResponseAsJson()); var questlist = new kcsapi_questlist { api_count = Convert.ToInt32(djson.api_data.api_count), api_disp_page = Convert.ToInt32(djson.api_data.api_disp_page), api_page_count = Convert.ToInt32(djson.api_data.api_page_count), api_exec_count = Convert.ToInt32(djson.api_data.api_exec_count), }; if (djson.api_data.api_list != null) { var list = new List <kcsapi_quest>(); var serializer = new DataContractJsonSerializer(typeof(kcsapi_quest)); foreach (var x in (object[])djson.api_data.api_list) { try { list.Add(serializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(x.ToString()))) as kcsapi_quest); } catch (SerializationException ex) { // 最後のページで任務数が 5 に満たないとき、api_list が -1 で埋められるというクソ API のせい Debug.WriteLine(ex.Message); } } questlist.api_list = list.ToArray(); } return(questlist); } catch (Exception ex) { Debug.WriteLine(ex); return(null); } }
private void Update(kcsapi_questlist questlist) { this.IsUntaken = false; // キャッシュしてるページの数が、取得したページ数 (api_page_count) より大きいとき // 取得したページ数と同じ数になるようにキャッシュしてるページを減らす if (this.questPages.Count > questlist.api_page_count) { while (this.questPages.Count > questlist.api_page_count) this.questPages.RemoveAt(this.questPages.Count - 1); } // 小さいときは、キャッシュしたページ数と同じ数になるようにページを増やす else if (this.questPages.Count < questlist.api_page_count) { while (this.questPages.Count < questlist.api_page_count) this.questPages.Add(null); } if (questlist.api_list == null) { this.IsEmpty = true; this.All = this.Current = new List<Quest>(); } else { var page = questlist.api_disp_page - 1; if (page >= this.questPages.Count) page = this.questPages.Count - 1; this.questPages[page] = new ConcurrentDictionary<int, Quest>(); this.IsEmpty = false; foreach (var quest in questlist.api_list.Select(x => new Quest(x))) { this.questPages[page].AddOrUpdate(quest.Id, quest, (_, __) => quest); } this.All = this.questPages.Where(x => x != null) .SelectMany(x => x.Select(kvp => kvp.Value)) .Distinct(x => x.Id) .OrderBy(x => x.Id) .ToList(); var current = this.All.Where(x => x.State == QuestState.TakeOn || x.State == QuestState.Accomplished) .OrderBy(x => x.Id) .ToList(); // 遂行中の任務数に満たない場合、未取得分として null で埋める while (current.Count < questlist.api_exec_count) current.Add(null); this.Current = current; } }
private static kcsapi_questlist Serialize(Session session) { try { var djson = DynamicJson.Parse(session.GetResponseAsJson()); var questlist = new kcsapi_questlist { api_count = Convert.ToInt32(djson.api_data.api_count), api_disp_page = Convert.ToInt32(djson.api_data.api_disp_page), api_page_count = Convert.ToInt32(djson.api_data.api_page_count), api_exec_count = Convert.ToInt32(djson.api_data.api_exec_count), }; if (djson.api_data.api_list != null) { var list = new List<kcsapi_quest>(); var serializer = new DataContractJsonSerializer(typeof(kcsapi_quest)); foreach (var x in (object[])djson.api_data.api_list) { try { list.Add(serializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(x.ToString()))) as kcsapi_quest); } catch (SerializationException ex) { // 最後のページで任務数が 5 に満たないとき、api_list が -1 で埋められるというクソ API のせい Debug.WriteLine(ex.Message); } } questlist.api_list = list.ToArray(); } return questlist; } catch (Exception ex) { Debug.WriteLine(ex); return null; } }
private void Update(kcsapi_questlist questlist) { this.IsUntaken = false; // キャッシュしてるページの数が、取得したページ数 (api_page_count) より大きいとき // 取得したページ数と同じ数になるようにキャッシュしてるページを減らす if (this.questPages.Count > questlist.api_page_count) { while (this.questPages.Count > questlist.api_page_count) { this.questPages.RemoveAt(this.questPages.Count - 1); } } // 小さいときは、キャッシュしたページ数と同じ数になるようにページを増やす else if (this.questPages.Count < questlist.api_page_count) { while (this.questPages.Count < questlist.api_page_count) { this.questPages.Add(null); } } this.questPages[questlist.api_disp_page - 1] = new ConcurrentDictionary <int, Quest>(); questlist.api_list.Select(x => new Quest(x)) .ForEach(x => this.questPages[questlist.api_disp_page - 1].AddOrUpdate(x.Id, x, (_, __) => x)); var current = this.All.Where(x => x.State == QuestState.TakeOn || x.State == QuestState.Accomplished) .OrderBy(x => x.Id) .ToList(); // 遂行中の任務数に満たない場合、未取得分として null で埋める while (current.Count < questlist.api_exec_count) { current.Add(null); } this.Current = current; this.RaisePropertyChanged("All"); }
private void Update(Nekoxy.Session session) { this.IsUntaken = false; var data = DynamicJson.Parse(SvData.JsonParse(session.Response.BodyAsString)); kcsapi_questlist questlist = new kcsapi_questlist { api_count = (int)data.api_data.api_count, api_disp_page = (int)data.api_data.api_disp_page, api_page_count = (int)data.api_data.api_page_count, api_exec_count = (int)data.api_data.api_exec_count }; if (data.api_data.api_list != null) { var list = new List <kcsapi_quest>(); var serializer = new DataContractJsonSerializer(typeof(kcsapi_quest)); foreach (var x in data.api_data.api_list) { try { list.Add( serializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(x.ToString()))) as kcsapi_quest ); } catch { } } questlist.api_list = list.ToArray(); } if (this.questPages.Count > questlist.api_page_count) { while (this.questPages.Count > questlist.api_page_count) { this.questPages.RemoveAt(this.questPages.Count - 1); } } else if (this.questPages.Count < questlist.api_page_count) { while (this.questPages.Count < questlist.api_page_count) { this.questPages.Add(null); } } if (questlist.api_list == null) { this.IsEmpty = true; this.All = this.Current = new List <Quest>(); } else { var page = questlist.api_disp_page - 1; if (page >= this.questPages.Count) { page = this.questPages.Count - 1; } this.questPages[page] = new ConcurrentDictionary <int, Quest>(); this.IsEmpty = false; var quests = questlist.api_list .Select(x => new Quest(x)); foreach (var quest in quests) { this.questPages[page].AddOrUpdate(quest.Id, quest, (_, __) => quest); } this.All = this.questPages.Where(x => x != null) .SelectMany(x => x.Select(kvp => kvp.Value)) .Distinct(x => x.Id) .OrderBy(x => x.Id) .ToList(); var current = this.All.Where(x => x.State == QuestState.TakeOn || x.State == QuestState.Accomplished) .OrderBy(x => x.Id) .ToList(); while (current.Count < questlist.api_exec_count) { current.Add(null); } this.Current = current; } }
private void Update(kcsapi_questlist questlist) { var tab = Quests.cur_tab_id; this.IsUntaken[tab] = false; Quests.last_exec_count = questlist.api_exec_count; /* * if(this.last_tab_id != Quests.cur_tab_id) * this.questPages.Clear(); */ if (!this.questPages.ContainsKey(tab)) { this.questPages[tab] = new List <ConcurrentDictionary <int, Quest> >(); } // キャッシュしてるページの数が、取得したページ数 (api_page_count) より大きいとき // 取得したページ数と同じ数になるようにキャッシュしてるページを減らす while (this.questPages[tab].Count > questlist.api_page_count) { this.questPages[tab].RemoveAt(this.questPages[tab].Count - 1); } // 小さいときは、キャッシュしたページ数と同じ数になるようにページを増やす while (this.questPages[tab].Count < questlist.api_page_count) { this.questPages[tab].Add(null); } if (questlist.api_list == null) { this.IsEmpty[tab] = true; } else { var page = questlist.api_disp_page - 1; if (page >= this.questPages[tab].Count) { page = this.questPages[tab].Count - 1; } this.questPages[tab][page] = new ConcurrentDictionary <int, Quest>(); this.IsEmpty[tab] = false; foreach (var quest in questlist.api_list.Select(x => new Quest(x))) { quest.Page = page; quest.Tab = tab; this.questPages[tab][page].AddOrUpdate(quest.Id, quest, (_, __) => quest); } } this.All = this.questPages .SelectMany(y => y.Value.Where(x => x != null) .SelectMany(x => x.Select(kvp => kvp.Value)) .Distinct(x => x.Id) .OrderBy(x => x.Id) ) .ToList(); }