Example #1
0
        /// <summary>Creates a ResourceData instance from a stream containing data convertible into a resource. For instance a stream containing a  *.bmp file's content can be converted into a BITMAP resource.</summary>
        public static ResourceData FromFile(Stream stream, String extension, ResourceSource source)
        {
            // 'intelligent reading' of the file itself is too resource intensive. Better just to trust the extension.

            extension = extension.ToLowerInvariant();
            if (extension.StartsWith("."))
            {
                extension = extension.Substring(1);
            }

            ResourceDataFactory[] factories = ResourceDataFactory.GetFactoriesForExtension(extension);

            // try the factories in order of compatibility.

            Int32        i    = 0;
            ResourceData data = null;

            while (data == null)
            {
                if (i >= factories.Length)
                {
                    throw new Exception("Unable to locate factory for resource data.");
                }

                data = factories[i++].FromFile(stream, extension, source);
            }

            return(data);

            throw new NotImplementedException();
        }
Example #2
0
        public static ResourceData FromResource(ResourceLang lang, Byte[] rawData)
        {
            ResourceTypeIdentifier typeId = lang.Name.Type.Identifier;

            // get a list of suitable factories

            ResourceDataFactory[] factories = ResourceDataFactory.GetFactoriesForType(typeId);

            // try the factories in order of compatibility.

            Int32        i    = 0;
            ResourceData data = null;

            while (data == null)
            {
                if (i >= factories.Length)
                {
                    throw new Exception("Unable to locate factory for resource data.");
                }

                data = factories[i++].FromResource(lang, rawData);
            }

            return(data);
        }
Example #3
0
        /// <summary>Loads all recognised factories which causes them to add their options to the dictionary</summary>
        public static void Populate()
        {
            // ResourceData
            ResourceDataFactory.GetFactories();

            // ResourceSource
            ResourceSourceFactory.GetFactories();

            // TypeViewers can't be done from this assembly (obviously)
            // so it's Resourcer's responsibility
        }
Example #4
0
        public void CastData(ResourceDataFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            ResourceData d = factory.FromResource(this, Data.RawData);

            if (d == null)
            {
                throw new ResourceDataException("Could not cast ResourceData to " + factory.Name);
            }

            _data = d;
        }