/// <summary> /// Tracks the new solutions. /// </summary> /// <param name="state">The state.</param> /// <param name="solution">The solution.</param> private static void TrackNewSolutions(IDictionary <string, object> state, Solution solution) { IEntityInternal entityInternal = solution as IEntityInternal; if (entityInternal == null) { throw new Exception("Could not convert Solution entity to IEntityInternal."); } if (entityInternal.IsTemporaryId) { List <IEntity> newSolutions; object newSolutionsObject; if (!state.TryGetValue(NewSolutionsKey, out newSolutionsObject)) { newSolutions = new List <IEntity>(); state[NewSolutionsKey] = newSolutions; } else { newSolutions = (List <IEntity>)newSolutionsObject; } newSolutions.Add(solution); } else { TrackNameChanges(state, solution); } }
/// <summary> /// Compares the equality. /// </summary> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="xInternal">The x internal.</param> /// <param name="yInternal">The y internal.</param> /// <returns> /// True of the instances are equal; false otherwise. /// </returns> private static bool CompareEquality(IEntity x, IEntity y, IEntityInternal xInternal, IEntityInternal yInternal) { return(x.Id == y.Id && xInternal.CloneSource == yInternal.CloneSource && xInternal.IsReadOnly == yInternal.IsReadOnly && xInternal.IsTemporaryId == yInternal.IsTemporaryId && xInternal.ModificationToken == yInternal.ModificationToken); }
/// <summary> /// Adds the metadata. /// </summary> /// <param name="entity">The entity.</param> /// <param name="isCreate"> /// if set to <c>true</c> [is create]. /// </param> public void AddMetadata(IEntity entity, bool isCreate) { WellKnownAliases aliases = WellKnownAliases.CurrentTenant; ///// // Set modified time ///// AddField("Data_DateTime", entity.Id, aliases.ModifiedDate, CurrentUtcDate, null, null); ///// // Check for creation ///// if (isCreate) { ///// // Set create time ///// AddField("Data_DateTime", entity.Id, aliases.CreatedDate, CurrentUtcDate, null, null); } if (CurrentUser != null) { IEntityInternal entityInternal = entity as IEntityInternal; if (!isCreate || (entityInternal?.CloneSource != null)) { ClearRelationship(entity.Id, aliases.LastModifiedBy, Direction.Forward); } AddRelationship(entity.Id, aliases.LastModifiedBy, CurrentUser.Id, Direction.Forward, true); ///// // Check for creation ///// if (isCreate) { if (entityInternal?.CloneSource != null) { ClearRelationship(entity.Id, aliases.SecurityOwner, Direction.Forward); ClearRelationship(entity.Id, aliases.CreatedBy, Direction.Forward); } ///// // Set security owner user ///// AddRelationship(entity.Id, aliases.SecurityOwner, CurrentUser.Id, Direction.Forward, true); ///// // Set created-by user ///// AddRelationship(entity.Id, aliases.CreatedBy, CurrentUser.Id, Direction.Forward, true); } } }
/// <summary> /// Is the entity internal equality. /// </summary> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="xInternal">The x internal.</param> /// <param name="yInternal">The y internal.</param> /// <returns> /// true if the specified objects are equal; otherwise, false. /// </returns> private static bool EntityInternalEquality(IEntity x, IEntity y, IEntityInternal xInternal, IEntityInternal yInternal) { if (xInternal == null && yInternal == null) { return(x.Id == y.Id && Equals(x.TypeIds, y.TypeIds)); } if (xInternal != null && yInternal != null) { return(CompareEquality(x, y, xInternal, yInternal)); } return(false); }
/// <summary> /// Validates the solution version. /// </summary> /// <param name="solution">The solution.</param> private void ValidateSolutionVersion(Solution solution) { IEntityInternal entityInternal = solution as IEntityInternal; string version; if (entityInternal == null) { throw new Exception("Could not convert Solution entity to IEntityInternal."); } if (entityInternal.TryGetField(Solution.SolutionVersionString_Field, out version)) { if (!string.IsNullOrEmpty(version)) { Version ver; string stringVersion = version.Trim().TrimStart('.').TrimEnd('.'); if (!Version.TryParse(stringVersion, out ver)) { int intValue; if (int.TryParse(stringVersion, out intValue)) { ver = new Version(intValue, 0, 0, 0); } else { ver = new Version(1, 0, 0, 0); } } int major = ver.Major >= 0 ? ver.Major : 1; int minor = ver.Minor >= 0 ? ver.Minor : 0; int build = ver.Build >= 0 ? ver.Build : 0; int revision = ver.Revision >= 0 ? ver.Revision : 0; var canonicalVersion = new Version(major, minor, build, revision); string canonicalVersionString = canonicalVersion.ToString(); if (canonicalVersionString != version) { solution.SolutionVersionString = canonicalVersionString; } } } }
public void TestEntityLoadWithActivationData( ) { var data = new ActivationData(123456789, RequestContext.TenantId, true); var entity = new Entity(data); Assert.AreEqual(123456789, entity.Id); Assert.AreEqual(true, entity.IsReadOnly); IEntityInternal entityInternal = entity; Assert.AreEqual(false, entityInternal.IsTemporaryId); Assert.AreEqual(123456789, entityInternal.ModificationToken.EntityId); Assert.IsNull(entityInternal.CloneSource); Assert.AreEqual(123456789, entityInternal.MutableId.Key); }
/// <summary> /// Activate using the specified activation data. /// </summary> /// <param name="activationData">Activation data.</param> internal StrongEntity(IActivationData activationData) { _entity = activationData.CreateEntity( ); _entityInternal = _entity as IEntityInternal; }
/// <summary> /// Activate using the specified type. /// </summary> /// <param name="entityType">Type of class that is being instantiated.</param> internal StrongEntity(Type entityType) { _entity = new Entity(entityType); _entityInternal = ( IEntityInternal )_entity; }