protected IOgmConnection GetConnection(IOgmEntity entity) { return(entity is IOgmConnection ? entity as IOgmConnection : Connections.FirstOrDefault(p => IsInverse ? p.Destination == entity : p.Source == entity)); }
public void Set(IOgmEntity entity) { if (entity is IOgmConnection && !IsInverse && (entity as IOgmConnection).Destination == null) { throw new InvalidOperationException($"'{nameof(IOgmConnection.Destination)}' property must be set."); } if (entity is IOgmConnection && IsInverse && (entity as IOgmConnection).Source == null) { throw new InvalidOperationException($"'{nameof(IOgmConnection.Source)}' property must be set."); } DiscardEffect(); long version = DateTimeOffset.Now.ToUnixTimeMilliseconds(); IOgmConnection tmp = Connection; Connection = null; Unwire(tmp); Connection = (entity as IOgmConnection) ?? new OgmConnection() { Order = 0, SourcePropertyName = SourceProperty?.Name ?? "", DestinationPropertyName = DestinationProperty?.Name ?? "", Version = version }; if (Connection is OgmConnection) { Connection.Source = IsInverse ? entity : ProxyAccessor as IOgmEntity; Connection.Destination = IsInverse ? ProxyAccessor as IOgmEntity : entity; } Wire(Connection); }
public EntityChangeNodeUpdate(IOgmEntity entity, PropertyInfo property, object oldValue, object currentValue) : base(entity, property, oldValue, currentValue) { if (entity is IOgmConnection) { throw new ArgumentException("A Connection cannot be used as node.", nameof(entity)); } }
protected void DiscardEffect(IOgmEntity entity) { IOgmConnection conn = GetConnection(entity); if (conn != null) { Context.ChangeTracker.Track(new EntityChangeRelDeletion(conn)); } }
public IOgmEntity Visit(IOgmEntity entity) { while ((entity as IDictionary <string, object>) != null && (entity as IDictionary <string, object>)["000_ChangeTracker"] != ChangeTracker) { entity = (entity as IProxyTargetAccessor)?.DynProxyGetTarget() as IOgmEntity; } if (entity == null) { return(entity); } if (entity is IProxyTargetAccessor) { return(entity); } else { using (ManagerAccess.Manager.ScopeOMnG()) { IOgmEntity result = (IOgmEntity)ProxyGenerator.CreateClassProxyWithTarget(entity.GetType(), entity, ProxyGenerationOptions, Interceptors.ToArray()); (result as IDictionary <string, object>).Add("000_ChangeTracker", ChangeTracker); if (entity.EntityId == null) { ChangeTracker.Track(new EntityChangeNodeCreation(entity)); } foreach (PropertyInfo pinfo in entity.GetType().GetProperties() .Where(p => !ObjectExtensions.IsPrimitive(p.PropertyType) && TypesManager.IsGraphProperty(p)) .Where(p => !TypesManager.KnownTypes.ContainsKey(p.ReflectedType) || !TypesManager.KnownTypes[p.ReflectedType].IgnoredProperties.Contains(p))) { object obj = ObjectExtensions.Configuration.Get(pinfo, entity); IEnumerable collection = obj as IEnumerable; if (collection != null) { if (!ManagedCollections.ContainsKey(obj.GetType().GetGenericArguments()[0])) { ManagedCollections.Add( obj.GetType().GetGenericArguments()[0], GetType().GetMethod(nameof(ManageCollection), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod).MakeGenericMethod(obj.GetType().GetGenericArguments()[0])); } ManagedCollections[obj.GetType().GetGenericArguments()[0]].Invoke(this, new[] { obj }); } else { ObjectExtensions.Configuration.Set(pinfo, entity, Visit(obj as IOgmEntity)); } } return(result); } } }
public EntityChangeRelCreation(IOgmConnection entity, IOgmEntity source, IOgmEntity destination) : base(entity) { Source = source ?? throw new ArgumentNullException(nameof(source)); Destination = destination ?? throw new ArgumentNullException(nameof(destination)); if (source is IOgmConnection) { throw new ArgumentException("A Connection cannot be a source of a connction.", nameof(source)); } if (destination is IOgmConnection) { throw new ArgumentException("A Connection cannot be a destination of a connction.", nameof(destination)); } }
public EntityChangeUpdate(IOgmEntity entity, PropertyInfo property, object oldValue, object currentValue) : base(entity) { Property = property ?? throw new ArgumentNullException(nameof(property)); if (!IsCompatibleWith(property, oldValue)) { throw new ArgumentException("The value must be compatible with the property type", nameof(oldValue)); } if (!IsCompatibleWith(property, currentValue)) { throw new ArgumentException("The value must be compatible with the property type", nameof(currentValue)); } OldValue = oldValue; CurrentValue = currentValue; }
public T this[int index] { get { return((IsInverse ? Connections[index].Source : Connections[index].Destination) as T); } set { IOgmEntity entity = value; if (entity is IOgmConnection && !IsInverse && (entity as IOgmConnection).Destination == null) { throw new InvalidOperationException($"'{nameof(IOgmConnection.Destination)}' property must be set."); } if (entity is IOgmConnection && IsInverse && (entity as IOgmConnection).Source == null) { throw new InvalidOperationException($"'{nameof(IOgmConnection.Source)}' property must be set."); } IOgmConnection tmp = Connections[index]; Connections[index] = null; Unwire(tmp); long version = DateTimeOffset.Now.ToUnixTimeMilliseconds(); IOgmConnection conn = (entity as IOgmConnection) ?? new OgmConnection() { Order = Connections.Count, SourcePropertyName = SourceProperty?.Name ?? "", DestinationPropertyName = DestinationProperty?.Name ?? "", Version = version }; Connections[index] = conn; if (conn is OgmConnection) { conn.Source = IsInverse ? entity : ProxyAccessor as IOgmEntity; conn.Destination = IsInverse ? ProxyAccessor as IOgmEntity : entity; } Wire(conn); for (int i = index; i < Connections.Count; i++) { Connections[i].Order = i; } } }
public EntityPlaceholder(IOgmEntity entity, bool allowNull = true, IEnumerable <string> excludePorperties = null) { Entity = entity ?? throw new ArgumentNullException(nameof(entity)); AllowNull = allowNull; ExcludedPorperties = excludePorperties ?? new string[0]; }
public void Untrack(IOgmEntity entity) { ChangeLog.RemoveAll(p => p.Entity == entity); ChangeLog.RemoveAll(p => p is EntityChangeRelCreation && (((EntityChangeRelCreation)p).Source == entity || ((EntityChangeRelCreation)p).Destination == entity)); }
public NodeEntity(IOgmEntity entity, bool allowNull = true, IEnumerable <string> excludePorperties = null) : base(entity, allowNull, excludePorperties) { }