Esempio n. 1
0
 /// <summary>Clone ctor. Generates a new instance with the same state as the specified instance.</summary>
 /// <exception cref="ArgumentNullException">The specified argument is <c>null</c>.</exception>
 public SnapshotGeneratorSettings(SnapshotGeneratorSettings settings)
 {
     if (settings == null)
     {
         throw Error.ArgumentNull(nameof(settings));
     }
     settings.CopyTo(this);
 }
Esempio n. 2
0
 /// <summary>Copy all configuration settings to another instance.</summary>
 /// <param name="other">Another <see cref="SnapshotGeneratorSettings"/> instance.</param>
 /// <exception cref="ArgumentNullException">The specified argument is <c>null</c>.</exception>
 public void CopyTo(SnapshotGeneratorSettings other)
 {
     if (other == null)
     {
         throw Error.ArgumentNull(nameof(other));
     }
     other.GenerateSnapshotForExternalProfiles = GenerateSnapshotForExternalProfiles;
     other.ForceRegenerateSnapshots            = ForceRegenerateSnapshots;
     other.GenerateExtensionsOnConstraints     = GenerateExtensionsOnConstraints;
     other.GenerateAnnotationsOnConstraints    = GenerateAnnotationsOnConstraints;
     other.GenerateElementIds = GenerateElementIds;
     // other.MergeTypeProfiles = MergeTypeProfiles;
 }
Esempio n. 3
0
 public SnapshotGenerator(ArtifactResolver resolver, SnapshotGeneratorSettings settings)
 {
     if (resolver == null)
     {
         throw Error.ArgumentNull("resolver");
     }
     if (settings == null)
     {
         throw Error.ArgumentNull("settings");
     }
     _resolver = resolver;
     _settings = settings;
 }
 /// <summary>Copy all configuration settings to another instance.</summary>
 public void CopyTo(SnapshotGeneratorSettings other)
 {
     if (other == null)
     {
         throw Error.ArgumentNull(nameof(other));
     }
     other.ExpandExternalProfiles          = ExpandExternalProfiles;
     other.ForceExpandAll                  = ForceExpandAll;
     other.MarkChanges                     = MarkChanges;
     other.AnnotateDifferentialConstraints = AnnotateDifferentialConstraints;
     other.GenerateElementIds              = GenerateElementIds;
     // other.MergeTypeProfiles = MergeTypeProfiles;
 }
Esempio n. 5
0
        internal static bool expandElement(ElementNavigator nav, ArtifactResolver resolver, SnapshotGeneratorSettings settings)
        {
            if (resolver == null)
            {
                throw Error.ArgumentNull("source");
            }
            if (nav.Current == null)
            {
                throw Error.ArgumentNull("Navigator is not positioned on an element");
            }

            if (nav.HasChildren)
            {
                return(true);                     // already has children, we're not doing anything extra
            }
            var defn = nav.Current;

            if (!String.IsNullOrEmpty(defn.NameReference))
            {
                var sourceNav = new ElementNavigator(nav);
                var success   = sourceNav.JumpToNameReference(defn.NameReference);

                if (!success)
                {
                    throw Error.InvalidOperation("Trying to navigate down a node that has a nameReference of '{0}', which cannot be found in the StructureDefinition".FormatWith(defn.NameReference));
                }

                nav.CopyChildren(sourceNav);
            }
            else if (defn.Type != null && defn.Type.Count > 0)
            {
                if (defn.Type.Count > 1)
                {
                    throw new NotSupportedException("Element at path '{0}' has a choice of types, cannot expand".FormatWith(nav.Path));
                }
                else
                {
                    // [WMR 20160720] Handle custom type profiles (GForge #9791)
                    // var coreType = resolver.GetStructureDefinitionForCoreType(defn.Type[0].Code.Value);
                    var primaryType = defn.Type[0];
                    var typeProfile = primaryType.Profile.FirstOrDefault();
                    StructureDefinition coreType = null;
                    if (!defn.IsExtension() && !defn.IsReference() && !string.IsNullOrEmpty(typeProfile) && settings.ExpandTypeProfiles)
                    {
                        coreType = resolver.GetStructureDefinition(typeProfile);
                        if ((coreType == null || coreType.Snapshot == null) && settings.IgnoreMissingTypeProfiles)
                        {
                            coreType = resolver.GetStructureDefinitionForCoreType(primaryType.Code.Value);
                        }
                    }
                    else
                    {
                        coreType = resolver.GetStructureDefinitionForCoreType(primaryType.Code.Value);
                    }

                    if (coreType == null)
                    {
                        throw Error.NotSupported("Trying to navigate down a node that has a declared base type of '{0}', which is unknown".FormatWith(defn.Type[0].Code));
                    }
                    if (coreType.Snapshot == null)
                    {
                        throw Error.NotSupported("Found definition of base type '{0}', but is does not contain a snapshot representation".FormatWith(defn.Type[0].Code));
                    }

                    generateBaseElements(coreType.Snapshot.Element);
                    var sourceNav = new ElementNavigator(coreType.Snapshot.Element);
                    sourceNav.MoveToFirstChild();
                    nav.CopyChildren(sourceNav);
                }
            }

            return(true);
        }