Exemple #1
0
        public ProjectInfo(string xml)
        {
            using (var sr = new StringReader(xml))
                using (var reader = XmlReader.Create(sr))
                {
                    this.doc = XDocument.Load(reader);
                    var ns = this.doc.Root.GetDefaultNamespace();
                    var namespaceManager = new XmlNamespaceManager(reader.NameTable);
                    namespaceManager.AddNamespace("xs", ns.NamespaceName);

                    {
                        var element = this.doc.Root.XPathSelectElement($"/xs:Project/xs:PropertyGroup/xs:RootNamespace", namespaceManager);
                        this.rootNamespace = element.Value;
                    }

                    {
                        var elements = this.doc.Root.XPathSelectElements($"/xs:Project/xs:ItemGroup/xs:EmbeddedResource", namespaceManager);

                        var resxInfoList = new List <ResxInfo>();
                        foreach (var item in elements)
                        {
                            var resxInfo = new ResxInfo();
                            resxInfo.Parse(item, namespaceManager);
                            resxInfoList.Add(resxInfo);
                        }
                        this.resxInfos = resxInfoList.ToArray();
                    }
                }
        }
Exemple #2
0
        static void Write(string outputPath, ResxInfo resxInfo, CremaDataTable dataTable)
        {
            var cultureInfo = resxInfo.CultureInfo;
            var valueName   = cultureInfo == null ? "Value" : cultureInfo.Name.Replace('-', '_');
            var path        = FileUtility.Prepare(outputPath, resxInfo.FileName);
            var writer      = new ResXResourceWriter(path);

            foreach (var item in dataTable.Rows)
            {
                var name = $"{item["Type"]}" == "None" ? $"{item["Name"]}" : $"{item["Type"]}_{item["Name"]}";
                var node = new ResXDataNode(name, item[valueName])
                {
                    Comment = $"{item["Comment"]}",
                };
                writer.AddResource(node);
            }
            writer.Close();
            Console.WriteLine(Path.Combine(outputPath, resxInfo.FileName));
        }