Esempio n. 1
0
        public void TestRemoveProject()
        {
            TestCandidate candidate = new TestCandidate();

            candidate.Name = "Palaksha";

            CandidateWorkProfile workProfile = new CandidateWorkProfile();

            workProfile.CompanyName = "ResumePro";
            Relation.Add(candidate, workProfile);

            candidate = SaveAndReFetch(candidate);

            workProfile = CollectionHelper.First(Relation.Collection <CandidateWorkProfile>(candidate));

            With.Transaction(delegate
            {
                //candidate.RemoveChild(project);
                Relation.Remove(candidate, workProfile);
            });

            candidate = SaveAndReFetch(candidate);

            Assert.AreEqual(Relation.Count <CandidateWorkProfile>(candidate), 0);
        }
        public object Set(Key key, object obj)
        {
            object s   = index.Get(key);
            int    oid = storage.GetOid(obj);

            if (oid == 0)
            {
                oid = storage.MakePersistent(obj);
            }
            if (s == null)
            {
                Relation r = Storage.CreateRelation(null);
                r.Add(obj);
                index[key] = r;
                nElems    += 1;
                Modify();
                return(null);
            }
            else if (s is Relation)
            {
                Relation r = (Relation)s;
                if (r.Count == 1)
                {
                    object prev = r[0];
                    r[0] = obj;
                    return(prev);
                }
            }
            throw new StorageError(StorageError.ErrorCode.KEY_NOT_UNIQUE);
        }
Esempio n. 3
0
        public V Set(Key key, V obj)
        {
            IPersistent s = index.Get(key);

            if (s == null)
            {
                Relation <V, V> r = Database.CreateRelation <V, V>(null);
                r.Add(obj);
                index.Put(key, r);
                nElems += 1;
                Modify();
                return(null);
            }
            else if (s is Relation <V, V> )
            {
                Relation <V, V> r = (Relation <V, V>)s;
                if (r.Count == 1)
                {
                    V prev = r[0];
                    r[0] = obj;
                    return(prev);
                }
            }
            throw new DatabaseException(DatabaseException.ErrorCode.KEY_NOT_UNIQUE);
        }
Esempio n. 4
0
        private void CreateIndexRelation(ValueType type)
        {
            int id = -1;

            switch (type)
            {
            case ValueType.Integer:
                id = Constants.IntIndexRelationId;
                break;

            case ValueType.UnsignedInteger:
                id = Constants.IntIndexRelationId;
                break;

            case ValueType.String:
                id = Constants.StringIndexRelationId;
                break;
            }

            if (id > -1)
            {
                Relation indexRelation = new Relation()
                {
                    Name = "IndexRelation", Id = id
                };
                indexRelation.Add(new AttributeDefinition()
                {
                    Name = "Value", Type = type
                });
                indexRelation.Add(new AttributeDefinition()
                {
                    Name = "LeftPointer", Type = ValueType.UnsignedInteger
                });
                indexRelation.Add(new AttributeDefinition()
                {
                    Name = "ValuePointer", Type = ValueType.UnsignedInteger
                });
                indexRelation.Add(new AttributeDefinition()
                {
                    Name = "RightPointer", Type = ValueType.UnsignedInteger
                });
                indexRelation.SyncRelation();
                Relations.Add(indexRelation);
            }
        }
        public bool Put(Key key, object obj)
        {
            object s   = index.Get(key);
            int    oid = storage.GetOid(obj);

            if (oid == 0)
            {
                oid = storage.MakePersistent(obj);
            }
            if (s == null)
            {
                Relation r = Storage.CreateRelation(null);
                r.Add(obj);
                index.Put(key, r);
            }
            else if (s is Relation)
            {
                Relation rel = (Relation)s;
                if (rel.Count == BTREE_THRESHOLD)
                {
                    ISet ps = Storage.CreateBag();
                    for (int i = 0; i < BTREE_THRESHOLD; i++)
                    {
                        ps.Add(rel.GetRaw(i));
                    }
                    ps.Add(obj);
                    index.Set(key, ps);
                    rel.Deallocate();
                }
                else
                {
                    int l = 0, n = rel.Count, r = n;
                    while (l < r)
                    {
                        int m = (l + r) >> 1;
                        if (Storage.GetOid(rel.GetRaw(m)) <= oid)
                        {
                            l = m + 1;
                        }
                        else
                        {
                            r = m;
                        }
                    }
                    rel.Insert(r, obj);
                }
            }
            else
            {
                ((ISet)s).Add(obj);
            }
            nElems += 1;
            Modify();
            return(true);
        }
