本文整理汇总了C#中System.Resources.ResXResourceWriter.AddResource方法的典型用法代码示例。如果您正苦于以下问题:C# ResXResourceWriter.AddResource方法的具体用法?C# ResXResourceWriter.AddResource怎么用?C# ResXResourceWriter.AddResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Resources.ResXResourceWriter
的用法示例。
在下文中一共展示了ResXResourceWriter.AddResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateResxWithChanges
public void UpdateResxWithChanges(string newResxPath)
{
var newFile = new FileInfo(newResxPath);
if (newFile.Exists)
newFile.Delete();
var addedKeys = _resourcesAdded.Select(pair => pair.Key);
var removedKeys = _resourcesRemoved.Select(pair => pair.Key);
using(var reader = new ResXResourceReader(_sourceResxPath))
using(var writer = new ResXResourceWriter(newResxPath))
{
foreach (DictionaryEntry resourceEntry in reader)
{
string currentKey = (string)resourceEntry.Key;
if (addedKeys.Contains(currentKey))
continue;
if (removedKeys.Contains(currentKey))
continue;
var modifiedResource = _resourcesModified.FirstOrDefault(mod => mod.ResourceName == currentKey);
if (modifiedResource != null)
writer.AddResource(currentKey, modifiedResource.NewValue);
else
writer.AddResource(currentKey, resourceEntry.Value);
}
_resourcesAdded.ForEach(res => writer.AddResource(res.Key, res.Value));
}
}
示例2: SaveAsResx
public void SaveAsResx(string filename, bool includeDescriptions)
{
using (ResXResourceWriter writer = new ResXResourceWriter(filename)) {
foreach (ResourceEntry entry in Entries.Values.OrderBy(e => e.Key, StringComparer.OrdinalIgnoreCase)) {
string normalizedValue = entry.Value.Replace("\r", "").Replace("\n", Environment.NewLine);
if (includeDescriptions) {
string normalizedDescription = entry.Description.Replace("\r", "").Replace("\n", Environment.NewLine);
writer.AddResource(new ResXDataNode(entry.Key, normalizedValue) { Comment = normalizedDescription });
} else {
writer.AddResource(entry.Key, normalizedValue);
}
}
}
}
示例3: UpdateResourceFile
public static void UpdateResourceFile(Hashtable data, string path, TranslatorForm form)
{
form.TextOutput = "Writing " + path + "...";
Hashtable resourceEntries = new Hashtable();
bool check = false;
//Get existing resources
ResXResourceReader reader = new ResXResourceReader(path);
if (reader != null)
{
IDictionaryEnumerator id = reader.GetEnumerator();
foreach (DictionaryEntry d in reader)
{
if (d.Value == null)
resourceEntries.Add(d.Key.ToString(), "");
else
resourceEntries.Add(d.Key.ToString(), d.Value.ToString());
}
reader.Close();
}
//Modify resources here...
foreach (String key in data.Keys)
{
if (!resourceEntries.ContainsKey(key))
{
String value = data[key].ToString();
if (value == null) value = "";
resourceEntries.Add(key, value);
}
}
//Write the combined resource file
ResXResourceWriter resourceWriter = new ResXResourceWriter(path);
foreach (String key in resourceEntries.Keys)
{
resourceWriter.AddResource(key, resourceEntries[key]);
}
resourceWriter.Generate();
resourceWriter.Close();
//Check if entered correctly
reader = new ResXResourceReader(path);
if (reader != null)
{
foreach (DictionaryEntry d in reader)
foreach (String key in resourceEntries.Keys)
{
if ((string) d.Key == key && (string) d.Value == (string) resourceEntries[key]) check = true;
}
reader.Close();
}
if (check) form.TextOutput = path + " written successfully";
else form.TextOutput = path + " not written !!";
}
示例4: Shutdown
public virtual void Shutdown() {
if (resources != null) {
using (var resourceWriter = new ResXResourceWriter(resourceFile)) {
resources.ForEach(kvp => resourceWriter.AddResource(kvp.Key, kvp.Value));
}
}
}
示例5: Op1_Click
protected void Op1_Click(object sender, EventArgs e) {
List<string> files = new List<string>();
foreach (LocPageGroup grp in groups().Where(g => g != LocPageGroup.newEA)) {
GenResxContext ctx = new GenResxContext(grp);
foreach (string s in TradosLib.GenResx(ctx)) files.Add(s);
LocCfgPageGroupFilter group = LocCfg.Instance().findPageGroup(grp);
//CSharp resources
string globalRes = group.GlobalResourcePath;
if (ctx.toTrans.Count > 0) {
LowUtils.AdjustFileDir(globalRes);
using (ResXResourceWriter wr = new ResXResourceWriter(globalRes))
foreach (TradosLib.resxNameValue nv in ctx.toTrans)
wr.AddResource(nv.Name, nv.Value);
files.Add(globalRes);
} else if (File.Exists(globalRes))
File.Delete(globalRes);
//JS resources
string globalResJS = group.GlobalResourcePathJS;
if (ctx.toTransJS.Count > 0) {
LowUtils.AdjustFileDir(globalResJS);
using (ResXResourceWriter wr = new ResXResourceWriter(globalResJS))
foreach (TradosLib.resxNameValue nv in ctx.toTransJS)
wr.AddResource(nv.Name, nv.Value);
files.Add(globalResJS);
} else if (File.Exists(globalResJS))
File.Delete(globalResJS);
}
string[] filesArr = (from LocPageGroup grp in groups() from string s in TradosLib.oper1(grp) select s).ToArray();
CountLab.Text = filesArr.Length.ToString();
LogRep.DataSource = files; LogRep.DataBind();
}
示例6: Convert
public static void Convert(string jsonFile, string resxFile)
{
resxKey.Clear();
JObject jsonJObject = JObject.Parse(File.ReadAllText(jsonFile));
if (jsonJObject != null)
using (ResXResourceWriter resx = new ResXResourceWriter(resxFile))
{
foreach (var property in jsonJObject.Properties())
{
if (property.HasValues)
{
foreach (var childToken in property.Children())
{
ProcessJtoken(resx, childToken);
}
}
else
{
var key = property.Name.ToLower();
if (!resxKey.Contains(key))
{
resxKey.Add(key);
resx.AddResource(property.Name, property.Value);
}
}
}
}
}
示例7: WorkbookToResx
private void WorkbookToResx(HSSFWorkbook workbook, string sheetName)
{
var sheet = NpoiHelper.GetSheet(workbook, sheetName);
var cultureRow = NpoiHelper.GetRow(sheet, CultureRowNum);
for (int cultureColumnIndex = 1; cultureColumnIndex < cultureRow.LastCellNum; cultureColumnIndex++)
{
string culture = cultureRow.GetCell(cultureColumnIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue;
var resourceFile = Path.Combine(_outputPath, sheetName + "." + culture + ".resx");
if(culture == _rootCulture)
{
resourceFile = Path.Combine(_outputPath, sheetName + ".resx");
}
using (var resxWriter = new ResXResourceWriter(resourceFile))
{
for (var rowIndex = 1; rowIndex <= sheet.LastRowNum; rowIndex++)
{
var row = NpoiHelper.GetRow(sheet, rowIndex);
var valueRow = row.GetCell(cultureColumnIndex);
if (valueRow != null)
{
resxWriter.AddResource(
row.GetCell(NameColumnNum, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue,
valueRow.StringCellValue);
}
}
}
}
}
示例8: Test
public void Test ()
{
Thread.CurrentThread.CurrentCulture =
Thread.CurrentThread.CurrentUICulture = new CultureInfo ("de-DE");
ResXResourceWriter w = new ResXResourceWriter (fileName);
w.AddResource ("point", new Point (42, 43));
w.Generate ();
w.Close ();
int count = 0;
ResXResourceReader r = new ResXResourceReader (fileName);
IDictionaryEnumerator e = r.GetEnumerator ();
while (e.MoveNext ()) {
if ((string) e.Key == "point") {
Assert.AreEqual (typeof (Point), e.Value.GetType (), "#1");
Point p = (Point) e.Value;
Assert.AreEqual (42, p.X, "#2");
Assert.AreEqual (43, p.Y, "#3");
count++;
}
}
r.Close ();
Assert.AreEqual (1, count, "#100");
}
示例9: Generate
protected override void Generate()
{
using (var resx = new ResXResourceWriter (Writer)) {
foreach (var resource_string in GetAllResourceStrings ()) {
resx.AddResource (new ResXDataNode (resource_string.Id, resource_string.Translated));
}
}
}
示例10: GenerateResxFile
public void GenerateResxFile(TextWriter textWriter)
{
var enumTables = LoadEnumTables();
var enumValues = LoadEnumValues(enumTables);
using (ResXResourceWriter writer = new ResXResourceWriter(textWriter))
{
foreach (EnumRecord value in enumValues)
{
writer.AddResource(new ResXDataNode(GetDescriptionResKey(value.Name, value.Lookup), value.Description));
writer.AddResource(new ResXDataNode(GetLongDescriptionResKey(value.Name, value.Lookup), value.LongDescription));
}
writer.Generate();
}
}
示例11: AddResource
public static void AddResource(string path, string key, string value)
{
var dict = ReadAllResources(path);
using (var writer = new ResXResourceWriter(path))
{
dict[key] = value;
foreach (var item in dict)
writer.AddResource(item.Key, item.Value);
}
}
示例12: Create
public override void Create(DecompileContext ctx) {
var list = ReadResourceEntries(ctx);
using (var writer = new ResXResourceWriter(Filename, TypeNameConverter)) {
foreach (var t in list) {
ctx.CancellationToken.ThrowIfCancellationRequested();
writer.AddResource(t);
}
}
}
示例13: AddResourceString
public static void AddResourceString(string path, string key, string value)
{
using (ResXResourceReader reader = new ResXResourceReader(path))
{
reader.UseResXDataNodes = true;
Hashtable resources = new Hashtable();
using (ResXResourceWriter writer = new ResXResourceWriter(path))
{
ITypeResolutionService iResoulution = null;
foreach (DictionaryEntry entry in reader)
{
if (entry.Value == null)
{
resources.Add(entry.Key.ToString(), "");
}
else
{
// ReSharper disable once ExpressionIsAlwaysNull
resources.Add(entry.Key.ToString(),
((ResXDataNode) entry.Value).GetValue(iResoulution).ToString());
}
ResXDataNode dataNode = (ResXDataNode) entry.Value;
if (dataNode != null)
{
writer.AddResource(dataNode);
}
}
if (!resources.ContainsKey(key))
{
writer.AddResource(key, value);
}
writer.Generate();
}
}
}
示例14: ExportFromDatabase
public void ExportFromDatabase(string exportPath)
{
var allRecords = new DbFunctions(_connectionString).GetAllResources();
foreach (ResourceRecord record in allRecords)
{
using (ResXResourceWriter writer = new ResXResourceWriter(GetExportPath(exportPath, record)))
{
writer.AddResource(record.Key, record.Value);
}
}
}
示例15: Main
public static void Main()
{
System.Resources.ResXResourceWriter resourceWriter = new ResXResourceWriter("Content.resx");
FileStream contentFile;
StreamReader fileReader;
contentFile = new System.IO.FileStream("ResourceHeader.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
fileReader = new StreamReader(contentFile);
resourceWriter.AddResource("ResourceHeader", fileReader.ReadToEnd());
contentFile = new System.IO.FileStream("gplexx.frame", FileMode.Open, FileAccess.Read, FileShare.Read);
fileReader = new StreamReader(contentFile);
resourceWriter.AddResource("GplexxFrame", fileReader.ReadToEnd());
contentFile = new System.IO.FileStream("GplexBuffers.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
fileReader = new StreamReader(contentFile);
resourceWriter.AddResource("GplexBuffers", fileReader.ReadToEnd());
resourceWriter.Generate();
resourceWriter.Close();
}