Example #1
0
        private void AddRelationship(string sourceName, string targetName, ModelRelationshipStereotype stereotype)
        {
            var parentNode = ModelService.TryGetUnderlyingNodeByName(sourceName).Value;
            var childNode  = ModelService.TryGetUnderlyingNodeByName(targetName).Value;

            ModelService.AddRelationship(parentNode.Id, childNode.Id, stereotype);
        }
Example #2
0
        public ModelEvent AddRelationship(
            ModelNodeId sourceId,
            ModelNodeId targetId,
            ModelRelationshipStereotype stereotype,
            object payload = null)
        {
            if (payload != null && _payloadToModelRelationshipMap.ContainsKey(payload))
            {
                throw new Exception($"The model already contains a relationship with payload: {payload}");
            }

            var relationship = CreateRelationship(sourceId, targetId, stereotype, payload);

            if (!IsRelationshipValid(relationship))
            {
                throw new ArgumentException($"{relationship} is invalid.");
            }

            var itemEvents = new List <ModelItemEventBase>();

            var(newGraph, newPayloadToModelRelationshipMap) = AddRelationshipCore(
                relationship,
                _graph,
                _payloadToModelRelationshipMap,
                itemEvents);

            var newModel = CreateInstance(newGraph, _payloadToModelNodeMap, newPayloadToModelRelationshipMap);

            return(ModelEvent.Create(newModel, itemEvents));
        }
Example #3
0
 public ModelRelationship(ModelRelationshipId id, ModelNodeId source, ModelNodeId target, ModelRelationshipStereotype stereotype)
 {
     Id         = id;
     Source     = source;
     Target     = target;
     Stereotype = stereotype ?? throw new ArgumentNullException(nameof(stereotype));
 }
        private void AddRelationship(ITestNode node, ITestNode baseNode, ModelRelationshipStereotype stereotype)
        {
            var underlyingNode     = ModelService.GetUnderlyingNode(node);
            var underlyingBaseNode = ModelService.GetUnderlyingNode(baseNode);

            ModelService.AddRelationship(underlyingNode.Id, underlyingBaseNode.Id, stereotype);
        }
 private static ModelRelationship CreateInstance(
     ModelRelationshipId id,
     ModelNodeId source,
     ModelNodeId target,
     ModelRelationshipStereotype stereotype,
     [CanBeNull] object payload)
 => new ModelRelationship(id, source, target, stereotype, payload);
        private IDiagramGraph GetGraph(ModelRelationshipStereotype stereotype)
        {
            var transitivityPartitionKey = _modelRelationshipFeatureProvider.GetTransitivityPartitionKey(stereotype);

            _diagramGraphsByRelationshipTransitivityGroup.TryGetValue(transitivityPartitionKey, out var graph);
            return(graph ?? DiagramGraph.Empty());
        }
Example #7
0
 private static IModelRelationship CreateRelationship(
     ModelNodeId sourceId,
     ModelNodeId targetId,
     ModelRelationshipStereotype stereotype,
     object payload = null)
 {
     return(new ModelRelationship(ModelRelationshipId.Create(), sourceId, targetId, stereotype, payload));
 }
Example #8
0
 private IModelRelationship CreateRelationship(
     ModelNodeId sourceId,
     ModelNodeId targetId,
     ModelRelationshipStereotype stereotype,
     [CanBeNull] object payload)
 {
     return(new ModelRelationship(CreateModelRelationshipId(), sourceId, targetId, stereotype, payload));
 }
Example #9
0
 public static IModelRelationship GetRelationship(
     [NotNull] this IModel model,
     IRoslynModelNode sourceNode,
     IRoslynModelNode targetNode,
     ModelRelationshipStereotype stereotype)
 {
     return(model.Relationships.FirstOrDefault(i => i.Source == sourceNode && i.Target == targetNode && i.Stereotype == stereotype));
 }
