本文整理汇总了C#中System.Resources.ResXResourceWriter.Generate方法的典型用法代码示例。如果您正苦于以下问题:C# ResXResourceWriter.Generate方法的具体用法?C# ResXResourceWriter.Generate怎么用?C# ResXResourceWriter.Generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Resources.ResXResourceWriter
的用法示例。
在下文中一共展示了ResXResourceWriter.Generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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 !!";
}
示例2: 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");
}
示例3: generateResourceFile
public static void generateResourceFile(string sourceDirectory, string targetResrouceFile)
{
IEnumerable<string> files = Directory.EnumerateFiles(sourceDirectory,"*.*",SearchOption.AllDirectories);
ResXResourceWriter rw=new ResXResourceWriter(targetResrouceFile);
string baseUI = "";
string baseCOM = "";
StringBuilder allACE = new StringBuilder();
StringBuilder allJS = new StringBuilder();
StringBuilder allCom = new StringBuilder();
StringBuilder allUI = new StringBuilder();
StringBuilder allCSS = new StringBuilder();
StringBuilder jquery = new StringBuilder();
string jq_timePicker = "";
foreach(string file in files){
if(!file.Contains(".svn")){/* don't include subversion files */
/* only include certain files. Other files don't get included */
if(file.EndsWith(".png")||file.EndsWith(".jpg")
||file.EndsWith(".gif")||file.EndsWith(".ico")) {
rw.AddResource(getRscString(file,sourceDirectory),File.ReadAllBytes(file));
}else if(file.EndsWith(".js")||file.EndsWith(".html")||
file.EndsWith(".css")||file.EndsWith(".aspx")||file.EndsWith(".sql")
||file.EndsWith(".txt")) {
string content = File.ReadAllText(file);
if(file.EndsWith(".css")){
allCSS.Append(content+Environment.NewLine);
} else if(file.EndsWith(".js")) {
if(file.ToLower().Contains("ui\\ui.js")){
baseUI = content+Environment.NewLine+Environment.NewLine;
} else if(file.ToLower().Contains("commerce\\commerce.js")) {
baseCOM = content+Environment.NewLine+Environment.NewLine;
} else if(file.ToLower().Contains("timepicker\\jquery-timepicker.js")) {
jq_timePicker = content + Environment.NewLine + Environment.NewLine;
} else if(file.ToLower().Contains("jquery\\jquery")) {
jquery.Append(content+Environment.NewLine+Environment.NewLine);
} else if(file.ToLower().Contains("ui\\")){
allUI.Append(content+Environment.NewLine+Environment.NewLine);
allJS.Append(content+Environment.NewLine+Environment.NewLine);
} else if(file.ToLower().Contains("ace\\")){
allACE.Append(content+Environment.NewLine+Environment.NewLine);
} else if(file.ToLower().Contains("commerce\\")){
allCom.Append(content+Environment.NewLine+Environment.NewLine);
allJS.Append(content+Environment.NewLine+Environment.NewLine);
}else{
allJS.Append(content+Environment.NewLine+Environment.NewLine);
}
}
rw.AddResource(getRscString(file,sourceDirectory),content);
} else if(file.ToLower() == "thumbs.db") {
File.Delete(file); /* evil */
}
}
}
rw.AddResource("admin__renditionjs", baseUI + baseCOM + allJS.ToString());
rw.AddResource("admin__acejs", allACE.ToString());
rw.AddResource("admin__jqueryjs", jquery.ToString());
rw.AddResource("admin__renditionUIjs", allACE.ToString() + baseUI + allUI.ToString());
rw.Generate();
rw.Close();
}
示例4: CreateResourceFile
public static void CreateResourceFile(String path)
{
var pathString = Path.GetDirectoryName(path);
if (!Directory.Exists(pathString)) System.IO.Directory.CreateDirectory(pathString);
ResXResourceWriter resourceWriter = new ResXResourceWriter(path);
resourceWriter.Generate();
resourceWriter.Close();
}
示例5: Main
static void Main(string[] args) {
if (args.Length != 2) {
Program.PrintUsage();
return;
}
string inputPath = args[0];
if (!File.Exists(inputPath)) {
Program.PrintUsage();
return;
}
string outputPath = args[1];
try {
if (File.Exists(outputPath)) {
File.Delete(outputPath);
}
} catch {
Console.WriteLine("Unable to delete the output file. Please make sure file is writable");
return;
}
using (ResXResourceWriter resourceWriter =
new ResXResourceWriter(outputPath)) {
using (FileStream fileStream = new FileStream(inputPath,
FileMode.Open,
FileAccess.Read,
FileShare.Read)) {
using (StreamReader reader = new StreamReader(fileStream)) {
while (reader.Peek() != -1) {
string line = reader.ReadLine();
int equalToIndex = line.IndexOf(Program.EqualTo);
string key = line.Substring(1, equalToIndex - 3);
string value = line.Substring(equalToIndex + 3,
line.Length - key.Length - 8);
if (value.IndexOf(Program.NumText) != -1) {
// Check if the value obtained contains a text which matches
// "NUM_*". If it does, replace the NUM_* by {*}.
int count = Regex.Matches(value, @"NUM_\d").Count;
for (int i = 0; i < count; ++i) {
value = value.Replace(Program.NumText + i, "{" + i + "}");
}
}
resourceWriter.AddResource(key, value);
}
}
}
resourceWriter.Generate();
}
}
示例6: btnSave_Click
private void btnSave_Click(object sender, EventArgs e)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Title = "Save resource file";
dlg.Filter = "Resource File|*.resx";
dlg.FileName = cbDestLang.SelectedValue.ToString() + ".resx";
if (dlg.ShowDialog() != DialogResult.OK) return;
ResXResourceWriter rsxw = new ResXResourceWriter(dlg.FileName);
var table = (DataTable) grid.DataSource;
foreach( DataRow row in table.Rows )
{
rsxw.AddResource( row[0].ToString(), row[2].ToString());
}
rsxw.Generate();
rsxw.Close();
}
示例7: Save
/// <summary>
/// Сохранить дерево ресурсов в каталог.
/// </summary>
public void Save(string directory)
{
ResourceItem[] ris = GetAllItems();
foreach (CultureInfo ci in GetCultures())
{
using (ResXResourceWriter rxrw = new ResXResourceWriter(
Path.Combine(directory, TreeName
+ (ci == CultureInfo.InvariantCulture ? "" : "." + ci.TwoLetterISOLanguageName)
+ ".resx")))
{
foreach (ResourceItem ri in ris)
if (ri.ValueCollection[ci] != null)
rxrw.AddResource(ri.Name, ri.ValueCollection[ci]);
rxrw.Generate();
}
}
}
示例8: GivenThereIsAResxFileWhichFullPathIsHasTheseContents
public void GivenThereIsAResxFileWhichFullPathIsHasTheseContents(string p0, Table table)
{
using (var fileStream = File.Create(Path.Combine(_testFolder, p0)))
{
using (var resxWriter = new ResXResourceWriter(fileStream))
{
foreach (var row in table.Rows)
{
resxWriter.AddResource(row["Name"], row["Value"]);
}
resxWriter.Generate();
resxWriter.Close();
}
fileStream.Close();
}
}
示例9: 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();
}
}
示例10: 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();
}
}
}
示例11: UpdateResourceFile
public static void UpdateResourceFile(Hashtable data, String path)
{
Hashtable resourceEntries = new Hashtable();
//Add all changes...
foreach (String key in data.Keys)
{
String value = data[key].ToString();
if (value == null) value = "";
resourceEntries.Add(key, value);
}
//Get existing resources
ResXResourceReader reader = new ResXResourceReader(path);
if (reader != null)
{
IDictionaryEnumerator id = reader.GetEnumerator();
foreach (DictionaryEntry d in reader)
{
if (!resourceEntries.ContainsKey(d.Key.ToString()))
{
if (d.Value == null)
resourceEntries.Add(d.Key.ToString(), "");
else
resourceEntries.Add(d.Key.ToString(), d.Value.ToString());
}
}
reader.Close();
}
//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();
}
示例12: 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();
}
示例13: OutputAltResx
private static bool OutputAltResx(string file, string locale)
{
Console.WriteLine("Processing: " + file);
ResXResourceReader resxReader = new ResXResourceReader(file);
FileInfo currentResxFile = new FileInfo(file);
string newResxFileName = String.Format("{0}.{1}{2}", currentResxFile.FullName.Substring(0, currentResxFile.FullName.Length - 5), locale, currentResxFile.Extension);
ResXResourceWriter resxWriter = new ResXResourceWriter(newResxFileName);
foreach (DictionaryEntry resource in resxReader)
{
if ("Sidebar.WidthInPixels".Equals(resource.Key))
{
resxWriter.AddResource(resource.Key.ToString(), "225");
continue;
}
if (resource.Value.GetType() == typeof(string))
resxWriter.AddResource(resource.Key.ToString(), MungeResource(resource.Value as string, StaticKeyValue(resource.Key.ToString())));
else
resxWriter.AddResource(resource.Key.ToString(), resource.Value);
}
resxWriter.Generate();
resxWriter.Close();
return true;
}
示例14: Write
// Write any localized strings to the localized file
public void Write()
{
// Create the new file.
ResXResourceWriter writer = new ResXResourceWriter(LocalizedFileName);
// Iterate the list view and write current items.
foreach (LocString locstr in AllStrings) {
if (!string.IsNullOrEmpty(locstr.Localized))
writer.AddResource(locstr.Name, locstr.Localized);
}
// Write all the non-string nodes back to the file.
foreach (ResXDataNode dataNode in nonStringNodes)
writer.AddResource(dataNode);
writer.Generate();
writer.Close();
}
示例15: Main
static void Main(string[] args)
{
Console.WriteLine("Psuedoizer: Adapted from MSDN BugSlayer 2004-Apr i18n Article.");
if(args.Length < 2)
{
Console.WriteLine("Purpose: Takes an English resource file (resx) and creates an artificial");
Console.WriteLine(" but still readable Euro-like language to exercise your i18n code");
Console.WriteLine(" without a formal translation.");
Console.WriteLine(String.Empty);
Console.WriteLine("Psuedoizer.exe infile outfile [/b]");
Console.WriteLine(" Example:");
Console.WriteLine(" Psuedoizer.exe strings.en.resx strings.ja-JP.resx");
Console.WriteLine(" /b - Include blank resources");
System.Environment.Exit(1);
}
string fileName = args[0];
string fileSaveName = args[1];
bool IncludeBlankResources = (args.Length >= 3 && args[2] == "/b");
// Open the input file.
ResXResourceReader reader = new ResXResourceReader ( fileName ) ;
try
{
// Get the enumerator. If this throws an ArguementException
// it means the file is not a .RESX file.
IDictionaryEnumerator enumerator = reader.GetEnumerator ( ) ;
// Allocate the list for this instance.
SortedList textResourcesList = new SortedList ( ) ;
// Run through the file looking for only true text related
// properties and only those with values set.
foreach ( DictionaryEntry dic in reader )
{
// Only consider this entry if the value is something.
if ( null != dic.Value )
{
// Is this a System.String.
if ( "System.String" == dic.Value.GetType().ToString())
{
String KeyString = dic.Key.ToString ( ) ;
// Make sure the key name does not start with the
// "$" or ">>" meta characters and is not an empty
// string (or we're explicitly including empty strings).
if ( ( false == KeyString.StartsWith ( ">>" ) ) &&
( false == KeyString.StartsWith ( "$" ) ) &&
( IncludeBlankResources || "" != dic.Value.ToString() ) )
{
// We've got a winner.
textResourcesList.Add ( dic.Key , dic.Value ) ;
}
// Special case the Windows Form "$this.Text" or
// I don't get the form titles.
if ( 0 == String.Compare ( KeyString,"$this.Text"))
{
textResourcesList.Add ( dic.Key , dic.Value ) ;
}
}
}
}
// It's entirely possible that there are no text strings in the
// .ResX file.
if ( textResourcesList.Count > 0 )
{
if ( null != fileSaveName )
{
// Create the new file.
ResXResourceWriter writer =
new ResXResourceWriter ( fileSaveName ) ;
foreach ( DictionaryEntry textdic in textResourcesList )
{
writer.AddResource ( textdic.Key.ToString(), Psuedoizer.ConvertToFakeInternationalized(textdic.Value.ToString()));
}
writer.Generate ( ) ;
writer.Close ( ) ;
Console.WriteLine("Converted " + textResourcesList.Count + " text resource(s).");
}
}
else
{
Console.Write("WARNING: No text resources found in " + fileName);
System.Environment.Exit(2);
}
}
catch(Exception e)
{
Console.Write(e.ToString());
System.Environment.Exit(1);
}
}