/// <summary>
        /// Retrieves the active references from the provided entity property. This only includes those references currently active and not those in the data store.
        /// </summary>
        /// <param name="entity">The entity containing the property that the references are assigned to.</param>
        /// <param name="property">The property that the references are assigned to.</param>
        /// <param name="mirrorPropertyName">The name of the mirror property.</param>
        /// <returns>An array of the entity references.</returns>
        protected virtual EntityReference[] GetActiveReferencesFromMultipleReferenceProperty(IEntity entity, PropertyInfo property, string mirrorPropertyName)
        {
            EntityReferenceCollection collection = new EntityReferenceCollection(entity);

            using (LogGroup logGroup = LogGroup.Start("Retrieving the references from a multiple reference property.", LogLevel.Debug))
            {
                LogWriter.Debug("Multiple reference property.");

                object propertyValue = property.GetValue(entity, null);

                LogWriter.Debug("Property value: " + (propertyValue == null ? "[null]" : propertyValue.ToString()));

                Collection <IEntity> referencedEntities = new Collection <IEntity>();

                referencedEntities.AddRange(EntitiesUtilities.GetReferencedEntities(entity, property));

                LogWriter.Debug("# of referenced entities found: " + referencedEntities.Count);

                EntityReferenceCollection references = new EntityReferenceCollection(entity, property.Name, referencedEntities.ToArray(), mirrorPropertyName);

                LogWriter.Debug("Reference objects created.");

                foreach (EntityReference reference in references)
                {
                    LogWriter.Debug("Adding reference with ID: " + reference.ID.ToString());

                    LogWriter.Debug("Source entity ID: " + reference.Entity1ID.ToString());
                    LogWriter.Debug("Referenced entity ID: " + reference.Entity2ID.ToString());

                    LogWriter.Debug("Source entity name: " + reference.Type1Name);
                    LogWriter.Debug("Referenced entity name: " + reference.Type2Name);

                    LogWriter.Debug("Source property name: " + reference.Property1Name);
                    LogWriter.Debug("Mirror property name: " + reference.Property2Name);


                    collection.Add((EntityReference)reference);
                }
            }

            return(collection.ToArray());
        }
示例#2
0
        public string Associate(string entityLogicalName, Guid entityId, Relationship relationship, EntityReferenceCollection relatedEntities, long duration)
        {
            if (relationship == null || relatedEntities == null || relatedEntities.Count <= 0)
            {
                return(GetActivityId());
            }

            var relatedEntitiesString = string.Join(";",
                                                    relatedEntities.ToArray().Select(o => string.Format("{0}:{1}", o.LogicalName, o.Id)));

            WriteEventAssociate(
                entityLogicalName,
                entityId.ToString(),
                relationship.SchemaName,
                relatedEntitiesString,
                duration,
                this.PortalUrl,
                this.PortalVersion,
                this.ProductionOrTrial,
                this.SessionId,
                this.ElapsedTime());

            return(GetActivityId());
        }
示例#3
0
 public bool UnlinkFrom(EntityReferenceCollection related) =>
 UnlinkFrom(related.ToArray());
示例#4
0
 public bool LinkTo(EntityReferenceCollection related) =>
 LinkTo(related.ToArray());
        /// <summary>
        /// Retrieves the active references from the provided entity property. This only includes those references currently active and not those in the data store.
        /// </summary>
        /// <param name="entity">The entity containing the property that the references are assigned to.</param>
        /// <param name="property">The property that the references are assigned to.</param>
        /// <param name="mirrorPropertyName">The name of the mirror property.</param>
        /// <returns>An array of the entity references.</returns>
        protected virtual EntityReference[] GetActiveReferencesFromMultipleReferenceProperty(IEntity entity, PropertyInfo property, string mirrorPropertyName)
        {
            EntityReferenceCollection collection = new EntityReferenceCollection(entity);

            using (LogGroup logGroup = LogGroup.Start("Retrieving the references from a multiple reference property.", LogLevel.Debug))
            {
                LogWriter.Debug("Multiple reference property.");

                object propertyValue = property.GetValue(entity, null);

                LogWriter.Debug("Property value: " + (propertyValue == null ? "[null]" : propertyValue.ToString()));

                Collection<IEntity> referencedEntities = new Collection<IEntity>();

                referencedEntities.AddRange(EntitiesUtilities.GetReferencedEntities(entity, property));

                LogWriter.Debug("# of referenced entities found: " + referencedEntities.Count);

                EntityReferenceCollection references = new EntityReferenceCollection(entity, property.Name, referencedEntities.ToArray(), mirrorPropertyName);

                LogWriter.Debug("Reference objects created.");

                foreach (EntityReference reference in references)
                {
                    LogWriter.Debug("Adding reference with ID: " + reference.ID.ToString());

                    LogWriter.Debug("Source entity ID: " + reference.Entity1ID.ToString());
                    LogWriter.Debug("Referenced entity ID: " + reference.Entity2ID.ToString());

                    LogWriter.Debug("Source entity name: " + reference.Type1Name);
                    LogWriter.Debug("Referenced entity name: " + reference.Type2Name);

                    LogWriter.Debug("Source property name: " + reference.Property1Name);
                    LogWriter.Debug("Mirror property name: " + reference.Property2Name);

                    collection.Add((EntityReference)reference);
                }

            }

            return collection.ToArray();
        }