/// <summary> /// Updates concept references to reference existing instances from DslModel matched by the concept key. /// Returns new unique concepts that did not previously exist in DslModel /// (note that some of the returned concepts might not have their references resolved yet). /// </summary> public AddNewConceptsReport AddNewConceptsAndReplaceReferences(IEnumerable <IConceptInfo> newConcepts) { _addConceptsStopwatch.Start(); var report = new AddNewConceptsReport(); report.NewUniqueConcepts = new List <IConceptInfo>(); foreach (var conceptInfo in newConcepts) { string conceptKey = conceptInfo.GetKey(); IConceptInfo existingConcept; if (!_resolvedConceptsByKey.TryGetValue(conceptKey, out existingConcept) && !_unresolvedConceptsByKey.TryGetValue(conceptKey, out existingConcept)) { report.NewUniqueConcepts.Add(conceptInfo); _unresolvedConceptsByKey.Add(conceptKey, conceptInfo); } else if (existingConcept != conceptInfo && existingConcept.GetFullDescription() != conceptInfo.GetFullDescription()) { throw new DslSyntaxException(string.Format( "Concept with same key is described twice with different values.\r\nValue 1: {0}\r\nValue 2: {1}\r\nSame key: {2}", existingConcept.GetFullDescription(), conceptInfo.GetFullDescription(), conceptKey)); } } var newlyResolved = ReplaceReferencesWithFullConcepts(errorOnUnresolvedReference: false); report.NewlyResolvedConcepts = newlyResolved.ToList(); _addConceptsStopwatch.Stop(); return(report); }
/// <summary> /// Updates concept references to reference existing instances from DslModel matched by the concept key. /// Returns new unique concepts that did not previously exist in DslModel /// (note that some of the returned concepts might not have their references resolved yet). /// </summary> public AddNewConceptsReport AddNewConceptsAndReplaceReferences(IEnumerable <IConceptInfo> newConcepts) { _addConceptsStopwatch.Start(); var newUniqueConceptsDesc = new List <ConceptDescription>(); foreach (var conceptDesc in newConcepts.Select(c => new ConceptDescription(c))) { ConceptDescription existingConcept; if (!_givenConceptsByKey.TryGetValue(conceptDesc.Key, out existingConcept)) { _givenConceptsByKey.Add(conceptDesc.Key, conceptDesc); newUniqueConceptsDesc.Add(conceptDesc); } else { ValidateNewConceptSameAsExisting(conceptDesc.Concept, existingConcept.Concept); } } var report = new AddNewConceptsReport(); report.NewlyResolvedConcepts = ReplaceReferencesWithFullConcepts(newUniqueConceptsDesc); report.NewUniqueConcepts = newUniqueConceptsDesc.Select(desc => desc.Concept).ToList(); _addConceptsStopwatch.Stop(); return(report); }
/// <summary> /// Updates concept references to reference existing instances from DslModel matched by the concept key. /// Returns new unique concepts that did not previously exist in DslModel /// (note that some of the returned concepts might not have their references resolved yet). /// </summary> public AddNewConceptsReport AddNewConceptsAndReplaceReferences(IEnumerable <IConceptInfo> newConcepts) { _addConceptsStopwatch.Start(); var report = new AddNewConceptsReport(); report.NewUniqueConcepts = new List <IConceptInfo>(); foreach (var conceptInfo in newConcepts) { string conceptKey = conceptInfo.GetKey(); IConceptInfo existingConcept; if (!_resolvedConceptsByKey.TryGetValue(conceptKey, out existingConcept) && !_unresolvedConceptsByKey.TryGetValue(conceptKey, out existingConcept)) { report.NewUniqueConcepts.Add(conceptInfo); _unresolvedConceptsByKey.Add(conceptKey, conceptInfo); } else { ValidateNewConceptSameAsExisting(conceptInfo, existingConcept); } } var newlyResolved = ReplaceReferencesWithFullConcepts(errorOnUnresolvedReference: false); report.NewlyResolvedConcepts = newlyResolved.ToList(); _addConceptsStopwatch.Stop(); return(report); }