コード例 #1
0
        protected void MergeIn(PwDatabase target, PwDatabase source)
        {
            //remember stats of destDB to guess if we merged in something
            //maybe we only look for the lastChanged entry
            var clone = source.CloneDeep(target.RootGroup);
            clone.Register(KeeShare.TemporaryDatabaseId, KeeShare.TemporaryDatabaseTag);
            var cyclicEntries = new List<PwEntry>();
            foreach (var cloneEntry in clone.RootGroup.GetEntries(true).ToList())
            {
                if(cloneEntry.HasExportSource(target.RootGroup.Uuid.ToHexString()))
                {
                    cloneEntry.DeleteFrom(cloneEntry.ParentGroup);
                    cyclicEntries.Add(cloneEntry);
                }
            }

            Console.WriteLine("Prevent import of nodes which are exported from here: " + String.Join(",", cyclicEntries.Select(e => e.GetTitle()).ToArray()));

            DateTime lastChange = DateTime.MinValue;
            foreach (var entry in target.RootGroup.GetEntries(true))
            {
                if (entry.LastModificationTime.Ticks > lastChange.Ticks)
                {
                    lastChange = entry.LastModificationTime;
                }
            }
            target.MergeIn(clone, PwMergeMethod.Synchronize);
            foreach (var entry in source.RootGroup.GetEntries(true))
            {
                if (entry.LastModificationTime.Ticks > lastChange.Ticks)
                {
                    //set the modified flag of the database true, so the uiUpdate knows which tab should be marked as changed
                    target.Modified = true;
                }
            }
            if (Imported != null) Imported.Invoke(this, target.RootGroup);
        }