コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }