Example #1
0
        /// <summary>
        /// Recursively builds entity graph hierarchy.
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="parent"></param>
        /// <param name="relationship"></param>
        private EntityGraph(Type entityType, EntityGraph parent, Relationship relationship)
        {
            _repos = MapRepository.Instance;

            _entityType       = entityType;
            _parent           = parent;
            _relationship     = relationship;
            IsParentReference = !IsRoot && AnyParentsAreOfType(entityType);
            if (!IsParentReference)
            {
                _columns = _repos.GetColumns(entityType);
            }

            _relationships    = _repos.GetRelationships(entityType);
            _children         = new List <EntityGraph>();
            Member            = relationship != null ? relationship.Member : null;
            _entityReferences = new Dictionary <string, EntityReference>();

            if (IsParentReference)
            {
                return;
            }

            // Create a new EntityGraph for each child relationship that is not lazy loaded
            foreach (Relationship childRelationship in Relationships)
            {
                if (!childRelationship.IsLazyLoaded)
                {
                    _children.Add(new EntityGraph(childRelationship.RelationshipInfo.EntityType, this, childRelationship));
                }
            }
        }
Example #2
0
 /// <summary>
 /// Creates a new instance of a person object.
 /// Each new instance will be given a unique identifier.
 /// This parameterless constructor is also required for serialization.
 /// </summary>
 public Shape()
 {
     this.id            = Guid.NewGuid().ToString();
     this.relationships = new RelationshipCollection();
     this.photos        = new PhotoCollection();
     this.name          = GlobalData.DefaultName;
 }
Example #3
0
 protected override void CreateRelationship(Type entityType, MemberInfo member, RelationshipAttribute relationshipAtt, RelationshipCollection relationships)
 {
     if (RelationshipPredicate(member))
     {
         relationships.Add(new Relationship(member));
     }
 }
 /// <summary>
 /// Registers any member with a RelationshipAttribute as a relationship.
 /// </summary>
 /// <param name="entityType">The entity that is being mapped.</param>
 /// <param name="member">The current member that is being inspected.</param>
 /// <param name="relationshipAtt">A RelationshipAttribute (is null if one does not exist).</param>
 /// <param name="relationships">A list of Relationships.</param>
 protected override void CreateRelationship(Type entityType, MemberInfo member, RelationshipAttribute relationshipAtt, RelationshipCollection relationships)
 {
     if (relationshipAtt != null)
     {
         Relationship relationship = new Relationship(member, relationshipAtt);
         relationships.Add(relationship);
     }
 }
Example #5
0
 /// <summary>
 /// Creates a new instance of a person object. Each new instance will be given a unique
 /// identifier. This parameterless constructor is also required for serialization.
 /// </summary>
 public Person()
 {
     this.id            = Guid.NewGuid().ToString();
     this.relationships = new RelationshipCollection();
     //this.photos = new PhotoCollection();
     this.firstName = Const.DefaultFirstName;
     this.isLiving  = true;
 }
Example #6
0
 /// <summary>
 /// Creates a new instance of a person object.
 /// Each new instance will be given a unique identifier.
 /// This parameterless constructor is also required for serialization.
 /// </summary>
 public Person()
 {
     id            = Guid.NewGuid().ToString();
     relationships = new RelationshipCollection();
     photos        = new PhotoCollection();
     firstName     = Const.DefaultFirstName;
     isLiving      = true;
 }
Example #7
0
 public EntityContext(EntityContextOptions options)
 {
     _options                = options ?? throw new ArgumentException(nameof(options));
     _pathBuilder            = new PathBuilder(options);
     _resolver               = new EntityResolver();
     _hierarchyCollection    = new HierarchyCollection(options.Collections, _resolver, _pathBuilder);
     _relationshipCollection = new RelationshipCollection(options.Collections, _resolver);
     _recycleBinCollection   = new RecycleBinCollection(options.Collections);
 }
