Exemple #1
0
        internal static string GetLibraryTextToBeInserted(LibraryInstallationState libraryInstallationState, Manifest manifest)
        {
            var fileConverter = new LibraryStateToFileConverter(manifest.DefaultProvider, manifest.DefaultDestination);
            LibraryInstallationStateOnDisk serializableState = fileConverter.ConvertToLibraryInstallationStateOnDisk(libraryInstallationState);

            var settings = new JsonSerializerSettings
            {
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore,
            };

            return(JsonConvert.SerializeObject(serializableState, settings));
        }
Exemple #2
0
        public static bool TryGetInstallationState(ObjectNode parent, out ILibraryInstallationState installationState, string defaultProvider = null)
        {
            installationState = null;

            if (parent == null)
            {
                return(false);
            }

            var state = new LibraryInstallationStateOnDisk();

            SortedNodeList <Node> children = GetChildren(parent);

            foreach (MemberNode child in children.OfType <MemberNode>())
            {
                switch (child.UnquotedNameText)
                {
                case ManifestConstants.Provider:
                    state.ProviderId = child.UnquotedValueText;
                    break;

                case ManifestConstants.Library:
                    state.LibraryId = child.UnquotedValueText;
                    break;

                case ManifestConstants.Destination:
                    state.DestinationPath = child.UnquotedValueText;
                    break;

                case ManifestConstants.Files:
                    state.Files = (child.Value as ArrayNode)?.Elements.Select(e => e.UnquotedValueText).ToList();
                    break;
                }
            }

            children = GetChildren(parent.Parent?.FindType <ObjectNode>());
            IEnumerable <MemberNode> rootMembers = children?.OfType <MemberNode>();

            // Check for defaultProvider
            if (string.IsNullOrEmpty(state.ProviderId))
            {
                if (rootMembers != null)
                {
                    foreach (MemberNode child in rootMembers)
                    {
                        if (child.UnquotedNameText == "defaultProvider")
                        {
                            state.ProviderId = child.UnquotedValueText;
                        }
                    }
                }
            }

            // Check for defaultDestination
            if (string.IsNullOrEmpty(state.DestinationPath))
            {
                if (rootMembers != null)
                {
                    foreach (MemberNode child in rootMembers)
                    {
                        if (child.UnquotedNameText == ManifestConstants.DefaultDestination)
                        {
                            state.DestinationPath = child.UnquotedValueText;
                        }
                    }
                }
            }

            var converter = new LibraryStateToFileConverter(defaultProvider, defaultDestination: null);

            installationState = converter.ConvertToLibraryInstallationState(state);

            return(!string.IsNullOrEmpty(installationState.ProviderId));
        }
Exemple #3
0
        public static bool TryGetInstallationState(ObjectNode parent, out ILibraryInstallationState installationState, string defaultProvider = null)
        {
            installationState = null;

            if (parent == null)
            {
                return(false);
            }

            var state = new LibraryInstallationStateOnDisk();

            SortedNodeList <Node> children = GetChildren(parent);

            string GetCanonicalizedValue(BlockChildNode m)
            {
                if (m.Value is TokenNode value)
                {
                    return(value.GetCanonicalizedText());
                }
                return(m.UnquotedValueText);
            }

            foreach (MemberNode child in children.OfType <MemberNode>())
            {
                // note: the Json parser escapes backslashes in the node's Value text,
                // so we need to unescape those so that they match the value from the manifest.
                switch (child.UnquotedNameText)
                {
                case ManifestConstants.Provider:
                    state.ProviderId = GetCanonicalizedValue(child);
                    break;

                case ManifestConstants.Library:
                    state.LibraryId = GetCanonicalizedValue(child);
                    break;

                case ManifestConstants.Destination:
                    state.DestinationPath = GetCanonicalizedValue(child);
                    break;

                case ManifestConstants.Files:
                    state.Files = (child.Value as ArrayNode)?.Elements.Select(e => GetCanonicalizedValue(e)).ToList();
                    break;
                }
            }

            children = GetChildren(parent.Parent?.FindType <ObjectNode>());
            IEnumerable <MemberNode> rootMembers = children?.OfType <MemberNode>();

            // Check for defaultProvider
            if (string.IsNullOrEmpty(state.ProviderId))
            {
                if (rootMembers != null)
                {
                    foreach (MemberNode child in rootMembers)
                    {
                        if (child.UnquotedNameText == "defaultProvider")
                        {
                            state.ProviderId = child.UnquotedValueText;
                        }
                    }
                }
            }

            // Check for defaultDestination
            if (string.IsNullOrEmpty(state.DestinationPath))
            {
                if (rootMembers != null)
                {
                    foreach (MemberNode child in rootMembers)
                    {
                        if (child.UnquotedNameText == ManifestConstants.DefaultDestination)
                        {
                            state.DestinationPath = child.UnquotedValueText;
                        }
                    }
                }
            }

            var converter = new LibraryStateToFileConverter(defaultProvider, defaultDestination: null);

            installationState = converter.ConvertToLibraryInstallationState(state);

            return(!string.IsNullOrEmpty(installationState.ProviderId));
        }