예제 #1
0
        public static ComponentResource Create(string imageFile, string xmlFile)
        {
            var resource = new ComponentResource();

            resource.Image = Image.FromFile(imageFile);

            var doc = new XmlDocument();

            doc.Load(xmlFile);

            var name   = doc.SelectSingleNode("Component/Name");
            var width  = doc.SelectSingleNode("Component/Width");
            var height = doc.SelectSingleNode("Component/Height");

            if (name != null &&
                width != null &&
                height != null)
            {
                resource.Name   = name.InnerText;
                resource.Width  = int.Parse(width.InnerText);
                resource.Height = int.Parse(height.InnerText);
            }

            return(resource);
        }
예제 #2
0
        public void LoadDirectory(string directory)
        {
            var rootDirectory = new DirectoryInfo(directory);

            foreach (var dir in rootDirectory.GetDirectories())
            {
                var files     = dir.GetFiles();
                var imageFile = files.Where((a) => string.Compare(a.Name, "component.png", true) == 0).FirstOrDefault();
                var xmlFile   = files.Where((a) => string.Compare(a.Name, "component.xml", true) == 0).FirstOrDefault();

                if (imageFile != null &&
                    xmlFile != null)
                {
                    _components.Add(ComponentResource.Create(imageFile.FullName, xmlFile.FullName));
                }
            }
        }