Example #1
0
        /// <summary>
        /// Function to deserialize a dependency from an XML node.
        /// </summary>
        /// <param name="files">Available files to evaluate.</param>
        /// <param name="element">Element containing the serialized dependency.</param>
        /// <returns>A dependency deserialized from the XML node.</returns>
        internal static Dependency Deserialize(EditorFileCollection files, XElement element)
        {
            XAttribute typeAttr = element.Attribute(DependencyTypeAttr);
            XElement   pathNode = element.Element(DependencyPathNode);

            if ((typeAttr == null) ||
                (pathNode == null) ||
                (string.IsNullOrWhiteSpace(typeAttr.Value)) ||
                (string.IsNullOrWhiteSpace(pathNode.Value)))
            {
                throw new GorgonException(GorgonResult.CannotRead, APIResources.GOREDIT_ERR_DEPENDENCY_CORRUPT);
            }

            EditorFile file;

            if (!files.TryGetValue(pathNode.Value, out file))
            {
                return(null);
            }

            var result = new Dependency(file, typeAttr.Value);

            XElement propertiesNode = element.Element(DependencyPropertyCollection.PropertiesNode);

            if (propertiesNode != null)
            {
                result.Properties = DependencyPropertyCollection.Deserialize(propertiesNode);
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Function to reset the meta data back to its initial state.
        /// </summary>
        public static void Reset()
        {
            _metaData = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
                                      new XElement(MetaDataRootName,
                                                   new XElement(WriterPlugInNode)));

            WriterPlugInType = string.Empty;
            Files            = new EditorFileCollection();
        }
Example #3
0
        /// <summary>
        /// Function to retrieve the list of files for the editor.
        /// </summary>
        /// <param name="parent">Parent node.</param>
        private static void GetFiles(XElement parent)
        {
            if (parent == null)
            {
                throw new GorgonException(GorgonResult.CannotRead, APIResources.GOREDIT_ERR_METADATA_CORRUPT);
            }

            XElement filesNode = parent.Element(EditorFilesNode);

            if (filesNode == null)
            {
                return;
            }

            Files = EditorFileCollection.Deserialize(filesNode.Elements(EditorFile.EditorFileNode));
        }
Example #4
0
        /// <summary>
        /// Function to deserialize a file collection from an XML node.
        /// </summary>
        /// <param name="fileNodes">The list of nodes that contain the files.</param>
        /// <returns>The deserialized files.</returns>
        internal static EditorFileCollection Deserialize(IEnumerable <XElement> fileNodes)
        {
            var result = new EditorFileCollection();

            if (fileNodes == null)
            {
                return(result);
            }

            // Get the files.
            // ReSharper disable PossibleMultipleEnumeration
            foreach (XElement fileNode in fileNodes)
            {
                EditorFile file = EditorFile.Deserialize(fileNode);
                result[file.FilePath] = file;
            }

            // Now that all the files are loaded, get the dependencies.
            foreach (EditorFile file in result)
            {
                XElement fileNode = fileNodes.FirstOrDefault(item =>
                {
                    XAttribute attr = item.Attribute(EditorFile.EditorFilePathAttr);

                    return(attr != null && string.Equals(file.FilePath, attr.Value, StringComparison.OrdinalIgnoreCase));
                });

                if (fileNode == null)
                {
                    continue;
                }

                XElement dependRoot = fileNode.Element(EditorFile.EditorDependenciesNodeRoot);

                if (dependRoot == null)
                {
                    continue;
                }

                file.DependsOn.CopyFrom(DependencyCollection.Deserialize(result, dependRoot.Elements(Dependency.DependencyNode)));
            }

            // ReSharper restore PossibleMultipleEnumeration
            return(result);
        }
Example #5
0
        /// <summary>
        /// Function to deserialize a dependency collection from an XML node.
        /// </summary>
        /// <param name="files">Available files to evaluate.</param>
        /// <param name="dependenciesNode">The list of nodes that contain the dependencies.</param>
        /// <returns>The deserialized dependencies.</returns>
        internal static DependencyCollection Deserialize(EditorFileCollection files, IEnumerable <XElement> dependenciesNode)
        {
            var result = new DependencyCollection();

            if (dependenciesNode == null)
            {
                return(result);
            }

            foreach (XElement dependencyNode in dependenciesNode)
            {
                Dependency dependency = Dependency.Deserialize(files, dependencyNode);

                // We couldn't find the dependency, skip it.
                if (dependency == null)
                {
                    continue;
                }

                result[dependency.EditorFile, dependency.Type] = dependency;
            }

            return(result);
        }