Example #8
0
        private void OnStateBody()
        {
            RelationshipCollection linkedCells = iCell.RelationshipManager.EmbeddedReferencesTo;

            if (linkedCells.Count > 0)
            {
                foreach (RelationshipInfo info in linkedCells)
                {
                    HeapCell linkedCell = info.ToCell;

                    // Start new row
                    WriteTableRowBegin();

                    // Address
                    WriteTableColumnHexAddress(linkedCell.Address, TAlignment.EAlignLeft);

                    // Length
                    WriteTableColumn(linkedCell.PayloadLength, TAlignment.EAlignRight);

                    // Symbol
                    string linkText = "[Unknown linked cell]";
                    if (linkedCell.Symbol != null)
                    {
                        linkText = linkedCell.Symbol.NameWithoutVTablePrefix;
                    }

                    string url          = "javascript:showMainFormCell(\'" + linkedCell.Address.ToString("x8") + "\')";
                    string windowTarget = "MainWindow";
                    WriteTableColumnBegin(TAlignment.EAlignLeft, string.Empty);
                    WriteAnchorWithTarget(windowTarget, url, linkText);
                    WriteTableColumnEnd();

                    WriteTableRowEnd();
                }

                #region Blank row
                WriteTableRowBegin();
                WriteTableColumnEmpty();
                WriteTableColumnEmpty();
                WriteTableColumnEmpty();
                WriteTableRowEnd();
                #endregion

                #region Total
                WriteTableRowBegin();
                WriteTableColumn("Total:", "tableRowTotal");
                WriteTableColumn((iCell.PayloadLengthIncludingLinkedCells - iCell.PayloadLength).ToString(""), TAlignment.EAlignRight, "tableRowTotal");
                WriteTableColumn("&nbsp;", "tableRowTotal");
                WriteTableRowEnd();
                #endregion
            }
        }
        public RelationshipCollection MapRelationships(Type entityType)
        {
            RelationshipCollection relationships = new RelationshipCollection();

            MemberInfo[] members = entityType.GetMembers(_bindingFlags);
            foreach (MemberInfo member in members)
            {
                RelationshipAttribute relationshipAtt = GetRelationshipAttribute(member);
                CreateRelationship(entityType, member, relationshipAtt, relationships);
            }

            return(relationships);
        }
        private void PopulateBranch(HeapCell aCell, TreeNode aParentNode)
        {
            RelationshipCollection linkedCells = aCell.RelationshipManager.EmbeddedReferencesTo;

            //
            if (linkedCells.Count == 0 && aParentNode.Parent == null)
            {
                TreeNode noChildrenNode = new TreeNode("Has no linked items");
                noChildrenNode.Tag = null;
                aParentNode.Nodes.Add(noChildrenNode);
            }
            else if (linkedCells.Count > 0)
            {
                foreach (RelationshipInfo relationshipInfo in linkedCells)
                {
                    TreeNode childNode = CreateChildNode(aCell, relationshipInfo.ToCell, relationshipInfo);
                    //
                    childNode.Tag = relationshipInfo.ToCell;
                    aParentNode.Nodes.Add(childNode);
                    //
                    if (IsCyclic(relationshipInfo.ToCell, childNode) == false)
                    {
                        if (aParentNode.Level < KMaxRecursiveDepth)
                        {
                            int childRelationshipCount = relationshipInfo.ToCell.RelationshipManager.EmbeddedReferencesTo.Count;
                            if (childRelationshipCount > 0)
                            {
                                // Make a place holder
                                TreeNode placeholder = new TreeNode(KPlaceHolderTreeNodeText);
                                childNode.Nodes.Add(placeholder);
                            }
                        }
                        else
                        {
                            childNode.Text     += " [Max. Depth Exceeded]";
                            childNode.ForeColor = Color.Red;
                        }
                    }
                    else
                    {
                        childNode.Text     += " [C]";
                        childNode.ForeColor = Color.Red;
                    }
                }
            }
        }
Example #11
0
        public RelationshipCollection GetRelationships(Type type)
        {
            if (!Relationships.ContainsKey(type))
            {
                lock (_relationshipsLock)
                {
                    if (!Relationships.ContainsKey(type))
                    {
                        RelationshipCollection relationships = GetMapStrategy(type).MapRelationships(type);
                        Relationships.Add(type, relationships);
                        return(relationships);
                    }
                }
            }

            return(Relationships[type]);
        }
