public async Task <bool> ToggleFollowOwnerAsync(NicoNicoUserEntry entry) { try { if (entry.IsFollow) { var form = new Dictionary <string, string> { ["id_list[1][]"] = entry.UserId, ["token"] = entry.CsrfToken }; var request = new HttpRequestMessage(HttpMethod.Post, UserUnFollowApi) { Content = new FormUrlEncodedContent(form) }; var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(request); var json = DynamicJson.Parse(a); if (json.status == "ok") { Owner.Status = "フォローを解除しました"; return(true); } else { Owner.Status = "フォロー解除に失敗しました"; return(false); } } else { var form = new Dictionary <string, string> { ["item_type"] = "1", ["item_id"] = entry.UserId, ["token"] = entry.CsrfToken }; var request = new HttpRequestMessage(HttpMethod.Post, UserFollowApi) { Content = new FormUrlEncodedContent(form) }; var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(request); var json = DynamicJson.Parse(a); if (json.status == "ok") { Owner.Status = "フォローしました"; return(true); } else { Owner.Status = "フォローに失敗しました"; return(false); } } } catch (RequestFailed) { return(false); } }
public async Task<NicoNicoUserEntry> GetUserInfoAsync() { try { Owner.Status = "ユーザー情報取得中"; var ret = new NicoNicoUserEntry(); //ユーザーページのhtmlを取得 var a = await NicoNicoWrapperMain.Session.GetAsync(UserPage); //htmlをロード var doc = new HtmlDocument(); doc.LoadHtml2(a); //ユーザープロファイル var detail = doc.DocumentNode.SelectSingleNode("//div[@class='userDetail']"); var profile = detail.SelectSingleNode("child::div[@class='profile']"); var account = profile.SelectSingleNode("child::div[@class='account']"); ret.UserIconUrl = detail.SelectSingleNode("child::div[@class='avatar']/img").Attributes["src"].Value; ret.UserName = profile.SelectSingleNode("child::h2").InnerText.Trim(); ret.Id = account.SelectSingleNode("child::p[@class='accountNumber']").InnerText.Trim(); var temp = profile.SelectSingleNode("child::ul[@class='userDetailComment channel_open_mt0']/li/p/span"); ret.Description = temp == null ? "" : temp.InnerHtml; ret.UserPage = UserPage; //html特殊文字をデコード ret.Description = HttpUtility.HtmlDecode(ret.Description); //URLをハイパーリンク化する エンコードされてると正しく動かない ret.Description = HyperLinkReplacer.Replace(ret.Description); //&だけエンコード エンコードしないとUIに&が表示されない ret.Description = ret.Description.Replace("&", "&"); Owner.Status = ""; return ret; } catch(RequestTimeout) { return null; } }
public NicoNicoUserEntry GetUserInfo() { Owner.Status = "ユーザー情報取得中"; var ret = new NicoNicoUserEntry(); //ユーザーページのhtmlを取得 var a = NicoNicoWrapperMain.Session.GetAsync(UserPage).Result; //htmlをロード var doc = new HtmlDocument(); doc.LoadHtml2(a); //ユーザープロファイル var detail = doc.DocumentNode.SelectSingleNode("//div[@class='userDetail']"); var profile = detail.SelectSingleNode("child::div[@class='profile']"); var account = profile.SelectSingleNode("child::div[@class='account']"); ret.UserIconUrl = detail.SelectSingleNode("child::div[@class='avatar']/img").Attributes["src"].Value; ret.UserName = profile.SelectSingleNode("child::h2").InnerText.Trim(); ret.Id = account.SelectSingleNode("child::p[@class='accountNumber']").InnerText.Trim(); ret.Gender = account.SelectSingleNode("child::p[2]").InnerText.Trim(); ret.BirthDay = account.SelectSingleNode("child::p[3]").InnerText.Trim(); ret.Region = account.SelectSingleNode("child::p[4]").InnerText.Trim(); var temp = profile.SelectSingleNode("child::ul[@class='userDetailComment channel_open_mt0']/li/p/span"); ret.Description = temp == null ? "" : temp.InnerHtml; ret.UserPage = UserPage; //html特殊文字をデコード ret.Description = HttpUtility.HtmlDecode(ret.Description); //URLをハイパーリンク化する エンコードされてると正しく動かない ret.Description = HyperLinkReplacer.Replace(ret.Description); //&だけエンコード エンコードしないとUIに&が表示されない ret.Description = ret.Description.Replace("&", "&"); Owner.Status = ""; return(ret); }
public NicoNicoUserEntry GetUserInfo() { Owner.Status = "ユーザー情報取得中"; var ret = new NicoNicoUserEntry(); //ユーザーページのhtmlを取得 var a = NicoNicoWrapperMain.Session.GetAsync(UserPage).Result; //htmlをロード HtmlDocument doc = new HtmlDocument(); doc.LoadHtml2(a); //ユーザープロファイル HtmlNode detail = doc.DocumentNode.SelectSingleNode("//div[@class='userDetail']"); HtmlNode profile = detail.SelectSingleNode("child::div[@class='profile']"); HtmlNode account = profile.SelectSingleNode("child::div[@class='account']"); ret.UserIconUrl = detail.SelectSingleNode("child::div[@class='avatar']/img").Attributes["src"].Value; ret.UserName = profile.SelectSingleNode("child::h2").InnerText.Trim(); ret.Id = account.SelectSingleNode("child::p[@class='accountNumber']").InnerText.Trim(); ret.Gender = account.SelectSingleNode("child::p[2]").InnerText.Trim(); ret.BirthDay = account.SelectSingleNode("child::p[3]").InnerText.Trim(); ret.Region = account.SelectSingleNode("child::p[4]").InnerText.Trim(); var temp = profile.SelectSingleNode("child::ul[@class='userDetailComment channel_open_mt0']/li/p/span"); ret.Description = temp == null ? "" : temp.InnerHtml; ret.UserPage = UserPage; //URLをハイパーリンク化する ret.Description = HyperLinkParser.Parse(ret.Description); Owner.Status = ""; return(ret); }
public NicoNicoUserEntry GetUserInfo() { Owner.Status = "ユーザー情報取得中"; var ret = new NicoNicoUserEntry(); //ユーザーページのhtmlを取得 var a = NicoNicoWrapperMain.Session.GetAsync(UserPage).Result; //htmlをロード HtmlDocument doc = new HtmlDocument(); doc.LoadHtml2(a); //ユーザープロファイル HtmlNode detail = doc.DocumentNode.SelectSingleNode("//div[@class='userDetail']"); HtmlNode profile = detail.SelectSingleNode("child::div[@class='profile']"); HtmlNode account = profile.SelectSingleNode("child::div[@class='account']"); ret.UserIconUrl = detail.SelectSingleNode("child::div[@class='avatar']/img").Attributes["src"].Value; ret.UserName = profile.SelectSingleNode("child::h2").InnerText.Trim(); ret.Id = account.SelectSingleNode("child::p[@class='accountNumber']").InnerText.Trim(); ret.Gender = account.SelectSingleNode("child::p[2]").InnerText.Trim(); ret.BirthDay = account.SelectSingleNode("child::p[3]").InnerText.Trim(); ret.Region = account.SelectSingleNode("child::p[4]").InnerText.Trim(); var temp = profile.SelectSingleNode("child::ul[@class='userDetailComment channel_open_mt0']/li/p/span"); ret.Description = temp == null ? "" : temp.InnerHtml; ret.UserPage = UserPage; //URLをハイパーリンク化する ret.Description = HyperLinkParser.Parse(ret.Description); Owner.Status = ""; return ret; }
//ログイン後の初期化処理 public void LogedInInit() { User = new NicoNicoUserEntry(); User.UserId = NicoNicoWrapperMain.GetSession().UserId; User.UserName = NicoNicoUser.LookupUserName(User.UserId); App.ViewModelRoot.Title += "(user:"******")"; TabItems.Add(Search = new SearchViewModel()); TabItems.Add(new FavoriteViewModel()); TabItems.Add(new NicoRepoViewModel()); TabItems.Add(new MylistViewModel()); TabItems.Add(new HistoryViewModel()); TabItems.Add(new OtherViewModel()); TabItems.Add(Config = new ConfigViewModel()); }
public void Initialize() { UserInstance = new NicoNicoUser(this, UserPageUrl); UserEntry = UserInstance.GetUserInfo(); Name = UserEntry.UserName; UserContentList = new DispatcherCollection<TabItemViewModel>(DispatcherHelper.UIDispatcher) { new UserNicoRepoViewModel(this), new UserMylistViewModel(this), new UserVideoViewModel(this) }; }
//ログイン後の初期化処理 public void LogedInInit() { User = new NicoNicoUserEntry(); User.UserId = NicoNicoWrapperMain.Session.UserId; User.UserName = NicoNicoUser.LookupUserName(User.UserId); App.ViewModelRoot.Title += "(user:"******")"; TabItems.Add(WebView = new WebViewViewModel()); TabItems.Add(Ranking = new RankingViewModel()); TabItems.Add(Search = new SearchViewModel()); TabItems.Add(new FavoriteViewModel()); TabItems.Add(new NicoRepoViewModel()); TabItems.Add(new MylistViewModel()); TabItems.Add(NotifyLive = new NotifyLiveViewModel()); TabItems.Add(new HistoryViewModel()); TabItems.Add(new OtherViewModel()); TabItems.Add(Config = new ConfigViewModel()); //生放送通知を更新するタイマーを動かす StatusBar.StartRefreshTimer(); //サーバーからアップデートがあるか確認してあったらアップデートダイアログを出す Update.CheckUpdate(); //公式NG機能を初期化 NGCommentInstance = new NicoNicoNGComment(); //NGCommentInstance.GetNGClient(); if(Environment.GetCommandLineArgs().Length > 1) { Task.Run(() => NicoNicoOpener.Open(Environment.GetCommandLineArgs()[1])); } }
public async Task <NicoNicoUserEntry> GetUserInfoAsync() { try { Owner.Status = "ユーザー情報取得中"; var ret = new NicoNicoUserEntry(); //ユーザーページのhtmlを取得 var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(Owner.UserPageUrl); //htmlをロード var doc = new HtmlDocument(); doc.LoadHtml(a); //ユーザープロファイル var detail = doc.DocumentNode.SelectSingleNode("//div[@class='userDetail']"); var profile = detail.SelectSingleNode("div[@class='profile']"); var account = profile.SelectSingleNode("div[@class='account']"); ret.UserIconUrl = detail.SelectSingleNode("div[@class='avatar']/img").Attributes["src"].Value; ret.UserName = profile.SelectSingleNode("h2").InnerText.Trim(); ret.IdAndMemberType = account.SelectSingleNode("p[@class='accountNumber']").InnerText.Trim(); var desc = profile.SelectSingleNode("ul[@class='userDetailComment channel_open_mt0']/li/p/span"); ret.Description = desc != null ? desc.InnerHtml : ""; var stats = profile.SelectSingleNode("ul[@class='stats channel_open_mb8']"); ret.FollowedCount = int.Parse(stats.SelectSingleNode("li/span").InnerText, System.Globalization.NumberStyles.AllowThousands); ret.StampExp = int.Parse(stats.SelectSingleNode("li/a/span").InnerText, System.Globalization.NumberStyles.AllowThousands); ret.CsrfToken = GlobalHashRegex.Match(a).Groups[1].Value; ret.UserId = Regex.Match(Owner.UserPageUrl, @"user/(\d+)").Groups[1].Value; ret.UserPageUrl = Owner.UserPageUrl; var watching = profile.SelectSingleNode("div[@class='watching']"); ret.IsFollow = watching != null; var channel = profile.SelectSingleNode("div[@class='channel_open_box']"); if (channel != null) { ret.HasChannel = true; ret.ChannelName = channel.SelectSingleNode("p/a").InnerText; ret.ChannelThumbNail = channel.SelectSingleNode("img").Attributes["src"].Value; ret.ChannelUrl = channel.SelectSingleNode("p/a").Attributes["href"].Value; } //html特殊文字をデコード ret.Description = HttpUtility.HtmlDecode(ret.Description); //URLをハイパーリンク化する エンコードされてると正しく動かない ret.Description = HyperLinkReplacer.Replace(ret.Description); //&だけエンコード エンコードしないとUIに&が表示されない ret.Description = ret.Description.Replace("&", "&"); Owner.Status = ""; return(ret); } catch (RequestFailed) { Owner.Status = "ユーザー情報の取得に失敗しました"; return(null); } }