Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        public void ShouldExportToTargets()
        {
            //we change the password which is used to encrypt the delta container so we can later access the delta container
            //more easily.
            PwEntry mrX = TestHelper.GetUserRootNodeFor(m_database, 0);
            //the first autoExport only checks if there is a delta container allready and if not it will export one
            //in our case there should be no existing container so a new one will be created.
            var exportFolder = m_database.GetExportGroup();

            Assert.IsTrue(0 == exportFolder.Groups.UCount);
            string exportPath = GetTestPath();

            m_syncManager.AddExportPath(exportPath);
            var exportGroup = exportFolder.Groups.GetAt(0);

            exportGroup.AddEntry(mrX.CreateProxyNode(), true);

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

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

            m_syncManager.RefeshSourcesList();
            m_syncManager.Export();

            mrX = TestHelper.GetUserRootNodeFor(m_database, 0);
            Assert.AreEqual("mrX", mrX.Strings.ReadSafe(KeeShare.KeeShare.TitleField));

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

            //now we open the creted delta container and verify the contend
            PwDatabase deltaDB = new PwDatabase();

            Assert.DoesNotThrow(delegate {
                deltaDB.Open(IOConnectionInfo.FromPath(exportFile), m_standardKey, null);
            });

            Assert.AreEqual(5, deltaDB.RootGroup.GetEntries(true).UCount);
            Assert.AreEqual(3, deltaDB.RootGroup.Entries.UCount);
            Assert.AreEqual("grp1", deltaDB.RootGroup.Groups.GetAt(0).Name);
            Assert.AreEqual(2, deltaDB.RootGroup.Groups.GetAt(0).Entries.UCount);
            //now we will test in detail if there are only the expected entries in the created delta container
            Assert.AreEqual(Uuid1, deltaDB.RootGroup.Entries.GetAt(0).Uuid);
            Assert.AreEqual(Uuid3, deltaDB.RootGroup.Entries.GetAt(2).Uuid);
            Assert.AreEqual(Uuid6, deltaDB.RootGroup.Entries.GetAt(1).Uuid);
            Assert.AreEqual(Uuid4, deltaDB.RootGroup.Groups.GetAt(0).Entries.GetAt(0).Uuid);
            Assert.AreEqual(Uuid5, deltaDB.RootGroup.Groups.GetAt(0).Entries.GetAt(1).Uuid);
            Assert.AreEqual("normalEntry1", deltaDB.RootGroup.Entries.GetAt(0).GetTitle());
            deltaDB.Close();
        }
Exemplo n.º 3
0
        /// <summary>
        /// The function collects all export pathes for the given user. All these
        /// pathes are used to get a copy of the delta container
        /// </summary>
        /// <param name="rootNode">Specifies the user we want to know the expPathes of.</param>
        /// <returns>A <c>List<string></c> containing all the expPathes.</returns>
        private List <string> GetAllExportPaths(PwDatabase database, PwEntry rootNode)
        {
            List <string> expList     = new List <string>();
            PwGroup       exportGroup = database.GetExportGroup();

            foreach (PwEntry proxy in exportGroup.GetEntries(true))
            {
                if (proxy.Strings.ReadSafe(KeeShare.UuidLinkField) == rootNode.Uuid.ToHexString())
                {
                    if (proxy.ParentGroup.IsValidExportInfo())
                    {
                        expList.Add(proxy.ParentGroup.Name);
                    }
                }
            }
            return(expList);
        }
Exemplo n.º 4
0
        /// <summary>
        /// The function creates a new PwGroup that represents an export path.
        /// All userProxies that will be placed in that group means taht this
        /// user will use this export path too.
        /// </summary>
        /// <param name="folderName">The path to the folder in your filesystem that should be used
        /// as export destination.</param>
        /// <returns><c>ChangeFlags.CommonChange</c> if the function has made any changes to the
        /// actual database structure (means if we added the expPath). 0 if the expPath allready exists
        /// and we don't have to make any changes anymore.</returns>
        public Changes AddExportPath(string folderName)
        {
            //is it a valid path?
            if (!Directory.Exists(folderName))
            {
                return(Changes.None);
            }
            //check if allready exists
            PwGroup exportGroup = m_database.GetExportGroup();

            foreach (PwGroup exp in exportGroup.GetGroups(false))
            {
                if (exp.Name == folderName)
                {
                    return(Changes.None);
                }
            }

            //create new export path
            PwGroup newExport = new PwGroup(true, true, folderName, PwIcon.NetworkServer);

            newExport.SetParent(exportGroup);
            return(Changes.GroupCreated);
        }