Example #1
0
        public Project(Solution parent, string name, string fullFilename, string relativeFilename)
        {
            this.parent = parent;
            this.name = name;
            this.fullFilename = fullFilename;
            this.relativeFilename = relativeFilename;

            XmlDocument projectFile = new XmlDocument();
            projectFile.Load(fullFilename);
            XmlNamespaceManager nsMgr = new XmlNamespaceManager(projectFile.NameTable);
            nsMgr.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/2003");

            XmlNodeList resourceNodes = projectFile.SelectNodes("/x:Project/x:ItemGroup/x:EmbeddedResource", nsMgr);

            Dictionary<string, ResourceHolder> holders = new Dictionary<string, ResourceHolder>();
            foreach (XmlNode xmlNode in resourceNodes)
            {
                string dependentUpon = null;
                foreach (XmlNode childNode in xmlNode.ChildNodes)
                {
                    if (childNode.Name == "DependentUpon")
                        dependentUpon = childNode.InnerText;
                }

                XmlAttribute attribute = xmlNode.Attributes["Include"];
                if (attribute != null)
                {
                    if(!attribute.Value.EndsWith(".resx", StringComparison.OrdinalIgnoreCase))
                        continue;

                    string baseFilename = attribute.Value.Substring(0, attribute.Value.Length - 5);

                    ResourceHolder holder = new ResourceHolder(baseFilename, dependentUpon);
                    holders.Add(baseFilename.ToLower(), holder);
                }
            }

            // Find the bases
            Dictionary<string, Resource> baseResources = new Dictionary<string, Resource>();
            foreach (KeyValuePair<string, ResourceHolder> kvp in holders)
            {
                int dotIndex = kvp.Key.LastIndexOf('.');
                if (dotIndex > -1)
                {
                    string baseName = kvp.Key.Substring(0, dotIndex);
                    ResourceHolder baseHolder;
                    if (holders.TryGetValue(baseName, out baseHolder))
                    {
                        // Found our base
                        Resource baseResource;
                        if (!baseResources.TryGetValue(baseName, out baseResource))
                        {
                            // Create new
                            baseResource = new Resource(Path.GetFileName(baseHolder.Filename),
                                baseHolder.Filename, baseHolder.DependentUpon);
                            baseResources.Add(baseName, baseResource);
                        }

                        string languageId = kvp.Value.Filename.Substring(baseName.Length + 1);
                        parent.AddLanguage(languageId);

                        baseResource.AddLanguageFile(languageId, Path.Combine(
                            Path.Combine(parent.RootPath, Path.GetDirectoryName(relativeFilename)),
                            kvp.Value.Filename + ".resx"));
                    }
                    else
                    {
                        // Specified language without a base resource file, ignore
                    }
                }
                else
                {
                    Resource baseResource;
                    if (!baseResources.TryGetValue(kvp.Key, out baseResource))
                    {
                        // Create new
                        baseResource = new Resource(Path.GetFileName(kvp.Value.Filename), kvp.Value.Filename, kvp.Value.DependentUpon);
                        baseResources.Add(kvp.Key, baseResource);
                    }

                    baseResource.AddLanguageFile(string.Empty, Path.Combine(
                        Path.Combine(parent.RootPath, Path.GetDirectoryName(relativeFilename)),
                        kvp.Value.Filename + ".resx"));
                }
            }

            this.resources = baseResources.Values.ToList();
        }
Example #2
0
 public ResourceData(Resource parent, string key)
 {
     this.parent = parent;
     this.key = key;
     this.data = new Dictionary<string, string>();
 }