Ejemplo n.º 1
0
        public void ShouldHandleCyclesOfNodesInImportAndExport()
        {
            var exportPath = GetTestPath();

            m_syncManager.AddExportPath(exportPath);

            var userMrX = TestHelper.GetUserRootNodeByNameFor(m_database, "mrX");

            m_database.GetExportGroup().Groups.GetAt(0).AddEntry(userMrX.CreateProxyNode(), true);

            var existingEntry = new PwEntry(true, true);

            existingEntry.SetTitle("Entry Version 1");
            m_database.RootGroup.AddEntry(existingEntry, true);
            m_database.RootGroup.AddEntry(userMrX.CreateProxyNode(), true);

            m_treeManager.CorrectStructure();

            string exportFile = exportPath + SyncSource.FileNameFor(userMrX) + SyncExporter.FileExtension;

            Assert.IsFalse(File.Exists(exportFile));

            m_syncManager.Export();

            var deltaDBInitial = new PwDatabase();

            deltaDBInitial.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
            Assert.AreEqual(1, deltaDBInitial.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Entry Version 1"));
            foreach (var entry in deltaDBInitial.RootGroup.GetEntries(true))
            {
                entry.SetTitle("Changed");
            }
            deltaDBInitial.Save(null);
            deltaDBInitial.Close();

            m_syncManager.AddImportPath(exportFile);
            m_database.GetImportGroup().Groups.GetAt(0).Entries.GetAt(0).SetPassword(userMrX.Strings.ReadSafe(KeeShare.KeeShare.PasswordField));

            m_syncManager.RefeshSourcesList();
            // Node normalEntry6 is within the user home and is relocated on export which changes the parent node - during import, the parents of
            // not "officially" relocated nodes is checked and an assertion is thrown
            Assert.AreEqual(0, m_database.RootGroup.GetEntries(true).Count(e => e.GetTitle() == "Changed"));
        }
Ejemplo n.º 2
0
        public void Initialize(PwDatabase database)
        {
            //do not activate the plugin if we open a DeltaContainer

            if (database.IsDeltaDatabase())
            {
                return;
            }
            m_initialized = true;
            m_database    = database;

            //====================== autocreating the neccassary groups ==================================
            m_database.GetExportGroup();
            m_database.GetImportGroup();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The function we have to call from the outside to trigger any tests we have to
        /// make after some changes to the given database, so we can ensure full functionality
        /// </summary>
        /// <param name="database">The database we should work on.</param>
        public void RefeshSourcesList()
        {
            Debug.Assert(m_initialized);
            Debug.Assert(m_database != null);
            if (!m_initialized || m_database == null)
            {
                return;
            }

            PwGroup importGroup = m_database.GetImportGroup();
            PwObjectList <PwEntry> activeSources = importGroup.GetEntries(true);

            // remove old/invalid sources
            foreach (SyncSource source in m_syncSourceList.ToArray())
            {
                //don't touch sources of closed tabs!
                if (source.DestinationDB != m_database)
                {
                    // The database where the source is configured in is not a target for the source!
                    // WTF: Why do we keep it in the DB?
                    continue;
                }
                bool isActive = false;
                foreach (PwEntry entry in activeSources)
                {
                    if (source.IsSimilar(entry, m_database) || source.IsSimilar(entry, m_database))
                    {
                        isActive = true;
                        break;
                    }
                }
                if (!isActive)
                {
                    source.StopWatch();
                    source.Changed -= m_importer.Import;
                    m_syncSourceList.Remove(source);
                }
            }

            //look for new sources
            foreach (PwEntry entry in activeSources)
            {
                if (entry.IsValidSource() && !SouceListContains(entry))
                {
                    //maybe only an update is needed
                    SyncSource source = GetSourceRepresentedBy(entry);
                    if (null != source && !source.IsEqual(entry, m_database))
                    {
                        source.Key = SyncSource.CreateKeyFor(entry);
                        source.StartWatch();
                    } //a syncSource without a Pasword that could be used as Key will be ignored!
                    else if (entry.Strings.ReadSafe(KeeShare.PasswordField) != "")
                    {
                        //create a new source otherwise
                        SyncSource src = new SyncSource(entry, m_database);
                        src.Changed += m_importer.Import;
                        src.StartWatch();
                        m_syncSourceList.Add(src);
                    }
                }
            }
        }