Ejemplo n.º 1
0
    public static List <DictionaryEntry> ReadResourceFile(string path)
    {
        List <DictionaryEntry> resourceEntries = new List <DictionaryEntry>();

        //Get existing resources
        ResXResourceReader reader = new ResXResourceReader(path);

        reader.UseResXDataNodes = true;
        System.ComponentModel.Design.ITypeResolutionService typeres = null;
        if (reader != null)
        {
            IDictionaryEnumerator id = reader.GetEnumerator();
            DictionaryEntry       emptyValue;
            emptyValue.Value = "";

            foreach (DictionaryEntry d in reader)
            {
                //Read from file:
                if (d.Value == null)
                {
                    emptyValue.Key = d.Key;
                    resourceEntries.Add(emptyValue);
                }
                else
                {
                    resourceEntries.Add(d);
                }
            }
            reader.Close();
        }

        return(resourceEntries);
    }
Ejemplo n.º 2
0
        private List <ResXDataNode> MergeResourceFile(string filePath, List <ResXDataNode> resourceEntries, ResourceFileLanguage language)
        {
#pragma warning disable CS0219 // Variable is assigned but its value is never used
            System.ComponentModel.Design.ITypeResolutionService typeres = null;
#pragma warning restore CS0219 // Variable is assigned but its value is never used

            List <ResXDataNode> entries = new List <ResXDataNode>();
            using (ResXResourceReader resx = new ResXResourceReader(filePath))
            {
                resx.UseResXDataNodes = true;
                foreach (DictionaryEntry entry in resx)
                {
                    ResXDataNode node = (ResXDataNode)entry.Value;
                    entries.Add(node);
                }
            }
            bool hasChanges = false;
            // Add the Resources Entries from the parse that don't already exist.
            foreach (var entry in resourceEntries)
            {
                if (!entries.Exists(x => x.Name == entry.Name))
                {
                    entries.Add(entry);
                    hasChanges = true;
                }
            }

            // Update Entries that are not found from the regex.
            foreach (var entry in entries)
            {
                if (!resourceEntries.Exists(x => x.Name == entry.Name))
                {
                    const string resourceText = "Resource Key not found from Auto Generation";
                    if (entry.Comment != "AUTO_IGNORE" && entry.Comment != resourceText)
                    {
                        entry.Comment = resourceText;
                        hasChanges    = true;
                    }
                }
            }

            if (hasChanges)
            {
                using (ResXResourceWriter resx = new ResXResourceWriter(filePath))
                {
                    foreach (var entry in entries)
                    {
                        resx.AddResource(entry);
                    }
                }
            }

            return(entries);
        }
        private void PopulateDataTable(ResourceExportLanguage language, FileInfo file, System.Data.DataTable table, bool update = false)
        {
#pragma warning disable CS0219 // Variable is assigned but its value is never used
            System.ComponentModel.Design.ITypeResolutionService typeres = null;
#pragma warning restore CS0219 // Variable is assigned but its value is never used

            using (ResXResourceReader resx = new ResXResourceReader(file.FullName))
            {
                resx.UseResXDataNodes = true;
                foreach (DictionaryEntry entry in resx)
                {
                    ResXDataNode node = (ResXDataNode)entry.Value;
                    if (SkipEntryComments?.Length > 0)
                    {
                        if (SkipEntryComments.Contains(node.Comment))
                        {
                            if (update)
                            {
                                for (int i = 0; i < table.Rows.Count; ++i)
                                {
                                    if (table.Rows[i][Key].ToString() == entry.Key.ToString())
                                    {
                                        table.Rows.RemoveAt(i);
                                        break;
                                    }
                                }
                            }

                            continue;
                        }
                    }

                    if (!update)
                    {
                        var row = table.Rows.Add(entry.Key);
                        row[language.Encoding] = node.GetValue(typeres);
                    }
                    else
                    {
                        for (int i = 0; i < table.Rows.Count; ++i)
                        {
                            if (table.Rows[i][Key].ToString() == entry.Key.ToString())
                            {
                                table.Rows[i][language.Encoding] = node.GetValue(typeres);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private List <ResXDataNode> GenerateResourceFile(
            ResourceFileData resourceFile
            , ResourceFileLanguage language
            , List <ResXDataNode> primaryEntries = null)
        {
            var fileName = $"{resourceFile.FileName}.{language.Encoding}.resx";
            var filePath = Path.Combine(ResourcesDirectory, resourceFile.ResourceFileDirectory, fileName);

            string prefix = language.IsPrimary ? null : language.NonPrimaryResourceValuePrefix;
            string suffix = language.IsPrimary ? null : language.NonPrimaryResourceValueSuffix;

            var resourceEntries = GenerateEntriesFromKeys(
                resourceFile.ResourceKeys,
                prefix,
                suffix);

            if (!language.IsPrimary && primaryEntries != null)
            {
                resourceEntries.RemoveAll(x => primaryEntries.Exists(p => p.Name == x.Name));

#pragma warning disable CS0219 // Variable is assigned but its value is never used
                System.ComponentModel.Design.ITypeResolutionService typeres = null;
#pragma warning restore CS0219 // Variable is assigned but its value is never used
                resourceEntries.AddRange(
                    primaryEntries.Select(x => new ResXDataNode(x.Name, $"{prefix}{x.GetValue(typeres)}{suffix}")
                {
                    Comment = "AUTO"
                })
                    );
            }

            if (File.Exists(filePath))
            {
                return(MergeResourceFile(filePath, resourceEntries, language));
            }
            else
            {
                var directory = new DirectoryInfo(Path.Combine(ResourcesDirectory, resourceFile.ResourceFileDirectory));
                if (!directory.Exists)
                {
                    directory.Create();
                }

                return(CreateResourceFile(filePath, resourceEntries));
            }
        }
 public object GetValue(System.ComponentModel.Design.ITypeResolutionService typeResolver)
 {
 }
 public string GetValueTypeName(System.ComponentModel.Design.ITypeResolutionService typeResolver)
 {
 }
Ejemplo n.º 7
0
 public ResXResourceReader(string fileName, System.ComponentModel.Design.ITypeResolutionService typeResolver)
 {
 }
Ejemplo n.º 8
0
 public static ResXResourceReader FromFileContents(string fileContents, System.ComponentModel.Design.ITypeResolutionService typeResolver)
 {
 }
Ejemplo n.º 9
0
 public ResXResourceReader(System.IO.Stream stream, System.ComponentModel.Design.ITypeResolutionService typeResolver)
 {
 }