private void openMappingNodeProperties(MP.MappingNode node)
 {
     if (node?.source != null)
     {
         node.source.openProperties();
     }
 }
 private void targetTreeView_SelectedIndexChanged(object sender, EventArgs e)
 {
     //set the selected node
     this.selectedNode = this.selectedTargetNode;
     //show the mappings
     showTargetMappings();
 }
 private void selectMappingNode(MP.MappingNode node)
 {
     if (node?.source != null)
     {
         node.source.select();
     }
 }
 private void sourceTreeView_SelectedIndexChanged(object sender, EventArgs e)
 {
     //set the selected node
     this.selectedNode = this.selectedSourceNode;
     //show the mappings
     this.showSourceMappings();
 }
Beispiel #5
0
 private void showAll(MP.MappingNode node)
 {
     node.showAll = true;
     foreach (var subnode in node.childNodes)
     {
         this.showAll(subnode);
     }
 }
Beispiel #6
0
 public MappingSet(MP.MappingNode source, MP.MappingNode target, MappingSettings settings)
 {
     this.source   = source;
     this.target   = target;
     this.settings = settings;
     //build the source node tree
     //get the list of mappings
     this._mappings = this.source.getMappings(target).Cast <Mapping>().ToList();
 }
Beispiel #7
0
 public MappingSet(MP.MappingNode source, MP.MappingNode target, MappingSettings settings)
 {
     this.source            = source;
     this.source.mappingSet = this;
     this.target            = target;
     this.target.mappingSet = this;
     this.settings          = settings;
     //get the mapings of the source object
     this.source.getMyMappings();
 }
 public MappingSet(MP.MappingNode source, MP.MappingNode target, MappingSettings settings)
 {
     this.source            = source;
     this.source.mappingSet = this;
     this.target            = target;
     this.target.mappingSet = this;
     this.settings          = settings;
     //get the list of mappings
     this._mappings = this.source.getMappings(target).Cast <Mapping>().ToList();
     //map source to target
     this.source.mapTo(target);
 }
Beispiel #9
0
        public override IEnumerable <MP.Mapping> getOwnedMappings(MP.MappingNode targetRootNode)
        {
            var foundMappings = new List <MP.Mapping>();

            //get the mappings using trace relations
            //TODO: is this fast enough?
            foreach (var trace in this.sourceElement.getRelationships <TSF_EA.Abstraction>().Where(x => x.target is TSF_EA.Element && x.stereotypes.Any(y => y.name == "trace")))
            {
                //get the mappings based on traces
                var mapping = MappingFactory.getMapping(this, trace, (MappingNode)targetRootNode);
                if (mapping != null)
                {
                    foundMappings.Add(mapping);
                }
            }
            //also add the base mappings
            foundMappings.AddRange(base.getOwnedMappings(targetRootNode));
            return(foundMappings);
        }