Esempio n. 6
0
        protected override void ImportRelations()
        {
            Relation <UserGroup, User> relation_User = new Relation <UserGroup, User>("User_UserGroup");

            relation_User.Add(new RelationDetail <UserGroup, User>()
            {
                PrimaryField = x => x.IDUserGroup,
                ForeignField = x => x.IDUserGroup
            });
            Relations.Add("User", relation_User);
        }
Esempio n. 7
0
        public void TestAddCandidateAndMailTogether()
        {
            TestCandidate candidate = new TestCandidate();

            candidate.Name = "Mohan";
            TestMail mail = new TestMail();

            mail.Subject = "Static Test";

            Relation.Add(candidate, mail);

            candidate = SaveAndReFetch(candidate);

            Assert.AreEqual(Relation.Count <TestMail>(candidate), 1);
        }
Esempio n. 8
0
        public void TestAddCandidateAndWorkProfileTogether()
        {
            TestCandidate candidate = new TestCandidate();

            candidate.Name = "Mohan";

            CandidateWorkProfile workProfile = new CandidateWorkProfile();

            workProfile.CompanyName = "ResumePro";

            Relation.Add(candidate, workProfile);

            candidate.AddToWorkProfile(workProfile);

            candidate = SaveAndReFetch(candidate);

            Assert.AreEqual(Relation.Count <CandidateWorkProfile>(candidate), 1);
        }
Esempio n. 9
0
        public void TestUpdateProjectDirect()
        {
            TestCandidate candidate = new TestCandidate();

            candidate.Name = "Palaksha";
            CandidateWorkProfile workProfile = new CandidateWorkProfile();

            workProfile.CompanyName = "AppServer";
            Relation.Add(candidate, workProfile);

            Save(candidate);

            workProfile = Repository <CandidateWorkProfile> .FindOne(Expression.Eq("CompanyName", "AppServer"));

            workProfile.CompanyName = "Changed" + workProfile.CompanyName;

            workProfile = CollectionHelper.First(Relation.Collection <CandidateWorkProfile>(candidate));
            Assert.IsTrue(workProfile.CompanyName.StartsWith("Changed"));
        }
Esempio n. 10
0
        public void SetListLength(int length)
        {
            while (Lefts.Count > length)
            {
                Rights.RemoveAt(Lefts.Count - 1);
                Lefts.RemoveAt(Lefts.Count - 1);
                Relation.RemoveAt(Lefts.Count - 1);
            }

            while (Lefts.Count < length)
            {
                Lefts.Add(new QPart {
                    Text = ""
                });
                Rights.Add(new QPart {
                    Text = ""
                });
                Relation.Add(Relation.Count);
            }
        }
Esempio n. 11
0
        public void TestRemoveProjectDirect()
        {
            TestCandidate candidate = new TestCandidate();

            candidate.Name = "Palaksha";

            CandidateWorkProfile workProfile = new CandidateWorkProfile();

            workProfile.CompanyName = "AppServer";
            Relation.Add(candidate, workProfile);
            Save(candidate);

            workProfile = Repository <CandidateWorkProfile> .FindOne(Expression.Eq("CompanyName", "AppServer"));

            //candidate.RemoveChild(project);
            Relation.Remove(candidate, workProfile);

            SaveAndReFetch(candidate);

            Assert.AreEqual(Relation.Count <CandidateWorkProfile>(candidate), 0);
        }
