public void Load() { //設定ファイルが無かったらロードしない(出来ないわ) if (!File.Exists(Dir + "nglist")) { return; } var info = new FileInfo(Dir + "nglist"); var reader = info.OpenText(); var raw = DynamicJson.Parse(reader.ReadToEnd()); reader.Close(); NGList.Clear(); foreach (var jsonentry in raw) { var entry = new NGCommentEntry(); entry.IsEnabled = jsonentry.IsEnabled; entry.Type = Enum.Parse(typeof(NGType), jsonentry.Type); entry.Content = jsonentry.Content; entry.PropertyChanged += ((sender, e) => Save()); NGList.Add(entry); } }
public void AddNGEntry(NGType type, string content) { var entry = new NGCommentEntry(); entry.IsEnabled = true; entry.Type = type; entry.Content = content; Settings.Instance.NGList.Add(entry); }
public void AddEmptyNGEntry() { var entry = new NGCommentEntry(); entry.IsEnabled = false; entry.Type = NGType.Word; entry.Content = ""; Settings.Instance.NGList.Add(entry); }
public List <NGCommentEntry> GetNGClient() { var pair = new Dictionary <string, string>(); pair["mode"] = "get"; try { var ret = new List <NGCommentEntry>(); var request = new HttpRequestMessage(HttpMethod.Post, NGApi); request.Content = new FormUrlEncodedContent(pair); var a = NicoNicoWrapperMain.Session.GetAsync(request).Result; var xml = new XmlDocument(); xml.LoadXml(a); if (xml.SelectSingleNode("/response_ngclient").Attributes["status"].Value != "ok") { throw new RequestFailed(FailedType.Failed); } foreach (XmlNode entry in xml.SelectNodes("/response_ngclient/ngclient")) { var obj = new NGCommentEntry(); obj.Type = entry.SelectSingleNode("type").InnerText == "id" ? NGType.UserId : NGType.Word; obj.Content = entry.SelectSingleNode("source").InnerText; ret.Add(obj); } return(ret); } catch (RequestTimeout) { throw new RequestFailed(FailedType.TimeOut); } }
public void DeleteNGEntry(NGCommentEntry target) { Settings.Instance.NGList.Remove(target); }
public List<NGCommentEntry> GetNGClient() { var pair = new Dictionary<string, string>(); pair["mode"] = "get"; try { var ret = new List<NGCommentEntry>(); var request = new HttpRequestMessage(HttpMethod.Post, NGApi); request.Content = new FormUrlEncodedContent(pair); var a = NicoNicoWrapperMain.Session.GetAsync(request).Result; var xml = new XmlDocument(); xml.LoadXml(a); if(xml.SelectSingleNode("/response_ngclient").Attributes["status"].Value != "ok") { throw new RequestFailed(FailedType.Failed); } foreach(XmlNode entry in xml.SelectNodes("/response_ngclient/ngclient")) { var obj = new NGCommentEntry(); obj.Type = entry.SelectSingleNode("type").InnerText == "id" ? NGType.UserId : NGType.Word; obj.Content = entry.SelectSingleNode("source").InnerText; ret.Add(obj); } return ret; } catch(RequestTimeout) { throw new RequestFailed(FailedType.TimeOut); } }
public void AddNGEntry(NGCommentEntry entry) { NGList.Insert(0, entry); Save(); }
//設定ファイルの値からインスタンスを生成する private object GetNeedValue(string name, PropertyInfo property, object value) { switch(name) { case "FontFamily": return new FontFamily((string)value); case "GridLength": return new GridLengthConverter().ConvertFrom(value); case "Uri": return new Uri((string)value); case "DispatcherCollection<NGCommentEntry>": { var col = new DispatcherCollection<NGCommentEntry>(DispatcherHelper.UIDispatcher); dynamic entries = (DynamicJson)value; //NGフィルターのエントリを設定ファイルからパースする foreach(var entry in entries) { var ng = new NGCommentEntry(); ng.Type = Enum.Parse(typeof(NGType), entry.Type); ng.Content = entry.Content; ng.IsEnabled = entry.IsEnabled; //NGフィルターの内容が更新されたら即セーブする ng.PropertyChanged += ((sender, e) => Save()); col.Add(ng); } //新しくフィルターリストにエントリが追加/削除されたらセーブする //追加だったら新しいエントリに即セーブするイベントを設定 col.CollectionChanged += ((sender, e) => { if(e.Action == NotifyCollectionChangedAction.Add && e.NewItems.Count != 0 && e.NewItems[0] is NGCommentEntry) { var ng = e.NewItems[0] as NGCommentEntry; ng.PropertyChanged += ((sdr, ee) => Save()); Save(); } else { Save(); } }); return col; } case "List<String>": { var col = new List<string>(); dynamic entries = (DynamicJson)value; //NGフィルターのエントリを設定ファイルからパースする foreach(var entry in entries) { col.Add(entry); } return col; } default: return value; } }