Example #1
0
 public EntityNodeLink(EntityNode node,EntityLink link,int weight)
 {
     Target = node;
     Weight = weight;
     Link = link;
 }
Example #2
0
        private static int GetSize(EntityNode node)
        {
            Entity entity = ((Entity)node.SourceData);
            int size = 0;
            switch (entity.LogicalName)
            {
                case "account":
                    size = 15;

                    break;
                case "contact":
                    size = 10;
                    break;
                default:

                    size = 20;
                    break;

            }
            // Make bigger if the root node
            size = size + (node.Root ? 2 : 0);
            return size;
        }
Example #3
0
 public EntityNodeLink(EntityNode node, EntityLink link, int weight)
 {
     Target = node;
     Weight = weight;
     Link   = link;
 }
Example #4
0
 public string GetXY(EntityNode node, decimal multipler)
 {
     int size = 0;
     Entity entity = ((Entity)node.SourceData);
     size = GetSize(node);
     return "-" + (size * multipler).ToString() + "px";
 }
Example #5
0
 private static string GetFilter(EntityNode d)
 {
     if (d.Root)
         return "url(#root-node-glow)";
     else
         return "";
 }
        private PendingLink AddPendingLink(EntityNode newNode, EntityReference pendingEntity)
        {
            Trace("Add Pending Link {0} {1} -> {2} {3}", new object[] { ((Entity)newNode.SourceData).LogicalName, newNode.Name, pendingEntity.LogicalName, pendingEntity.Id });
            PendingLink pending = new PendingLink();
            pending.Source = newNode;
            pending.Target = pendingEntity;

            if (!pendingLinks.ContainsKey(pendingEntity.LogicalName))
            {
                pendingLinks[pendingEntity.LogicalName] = new Dictionary<string, PendingLink>();

            }
            if (!IsAlsoAUserFromEntityReference(pendingEntity))
            {
                pendingLinks[pendingEntity.LogicalName][pendingEntity.Id.ToString()] = pending;

            }

            return pending;
        }
