Exemplo n.º 1
0
        private bool IsRelationshipValid([NotNull] IModelRelationship relationship)
        {
            var sourceNode = GetNode(relationship.Source);
            var targetNode = GetNode(relationship.Target);

            return(_modelRuleProviders?.All(i => i.IsRelationshipTypeValid(relationship.Stereotype, sourceNode, targetNode)) == true);
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Initializes a new instance of the <see cref="AddRelationshipCommand" /> class.
        /// </summary>
        /// <param name="relationship">
        ///  The relationship.
        /// </param>
        /// <param name="version">
        ///  (Optional) the version.
        /// </param>
        ///-------------------------------------------------------------------------------------------------
        internal AddRelationshipCommand(IModelRelationship relationship, long?version = null)
            : this(relationship.SchemaInfo as ISchemaRelationship, relationship.Start, relationship.End, relationship.Id, version)
        {
            Contract.Requires(relationship, "relationship");

            _element = relationship;
        }
 protected static bool DiagramConnectorWouldBeRedundant(IModelRelationship modelRelationship, IDiagram diagram)
 {
     return(diagram.PathExists(
                diagram.TryGetNode(modelRelationship.Source).Select(i => i.Id),
                diagram.TryGetNode(modelRelationship.Target).Select(i => i.Id),
                modelRelationship.Stereotype));
 }
Exemplo n.º 4
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Initializes a new instance of the <see cref="RemoveRelationshipCommand" /> class.
 /// </summary>
 /// <param name="relationship">
 ///  The relationship.
 /// </param>
 /// <param name="version">
 ///  (Optional) the version.
 /// </param>
 ///-------------------------------------------------------------------------------------------------
 public RemoveRelationshipCommand(IModelRelationship relationship, long?version = null)
     : base(relationship.DomainModel, version)
 {
     Contract.Requires(relationship, "relationship");
     Relationship = relationship;
     _startId     = Relationship.Start.Id;
 }
Exemplo n.º 5
0
        private static bool IsMatchPropertyName(IModelRelationship relationship, string propertyName)
        {
            // TODO a reprendre completement pour utiliser
            // relationship.SchemaRelationship.StartPropertyName ou end
            var name = relationship.Id.Key;

            if (String.Compare(name, propertyName, StringComparison.Ordinal) == 0)
            {
                return(true);
            }

            var sourceName = Types.SplitFullName(relationship.Start.Id.Key).Item2;

            if (name.StartsWith(sourceName, StringComparison.Ordinal))
            {
                name = name.Substring(sourceName.Length);
                var cases = new[] { "Has" + propertyName, "References" + propertyName, propertyName };

                if (cases.Any(c => String.Compare(name, c, StringComparison.Ordinal) == 0))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        // Création d'une référence 0..1 à partir de l'élément courant ou vers l'élement courant si opposite vaut true
        internal void SetReference(ref Identity relationshipId, ISchemaRelationship relationshipSchema, IModelElement target, bool opposite)
        {
            DebugContract.Requires(relationshipSchema, "relationshipMetadata");

            using (var session = EnsuresRunInSession())
            {
                var commands = new List <IDomainCommand>();
                IModelRelationship relationship = null;

                // !opposite ? this -> target : target -> this
                IModelElement start = !opposite ? this : null;
                IModelElement end   = !opposite ? null : this;

                // Si l'identifiant est fourni c'est que la relation existe surement dèjà
                if (relationshipId != null)
                {
                    relationship = DomainModel.GetRelationship(relationshipId);
                }

                if (relationship == null)
                {
                    relationship = DomainModel.GetRelationships(relationshipSchema, start, end).FirstOrDefault();
                }

                start = !opposite ? this : target;
                end   = !opposite ? target : this;

                // Si cette relation existe dèjà mais sur un autre élement, on la supprime
                if (relationship != null)
                {
                    // Si elle existe sur le même élement, c'est bon on la conserve
                    if (end != null && relationship.End.Id == end.Id && start != null && relationship.Start.Id == start.Id)
                    {
                        relationshipId = relationship.Id;
                        return;
                    }

                    // Suppression car elle pointe sur un élement diffèrent
                    commands.Add(new RemoveRelationshipCommand(relationship));
                }

                relationship   = null;
                relationshipId = null;

                // Si elle n'a pas été mise à null
                if (end != null && start != null)
                {
                    relationshipId = DomainModel.IdGenerator.NextValue(relationshipSchema);
                    commands.Add(new AddRelationshipCommand(relationshipSchema, start, end, relationshipId));
                }

                Session.Current.Execute(commands.ToArray());

                if (session != null)
                {
                    session.AcceptChanges();
                }
            }
        }
Exemplo n.º 7
0
 public void AddRelationship(IModelRelationship relationship)
 {
     lock (ModelUpdateLockObject)
     {
         Model = Model.AddRelationship(relationship);
         ModelChanged?.Invoke(new ModelRelationshipAddedEvent(Model, relationship));
     }
 }
Exemplo n.º 8
0
 public DiagramConnector(
     IModelRelationship relationship,
     ModelNodeId source,
     ModelNodeId target,
     ConnectorType connectorType)
     : this(relationship, source, target, connectorType, Route.Empty)
 {
 }
Exemplo n.º 9
0
 private IEnumerable <ModelEventBase> AddRelationshipCore([NotNull] IModelRelationship relationship)
 {
     lock (ModelUpdateLockObject)
     {
         Model = Model.AddRelationship(relationship);
         yield return(new ModelRelationshipAddedEvent(Model, relationship));
     }
 }
Exemplo n.º 10
0
 private static IModelGraph AddRelationshipCore(
     [NotNull] IModelRelationship relationship,
     [NotNull] IModelGraph modelGraph,
     [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents)
 {
     itemEvents.Add(new ModelRelationshipAddedEvent(relationship));
     return(modelGraph.AddEdge(relationship));
 }
        protected void AddDiagramConnectorIfNotExists(IModelRelationship modelRelationship, IDiagram diagram)
        {
            if (diagram.ConnectorExists(modelRelationship.Id))
            {
                return;
            }

            DiagramService.AddConnector(modelRelationship.Id);
        }
Exemplo n.º 12
0
        private bool IsSymbolPairMatchingRelationship(RelatedSymbolPair symbolPair, [NotNull] IModelRelationship relationship)
        {
            var sourceNode = LatestModel.TryGetNode(relationship.Source).Value;
            var targetNode = LatestModel.TryGetNode(relationship.Target).Value;

            return(relationship.Stereotype == symbolPair.Stereotype &&
                   _symbolEqualityComparer.Equals((ISymbol)sourceNode.Payload, symbolPair.SourceSymbol) &&
                   _symbolEqualityComparer.Equals((ISymbol)targetNode.Payload, symbolPair.TargetSymbol));
        }
Exemplo n.º 13
0
 public DiagramConnector(IModelRelationship relationship, IDiagramNode source, IDiagramNode target,
                         ConnectorType connectorType, Route route)
 {
     ModelRelationship = relationship ?? throw new ArgumentNullException(nameof(relationship));
     Source            = source ?? throw new ArgumentNullException(nameof(source));
     Target            = target ?? throw new ArgumentNullException(nameof(target));
     ConnectorType     = connectorType ?? throw new ArgumentNullException(nameof(connectorType));
     Route             = route;
 }
Exemplo n.º 14
0
 public DiagramConnector(
     [NotNull] IModelRelationship relationship,
     ConnectorType connectorType,
     Route route)
 {
     ModelRelationship = relationship;
     ConnectorType     = connectorType;
     Route             = route;
 }
        private void ShowContainment([NotNull] IModelRelationship addedRelationship)
        {
            var diagram = DiagramService.LatestDiagram;

            if (diagram.NodeExists(addedRelationship.Source) && diagram.NodeExists(addedRelationship.Target))
            {
                DiagramService.UpdateParent(addedRelationship.Target, addedRelationship.Source);
            }
        }
Exemplo n.º 16
0
        private void RemoveDiagramConnector(IModelRelationship modelRelationship)
        {
            var edgeRemoved = _graph.RemoveEdge(i => i.ModelRelationship.Equals(modelRelationship));

            if (edgeRemoved)
            {
                ShowModelRelationshipsIfBothEndsAreVisible(modelRelationship.Source);
                ShowModelRelationshipsIfBothEndsAreVisible(modelRelationship.Target);
            }
        }
Exemplo n.º 17
0
        private IEnumerable <ModelEventBase> AddRelationshipCore([NotNull] IModelRelationship relationship)
        {
            if (!IsRelationshipValid(relationship))
            {
                throw new ArgumentException($"{relationship} is invalid.");
            }

            LatestModel = LatestModel.AddRelationship(relationship);
            yield return(new ModelRelationshipAddedEvent(LatestModel, relationship));
        }
        protected static bool DiagramConnectorWouldBeRedundant(IModelRelationship modelRelationship, IDiagram diagram)
        {
            if (diagram.TryGetNode(modelRelationship.Source.Id, out IDiagramNode sourceNode) &&
                diagram.TryGetNode(modelRelationship.Target.Id, out IDiagramNode targetNode))
            {
                return(diagram.PathExists(sourceNode.Id, targetNode.Id));
            }

            return(false);
        }
        protected void AddDiagramConnectorIfNotExists(IModelRelationship modelRelationship, IDiagram diagram)
        {
            if (diagram.ConnectorExists(modelRelationship.Id))
            {
                return;
            }

            // TODO
            //DiagramService.ShowModelRelationship(modelRelationship);
        }
Exemplo n.º 20
0
 private bool DiagramConnectorWouldBeRedundant(IModelRelationship modelRelationship)
 {
     lock (_graph.SyncRoot)
     {
         var sourceNode = FindDiagramNode(modelRelationship.Source);
         var targetNode = FindDiagramNode(modelRelationship.Target);
         var paths      = _graph.GetShortestPaths(sourceNode, targetNode, 1).ToList();
         return(paths.Any());
     }
 }
Exemplo n.º 21
0
        private DiagramConnector CreateDiagramConnector(IModelRelationship relationship)
        {
            var sourceNode       = FindDiagramNode(relationship.Source);
            var targetNode       = FindDiagramNode(relationship.Target);
            var diagramConnector = new DiagramConnector(relationship, sourceNode, targetNode);

            diagramConnector.RouteChanged += OnDiagramConnectorRouteChanged;

            return(diagramConnector);
        }
 public static void ShouldMatch(
     [NotNull] this IModelRelationship relationship,
     ModelNodeId expectedSourceId,
     ModelNodeId expectedTargetId,
     ModelRelationshipStereotype expectedStereotype)
 {
     relationship.Stereotype.Should().Be(expectedStereotype);
     relationship.Source.Should().Be(expectedSourceId);
     relationship.Target.Should().Be(expectedTargetId);
 }
Exemplo n.º 23
0
        public DiagramConnector(
            [NotNull] IModelRelationship relationship,
            ConnectorType connectorType,
            Route route)
        {
            ModelRelationship = relationship;
            ConnectorType     = connectorType;
            Route             = route;

            ShapeId      = relationship.Id.ToShapeId();
            AbsoluteRect = route.ToRect();
        }
        protected void ShowModelRelationshipIfBothEndsAreVisible(IModelRelationship modelRelationship, IDiagram diagram)
        {
            var shouldShowModelRelationship =
                modelRelationship.Stereotype != ModelRelationshipStereotype.Containment &&
                diagram.NodeExists(modelRelationship.Source) &&
                diagram.NodeExists(modelRelationship.Target) &&
                !DiagramConnectorWouldBeRedundant(modelRelationship, diagram);

            if (shouldShowModelRelationship)
            {
                AddDiagramConnectorIfNotExists(modelRelationship, diagram);
            }
        }
Exemplo n.º 25
0
        private bool ShouldSerialize(IModelRelationship rel)
        {
            if (HasOption(JSonSerializationOption.SerializeGraphObject))
            {
                _elements.Enqueue(rel.End);
                if (HasOption(JSonSerializationOption.SerializeRelationship))
                {
                    _elements.Enqueue(rel);
                }
                return(true);
            }

            return(_toSerialize.Contains(rel));
        }
Exemplo n.º 26
0
        private static (IModelGraph, ImmutableDictionary <object, IModelRelationship> payloadToModelRelationshipMap) AddRelationshipCore(
            [NotNull] IModelRelationship relationship,
            [NotNull] IModelGraph modelGraph,
            [NotNull] ImmutableDictionary <object, IModelRelationship> payloadToModelRelationshipMap,
            [NotNull][ItemNotNull] ICollection <ModelItemEventBase> itemEvents)
        {
            itemEvents.Add(new ModelRelationshipAddedEvent(relationship));

            return(
                modelGraph.AddEdge(relationship),
                relationship.Payload == null
                    ? payloadToModelRelationshipMap
                    : payloadToModelRelationshipMap.Add(relationship.Payload, relationship)
                );
        }
Exemplo n.º 27
0
        public DiagramConnector(IModelRelationship relationship, DiagramNode source, DiagramNode target)
            : base(relationship)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            Source = source;
            Target = target;
        }
Exemplo n.º 28
0
        private void ShowModelRelationshipIfBothEndsAreVisible(IModelRelationship modelRelationship)
        {
            bool shouldShowModelRelationsip;

            lock (_graph.SyncRoot)
            {
                shouldShowModelRelationsip =
                    DiagramNodeExists(modelRelationship.Source) &&
                    DiagramNodeExists(modelRelationship.Target) &&
                    !DiagramConnectorWouldBeRedundant(modelRelationship);
            }

            if (shouldShowModelRelationsip)
            {
                GetOrAddDiagramConnector(modelRelationship);
            }
        }
Exemplo n.º 29
0
        internal IModelElement GetReference(ref Identity relationshipId, ISchemaRelationship relationshipSchema, bool isOpposite)
        {
            DebugContract.Requires(relationshipSchema, "relationshipSchema");

            var propertyName = isOpposite ? relationshipSchema.EndPropertyName : relationshipSchema.StartPropertyName;

            SetCalculatedPropertySource(propertyName);

            IModelRelationship relationship = null;

            if (relationshipId != null)
            {
                relationship = DomainModel.GetRelationship(relationshipId);
            }

            if (relationship == null)
            {
                var start = isOpposite ? null : this;
                var end   = isOpposite ? this : null;
                relationship = DomainModel.GetRelationships(relationshipSchema, start, end).FirstOrDefault();
            }

            if (relationship != null)
            {
                relationshipId = relationship.Id;

                var opposite = isOpposite ? relationship.Start : relationship.End;
                if (opposite != null)
                {
                    var mel = _store.GetElement(opposite.Id);
                    if (mel == null)
                    {
                        throw new InvalidElementException(opposite.Id, ExceptionMessages.InvalidReference);
                    }

                    return(mel);
                }
                return(opposite);
            }

            relationshipId = null;
            return(null);
        }
Exemplo n.º 30
0
        private void ReadRelationships()
        {
            if (_reader.LocalName == "relationships")
            {
                string elem = ReadNextElement();
                while (elem == "relationship")
                {
                    var id      = ReadId("id");
                    var deleted = ReadAttribute("deleted", false);
                    if (deleted == "true")
                    {
                        var cmd = new Hyperstore.Modeling.Commands.RemoveRelationshipCommand(_domain, id, false);
                        Session.Current.Execute(cmd);
                        elem = ReadNextElement();
                        continue;
                    }
                    var metadata = ReadAttribute("schema");
                    var schema   = GetSchemaFromMoniker(metadata) as ISchemaRelationship;
                    if (schema == null)
                    {
                        throw new MetadataNotFoundException(String.Format("Invalid metadata {0} for relationship {1}", metadata, id));
                    }

                    var startId = ReadId("start");
                    var endId   = ReadId("end");
                    IModelRelationship entity = null;
                    if (_allowElementOverriding)
                    {
                        entity = _domain.GetRelationship(id);
                    }

                    if (entity == null)
                    {
                        entity = _domain.CreateRelationship(schema, startId, endId, id);
                    }

                    elem = ReadProperties(entity, schema);
                }
            }
        }