示例#1
0
        private void importRecord(TreeNode <Records.BaseRecord> currentNode, PwGroup pwGroupAddTo, PwDatabase pwDatabase, UserPrefs userPrefs)
        {
            Records.BaseRecord record = currentNode.AssociatedObject;

            if (record is Records.RegularFolderRecord)
            {
                PwGroup folder = (record as Records.RegularFolderRecord).CreatePwGroup();

                if (folder != null)
                {
                    pwGroupAddTo.AddGroup(folder, true);

                    foreach (TreeNode <Records.BaseRecord> child in currentNode.Children)
                    {
                        importRecord(child, folder, pwDatabase, userPrefs);
                    }
                }
            }
            else
            {
                Records.ItemRecord itemRecord = record as Records.ItemRecord;

                PwEntry entry = itemRecord.CreatePwEntry(pwDatabase, userPrefs);

                if (entry != null)
                {
                    PwCustomIcon customIcon = itemRecord.GetPwCustomIcon();

                    if (customIcon != null)
                    {
                        if (!pwDatabase.CustomIcons.Exists(icon => icon.Uuid.Equals(customIcon.Uuid)))
                        {
                            pwDatabase.CustomIcons.Add(customIcon);
                        }

                        pwDatabase.UINeedsIconUpdate = true;
                    }

                    pwGroupAddTo.AddEntry(entry, true);
                }
            }
        }
示例#2
0
        public List <Records.BaseRecord> Parse(Stream input)
        {
            List <Records.BaseRecord> records = new List <Records.BaseRecord>();

            using (TextReader textReader = new StreamReader(input))
            {
                StringBuilder stringBuilder = null;
                string        line          = textReader.ReadLine();

                while (line != null)
                {
                    stringBuilder = new StringBuilder();

                    while (line != null && !line.Equals(recordSeparator))
                    {
                        stringBuilder.AppendLine(line);
                        line = textReader.ReadLine();
                    }

                    string stringRecord = stringBuilder.ToString();

                    if (!string.IsNullOrEmpty(stringRecord))
                    {
                        Records.BaseRecord record = JsonConvert.DeserializeObject <Records.BaseRecord>(stringRecord);

                        // Unknown records are currently not imported
                        if (record != null && !(record is Records.UnknownRecord))
                        {
                            records.Add(record as Records.BaseRecord);
                        }
                    }

                    line = textReader.ReadLine();
                }
            }

            return(records);
        }