public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { const string BOM = "0123456789_IC"; var text = value as string; if (text == null || text.StartsWith(BOM) == false) { return(base.ConvertFrom(context, culture, value)); } text = text.Substring(BOM.Length); var restoredValues = new Dictionary <string, string>(); for (var i = 0; i < text.Length; i++) { var nmCronIdx = text.IndexOf(':', i); var name = text.Substring(i, nmCronIdx - i); var lenCronIdx = text.IndexOf(':', nmCronIdx + 1); var valLen = int.Parse(text.Substring(nmCronIdx + 1, lenCronIdx - nmCronIdx - 1)); var val = text.Substring(lenCronIdx + 1, valLen); //項目の末尾まで移動 i = lenCronIdx + valLen; restoredValues.Add(name, val); } //値を展開 bool isCustom = false; string browserName = null, profileName = null, cookiePath = null, engineId = null; foreach (var pair in restoredValues) { switch (pair.Key) { case "IsCustomized": isCustom = pair.Value == true.ToString(); break; case "BrowserName": browserName = pair.Value; break; case "ProfileName": profileName = pair.Value; break; case "CookiePath": cookiePath = pair.Value; break; case "EngineId": engineId = pair.Value; break; } } var info = new CookieSourceInfo(browserName, profileName, cookiePath, engineId, isCustom); return(info); }
/// <summary> /// 設定値を指定したICookieImporterを取得します。アプリ終了時に直前まで使用していた /// ICookieImporterのSourceInfoを設定として保存すれば、起動時にSourceInfoをこのメソッドに /// 渡す事で適切なICookieImporterを再取得する事ができます。 /// </summary> /// <param name="targetInfo">再取得対象のブラウザの構成情報</param> /// <param name="allowDefault">取得不可の場合に既定のCookieImporterを返すかを指定できます。</param> public async Task<ICookieImporter> GetInstanceAsync(CookieSourceInfo targetInfo = null, bool allowDefault = true) { var foundImporter = null as ICookieImporter; var importerList = await GetInstancesAsync(false); if (targetInfo != null) { //引数targetInfoと同一のImporterを探す。 //あればそのまま使う。なければ登録されたジェネレータから新たに生成する。 foundImporter = importerList.FirstOrDefault(item => item.SourceInfo == targetInfo); ICookieImporterFactory foundFactory; if (foundImporter == null && _factoryDict.TryGetValue(targetInfo.EngineId, out foundFactory)) { foundImporter = foundFactory.GetCookieImporter(targetInfo); foundImporter = foundImporter.IsAvailable ? foundImporter : null; } } if (allowDefault && foundImporter == null) foundImporter = importerList.FirstOrDefault(importer => importer.IsAvailable); return foundImporter; }
/// <summary> /// 設定値を指定したICookieImporterを取得します。アプリ終了時に直前まで使用していた /// ICookieImporterのSourceInfoを設定として保存すれば、起動時にSourceInfoをこのメソッドに /// 渡す事で適切なICookieImporterを再取得する事ができます。 /// </summary> /// <param name="targetInfo">再取得対象のブラウザの構成情報</param> /// <param name="allowDefault">取得不可の場合に既定のCookieImporterを返すかを指定できます。</param> public async Task <ICookieImporter> GetInstanceAsync(CookieSourceInfo targetInfo = null, bool allowDefault = true) { var foundImporter = null as ICookieImporter; var importerList = await GetInstancesAsync(false); if (targetInfo != null) { //引数targetInfoと同一のImporterを探す。 //あればそのまま使う。なければ登録されたジェネレータから新たに生成する。 foundImporter = importerList.FirstOrDefault(item => item.SourceInfo == targetInfo); ICookieImporterFactory foundFactory; if (foundImporter == null && _factoryDict.TryGetValue(targetInfo.EngineId, out foundFactory)) { foundImporter = foundFactory.GetCookieImporter(targetInfo); foundImporter = foundImporter.IsAvailable ? foundImporter : null; } } if (allowDefault && foundImporter == null) { foundImporter = importerList.FirstOrDefault(importer => importer.IsAvailable); } return(foundImporter); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { const string BOM = "0123456789_IC"; var text = value as string; if (text == null || text.StartsWith(BOM) == false) return base.ConvertFrom(context, culture, value); text = text.Substring(BOM.Length); var restoredValues = new Dictionary<string, string>(); for (var i = 0; i < text.Length; i++) { var nmCronIdx = text.IndexOf(':', i); var name = text.Substring(i, nmCronIdx - i); var lenCronIdx = text.IndexOf(':', nmCronIdx + 1); var valLen = int.Parse(text.Substring(nmCronIdx + 1, lenCronIdx - nmCronIdx - 1)); var val = text.Substring(lenCronIdx + 1, valLen); //項目の末尾まで移動 i = lenCronIdx + valLen; restoredValues.Add(name, val); } //値を展開 bool isCustom = false; string browserName = null, profileName = null, cookiePath = null, engineId = null; foreach (var pair in restoredValues) switch (pair.Key) { case "IsCustomized": isCustom = pair.Value == true.ToString(); break; case "BrowserName": browserName = pair.Value; break; case "ProfileName": profileName = pair.Value; break; case "CookiePath": cookiePath = pair.Value; break; case "EngineId": engineId = pair.Value; break; } var info = new CookieSourceInfo(browserName, profileName, cookiePath, engineId, isCustom); return info; }