/// <summary> /// 指定されたICookieImporterからインスタンスを生成します。 /// </summary> /// <param name="importer">対象のブラウザ</param> public CookieSourceItem(ICookieImporter importer) { Importer = importer; BrowserName = importer.SourceInfo.BrowserName; ProfileName = importer.SourceInfo.ProfileName; IsCustomized = importer.SourceInfo.IsCustomized; }
static async Task CheckImporters(ICookieImporter importer, CookieImportState expectedState, bool expectedIsAvailable, bool checkUserSession) { var cookies = new CookieContainer(); var url = new Uri("http://nicovideo.jp/"); var res = await importer.GetCookiesAsync(url); res.AddTo(cookies); LogWriter.WriteLine("{0}:\t{1} ({2})", importer.IsAvailable ? "OK" : "Error", importer.SourceInfo.BrowserName, importer.SourceInfo.ProfileName); Assert.AreEqual(expectedState, res.Status); Assert.IsNotNull(importer.SourceInfo.BrowserName); Assert.IsNotNull(importer.SourceInfo.ProfileName); Assert.AreEqual(expectedIsAvailable, importer.IsAvailable); if (expectedIsAvailable) { Assert.IsNotNull(importer.SourceInfo.CookiePath, string.Format("{0}のSourceInfo.CookiePathにはプロフィール名が入りますが、取得できませんでした。", importer.SourceInfo.BrowserName)); Assert.AreNotEqual(0, cookies.GetCookies(url).Count, string.Format("{0}からCookieを取得できませんでした。", importer.SourceInfo.BrowserName)); if (checkUserSession) { Assert.IsNotNull(cookies.GetCookies(new Uri("http://nicovideo.jp"))["user_session"]); } } else { Assert.AreEqual(0, cookies.GetCookies(url).Count, string.Format("{0}からIsAvailableがfalse状態でCookieを取得する事は出来ませんが、取得されてしまっています。", importer.SourceInfo.BrowserName)); } }
static async Task <string> GetUserName(ICookieImporter cookieImporter) { try { var url = new Uri("http://www.nicovideo.jp/my/channel"); var container = new CookieContainer(); var client = new HttpClient(new HttpClientHandler() { CookieContainer = container }); var result = await cookieImporter.GetCookiesAsync(url); if (result.AddTo(container) != CookieImportState.Success) { return(null); } var res = await client.GetStringAsync(url); if (string.IsNullOrEmpty(res)) { return(null); } var namem = Regex.Match(res, "nickname = \"([^<>]+)\";", RegexOptions.Singleline); if (namem.Success) { return(namem.Groups[1].Value); } else { return(null); } } catch (System.Net.Http.HttpRequestException) { return(null); } }
public static Task<IPlatformClientBuilder[]> ImportFrom(this PlatformClientFactory factory, ICookieImporter source, IApiAccessor accessor = null) { return Task.Run(async () => { accessor = accessor ?? new DefaultAccessor(); return await accessor.GetAccountListAsync(ImportCookiesFrom(source)); }); }
static async Task <string> GetUserName(ICookieImporter cookieImporter) { try { var url = new Uri("https://www.nicovideo.jp/my/channel"); var container = new CookieContainer(); var client = new HttpClient(new HttpClientHandler() { CookieContainer = container }); var result = await cookieImporter.GetCookiesAsync(url); if (result.Status != CookieImportState.Success) { return(null); } foreach (Cookie c in result.Cookies) { if (Regex.IsMatch(c.Name, "[^0-9a-zA-Z\\._\\-\\[\\]%#&=\":\\{\\} \\(\\)/\\?\\|]") || Regex.IsMatch(c.Value, "[^0-9a-zA-Z\\._\\-\\[\\]%#&=\":\\{\\} \\(\\)/\\?\\|]")) { util.debugWriteLine(c.Name + " " + c.Value); continue; } try { container.Add(new Cookie(c.Name, c.Value, c.Path, c.Domain)); } catch (Exception e) { util.debugWriteLine(e.Message + e.StackTrace + e.TargetSite + e.Source); } } // if (result.AddTo(container) != CookieImportState.Success) // return null; var res = await client.GetStringAsync(url); if (string.IsNullOrEmpty(res)) { return(null); } var namem = Regex.Match(res, "nickname = \"([^<>]+)\";", RegexOptions.Singleline); if (namem.Success) { return(namem.Groups[1].Value); } else { return(null); } } catch (System.Net.Http.HttpRequestException) { return(null); } }
public static CookieContainer ImportCookiesFrom(ICookieImporter source) { var cookie = new CookieContainer(); Uri targetUrl; foreach (var target in new[] { "https://plus.google.com", "https://accounts.google.com", "https://talkgadget.google.com" }) { targetUrl = new Uri(target); source.GetCookies(targetUrl, cookie); } return cookie; }
async private Task <CookieContainer> getBrowserCookie(bool isSub) { var si = SourceInfoSerialize.load(isSub); // var importer = await SunokoLibrary.Application.CookieGetters.Default.GetInstanceAsync(si, false); ICookieImporter importer = await SunokoLibrary.Application.CookieGetters.Default.GetInstanceAsync(si, false).ConfigureAwait(false); // var importers = new SunokoLibrary.Application.CookieGetters(true, null); // var importera = (await SunokoLibrary.Application.CookieGetters.Browsers.IEProtected.GetCookiesAsync(TargetUrl)); // foreach (var rr in importer.Cookies) // util.debugWriteLine(rr); //importer = await importers.GetInstanceAsync(si, true); if (importer == null) { return(null); } CookieImportResult result = await importer.GetCookiesAsync(TargetUrl).ConfigureAwait(false); if (result.Status != CookieImportState.Success) { return(null); } //if (result.Cookies["user_session"] == null) return null; //var cookie = result.Cookies["user_session"].Value; //util.debugWriteLine("usersession " + cookie); var cc = new CookieContainer(); cc.PerDomainCapacity = 200; foreach (Cookie _c in result.Cookies) { try { if (_c.Name == "age_auth" || _c.Name.IndexOf("user_session") > -1) { cc.Add(new Cookie(_c.Name, _c.Value, "/", ".nicovideo.jp")); } } catch (Exception e) { util.debugWriteLine("cookie add browser " + _c.ToString() + e.Message + e.Source + e.StackTrace + e.TargetSite); } } // result.AddTo(cc); var c = cc.GetCookies(TargetUrl)["user_session"]; var secureC = cc.GetCookies(TargetUrl)["user_session_secure"]; //cc = setUserSession(cc, c, secureC); return(cc); }
static async Task<string> GetUserName(ICookieImporter cookieImporter) { try { var url = new Uri("http://www.nicovideo.jp/my/channel"); var container = new CookieContainer(); var client = new HttpClient(new HttpClientHandler() { CookieContainer = container }); var result = await cookieImporter.GetCookiesAsync(url); if (result.AddTo(container) != CookieImportState.Success) return null; var res = await client.GetStringAsync(url); if (string.IsNullOrEmpty(res)) return null; var namem = Regex.Match(res, "nickname = \"([^<>]+)\";", RegexOptions.Singleline); if (namem.Success) return namem.Groups[1].Value; else return null; } catch (System.Net.Http.HttpRequestException) { return null; } }
public NicoAccountSelectorItem(ICookieImporter importer) : base(importer) { }
/// <summary> /// 失敗した処理の情報を出力します。 /// </summary> /// <param name="target">失敗した処理が行われた対象</param> /// <param name="message">失敗した処理の名前</param> /// <param name="detailMessage">詳細な状況説明文</param> protected static void TraceError(ICookieImporter target, string message, string detailMessage) { Trace.TraceError(string.Format("SnkLib.App.CookieGetter.dll:\r\n{0}のCookieの{1}", target.SourceInfo.BrowserName, message), detailMessage); }
public NicoAccountSelectorItem(ICookieImporter importer) : base(importer) { }
/// <summary> /// 失敗した処理の情報を出力します。 /// </summary> /// <param name="target">失敗した処理が行われた対象</param> /// <param name="message">失敗した処理の名前</param> /// <param name="detailMessage">詳細な状況説明文</param> protected static void TraceError(ICookieImporter target, string message, string detailMessage) { Trace.TraceError(string.Format("SnkLib.App.CookieGetter.dll:\r\n{0}のCookieの{1}", target.SourceInfo.BrowserName, message), detailMessage); }
internal CookieGetter(ICookieImporter importer) { Importer = importer; Status = new CookieStatus(this, ConvertBrowserType(importer.SourceInfo.BrowserName)); }
internal CookieGetter(ICookieImporter importer) { Importer = importer; Status = new CookieStatus(this, ConvertBrowserType(importer.SourceInfo.BrowserName)); }
static async Task <string> GetUserName(ICookieImporter cookieImporter) { try { var myPage = new Uri("https://www.nicovideo.jp/my/channel"); var container = new CookieContainer(); container.PerDomainCapacity = 200; var client = new HttpClient(new HttpClientHandler() { CookieContainer = container, Proxy = util.httpProxy, UseProxy = true }); var result = await cookieImporter.GetCookiesAsync(myPage); if (result.Status != CookieImportState.Success) { return(null); } foreach (Cookie c in result.Cookies) { if (Regex.IsMatch(c.Name, "[^0-9a-zA-Z\\._\\-\\[\\]%#&=\":\\{\\} \\(\\)/\\?\\|]") || Regex.IsMatch(c.Value, "[^0-9a-zA-Z\\._\\-\\[\\]%#&=\":\\{\\} \\(\\)/\\?\\|]")) { util.debugWriteLine(c.Name + " " + c.Value); continue; } if (c.Name != "user_session") { continue; } try { container.Add(new Cookie(c.Name, c.Value, c.Path, c.Domain)); } catch (Exception e) { util.debugWriteLine(e.Message + e.StackTrace + e.TargetSite + e.Source); } } // if (result.AddTo(container) != CookieImportState.Success) // return null; var us = container.GetCookies(myPage)["user_session"]; if (us == null) { return(null); } var n = util.getMyName(container, us.Value); return(n); /* * //if (n != null) return n; * var res = await client.GetStringAsync(myPage); * if (string.IsNullOrEmpty(res)) * return null; * var namem = Regex.Match(res, "nickname = \"([^<>]+)\";", RegexOptions.Singleline); * if (namem.Success) * return namem.Groups[1].Value; * else * return null; */ } catch (System.Net.Http.HttpRequestException) { return(null); } }
static async Task CheckImporters(ICookieImporter importer, CookieImportState expectedState, bool expectedIsAvailable, bool checkUserSession) { var cookies = new CookieContainer(); var url = new Uri("http://nicovideo.jp/"); var res = await importer.GetCookiesAsync(url); res.AddTo(cookies); LogWriter.WriteLine("{0}:\t{1} ({2})", importer.IsAvailable ? "OK" : "Error", importer.SourceInfo.BrowserName, importer.SourceInfo.ProfileName); Assert.AreEqual(expectedState, res.Status); Assert.IsNotNull(importer.SourceInfo.BrowserName); Assert.IsNotNull(importer.SourceInfo.ProfileName); Assert.AreEqual(expectedIsAvailable, importer.IsAvailable); if (expectedIsAvailable) { Assert.IsNotNull(importer.SourceInfo.CookiePath, string.Format("{0}のSourceInfo.CookiePathにはプロフィール名が入りますが、取得できませんでした。", importer.SourceInfo.BrowserName)); Assert.AreNotEqual(0, cookies.GetCookies(url).Count, string.Format("{0}からCookieを取得できませんでした。", importer.SourceInfo.BrowserName)); if (checkUserSession) Assert.IsNotNull(cookies.GetCookies(new Uri("http://nicovideo.jp"))["user_session"]); } else { Assert.AreEqual(0, cookies.GetCookies(url).Count, string.Format("{0}からIsAvailableがfalse状態でCookieを取得する事は出来ませんが、取得されてしまっています。", importer.SourceInfo.BrowserName)); } }
/// <summary> /// Itemsを更新します。 /// </summary> public async Task UpdateAsync() { ICookieImporter currentImporter = null; CookieSourceInfo currentInfo = null; SqlCookieImporter.tempNameList.Clear(); GeckoImporterFactory.fileDataList.Clear(); try { //設定復元用に選択中のブラウザを取得。 await _updateSem.WaitAsync(); currentImporter = SelectedImporter; currentInfo = currentImporter != null ? currentImporter.SourceInfo : null; SelectedIndex = -1; IsUpdating = true; var browserItems = (await _importerManager.GetInstancesAsync(!IsAllBrowserMode)) .ToArray() .OrderBy(importer => importer, _importerComparer) .Select(importer => { try { var item = _itemGenerator(importer); item.Initialize(); return(item); } catch (Exception e) { throw new CookieImportException( string.Format("{0}の生成に失敗しました。", typeof(CookieSourceItem).Name), CookieImportState.UnknownError, e); } }); lock (_updaterSyn) { _addedCustom = false; for (var i = Items.Count - 1; i >= 0; i--) { Items.RemoveAt(i); } foreach (var item in browserItems) { Items.Add(item); } } //更新前に選択していた項目を再選択させる if (currentInfo != null) { await PrivateSetInfoAsync(currentInfo); } } catch (CookieImportException e) { lock (_updaterSyn) for (var i = Items.Count - 1; i >= 0; i--) { Items.RemoveAt(i); } System.Diagnostics.Trace.TraceInformation("選択中のブラウザの設定カスタマイズに失敗。", e); } finally { _updateSem.Release(); IsUpdating = false; } }