Example #12
0
        public Contracts.GenericListResult <Contracts.PersonRelationship> GetPersonRelationships(int id)
        {
            Contracts.GenericListResult <Contracts.PersonRelationship> list = new Contracts.GenericListResult <Contracts.PersonRelationship>();
            Contracts.PersonRelationshipMapper mapper        = new Contracts.PersonRelationshipMapper();
            RelationshipCollection             relationships = new RelationshipCollection(id);


            list.Items = new List <Contracts.PersonRelationship>();
            list.Total = relationships.Count;
            list.Max   = list.Total;
            list.Start = 0;
            foreach (Relationship relationship in relationships)
            {
                list.Items.Add(mapper.FromArena(relationship));
            }

            return(list);
        }
 /// <summary>
 /// Maps a relationship if a RelationshipAttribute is present.
 /// </summary>
 /// <param name="entityType">The entity that is being mapped.</param>
 /// <param name="member">The current member that is being inspected.</param>
 /// <param name="relationshipAtt">A RelationshipAttribute (is null if one does not exist).</param>
 /// <param name="relationships">A list of Relationships.</param>
 protected override void CreateRelationship(Type entityType, MemberInfo member, RelationshipAttribute relationshipAtt, RelationshipCollection relationships)
 {
     if (relationshipAtt != null)
     {
         // Add relationships by RelationshipAttribute
         base.CreateRelationship(entityType, member, relationshipAtt, relationships);
     }
     else
     {
         if (member.MemberType == MemberTypes.Property)
         {
             PropertyInfo propertyInfo = member as PropertyInfo;
             if (typeof(System.Collections.ICollection).IsAssignableFrom(propertyInfo.PropertyType))
             {
                 Relationship relationship = new Relationship(member);
                 relationships.Add(relationship);
             }
         }
     }
 }
Example #14
0
        /// <summary>
        /// Recursively builds entity graph hierarchy.
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="parent"></param>
        /// <param name="relationship"></param>
        private EntityGraph(Type entityType, EntityGraph parent, Relationship relationship, GraphIndexGenerator indexGen)
        {
            GraphIndex = indexGen.Next();

            _repos = MapRepository.Instance;

            if (relationship != null && relationship.IsLazyLoaded)
            {
                _entityType = relationship.GetLazyLoadedEntityType();
            }
            else
            {
                _entityType = entityType;
            }
            _parent       = parent;
            _relationship = relationship;

            var anyParentsAreOfSameType = AnyParentsAreOfType(_entityType);

            IsParentReference = relationship != null && !relationship.IsEagerLoaded && !relationship.IsLazyLoaded && anyParentsAreOfSameType;
            if (!IsParentReference)
            {
                _columns = _repos.GetColumns(_entityType);
            }
            _relationships    = _repos.GetRelationships(_entityType);
            _children         = new List <EntityGraph>();
            Member            = relationship != null ? relationship.Member : null;
            _entityReferences = new Dictionary <string, EntityReference>();

            if (anyParentsAreOfSameType)
            {
                return;
            }

            // Create a new EntityGraph for each child relationship
            foreach (Relationship childRelationship in this.Relationships)
            {
                _children.Add(new EntityGraph(childRelationship.RelationshipInfo.EntityType, this, childRelationship, indexGen));
            }
        }
        public RelationshipCollection MapRelationships(Type entityType)
        {
            RelationshipCollection relationships = new RelationshipCollection();

            MemberInfo[] members = entityType.GetMembers(_bindingFlags);
            foreach (MemberInfo member in members)
            {
                RelationshipAttribute relationshipAtt = GetRelationshipAttribute(member);
                CreateRelationship(entityType, member, relationshipAtt, relationships);
            }

            return relationships;
        }
 /// <summary>
 /// Inspect a member and optionally add a Relationship.
 /// </summary>
 /// <param name="entityType">The entity that is being mapped.</param>
 /// <param name="member">The current member that is being inspected.</param>
 /// <param name="relationshipAtt">A RelationshipAttribute (is null if one does not exist).</param>
 /// <param name="relationships">A list of Relationships.</param>
 protected abstract void CreateRelationship(Type entityType, MemberInfo member, RelationshipAttribute relationshipAtt, RelationshipCollection relationships);
 /// <summary>
 /// Registers any member with a RelationshipAttribute as a relationship.
 /// </summary>
 /// <param name="entityType">The entity that is being mapped.</param>
 /// <param name="member">The current member that is being inspected.</param>
 /// <param name="relationshipAtt">A RelationshipAttribute (is null if one does not exist).</param>
 /// <param name="relationships">A list of Relationships.</param>
 protected override void CreateRelationship(Type entityType, MemberInfo member, RelationshipAttribute relationshipAtt, RelationshipCollection relationships)
 {
     if (relationshipAtt != null)
     {
         Relationship relationship = new Relationship(member, relationshipAtt);
         relationships.Add(relationship);
     }
 }
Example #18
0
 /// <summary>
 /// Maps a relationship if a RelationshipAttribute is present.
 /// </summary>
 /// <param name="entityType">The entity that is being mapped.</param>
 /// <param name="member">The current member that is being inspected.</param>
 /// <param name="relationshipAtt">A RelationshipAttribute (is null if one does not exist).</param>
 /// <param name="relationships">A list of Relationships.</param>
 protected override void CreateRelationship(Type entityType, MemberInfo member, RelationshipAttribute relationshipAtt, RelationshipCollection relationships)
 {
     if (relationshipAtt != null)
     {
         // Add relationships by RelationshipAttribute
         base.CreateRelationship(entityType, member, relationshipAtt, relationships);
     }
     else
     {
         if (member.MemberType == MemberTypes.Property)
         {
             PropertyInfo propertyInfo = member as PropertyInfo;
             if (typeof(ICollection).IsAssignableFrom(propertyInfo.PropertyType))
             {
                 Relationship relationship = new Relationship(member);
                 relationships.Add(relationship);
             }
         }
     }
 }
Example #19
0
        public Contracts.GenericListResult<Contracts.PersonRelationship> GetPersonRelationships(int id)
        {
            Contracts.GenericListResult<Contracts.PersonRelationship> list = new Contracts.GenericListResult<Contracts.PersonRelationship>();
            Contracts.PersonRelationshipMapper mapper = new Contracts.PersonRelationshipMapper();
            RelationshipCollection relationships = new RelationshipCollection(id);

            list.Items = new List<Contracts.PersonRelationship>();
            list.Total = relationships.Count;
            list.Max = list.Total;
            list.Start = 0;
            foreach (Relationship relationship in relationships)
            {
                list.Items.Add(mapper.FromArena(relationship));
            }

            return list;
        }
Example #20
0
 public Entity()
 {
     Properties = new PropertyCollection();
     Relationships = new RelationshipCollection();
     Methods = new MethodCollection();
 }
Example #21
0
 protected override void CreateRelationship(Type entityType, System.Reflection.MemberInfo member, RelationshipAttribute relationshipAtt, RelationshipCollection relationships)
 {
     if (RelationshipPredicate(member))
     {
         relationships.Add(new Relationship(member));
     }
 }