Esempio n. 12
0
        public void Test_GetAny_Object()
        {
            TestCandidate candidate1 = new TestCandidate();

            candidate1.Name = "Mohan";
            TestMail mail1 = new TestMail();

            mail1.Subject = "Static Test";

            Relation.Add(candidate1, mail1);

            candidate1 = SaveAndReFetch(candidate1);

            AnyTypeRepository repo = new AnyTypeRepository();

            TestCandidate candidate2 = (TestCandidate)repo.GetAnyObject(typeof(TestCandidate), candidate1.ObjectId);
            TestMail      mail2      = (TestMail)repo.GetAnyObject(typeof(TestMail), mail1.PrimaryKey);

            Assert.AreEqual(candidate1, candidate2);
            Assert.AreEqual(mail1.Subject, mail2.Subject);
        }
Esempio n. 13
0
        public void TestUpdateWorkProfile()
        {
            TestCandidate candidate = new TestCandidate();

            candidate.Name = "Palaksha";

            CandidateWorkProfile workProfile = new CandidateWorkProfile();

            workProfile.CompanyName = "ResumePro";
            Relation.Add(candidate, workProfile);

            candidate = SaveAndReFetch(candidate);

            workProfile             = CollectionHelper.First(Relation.Collection <CandidateWorkProfile>(candidate));
            workProfile.CompanyName = "Changed" + workProfile.CompanyName;


            candidate = SaveAndReFetch(candidate);

            workProfile = CollectionHelper.First(Relation.Collection <CandidateWorkProfile>(candidate));
            Assert.IsTrue(workProfile.CompanyName.StartsWith("Changed"));
        }
Esempio n. 14
0
        public bool Put(Key key, V obj)
        {
            IPersistent s = index.Get(key);

            if (s == null)
            {
                Relation <V, V> r = Database.CreateRelation <V, V>(null);
                r.Add(obj);
                index.Put(key, r);
            }
            else if (s is Relation <V, V> )
            {
                Relation <V, V> r = (Relation <V, V>)s;
                if (r.Count == BTREE_THRESHOLD)
                {
                    ISet <V> ps = ((DatabaseImpl)Database).CreateBtreeSet <V>();
                    for (int i = 0; i < BTREE_THRESHOLD; i++)
                    {
                        ps.Add(r[i]);
                    }
                    ps.Add(obj);
                    index.Set(key, ps);
                    r.Deallocate();
                }
                else
                {
                    r.Add(obj);
                }
            }
            else
            {
                ((ISet <V>)s).Add(obj);
            }
            nElems += 1;
            Modify();
            return(true);
        }
Esempio n. 15
0
        public void TestAddCandidateAndWorkProfileAndProject()
        {
            TestCandidate candidate = new TestCandidate();

            candidate.Name = "Mohan";

            CandidateWorkProfile workProfile;

            Relation.AddNew(candidate, out workProfile);
            workProfile.CompanyName = "HirePro";

            CandidateProject project = new CandidateProject();

            project.Name = "ResumePro";
            Relation.Add(workProfile, project);

            candidate = SaveAndReFetch(candidate);

            Assert.AreEqual(Relation.Count <CandidateWorkProfile>(candidate), 1);
            Assert.AreEqual(Relation.Count <CandidateProject>(workProfile), 1);
            Assert.AreEqual(
                CollectionHelper.First(Relation.Collection <CandidateProject>(workProfile)).Name,
                "ResumePro");
        }
 public virtual IMutableRelation Reverse()
 {
   IMutableRelation reverse = new Relation();
   foreach(object key in GetKeys())
     foreach(object value in GetValues(key))
       reverse.Add(value, key);
   return reverse;
 }
Esempio n. 17
0
 public virtual void AddToWorkProfile(CandidateWorkProfile workProfile)
 {
     Relation.Add <TestCandidate, CandidateWorkProfile>(this, workProfile);
 }
Esempio n. 18
0
 public void Add(M m)
 {
     GetCollection().Add(m);
     Relation.Add(m.Id());
     Handler <M> .AddRelation(m, ModlInstance);
 }