Example #10
0
 public static bool RelationshipExists(
     [NotNull] this IModel model,
     IRoslynModelNode sourceNode,
     IRoslynModelNode targetNode,
     ModelRelationshipStereotype stereotype)
 {
     return(model.GetRelationship(sourceNode, targetNode, stereotype) != null);
 }
Example #11
0
        public override ConnectorType GetConnectorType(ModelRelationshipStereotype stereotype)
        {
            if (!ModelRelationshipTypeToConnectorTypeMap.ContainsKey(stereotype))
            {
                throw new Exception($"Unexpected model relationship type {stereotype}");
            }

            return(ModelRelationshipTypeToConnectorTypeMap[stereotype]);
        }
Example #12
0
        public ConnectorType GetConnectorType(ModelRelationshipStereotype stereotype)
        {
            if (ModelRelationshipTypeToConnectorTypeMap.ContainsKey(stereotype))
            {
                return(ModelRelationshipTypeToConnectorTypeMap[stereotype]);
            }

            throw new Exception($"No connector type found for {stereotype}");
        }
 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);
 }
        public IModelRelationship AddRelationship(
            ModelNodeId sourceId,
            ModelNodeId targetId,
            ModelRelationshipStereotype stereotype,
            object payload = null)
        {
            var modelEvent = MutateWithLockThenRaiseEvents(() => LatestModel.AddRelationship(sourceId, targetId, stereotype, payload));

            return(modelEvent.ItemEvents.OfType <ModelRelationshipAddedEvent>().First().AddedRelationship);
        }
Example #15
0
        public ModelRelationship(ModelRelationshipId id, IModelNode source, IModelNode target, ModelRelationshipStereotype stereotype)
        {
            Id         = id;
            Source     = source ?? throw new ArgumentNullException(nameof(source));
            Target     = target ?? throw new ArgumentNullException(nameof(target));
            Stereotype = stereotype ?? throw new ArgumentNullException(nameof(stereotype));

            if (!IsValidSourceAndTargetType(source, target))
            {
                throw new ArgumentException($"{source.Stereotype} and {target.Stereotype} can not be in {Stereotype} relationship.");
            }
        }
 public ModelRelationship(
     ModelRelationshipId id,
     ModelNodeId source,
     ModelNodeId target,
     ModelRelationshipStereotype stereotype,
     [CanBeNull] object payload = null)
 {
     Id         = id;
     Source     = source;
     Target     = target;
     Stereotype = stereotype;
     Payload    = payload;
 }
        public ModelRelationship(IModelEntity source, IModelEntity target,
                                 ModelRelationshipClassifier classifier, ModelRelationshipStereotype stereotype)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            Source     = source;
            Target     = target;
            Classifier = classifier;
            Stereotype = stereotype;
        }
Example #18
0
        public ModelEvent AddRelationship(
            ModelNodeId sourceId,
            ModelNodeId targetId,
            ModelRelationshipStereotype stereotype,
            object payload = null)
        {
            var relationship = CreateRelationship(sourceId, targetId, stereotype, payload);

            if (!IsRelationshipValid(relationship))
            {
                throw new ArgumentException($"{relationship} is invalid.");
            }

            var itemEvents = new List <ModelItemEventBase>();
            var newGraph   = AddRelationshipCore(relationship, _graph, itemEvents);

            var newModel = CreateInstance(newGraph);

            return(ModelEvent.Create(newModel, itemEvents));
        }
Example #19
0
        public IModelRelationship CreateRelationship(IModelNode source, IModelNode target, ModelRelationshipStereotype stereotype)
        {
            var id = ModelRelationshipId.Create();

            if (stereotype == ModelRelationshipStereotype.Containment)
            {
                return(new ContainmentRelationship(id, source, target));
            }
            if (stereotype == ModelRelationshipStereotypes.Implementation)
            {
                return(new ImplementationRelationship(id, source, target));
            }
            if (stereotype == ModelRelationshipStereotypes.Inheritance)
            {
                return(new InheritanceRelationship(id, source, target));
            }
            if (stereotype == ModelRelationshipStereotypes.Association)
            {
                return(new AssociationRelationship(id, source, target));
            }

            throw new NotImplementedException($"Model relationship not implemented for stereotype {stereotype}");
        }