Example #22
0
        private string CreateStaffXML()
        {
            StringBuilder sbMessages = new StringBuilder();

            AttributeGroup StaffDetailsGroup = new AttributeGroup(StaffDetailsAttributeGroupID);

            Arena.Core.Attribute departmentAttribute = new Arena.Core.Attribute(DepartmentAttributeID);
            LookupType           departments         = new LookupType(Convert.ToInt32(departmentAttribute.TypeQualifier));

            List <StaffMember> staff  = new List <StaffMember>();
            PersonCollection   people = new PersonCollection();

            people.LoadStaffMembers();
            foreach (Person person in people)
            {
                string title              = string.Empty;
                Lookup department         = null;
                Lookup departmentPosition = null;

                PersonAttribute pa = (PersonAttribute)person.Attributes.FindByID(PositionAttributeID);
                if (pa != null)
                {
                    title = pa.StringValue;
                }

                pa = (PersonAttribute)person.Attributes.FindByID(DepartmentAttributeID);
                if (pa != null && pa.IntValue != -1)
                {
                    department = new Lookup(pa.IntValue);
                }

                pa = (PersonAttribute)person.Attributes.FindByID(DepartmentPositionAttributeID);
                if (pa != null && pa.IntValue != -1)
                {
                    departmentPosition = new Lookup(pa.IntValue);
                }

                if (department != null && departmentPosition != null)
                {
                    staff.Add(new StaffMember(
                                  person.PersonID,
                                  person.PersonGUID,
                                  person.NickName,
                                  person.LastName,
                                  person.Blob != null ? person.Blob.GUID : Guid.Empty,
                                  person.Emails.FirstActive,
                                  title,
                                  department,
                                  departmentPosition));
                }
            }

            staff.Sort();

            // Delete any existing department XML files in the staff folder
            DirectoryInfo staffFolder = new DirectoryInfo(Path.Combine(XMLFolderPath, "Staff"));

            if (staffFolder.Exists)
            {
                foreach (FileInfo fi in staffFolder.GetFiles())
                {
                    try
                    {
                        fi.Delete();
                    }
                    catch (System.Exception ex)
                    {
                        sbMessages.AppendFormat("Could not delete {0} file: {1}\n", fi.FullName, ex.Message);
                    }
                }
            }
            else
            {
                staffFolder.Create();
            }

            if (staff.Count > 0)
            {
                LookupCollection activeDepartments = new LookupCollection();

                Lookup      currentDepartment = new Lookup();
                XmlDocument xdoc           = null;
                XmlNode     departmentNode = null;

                foreach (StaffMember StaffMember in staff)
                {
                    if (currentDepartment.LookupID != StaffMember.Department.LookupID)
                    {
                        if (xdoc != null)
                        {
                            string path = Path.Combine(staffFolder.FullName, currentDepartment.Guid.ToString() + ".xml");
                            try
                            {
                                xdoc.Save(path);
                            }
                            catch (System.Exception ex)
                            {
                                sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message);
                            }
                        }

                        currentDepartment = StaffMember.Department;
                        activeDepartments.Add(currentDepartment);

                        xdoc           = new XmlDocument();
                        departmentNode = xdoc.CreateNode(XmlNodeType.Element, "department", xdoc.NamespaceURI);
                        XmlAttribute xattr = xdoc.CreateAttribute("", "name", xdoc.NamespaceURI);
                        xattr.Value = currentDepartment.Value;
                        departmentNode.Attributes.Append(xattr);
                        xdoc.AppendChild(departmentNode);
                    }

                    departmentNode.AppendChild(StaffMember.XMLNode(xdoc));

                    if (StaffMember.DepartmentPosition.Qualifier2 == "1")
                    {
                        XmlDocument xdocStaff  = new XmlDocument();
                        XmlNode     xnodeStaff = StaffMember.XMLNode(xdocStaff);
                        xdocStaff.AppendChild(xnodeStaff);

                        if (_assistantTypeID != -1)
                        {
                            RelationshipCollection relationships = new RelationshipCollection(StaffMember.ID);
                            foreach (Relationship relationship in relationships)
                            {
                                if (relationship.RelationshipTypeId == _assistantTypeID)
                                {
                                    XmlNode xnodeAssistant = xdocStaff.CreateNode(XmlNodeType.Element, "assistant", xdocStaff.NamespaceURI);

                                    XmlAttribute xattr = xdocStaff.CreateAttribute("", "fn", xdocStaff.NamespaceURI);
                                    xattr.Value = relationship.RelatedPerson.NickName;
                                    xnodeAssistant.Attributes.Append(xattr);

                                    xattr       = xdocStaff.CreateAttribute("", "ln", xdocStaff.NamespaceURI);
                                    xattr.Value = relationship.RelatedPerson.LastName;
                                    xnodeAssistant.Attributes.Append(xattr);

                                    xattr       = xdocStaff.CreateAttribute("", "email", xdocStaff.NamespaceURI);
                                    xattr.Value = relationship.RelatedPerson.Emails.FirstActive;
                                    xnodeAssistant.Attributes.Append(xattr);

                                    xnodeStaff.AppendChild(xnodeAssistant);

                                    break;
                                }
                            }
                        }

                        PersonAttributeCollection pAttributes = new PersonAttributeCollection();
                        pAttributes.LoadByGroup(StaffDetailsGroup, StaffMember.ID);
                        foreach (PersonAttribute pa in pAttributes)
                        {
                            if (pa.AttributeType == Arena.Enums.DataType.Document)
                            {
                                if (BioDocumentTypeID != -1 && pa.TypeQualifier == BioDocumentTypeID.ToString())
                                {
                                    Arena.Utility.ArenaDataBlob bioDoc = new Arena.Utility.ArenaDataBlob(pa.IntValue);
                                    if (bioDoc.FileExtension == "txt")
                                    {
                                        ASCIIEncoding enc = new ASCIIEncoding();
                                        string        bio = enc.GetString(bioDoc.ByteArray);

                                        if (bio != string.Empty)
                                        {
                                            XmlNode xnodeBio = xdocStaff.CreateNode(XmlNodeType.Element, "biography", xdocStaff.NamespaceURI);
                                            xnodeBio.AppendChild(xdocStaff.CreateCDataSection(bio));
                                            xnodeStaff.AppendChild(xnodeBio);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                XmlNode xnodeAttribute = xdocStaff.CreateNode(XmlNodeType.Element, "attribute", xdocStaff.NamespaceURI);

                                XmlAttribute xattr = xdocStaff.CreateAttribute("", "name", xdocStaff.NamespaceURI);
                                xattr.Value = pa.AttributeName;
                                xnodeAttribute.Attributes.Append(xattr);

                                xattr       = xdocStaff.CreateAttribute("", "value", xdocStaff.NamespaceURI);
                                xattr.Value = pa.ToString();
                                xnodeAttribute.Attributes.Append(xattr);

                                xnodeStaff.AppendChild(xnodeAttribute);
                            }
                        }

                        string path = Path.Combine(staffFolder.FullName, StaffMember.Guid.ToString() + ".xml");
                        try
                        {
                            xdocStaff.Save(path);
                        }
                        catch (System.Exception ex)
                        {
                            sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message);
                        }
                    }
                }

                if (xdoc != null)
                {
                    string path = Path.Combine(staffFolder.FullName, currentDepartment.Guid.ToString() + ".xml");
                    try
                    {
                        xdoc.Save(path);
                    }
                    catch (System.Exception ex)
                    {
                        sbMessages.AppendFormat("Could not save {0} file: {1}\n", path, ex.Message);
                    }
                }

                XmlDocument xdocDepartments  = new XmlDocument();
                XmlNode     xnodeDepartments = xdocDepartments.CreateNode(XmlNodeType.Element, "departments", xdocDepartments.NamespaceURI);
                xdocDepartments.AppendChild(xnodeDepartments);

                foreach (Lookup activeDepartment in activeDepartments)
                {
                    XmlNode xnodeDepartment = xdocDepartments.CreateNode(XmlNodeType.Element, "department", xdocDepartments.NamespaceURI);

                    XmlAttribute xattr = xdocDepartments.CreateAttribute("", "guid", xdocDepartments.NamespaceURI);
                    xattr.Value = activeDepartment.Guid.ToString();
                    xnodeDepartment.Attributes.Append(xattr);

                    xattr       = xdocDepartments.CreateAttribute("", "name", xdocDepartments.NamespaceURI);
                    xattr.Value = activeDepartment.Value;
                    xnodeDepartment.Attributes.Append(xattr);

                    XmlNode xnodeDeptDescription = xdocDepartments.CreateNode(XmlNodeType.Element, "description", xdocDepartments.NamespaceURI);
                    xnodeDeptDescription.InnerText = activeDepartment.Qualifier8;
                    xnodeDepartment.AppendChild(xnodeDeptDescription);

                    xnodeDepartments.AppendChild(xnodeDepartment);
                }

                try
                {
                    xdocDepartments.Save(Path.Combine(staffFolder.FullName, "departments.xml"));
                }
                catch (System.Exception ex)
                {
                    sbMessages.AppendFormat("Could not save {0} file: {1}\n", Path.Combine(staffFolder.FullName, "departments.xml"), ex.Message);
                }
            }

            return(sbMessages.ToString());
        }
 /// <summary>
 /// Inspect a member and optionally add a Relationship.
 /// </summary>
 /// <param name="entityType">The entity that is being mapped.</param>
 /// <param name="member">The current member that is being inspected.</param>
 /// <param name="relationshipAtt">A RelationshipAttribute (is null if one does not exist).</param>
 /// <param name="relationships">A list of Relationships.</param>
 protected abstract void CreateRelationship(Type entityType, MemberInfo member, RelationshipAttribute relationshipAtt, RelationshipCollection relationships);