/// <summary> /// Function to load a single dependency for a file. /// </summary> /// <param name="dependency">Dependency to load.</param> /// <param name="childDependencies">The dependencies for this dependency.</param> /// <returns>The loaded dependency object.</returns> private object LoadDependency(GorgonEditorDependency dependency, IReadOnlyDictionary <GorgonEditorDependency, object> childDependencies) { GorgonFileSystemFileEntry dependencyFile = FileSystem.GetFile(dependency.Path); if (dependencyFile == null) { throw new IOException(string.Format(Resources.GORFS_ERR_DEPENDENCY_NOT_FOUND, dependency.Path)); } // Find a handler for this file. KeyValuePair <Type, Func <Stream, IReadOnlyDictionary <GorgonEditorDependency, object>, object> > handler = _fileHandlers.FirstOrDefault(item => string.Equals(item.Key.FullName, dependency.Type, StringComparison.OrdinalIgnoreCase)); if (handler.Key == null) { throw new IOException(string.Format(Resources.GORFS_ERR_FILE_NO_HANDLER, dependency.Path)); } using (Stream dependencyStream = dependencyFile.OpenStream(false)) { return(handler.Value(dependencyStream, childDependencies)); } }
/// <summary> /// Function to deserialize a dependency from an XML node. /// </summary> /// <param name="element">Element containing the serialized dependency.</param> /// <returns>A dependency deserialized from the XML node.</returns> internal static GorgonEditorDependency Deserialize(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, Resources.GORFS_ERR_DEPENDENCY_CORRUPT); } var result = new GorgonEditorDependency(pathNode.Value, typeAttr.Value); XElement propertiesNode = element.Element(GorgonEditorDependencyPropertyCollection.PropertiesNode); if (propertiesNode != null) { result.Properties = GorgonEditorDependencyPropertyCollection.Deserialize(propertiesNode); } return(result); }