コード例 #1
0
            private static void AssertDependencies(EntityDependencyInfo entity, List <string> accountDependencies, List <string> contactDependencies, List <string> leadDependencies)
            {
                switch (entity.LogicalName)
                {
                case Account.EntityLogicalName:
                    Assert.AreEqual(ConvertToString(entity.CyclicAttributes), ConvertToString(accountDependencies), "Account's Cyclic Dependencies didn't match expected.");
                    contactDependencies.Remove(Contact.Fields.AccountId);
                    leadDependencies.Remove(Lead.Fields.CustomerId);
                    leadDependencies.Remove(Lead.Fields.ParentAccountId);
                    break;

                case Contact.EntityLogicalName:
                    Assert.AreEqual(ConvertToString(entity.CyclicAttributes), ConvertToString(contactDependencies), "Contacts's Cyclic Dependencies didn't match expected.");
                    accountDependencies.Remove(Account.Fields.PrimaryContactId);
                    leadDependencies.Remove(Lead.Fields.CustomerId);
                    leadDependencies.Remove(Lead.Fields.ParentContactId);
                    break;

                case Lead.EntityLogicalName:
                    Assert.AreEqual(ConvertToString(entity.CyclicAttributes), ConvertToString(leadDependencies), "Lead's Cyclic Dependencies didn't match expected.");
                    accountDependencies.Remove(Account.Fields.OriginatingLeadId);
                    contactDependencies.Remove(Contact.Fields.OriginatingLeadId);
                    break;
                }
            }
コード例 #2
0
 /// <summary>
 /// Returns true if the Entity Dependency Info depends on given Entity Dependency Info.
 /// </summary>
 /// <param name="info">The info to check to see if it is a dependency.</param>
 /// <returns></returns>
 public bool DependsOn(EntityDependencyInfo info)
 {
     return Dependencies.Contains(info.LogicalName) || info.Dependents.Contains(LogicalName);
 }
コード例 #3
0
        /// <summary>
        /// Runs in the Context of a lock, and therefor can contain non thread safe calls.
        /// </summary>
        /// <param name="logicalName">Name of the logical.</param>
        private void SingleThreadAdd(string logicalName)
        {
            var info = new EntityDependencyInfo(logicalName);
            Infos.Add(logicalName, info);

            if (Types.Count == 0 || Types.First.Value.DependsOn(info))
            {
                // No values in the list or the first value depends on the new info value
                info.Node = Types.AddFirst(info);

                /* Check for any Types that this new type is dependent on.
                 * Consider the Case of A -> B and B -> C
                 * A is added first, it becomes first.  C is added next, and it has no dependency on A or visa versa, so it is added last, then B is added, and it is added first, but C isn't moved
                 * Need to move C to the front, or list discrepency
                 */

                var existingDependent = Types.Skip(1).FirstOrDefault(existingInfo => info.DependsOn(existingInfo));
                if (existingDependent == null)
                {
                    return;
                }

                foreach (var type in Types)
                {
                    if (type == existingDependent)
                    {
                        // Have walked the entire list and come to the one that needs to be moved without finding anything that it depends on, free to move.
                        Types.Remove(existingDependent);
                        existingDependent.Node = Types.AddFirst(existingDependent);
                        return;
                    }
                    if (existingDependent.Dependencies.Contains(type.LogicalName))
                    {
                        Conflicts.Add(string.Format("Circular Reference Found!  {0} was added, which depends on {1}, but {2} depends on {0} and was found before {1}.  If {1} is needed first, add it after {0}", logicalName, existingDependent.LogicalName, type.LogicalName));
                        return;
                    }
                }
            }

            var dependent = Types.Skip(1).FirstOrDefault(existingInfo => existingInfo.DependsOn(info));
            info.Node = dependent == null ? Types.AddLast(info) : Types.AddBefore(dependent.Node, info);
        }