Example #20
0
 public bool IsRelationshipTypeValid(ModelRelationshipStereotype modelRelationshipStereotype, IModelNode source, IModelNode target)
 {
     return(false);
 }
Example #21
0
 public IModelRelationship GetRelationship(IRoslynModelNode sourceNode, IRoslynModelNode targetNode, ModelRelationshipStereotype stereotype)
 => Relationships.FirstOrDefault(i => i.Source == sourceNode && i.Target == targetNode && i.Stereotype == stereotype);
Example #22
0
 public bool RelationshipExists(IRoslynModelNode sourceNode, IRoslynModelNode targetNode, ModelRelationshipStereotype stereotype)
 => GetRelationship(sourceNode, targetNode, stereotype) != null;
 public ConnectorType GetConnectorType(ModelRelationshipStereotype stereotype) => ConnectorTypes.Dependency;
Example #24
0
        private TestModelBuilder AddRelationship(string sourceName, string targetName,
                                                 ModelRelationshipClassifier classifier, ModelRelationshipStereotype stereotype)
        {
            if (_testModel.Relationships
                .Any(i => i.Source.Name == sourceName && i.Classifier == classifier && i.Stereotype == stereotype && i.Target.Name == targetName))
            {
                throw new InvalidOperationException($"Relationship already exists {sourceName}--{classifier}({stereotype})-->{targetName}.");
            }

            var sourceEntity = _testModel.Entities.FirstOrDefault(i => i.Name == sourceName) as ModelEntity;

            if (sourceEntity == null)
            {
                throw new InvalidOperationException($"Entity with name {sourceName} not found.");
            }

            var targetEntity = _testModel.Entities.FirstOrDefault(i => i.Name == targetName) as ModelEntity;

            if (targetEntity == null)
            {
                throw new InvalidOperationException($"Entity with name {targetName} not found.");
            }

            var newRelationship = new ModelRelationship(sourceEntity, targetEntity, classifier, stereotype);

            _testModel.GetOrAddRelationship(newRelationship);

            return(this);
        }
Example #25
0
 protected virtual ModelRelationship CreateInstance(ModelRelationshipId id, ModelNodeId source, ModelNodeId target, ModelRelationshipStereotype stereotype)
 => new ModelRelationship(id, source, target, stereotype);
        public static ModelRelationship CreateRoslynRelationship(IRoslynModelNode sourceNode, IRoslynModelNode targetNode, ModelRelationshipStereotype stereotype)
        {
            var id = ModelRelationshipId.Create();

            if (stereotype == ModelRelationshipStereotypes.Inheritance)
            {
                return(new InheritanceRelationship(id, sourceNode, targetNode));
            }

            if (stereotype == ModelRelationshipStereotypes.Implementation)
            {
                return(new ImplementationRelationship(id, sourceNode, targetNode));
            }

            throw new InvalidOperationException($"Unexpected relationship type {stereotype.Name}");
        }
 public string GetTransitivityPartitionKey(ModelRelationshipStereotype stereotype)
 {
     return(stereotype.In(InheritanceGroup)
         ? "Inheritance"
         : "Others");
 }
 public bool IsTransitive(ModelRelationshipStereotype stereotype) => stereotype.In(InheritanceGroup);
Example #29
0
 public EntityRelationType(string name, ModelRelationshipClassifier classifier, ModelRelationshipStereotype stereotype,
                           EntityRelationDirection direction)
     : this(name, new ModelRelationshipType(classifier, stereotype), direction)
 {
 }
Example #30
0
 public ConnectorType GetConnectorType(ModelRelationshipStereotype stereotype)
 {
     return(_connectorTypeResolver.GetConnectorType(stereotype));
 }