Esempio n. 19
0
        private void LoadEpubMetaDataFromOpfFile(string opfFilePath)
        {
            ZipEntry zipEntry = _EpubFile.Entries.FirstOrDefault(e => e.FileName.Equals(opfFilePath, StringComparison.InvariantCultureIgnoreCase));

            if (zipEntry == null)
            {
                throw new Exception("Invalid epub file.");
            }

            XElement contentOpf;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                zipEntry.Extract(memoryStream);
                // Fix buggy "<?xml verison="1.1"?>
                // See http://stackoverflow.com/questions/912440/xdocument-cant-load-xml-with-version-1-1-in-c-sharp-linq
                byte[] b = memoryStream.ToArray();
                for (int i = 0; i < 50; i++)
                {
                    // Check for version="1.1" and replace if found
                    if (b[i] == 0x76 && b[i + 1] == 0x65 && b[i + 2] == 0x72 && b[i + 3] == 0x73 && b[i + 4] == 0x69 && b[i + 5] == 0x6F && b[i + 6] == 0x6E &&
                        b[i + 7] == 0x3D && b[i + 8] == 0x22 && b[i + 9] == 0x31 && b[i + 10] == 0x2E && b[i + 11] == 0x31)
                    {
                        b[i + 11] = 0x30;
                    }
                }
                using (MemoryStream fixedStream = new MemoryStream(b))
                {
                    contentOpf = XElement.Load(fixedStream);
                }
                b = null;
            }

            XNamespace xNamespace = contentOpf.Attribute("xmlns") != null?contentOpf.Attribute("xmlns").Value : XNamespace.None;

            string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value;

            try { UUID = contentOpf.Elements(xNamespace + "metadata").Elements().FirstOrDefault(e => e.Name.LocalName == "identifier" && e.Attributes("id").FirstOrDefault() != null && e.Attribute("id").Value == uniqueIdentifier).Value; }
            catch { }
            foreach (var metadataElement in contentOpf.Elements(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty))
            {
                switch (metadataElement.Name.LocalName)
                {
                case "title": Title.Add(metadataElement.Value); break;

                case "creator": Creator.Add(metadataElement.Value); break;

                case "date":
                    var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event");
                    if (attribute != null)
                    {
                        Date.Add(new DateData(attribute.Value, metadataElement.Value));
                    }
                    break;

                case "publisher": Publisher.Add(metadataElement.Value); break;

                case "subject": Subject.Add(metadataElement.Value); break;

                case "source": Source.Add(metadataElement.Value); break;

                case "rights": Rights.Add(metadataElement.Value); break;

                case "description": Description.Add(metadataElement.Value); break;

                case "contributor": Contributer.Add(metadataElement.Value); break;

                case "type": Type.Add(metadataElement.Value); break;

                case "format": Format.Add(metadataElement.Value); break;

                case "identifier": ID.Add(metadataElement.Value); break;

                case "language": Language.Add(metadataElement.Value); break;

                case "relation": Relation.Add(metadataElement.Value); break;

                case "coverage": Coverage.Add(metadataElement.Value); break;
                }
            }

            LoadManifestSectionFromOpfFile(contentOpf, xNamespace);
        }
