Example #1
0
        /// <summary>
        /// Attempts to resolve (e.g., load from a file) the resource associated with the given URI</summary>
        /// <param name="uri">Resource URI</param>
        /// <returns>The resolved resource or null if there was a failure of some kind</returns>
        public IResource Resolve(Uri uri)
        {
            DomNode domNode = null;
            try
            {
                string fileName;
                if (uri.IsAbsoluteUri)
                    fileName = PathUtil.GetCanonicalPath(uri);
                else
                    fileName = uri.OriginalString;

                if (!fileName.EndsWith(".atgi"))
                    return null; // unable to resolve this asset

                using (Stream stream = File.OpenRead(fileName))
                {
                    if (stream != null)
                    {
                        var persister = new AtgiXmlPersister(m_loader);
                        domNode = persister.Read(stream, uri);
                    }
                }
            }
            catch (System.IO.IOException e)
            {
                Outputs.WriteLine(OutputMessageType.Warning, "Could not load resource: " + e.Message);
            }

            IResource resource = domNode.As<IResource>();
            if (resource != null)
                resource.Uri = uri;

            return resource;
        }
Example #2
0
        /// <summary>
        /// Attempts to resolve (e.g., load from a file) the resource associated with the given URI</summary>
        /// <param name="uri">Resource URI</param>
        /// <returns>The resolved resource or null if there was a failure of some kind</returns>
        public IResource Resolve(Uri uri)
        {
            DomNode domNode = null;

            try
            {
                string fileName;
                if (uri.IsAbsoluteUri)
                {
                    fileName = PathUtil.GetCanonicalPath(uri);
                }
                else
                {
                    fileName = uri.OriginalString;
                }

                if (!fileName.EndsWith(".atgi"))
                {
                    return(null); // unable to resolve this asset
                }
                using (Stream stream = File.OpenRead(fileName))
                {
                    if (stream != null)
                    {
                        var persister = new AtgiXmlPersister(m_loader);
                        domNode = persister.Read(stream, uri);
                    }
                }
            }
            catch (System.IO.IOException e)
            {
                Outputs.WriteLine(OutputMessageType.Warning, "Could not load resource: " + e.Message);
            }

            IResource resource = domNode.As <IResource>();

            if (resource != null)
            {
                resource.Uri = uri;
            }

            return(resource);
        }