/// <summary> /// ニコニコのユーザーを指定しログインする /// 失敗した場合オブジェクトの状態は変化しない /// </summary> /// <param name="userId">ニコニコのユーザーID</param> /// <param name="userPassword">ニコニコのパスワード</param> /// <param name="nicoSid">ログインセッション(nicosid)</param> /// <param name="session">ログインセッション(user_session)</param> /// <param name="sessionSecure">ログインセッション(user_session_secure)</param> /// <exception cref="ArgumentException"><paramref name="userId"/>または<paramref name="userPassword"/>がnull若しくはホワイトスペースだった時</exception> /// <exception cref="NiconicoUtils.NiconicoLoginSessionException">ログインに失敗した時</exception> public async Task SetUser(string userId, string userPassword, string nicoSid, string session, string sessionSecure) { if (string.IsNullOrWhiteSpace(userId)) { throw new ArgumentException($"{nameof(userId)} must not be null nor white space", nameof(userId)); } if (string.IsNullOrWhiteSpace(userPassword)) { throw new ArgumentException($"{nameof(userPassword)} must not be null nor white space", nameof(userPassword)); } //ログインしてみる var tmpSession = new NiconicoUtils.NiconicoLoginSession(userId, userPassword, nicoSid, session, sessionSecure); await tmpSession.Login().ConfigureAwait(false); //成功したら設定、セッションを置き換える this.IsLoggedin = true; this.settings.UserId = userId; this.settings.Password = userPassword; this.settings.NicoSid = tmpSession.nicosid; this.settings.Session = tmpSession.session; this.settings.SessionSecure = tmpSession.secure; try { await(this.loginSession.Value?.Logout() ?? Task.CompletedTask); } catch (NiconicoUtils.NiconicoLoginSessionException) { } this.loginSession.Value = tmpSession; }
public NiconicoLogChatCollectService(ChatCollectServiceEntry.IChatCollectServiceEntry serviceEntry, NiconicoUtils.JkIdResolver jkIdResolver, NiconicoUtils.NiconicoLoginSession session) : base(new TimeSpan(0, 0, 10)) { this.ServiceEntry = serviceEntry; this.jkIdResolver = jkIdResolver; this.session = session; var handler = new HttpClientHandler(); client = new HttpClient(handler); handler.CookieContainer.Add(session.Cookie); }
public NewNiconicoJikkyouChatCollectService( ChatCollectServiceEntry.IChatCollectServiceEntry serviceEntry, NiconicoUtils.LiveIdResolver liveIdResolver, NiconicoUtils.NiconicoLoginSession niconicoLoginSession ) { this.ServiceEntry = serviceEntry; this.liveIdResolver = liveIdResolver; var assembly = Assembly.GetExecutingAssembly().GetName(); var ua = assembly.Name + "/" + assembly.Version.ToString(3); var handler = new HttpClientHandler(); handler.CookieContainer.Add(niconicoLoginSession.Cookie); this.httpClient = new HttpClient(handler); this.httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", ua); this.commentReceiver = new NiconicoUtils.NicoLiveCommentReceiver(niconicoLoginSession); this.commentSender = new NiconicoUtils.NicoLiveCommentSender(niconicoLoginSession); }
public NiconicoLiveChatCollectService( ChatCollectServiceEntry.IChatCollectServiceEntry serviceEntry, string liveId, NiconicoUtils.NiconicoLoginSession session ) { this.ServiceEntry = serviceEntry; this.originalLiveId = liveId; var assembly = Assembly.GetExecutingAssembly().GetName(); var ua = assembly.Name + "/" + assembly.Version.ToString(3); var handler = new HttpClientHandler(); handler.CookieContainer.Add(session.Cookie); this.httpClient = new HttpClient(handler); this.httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", ua); this.commentReceiver = new NiconicoUtils.NicoLiveCommentReceiver(session); this.commentSender = new NiconicoUtils.NicoLiveCommentSender(session); this.chatCollectTask = this.collectChat(this.cancel.Token); }
public NiconicoChatCollectService(ChatCollectServiceEntry.IChatCollectServiceEntry serviceEntry, NiconicoUtils.JkIdResolver jkIdResolver, NiconicoUtils.NiconicoLoginSession session) { ServiceEntry = serviceEntry; this.jkIdResolver = jkIdResolver; if (session != null) { var handler = new HttpClientHandler(); handler.CookieContainer.Add(session.Cookie); httpClient = new HttpClient(handler); CanPost = true; } else { httpClient = new HttpClient(); CanPost = false; } httpClient.BaseAddress = new Uri("http://jk.nicovideo.jp"); }