Esempio n. 20
0
        private void LoadEpubMetaDataFromOpfFile(string opfFilePath)
        {
            ZipEntry zipEntry = _EpubFile.GetEntry(opfFilePath);

            if (zipEntry == null)
            {
                throw new Exception("Invalid epub file.");
            }

            XElement contentOpf;

            using (Stream zipStream = _EpubFile.GetInputStream(zipEntry))
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    byte[] buffer = new byte[4096]; // 4K is optimum
                    StreamUtils.Copy(zipStream, memoryStream, buffer);
                    memoryStream.Position = 0;
                    contentOpf            = XElement.Load(memoryStream);
                }
            }

            XNamespace xNamespace = contentOpf.Attribute("xmlns") != null
                ? contentOpf.Attribute("xmlns").Value
                : XNamespace.None;

            string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value;

            UUID = contentOpf.Elements(xNamespace + "metadata").Elements()
                   .FirstOrDefault(e =>
                                   e.Name.LocalName == "identifier" &&
                                   e.HasAttributes &&
                                   e.Attribute("id") != null &&
                                   e.Attribute("id").Value == uniqueIdentifier
                                   ).Value;
            foreach (
                var metadataElement in
                contentOpf.Element(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty))
            {
                switch (metadataElement.Name.LocalName)
                {
                case "title":
                    Title.Add(metadataElement.Value);
                    break;

                case "creator":
                    Creator.Add(metadataElement.Value);
                    break;

                case "date":
                    var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event");
                    if (attribute != null)
                    {
                        Date.Add(new DateData(attribute.Value, metadataElement.Value));
                    }
                    break;

                case "publisher":
                    Publisher.Add(metadataElement.Value);
                    break;

                case "subject":
                    Subject.Add(metadataElement.Value);
                    break;

                case "source":
                    Source.Add(metadataElement.Value);
                    break;

                case "rights":
                    Rights.Add(metadataElement.Value);
                    break;

                case "description":
                    Description.Add(metadataElement.Value);
                    break;

                case "contributor":
                    Contributer.Add(metadataElement.Value);
                    break;

                case "type":
                    Type.Add(metadataElement.Value);
                    break;

                case "format":
                    Format.Add(metadataElement.Value);
                    break;

                case "identifier":
                    ID.Add(metadataElement.Value);
                    break;

                case "language":
                    Language.Add(metadataElement.Value);
                    break;

                case "relation":
                    Relation.Add(metadataElement.Value);
                    break;

                case "coverage":
                    Coverage.Add(metadataElement.Value);
                    break;
                }
            }

            LoadManifestSectionFromOpfFile(contentOpf, xNamespace);
        }
Esempio n. 21
0
        private void LoadEpubMetaDataFromOpfFile(string opfFilePath)
        {
            ZipEntry zipEntry = _EpubFile.Entries.FirstOrDefault(e => e.FileName.Equals(opfFilePath, StringComparison.InvariantCultureIgnoreCase));

            if (zipEntry == null)
            {
                throw new Exception("Invalid epub file.");
            }

            XElement contentOpf;

            using (MemoryStream memoryStream = new MemoryStream()) {
                zipEntry.Extract(memoryStream);
                memoryStream.Position = 0;
                contentOpf            = XElement.Load(memoryStream);
            }

            XNamespace xNamespace = contentOpf.Attribute("xmlns") != null?contentOpf.Attribute("xmlns").Value : XNamespace.None;

            string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value;

            try
            {
                UUID = contentOpf.Elements(xNamespace + "metadata").Elements().FirstOrDefault(e => e.Name.LocalName == "identifier" && e.Attribute("id").Value == uniqueIdentifier).Value;
            }
            catch { }
            foreach (var metadataElement in contentOpf.Elements(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty))
            {
                switch (metadataElement.Name.LocalName)
                {
                case "title": Title.Add(metadataElement.Value); break;

                case "creator": Creator.Add(metadataElement.Value); break;

                case "date":
                    var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event");
                    if (attribute != null)
                    {
                        Date.Add(new DateData(attribute.Value, metadataElement.Value));
                    }
                    break;

                case "publisher": Publisher.Add(metadataElement.Value); break;

                case "subject": Subject.Add(metadataElement.Value); break;

                case "source": Source.Add(metadataElement.Value); break;

                case "rights": Rights.Add(metadataElement.Value); break;

                case "description": Description.Add(metadataElement.Value); break;

                case "contributor": Contributer.Add(metadataElement.Value); break;

                case "type": Type.Add(metadataElement.Value); break;

                case "format": Format.Add(metadataElement.Value); break;

                case "identifier": ID.Add(metadataElement.Value); break;

                case "language": Language.Add(metadataElement.Value); break;

                case "relation": Relation.Add(metadataElement.Value); break;

                case "coverage": Coverage.Add(metadataElement.Value); break;
                }
            }

            LoadManifestSectionFromOpfFile(contentOpf, xNamespace);
        }