Example #7
0
        public string GetHeightWidth(EntityNode node, decimal multipler)
        {
            int size = 0;
            Entity entity = ((Entity)node.SourceData);
            size = GetSize(node) * 2;

            return (size * multipler).ToString() + "px";
        }
        /// <summary>
        /// Adds a link from one entity to another
        /// </summary>
        /// <param name="delayAdd">creates the link but doesn't add it to the model yet</param>
        /// <returns></returns>
        private EntityLink AddLink(EntityNode target, EntityNode source, bool delayAdd)
        {
            Entity sourceEntity = (Entity)source.SourceData;
            Entity targetEntity = (Entity)target.SourceData;
            if ((target.LinkedToIds != null) && (source.LinkedToIds != null))
            {
                if (target.LinkedToIds.ContainsKey(sourceEntity.Id) && source.LinkedToIds.ContainsKey(targetEntity.Id))
                {
                    // return the current link
                    return target.LinkedToIds[sourceEntity.Id].Link;
                }
            }
            EntityLink link = new EntityLink();

            link.Source = source;
            link.Target = target;
            SetLinkedIds(link.Target, link.Source, sourceEntity, targetEntity, link);

            // If either side has an overflow - then set it to that instead
            if (!source.IsActivity && link.Source.ParentNode != null && link.Source.ParentNode.OverflowNode != null)
            {
                link.Source = link.Source.ParentNode.OverflowNode;
                link.Source.Links.Add(link);
            }
            else if (source.IsActivity && link.Source.OverflowNode != null)
            {
                link.Source = link.Source.OverflowNode;
                link.Source.Links.Add(link);
            }

            if (!target.IsActivity && link.Target.ParentNode != null && link.Target.ParentNode.OverflowNode != null)
            {
                link.Target = link.Target.ParentNode.OverflowNode;
            }
            else if (target.IsActivity && link.Target.OverflowNode != null)
            {
                link.Target = link.Target.OverflowNode;
                link.Target.Links.Add(link);
            }

            link.Id = GetLinkId(sourceEntity.Id, targetEntity.Id);

            if (!linkIndex.ContainsKey(link.Id))
            {
                if (!delayAdd)
                {
                    linkIndex[link.Id] = link;
                    Links.Add(link);
                }
            }
            return link;
        }
 private EntityLink AddLinkIfLoaded(EntityNode target, EntityReference source, bool delayAdd)
 {
     EntityNode sourceNode = GetEntityFromReference(source);
     if (sourceNode != null)
     {
         // Create Link
         EntityLink link = AddLink(sourceNode, target, delayAdd);
         return link;
     }
     return null;
 }
        private bool AddEntity(Entity record, EntityNode newNode, EntitySetting settings, bool delayAdd)
        {
            if (((Nodes.Count + 1) % 40) == 0)
            {
                // Zoom out the more nodes there are - maybe better to use the extent of the layout...
                OnZoom.Invoke(this, -1);
            }
            string key = GetIdIndexKey(record);
            idIndex[key] = newNode;

            if (settings != null)
            {
                if (!newNode.LoadedActivities && settings.LoadActivities)
                {
                    idIndexActivityLoad[key] = newNode;
                    newNode.LoadedActivities = true;
                }
                if (!newNode.LoadedConnections && settings.LoadConnections)
                {
                    idIndexConnectionLoad[key] = newNode;
                    newNode.LoadedConnections = true;
                }
            }

            if (!delayAdd)
            {
                Nodes.Add(newNode);
            }

            return true;
        }
 private static void SetLinkedIds(EntityNode target, EntityNode source, Entity sourceEntity, Entity targetEntity, EntityLink link)
 {
     if (source.LinkedToIds == null) source.LinkedToIds = new Dictionary<string, EntityNodeLink>();
     if (target.LinkedToIds == null) target.LinkedToIds = new Dictionary<string, EntityNodeLink>();
     source.LinkedToIds[targetEntity.Id] = new EntityNodeLink(target, link, 1);
     target.LinkedToIds[sourceEntity.Id] = new EntityNodeLink(source, link, 1);
 }
        public void ExpandOverflow(EntityNode entityNode)
        {
            // Clear the selected user
            SelectedUserId.SetValue(null);
            SelectedConnectionRoles.RemoveAll();
            UnselectAll();
            OnSelectedNodesAdded(this, null);
            OnSelectedLinksAdded(this, null);

            if (entityNode.Children != null)
            {
                // Add any overflow nodes
                int expandedCount = 0;
                foreach (EntityNode node in entityNode.Children)
                {
                    node.X = entityNode.X;
                    node.Y = entityNode.Y;
                    node.Fixed = false;
                    if (!Nodes.Contains(node))
                        Nodes.Add(node);
                    node.ReplacedByOverflow = null;
                    expandedCount++;

                    // Add the links
                    foreach (KeyValuePair<string, EntityNodeLink> linkedTo in node.LinkedToIds)
                    {
                        EntityLink link = new EntityLink(); ;
                        link.Source = node;
                        link.Target = linkedTo.Value.Target;
                        link.Id = GetLinkId(((Entity)node.SourceData).Id, ((Entity)link.Target.SourceData).Id);

                        if (linkIndex.ContainsKey(link.Id))
                        {
                            link = linkIndex[link.Id];

                        }
                        else
                        {
                            linkIndex[link.Id] = link;
                            Links.Add(link);
                        }

                    }
                    if (expandedCount == OverflowMax && entityNode.Children.Count > (OverflowMax + 1))
                    {
                        break;
                    }
                }
                entityNode.Children.RemoveRange(0, expandedCount);
                entityNode.ParentNode.ActivityCount = entityNode.Children.Count;

                if (entityNode.Children.Count == 0)
                {
                    entityNode.Children = null;
                    // Remove the overflow links and node
                    Nodes.Remove(entityNode);
                    foreach (EntityLink link in entityNode.Links)
                    {
                        linkIndex.Remove(link.Id);
                        Links.Remove(link);
                    }
                }

                RaiseOnNodesChangedWithNoFastForward();

            }
        }
        private void ProcessQueryResults(QueuedLoad load, EntityCollection rootResults)
        {
            int total = rootResults.Entities.Count;
            int index = 0;
            List<string> ids = new List<string>();

            foreach (Entity record in rootResults.Entities)
            {
                if (IsCancelRequested())
                    return;
                SetMessage(ResourceStrings.Processing, load.Entity.DisplayName, index, total);

                // Check if this is a pending load - and remove it
                RemovePendingID(record.LogicalName, record.Id);

                index++;
                ids.Add(record.Id);
                string name = record.GetAttributeValueString(load.Entity.NameAttribute == null ? "name" : load.Entity.NameAttribute);
                // If this is the root entity then set the window title
                bool rootNode = (RootEntityId.Value.ToLowerCase().Substr(1, 36) == record.Id.ToLowerCase());

                if (rootNode)
                {
                    Window.Document.Title = name;
                }

                if (!IsAlsoAUser(record) && !IndexContainsEntity(record))
                {
                    EntityNode newNode = new EntityNode(name, 100);
                    newNode.Root = rootNode;
                    newNode.X = _startX;
                    newNode.Y = _startY;
                    newNode.SourceData = record;
                    if (!AddEntity(record, newNode, load.Entity, false))
                        return;

                    // Add User reference for owner
                    EntityReference owner = record.GetAttributeValueEntityReference("ownerid");
                    if (owner != null)
                    {
                        UserOrTeam user = GetUserOrTeamReference(owner);
                        user.Parties[record.Id.ToString()] = record.ToEntityReference();
                    }
                }
            }

            Trace("Linking to Parents {0} {1} records", new object[] { load.Entity.LogicalName, rootResults.Entities.Count });
            index = 0;
            // Add the parent links
            foreach (Entity record in rootResults.Entities)
            {
                if (IsCancelRequested())
                    return;
                SetMessage(ResourceStrings.Linking, load.Entity.DisplayName, index, total);

                EntityNode thisNode = GetEntity(record);

                if (thisNode == null)
                    continue;
                // Add the heiarchical links
                EntityNode parentNode = GetParentEntity(record, load.Entity.ParentAttributeId, load.Entity.LogicalName);

                if (parentNode != null)
                {
                    // Create Link
                    AddLink(thisNode, parentNode, false);
                }

                // Add the backlinks
                // e.g. if this is a contact then back link via the parentcustomerid field
                if (load.Join != null)
                {
                    Trace("Adding backlinks {0}->{1}", new object[] { load.Entity.LogicalName, load.Join.RightEntity });
                    EntityNode joinedNode = GetParentEntity(record, load.Join.RightAttribute, load.Join.RightEntity);
                    if (joinedNode != null)
                    {
                        AddLink(thisNode, joinedNode, false);
                    }
                    else
                    {

                        // Add pending link

                    }
                }
            }

            if (ids.Count > 0)
            {

                // add links
                if (load.Entity.Joins != null)
                {
                    Trace("Adding Joins to {0}", new object[] { ids.Count });
                    foreach (JoinSetting join in load.Entity.Joins)
                    {
                        EntitySetting joinedTo = Config.Entities[join.RightEntity];
                        if (joinedTo != null)
                        {
                            Trace("Queing Join  {0}.{1} -> {2}.{3} {4}", new object[] { join.LeftEntity, join.LeftAttribute, join.RightEntity, join.RightAttribute, join.Name });
                            Queue.Enqueue(new QueuedLoad(ids, joinedTo, join));
                        }
                    }
                }

                if (load.Entity.LoadActivities)
                {
                    Queue.Enqueue(new QueuedLoad(ids, load.Entity, NewJoinSetting(load.Entity.LogicalName, "activity")));
                }

                if (load.Entity.LoadConnections)
                {
                    Queue.Enqueue(new QueuedLoad(ids, load.Entity, NewJoinSetting(load.Entity.LogicalName, "connection")));
                }
            }
            _currentLoad = null;
            CallNextProcessQueue();
        }
        private void ProcessActivity(EntityCollection rootResults2, int index, int total)
        {
            Entity record = rootResults2.Entities[index];

            SetMessage(ResourceStrings.Processing, ResourceStrings.Activities, index, total);
            EntityNode newNode;
            record.LogicalName = record.GetAttributeValueString("activitytypecode");

            bool alreadyAdded = false;
            if (!IndexContainsEntity(record))
            {

                newNode = new EntityNode(record.GetAttributeValueString("name"), 100);
                newNode.IsActivity = true;
                newNode.X = _startX;
                newNode.Y = _startY;
                newNode.SourceData = record;

                if (!AddEntity(record, newNode, null, true))
                    return;
            }
            else
            {
                newNode = GetEntity(record);
                alreadyAdded = true;
            }

            // Go through the activity parties and link to the records
            EntityCollection allParties = (EntityCollection)record.GetAttributeValue("allparties");
            int i = 0;
            bool overflow = false;

            foreach (Entity item in allParties.Entities)
            {
                if (IsCancelRequested())
                    return;
                if ((index % 20) == 0)
                {
                    SetMessage(ResourceStrings.Processing, ResourceStrings.ActivityLinks, index, total);
                }
                i++;

                ActivityParty party = (ActivityParty)item;
                EntityReference partyid = party.PartyId;
                if (partyid != null) // Only load resolved parties
                {
                    //Trace(String.Format("Party {0} {1} {2}",partyid.LogicalName, partyid.Name,partyid.Id));
                    // Do we have it?
                    // We must have at least one since the activity has been loaded in the first place!
                    EntityLink linkToExisting = AddLinkIfLoaded(newNode, partyid, true);

                    if (linkToExisting == null)
                    {

                        // Any records not loaded - add a pending link
                        if (party.PartyId.LogicalName == "systemuser" || party.PartyId.LogicalName == "team")
                        {

                            party.ActivityID.LogicalName = ((Entity)newNode.SourceData).LogicalName;
                            UserOrTeam user = GetUserOrTeamReference(party.PartyId);

                            user.Parties[party.ActivityID.Id.ToString()] = party.ActivityID;
                        }
                        else
                        {

                            AddPendingLink(newNode, partyid);
                        }
                    }
                    else
                    {
                        if (newNode.ParentNode == null)
                        {
                            // Allocate each entity a single parent - which is the first found party

                            newNode.ParentNode = linkToExisting.Target;
                            newNode.ParentNode.ActivityCount++;
                        }

                        // Check the count of activities

                        bool overflowAlreadyAdded = false;

                        bool overflowed = newNode.ParentNode.ActivityCount > OverflowMax && newNode.ParentNode == linkToExisting.Target;

                        // If the linked to source activity is already load then don't overflow it
                        if (alreadyAdded)
                        {

                            overflow = false;
                        }

                        if (overflowed)
                        {

                            if (newNode.ParentNode.OverflowNode == null)
                            {

                                // Create overflow node if not already
                                EntityNode overflowNode = new EntityNode(ResourceStrings.DoubleClickToExpand, 1);
                                overflowNode.Id = "overflow" + partyid.Id.Value;
                                overflowNode.ParentNode = newNode.ParentNode;
                                overflowNode.X = _startX;
                                overflowNode.Y = _startY;
                                Entity overflowEntity = new Entity("overflow");
                                overflowEntity.Id = "overflow" + ((Entity)newNode.SourceData).Id;
                                overflowNode.SourceData = overflowEntity;

                                Nodes.Add(overflowNode);
                                newNode.ParentNode.OverflowNode = overflowNode;
                                newNode.ReplacedByOverflow = overflowNode;

                            }
                            else if (linkToExisting.Source.ParentNode == linkToExisting.Target && !alreadyAdded)
                            {
                                overflowAlreadyAdded = true;
                                linkToExisting.Source.ReplacedByOverflow = linkToExisting.Target.OverflowNode;

                            }

                            if (newNode.ReplacedByOverflow != null)
                            {
                                if (newNode.ReplacedByOverflow.Children == null)
                                    newNode.ReplacedByOverflow.Children = new List<EntityNode>();
                                if (!newNode.ReplacedByOverflow.Children.Contains(newNode))
                                    newNode.ReplacedByOverflow.Children.Add(newNode);
                            }

                        }

                        if (!overflowAlreadyAdded)
                        {
                            if (linkToExisting.Source.ReplacedByOverflow != null)
                            {
                                linkToExisting.Source = linkToExisting.Source.ReplacedByOverflow;
                                linkToExisting.Source.Links.Add(linkToExisting);
                                if (!linkToExisting.Id.StartsWith("overflow"))
                                    linkToExisting.Id = "overflow" + linkToExisting.Id;
                            }

                            if (!linkIndex.ContainsKey(linkToExisting.Id))
                            {
                                linkIndex[linkToExisting.Id] = linkToExisting;

                                Links.Add(linkToExisting);
                            }
                            else
                            {

                            }
                        }

                    }

                }
            }
            if (newNode.ReplacedByOverflow == null)
            {
                if (!alreadyAdded)
                {
                    Nodes.Add(newNode);
                }
            }
        }