Beispiel #1
0
        [Test] public void RepairUniqueRestrictionWithLinkRestrictions()
        {
            int       testLink = _storage.PropTypes.Register("TestLink", PropDataType.Link); testLink = testLink;
            IResource email1   = _storage.NewResource("Email");
            IResource email2   = _storage.NewResource("Email");
            IResource from1    = _storage.NewResource("Person");
            IResource from2    = _storage.NewResource("Person");

            email1.AddLink(_propAuthor, from1);
            email2.AddLink(_propAuthor, from2);

            from1.SetProp("Name", "Dmitry");
            from2.SetProp("Name", "Dmitry");

            _storage.RegisterLinkRestriction("Email", _propAuthor, null, 1, Int32.MaxValue);
            _storage.RegisterUniqueRestriction("Person", _storage.PropTypes ["Name"].Id);

            ResourceStoreRepair repair = new ResourceStoreRepair(null);

            repair.FixErrors = true;
            repair.RepairRestrictions();

            Assert.IsTrue(!from1.IsDeleted);
            Assert.IsTrue(!from2.IsDeleted);
        }
Beispiel #2
0
        public void Diagnose(RepairProgressEventHandler progress)
        {
            ResourceStoreRepair rsRepair = new ResourceStoreRepair(_database);

            rsRepair.FixErrors       = false;
            rsRepair.DumpStructure   = false;
            rsRepair.RepairProgress += progress;
            rsRepair.Run();
            rsRepair.RepairProgress -= progress;
        }
Beispiel #3
0
        [Test] public void TypedLinkRestrictionRepair()
        {
            int       replyLink = _storage.PropTypes.Register("Reply", PropDataType.Link, PropTypeFlags.DirectedLink);
            IResource email     = _storage.NewResource("Email");
            IResource from1     = _storage.NewResource("Person");

            email.AddLink(replyLink, from1);

            _storage.RegisterLinkRestriction("Email", replyLink, "Email", 1, 1);

            ResourceStoreRepair repair = new ResourceStoreRepair(null);

            repair.FixErrors = true;
            repair.RepairRestrictions();
        }
Beispiel #4
0
        [Test] public void InvalidPropTypeInLinkRestriction()
        {
            int initialRestrictionCount = _storage.GetAllResources("LinkRestriction").Count;

            IResource linkRestriction = _storage.NewResource("LinkRestriction");

            linkRestriction.SetProp("fromResourceType", "Email");
            linkRestriction.SetProp("LinkType", 4096);

            ResourceStoreRepair repair = new ResourceStoreRepair(null);

            repair.FixErrors = true;
            repair.RepairRestrictions();

            Assert.IsTrue(linkRestriction.IsDeleted);
            Assert.AreEqual(initialRestrictionCount, _storage.GetAllResources("LinkRestriction").Count);
        }
Beispiel #5
0
        [Test] public void NotEnoughRestrictionsRepair()  // #5603
        {
            int       testLink = _storage.PropTypes.Register("TestLink", PropDataType.Link);
            IResource email    = _storage.NewResource("Email");
            IResource from1    = _storage.NewResource("Person");

            email.AddLink(_propAuthor, from1);

            _storage.RegisterLinkRestriction("Email", _propAuthor, null, 1, Int32.MaxValue);
            _storage.RegisterLinkRestriction("Person", testLink, null, 1, Int32.MaxValue);

            ResourceStoreRepair repair = new ResourceStoreRepair(null);

            repair.FixErrors = true;
            repair.RepairRestrictions();

            Assert.IsTrue(!email.IsDeleted);
            Assert.IsTrue(!from1.IsDeleted);
        }
Beispiel #6
0
        [Test] public void TooManyRestrictionsRepair()  // see bug #5482
        {
            IResource email = _storage.NewResource("Email");
            IResource from1 = _storage.NewResource("Person");
            IResource from2 = _storage.NewResource("Person");
            IResource from3 = _storage.NewResource("Person");

            email.AddLink(_propAuthor, from1);
            email.AddLink(_propAuthor, from2);
            email.AddLink(_propAuthor, from3);

            _storage.RegisterLinkRestriction("Email", _propAuthor, null, 0, 1);

            ResourceStoreRepair repair = new ResourceStoreRepair(null);

            repair.FixErrors = true;
            repair.RepairRestrictions();

            IResourceList links = email.GetLinksOfType(null, _propAuthor);

            Assert.AreEqual(1, links.Count);
            Assert.AreEqual(from1.Id, links [0].Id);
        }
