protected override PasswordBoss.ImportFromAppResult ImportInternal(PasswordBoss.FileImportArgs args) { if (args == null) { throw new ArgumentNullException("args"); } var res = new PasswordBoss.ImportFromAppResult(); string[] file; try { file = System.IO.File.ReadAllLines(args.FilePath); } catch { throw new System.IO.FileLoadException(string.Format(CultureInfo.InvariantCulture, "Error while loading file '{0}'.", args.FilePath)); } using (TextReader reader = File.OpenText(args.FilePath)) { var csvReader = new CsvHelper.CsvReader(reader); var records = csvReader.GetRecords <CsvExportItem>() .ToArray() // store records in memory .Select(i => i.ToSecureItem()) .ToArray(); res.SecureItems.AddRange(records); } return(res); }
protected override PasswordBoss.ImportFromAppResult ImportInternal(PasswordBoss.FileImportArgs args) { if (args == null) { throw new ArgumentNullException("args"); } var res = new PasswordBoss.ImportFromAppResult(); string[] file; try { file = System.IO.File.ReadAllLines(args.FilePath); } catch { throw new System.IO.FileLoadException(string.Format(CultureInfo.InvariantCulture, "Error while loading file '{0}'.", args.FilePath)); } int lncnt = 0; var locator = new Common.TypeParsers.TypeParserLocator <JObject>(); foreach (string fileLine in file) { lncnt++; try { if (fileLine.StartsWith("***", StringComparison.Ordinal)) { continue; } JObject jsonData = JObject.Parse(fileLine); var processor = locator.Locate((string)jsonData["typeName"]); if (processor != null) { processor.AddParsedItem(res.SecureItems, res.ImportMessages, jsonData); } } catch (Exception ex) { if (ex is IndexOutOfRangeException || ex is ArgumentException || ex is NullReferenceException) { res.ImportMessages.Add(string.Format(CultureInfo.InvariantCulture, "Input file:{0}. Error in line:{1}.", args.FilePath, lncnt)); } else { throw; } } } return(res); }
protected override PasswordBoss.ImportFromAppResult ImportInternal(PasswordBoss.FileImportArgs args) { if (args == null) { throw new ArgumentNullException("args"); } RoboformExportType currentRBExportType; var importResult = new PasswordBoss.ImportFromAppResult(); var dataList = HtmlParser.ParseFile(args.FilePath, importResult.ImportMessages, out currentRBExportType); var parser = new TypeParserLocator <RoboFormData>().Locate(currentRBExportType.ToString()); foreach (RoboFormData rdata in dataList) { try { parser.AddParsedItem(importResult.SecureItems, importResult.ImportMessages, rdata); } catch (Exception ex) { if (ex is ArgumentException || ex is InvalidOperationException) { importResult.ImportMessages.Add(string.Format(CultureInfo.InvariantCulture, "Input file:{0}. Error in parsed data object:{1}.", args.FilePath, rdata.Caption)); } else { throw; } } } return(importResult); }
protected override PasswordBoss.ImportFromAppResult ImportInternal(PasswordBoss.FileImportArgs args) { if (args == null) { throw new ArgumentNullException("args"); } var res = new ImportFromAppResult(); string[] file; try { file = System.IO.File.ReadAllLines(args.FilePath); } catch { throw new System.IO.FileLoadException(string.Format(CultureInfo.InvariantCulture, "Error while loading file '{0}'.", args.FilePath)); } int lncnt = 0; string[] fline; // "Account","Login Name","Password","Web Site","Comments" KeePass row structure foreach (string fileLine in file) { lncnt++; try { fline = fileLine.Substring(1, fileLine.Length - 2).Replace(@""",""", Environment.NewLine).Split(new string[] { Environment.NewLine }, StringSplitOptions.None); if ((fileLine.Trim().Length == 0) || (fileLine.Trim() == @"""Account"",""Login Name"",""Password"",""Web Site"",""Comments""")) { continue; } else { PBSubType.PasswordVault.Login data = new PBSubType.PasswordVault.Login(); data.SiteName = fline[0].Trim(); // Account data.UserName = fline[1].Trim(); //Login Name data.Password = fline[2].Trim(); //Password data.Url = fline[3].Trim(); //Web Site data.Notes = fline[4].Trim(); //Comments res.SecureItems.Add(data.GetSecureItem()); } } catch (Exception ex) { if (ex is IndexOutOfRangeException || ex is ArgumentException || ex is NullReferenceException) { res.ImportMessages.Add(string.Format(CultureInfo.InvariantCulture, "Input file:{0}. Error in line:{1}.", args.FilePath, lncnt)); } else { throw; } } } return(res); }