Beispiel #10
0
        public override IEnumerable <MP.Mapping> getOwnedMappings(MP.MappingNode targetRootNode)
        {
            //the mappings are stored in a tagged value
            var foundMappings = new List <MP.Mapping>();

            //Mappings are stored in tagged values
            foreach (var mappingTag in this.sourceAssociation.taggedValues.Where(x => x.name == this.settings.linkedAttributeTagName))
            {
                var mapping = MappingFactory.getMapping(this, (TSF_EA.TaggedValue)mappingTag, (MappingNode)targetRootNode);
                if (mapping != null)
                {
                    foundMappings.Add(mapping);
                }
            }
            //loop subNodes
            foreach (MappingNode childNode in this.allChildNodes)
            {
                foundMappings.AddRange(childNode.getOwnedMappings(targetRootNode));
            }
            return(foundMappings);
        }
        public override IEnumerable <MP.Mapping> getOwnedMappings(MP.MappingNode targetRootNode)
        {
            var foundMappings = new List <MP.Mapping>();

            //TODO: is this fast enough?
            foreach (var trace in this.sourceElement.relationships.OfType <TSF_EA.Abstraction>().Where(x => x.target is TSF_EA.Element && x.stereotypes.Any(y => y.name == "trace")))
            {
                //check if this trace represents a mappingNode to somewhere in in the targetNode
                //get the mapping path
                var mapping = MappingFactory.getMapping(this, trace, (MappingNode)targetRootNode);
                if (mapping != null)
                {
                    foundMappings.Add(mapping);
                }
            }
            //loop subNodes
            foreach (MappingNode childNode in this.allChildNodes)
            {
                foundMappings.AddRange(childNode.getOwnedMappings(targetRootNode));
            }
            return(foundMappings);
        }
        /// <summary>
        /// import the mapings specified in the file into the given mappingSet
        /// </summary>
        /// <param name="mappingSet">the mappingset to import the mappings into</param>
        /// <param name="filePath">the path to the file containing the mappings</param>
        public static void importMappings(MappingSet mappingSet, string filePath, Model model)
        {
            IEnumerable <CSVMappingRecord> mappingRecords;

            //remove all existing mappings
            foreach (var mapping in mappingSet.mappings)
            {
                mapping.delete();
            }
            //map source and target to be sure
            mappingSet.source.mapTo(mappingSet.target);
            //make sure the target node tree has been build
            ((MappingNode)mappingSet.target).buildNodeTree();
            //read the csv file
            using (var textReader = new StreamReader(filePath))
            {
                var csv = new CSV.CsvReader(textReader, false);
                csv.Configuration.RegisterClassMap <CSVMappingRecordMap>();
                csv.Configuration.Delimiter = ";";
                mappingRecords = csv.GetRecords <CSVMappingRecord>();
                var sourceNodes = new Dictionary <string, MP.MappingNode>();
                var targetNodes = new Dictionary <string, MP.MappingNode>();
                //now loop the records
                foreach (var csvRecord in mappingRecords)
                {
                    if (string.IsNullOrEmpty(csvRecord.sourcePath) ||
                        (string.IsNullOrEmpty(csvRecord.targetPath) &&
                         string.IsNullOrEmpty(csvRecord.mappingLogic)))
                    {
                        //don't even bother if not both fields are filled in
                        continue;
                    }
                    //convert any newLines (\n") coming from excel (Alt-Enter) to "real" newlines
                    csvRecord.mappingLogic = csvRecord.mappingLogic.Replace("\n", Environment.NewLine);
                    //find the source
                    //first check if we already known the node
                    MP.MappingNode sourceNode = null;
                    if (!string.IsNullOrEmpty(csvRecord.sourcePath) &&
                        !sourceNodes.TryGetValue(csvRecord.sourcePath, out sourceNode))
                    {
                        //find out if we know a parent node of this node
                        var parentNode = findParentNode(sourceNodes, csvRecord.sourcePath);
                        if (parentNode == null)
                        {
                            //no parent found, start at the top
                            parentNode = mappingSet.source;
                        }
                        //find the node from the parent
                        sourceNode = parentNode.findNode(csvRecord.sourcePath.Split('.').ToList());
                    }
                    if (sourceNode == null)
                    {
                        EAOutputLogger.log($"Could not find source element corresponding to '{csvRecord.sourcePath}'", 0, LogTypeEnum.warning);
                        //don't bother going any further
                        continue;
                    }
                    //find the target
                    MP.MappingNode targetNode = null;
                    //first check if we already known the node
                    if (!string.IsNullOrEmpty(csvRecord.targetPath) &&
                        !targetNodes.TryGetValue(csvRecord.targetPath, out targetNode))
                    {
                        //find out if we know a parent node of this node
                        var parentNode = findParentNode(targetNodes, csvRecord.targetPath);
                        if (parentNode == null)
                        {
                            //no parent found, start at the top
                            parentNode = mappingSet.target;
                        }
                        //find the node from the parent
                        targetNode = parentNode.findNode(csvRecord.targetPath.Split('.').ToList());
                        if (targetNode == null)
                        {
                            EAOutputLogger.log($"Could not find target element corresponding to '{csvRecord.targetPath}'", 0, LogTypeEnum.warning);
                        }
                    }

                    //if we found both then we map them
                    if (sourceNode != null)
                    {
                        if (targetNode != null)
                        {
                            var newMapping = sourceNode.mapTo(targetNode);
                            newMapping.mappingLogics = createMappingLogicsFromCSVString(csvRecord.mappingLogic, mappingSet.EAContexts, model);
                            newMapping.save();
                            EAOutputLogger.log($"Mapping created from '{csvRecord.sourcePath}' to '{csvRecord.targetPath}'", 0);
                        }
                        else
                        {
                            var newMapping = sourceNode.createEmptyMapping(false);
                            newMapping.mappingLogics = createMappingLogicsFromCSVString(csvRecord.mappingLogic, mappingSet.EAContexts, model);
                            newMapping.save();
                            EAOutputLogger.log($"Empty mapping created for '{csvRecord.sourcePath}' ", 0);
                        }
                    }
                }
            }
        }