Beispiel #7
0
        [Test] public void RepairRequired()
        {
            _storage.RegisterUniqueRestriction("Email", _propSubject);

            IResource email1 = _storage.NewResource("Email");

            email1.SetProp("Subject", "A");

            IResource email2 = _storage.NewResource("Email");

            try
            {
                email2.SetProp("Subject", "A");
            }
            catch (ResourceRestrictionException)
            {
                // ignore
            }

            Assert.IsTrue(_storage.RepairRequired);
            ReopenStorage();
            Assert.IsTrue(!_storage.RepairRequired);

            IResource email = _storage.FindUniqueResource("Email", "Subject", "A"); email = email;

            Assert.IsTrue(_storage.RepairRequired);

            ResourceStoreRepair repair = new ResourceStoreRepair(null);

            repair.FixErrors = true;
            repair.RepairRestrictions();

            IResourceList resultList = _storage.FindResources("Email", "Subject", "A");

            Assert.AreEqual(1, resultList.Count);
            Assert.AreEqual(email1.Id, resultList [0].Id);
        }
Beispiel #8
0
        [Test] public void DirectedLinkRestrictionRepair()
        {
            int parentLink = _storage.PropTypes.Register("ParentLink", PropDataType.Link, PropTypeFlags.DirectedLink);

            IResource email = _storage.NewResource("Email");
            IResource from1 = _storage.NewResource("Person");
            IResource from2 = _storage.NewResource("Person");
            IResource from3 = _storage.NewResource("Person");

            from1.AddLink(parentLink, email);
            from2.AddLink(parentLink, email);
            from3.AddLink(parentLink, email);

            _storage.RegisterLinkRestriction("Email", parentLink, null, 0, 1);

            ResourceStoreRepair repair = new ResourceStoreRepair(null);

            repair.FixErrors = true;
            repair.RepairRestrictions();

            IResourceList links = email.GetLinksOfType(null, parentLink);

            Assert.AreEqual(3, links.Count);
        }
Beispiel #9
0
        private void ProcessDB()
        {
            if (!DBHelper.DatabaseExists(MyPalStorage.DBPath, "MyPal"))
            {
                Console.WriteLine("Omea database not found");
                return;
            }

            DBStructure dbStructure = new DBStructure(MyPalStorage.DBPath, "MyPal");

            dbStructure.ProgressListenerEvent += new DBStructure.ProgressEventHandler(dbStructure_ProgressListenerEvent);

            Console.WriteLine("Loading database...");

            bool structureCorrupted = false;

            try
            {
                dbStructure.LoadStructure(true);
            }
            catch (Exception)
            {
                structureCorrupted = true;
            }

            if (structureCorrupted || !AllTablesExist(dbStructure))
            {
                Console.WriteLine("Rebuilding database structure...");
                dbStructure.Shutdown();

                MyPalStorage.CreateDatabase();
                dbStructure = new DBStructure(MyPalStorage.DBPath, "MyPal");
                dbStructure.LoadStructure(true);
                _forceRebuild = true;
            }

            if (_defrag)
            {
                Console.WriteLine("Defragmenting database...");
                dbStructure.Defragment();
            }
            else if (!dbStructure.IsDatabaseCorrect())
            {
                Console.WriteLine("Database indexes are corrupt. Rebuilding...");
                dbStructure.RebuildIndexes();
            }
            else if (_forceRebuild)
            {
                Console.WriteLine("Performing forced rebuild of database indexes...");
                dbStructure.RebuildIndexes(true);
            }
            else if (_lowCheck)
            {
                dbStructure.LowLevelCheck( );
                return;
            }

            if (_dbdump)
            {
                Console.WriteLine("Dumping database...");
                dbStructure.Dump();
            }

            IDatabase db = dbStructure.OpenDatabase();

            if (_calcSpace)
            {
                CalcSpace(db, "ResourceTypes");
                CalcSpace(db, "PropTypes");
                CalcSpace(db, "IntProps");
                CalcSpace(db, "StringProps");
                CalcSpace(db, "LongStringProps");
                CalcSpace(db, "StringListProps");
                CalcSpace(db, "DateProps");
                CalcSpace(db, "BlobProps");
                CalcSpace(db, "DoubleProps");
                CalcSpace(db, "Resources");
                CalcSpace(db, "Links");
                return;
            }

            ResourceStoreRepair rsRepair = new ResourceStoreRepair(db);

            rsRepair.FixErrors       = _fixErrors;
            rsRepair.DumpStructure   = _dump;
            rsRepair.RepairProgress += new RepairProgressEventHandler(RsRepair_OnRepairProgress);
            rsRepair.Run();
        }