public void Close() { MemoryStream ms = new MemoryStream(); ResourceWriter writer = new ResourceWriter(ms); writer.AddResource("Name", "Miguel"); Assert.IsTrue(ms.CanWrite, "#A1"); Assert.IsTrue(ms.GetBuffer().Length == 0, "#A2"); writer.Close(); Assert.IsFalse(ms.CanWrite, "#B1"); Assert.IsFalse(ms.GetBuffer().Length == 0, "#B2"); writer.Close(); }
private void cmdSave_Click(object sender, EventArgs e) { if (!Directory.Exists($"{Application.StartupPath}\\Languages")) { Directory.CreateDirectory($"{Application.StartupPath}\\Languages"); } dsLanguages.WriteXml($"{Application.StartupPath}\\Languages\\Languages.xml"); ResourceWriter englishResourceWriter = new ResourceWriter($"{Application.StartupPath}\\Languages\\resource.en-ZA.resources"); ResourceWriter afrikaansResourceWriter = new ResourceWriter($"{Application.StartupPath}\\Languages\\resource.af-ZA.resources"); foreach (dsLanguages.LanguagesRow row in dsLanguages.Languages.Rows) { englishResourceWriter.AddResource(row.Id, row.English); afrikaansResourceWriter.AddResource(row.Id, row.Afrikaans); } englishResourceWriter.Generate(); englishResourceWriter.Close(); afrikaansResourceWriter.Generate(); afrikaansResourceWriter.Close(); MessageBox.Show("Saved", "CloudMagic", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public SpecialResourceWriter() { // Load all bunlde IList <IResourceBundle> allBundle = new List <IResourceBundle>(20); allBundle.Add(ResourceBundleFactory.CreateBundle("CanonMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("CasioMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("Commons", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("ExifInteropMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("ExifMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("FujiFilmMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("GpsMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("IptcMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("JpegMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("KodakMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("KyoceraMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("NikonTypeMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("OlympusMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("PanasonicMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("PentaxMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); allBundle.Add(ResourceBundleFactory.CreateBundle("SonyMarkernote", null, ResourceBundleFactory.USE_TXTFILE)); foreach (IResourceBundle bdl in allBundle) { ResourceWriter rw = new ResourceWriter(bdl.Fullname + ".resources"); IDictionary <string, string> idic = bdl.Entries; IDictionaryEnumerator enumDic = (IDictionaryEnumerator)idic.GetEnumerator(); while (enumDic.MoveNext()) { rw.AddResource((string)enumDic.Key, (string)enumDic.Value); } rw.Close(); rw.Dispose(); } }
public void SaveResourceFile(String FileName) { this.FileName = FileName; String x = Path.GetExtension(FileName); if ((String.Compare(x, ".xml", true) == 0) || (String.Compare(x, ".resX", true) == 0)) { ResXResourceWriter r = new ResXResourceWriter(FileName); IDictionaryEnumerator n = Resource.GetEnumerator(); while (n.MoveNext()) { r.AddResource((string)n.Key, (object)n.Value); } r.Generate(); r.Close(); } else { ResourceWriter r = new ResourceWriter(FileName); IDictionaryEnumerator n = Resource.GetEnumerator(); while (n.MoveNext()) { r.AddResource((string)n.Key, (object)n.Value); } r.Generate(); r.Close(); } }
public static void Main(string[] args) { String fileName = "genstrings.resources"; if (File.Exists(Environment.CurrentDirectory + "\\" + fileName)) { File.Delete(Environment.CurrentDirectory + "\\" + fileName); } ResourceWriter writer = new ResourceWriter(fileName); writer.AddResource("English_Text", ReadTextFile("english.txt")); writer.AddResource("Japanese_Text", ReadTextFile("japanese.txt")); writer.AddResource("German_Text", ReadTextFile("german.txt")); writer.AddResource("Arabic_Text", ReadTextFile("arabic.txt")); writer.AddResource("Korean_Text", ReadTextFile("korean.txt")); writer.AddResource("ChineseTra_Text", ReadTextFile("chinesetra.txt")); writer.AddResource("ChineseSim_Text", ReadTextFile("chinesesim.txt")); writer.AddResource("Spanish_Text", ReadTextFile("spanish.txt")); writer.AddResource("Italian_Text", ReadTextFile("italian.txt")); writer.AddResource("French_Text", ReadTextFile("french.txt")); writer.AddResource("Turkish_Text", ReadTextFile("turkish.txt")); writer.AddResource("NorwegianBok_Text", ReadTextFile("norwegianbok.txt")); writer.AddResource("NorwegianNyn_Text", ReadTextFile("norwegiannyn.txt")); writer.Generate(); writer.Close(); }
public static int Main(string[] args) { try{ Console.WriteLine("! MakeRes is using .NET version: " + Environment.Version.ToString()); ResourceWriter rw = new ResourceWriter(args[0] + ".resources"); for (int i = 1; i < args.Length; i = i + 2) { using (FileStream fs = File.OpenRead(args[i + 1])) { byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); Console.WriteLine("ID = " + args[i]); rw.AddResource(args[i], buffer); fs.Close(); SHA1 sha = new SHA1CryptoServiceProvider(); byte[] result = sha.ComputeHash(buffer); WriteHash(args[0] + "." + args[i], result); } } rw.Close(); }catch (Exception ex) { Console.WriteLine("# MareRes Error: " + ex.Message + "\r\n" + ex.StackTrace); return(1); } return(0); }
public void AddResource_Stream_Errors() { MemoryStream ms = new MemoryStream(); ResourceWriter rw = new ResourceWriter(ms); ResourceStream stream = new ResourceStream("Test"); stream.SetCanSeek(false); // // Seek not supported. // try { rw.AddResource("Name", stream); Assert.Fail("#Exc1"); } catch (ArgumentException) { } // // Even using the overload taking an object // seems to check for that // try { rw.AddResource("Name", (object)stream); Assert.Fail("#Exc2"); } catch (ArgumentException) { } rw.Close(); }
public void Generate() { MemoryStream ms = new MemoryStream(); ResourceWriter writer = new ResourceWriter(ms); writer.AddResource("Name", "Miguel"); Assert.IsTrue(ms.Length == 0, "#A1"); Assert.IsTrue(ms.CanWrite, "#A2"); writer.Generate(); Assert.IsFalse(ms.Length == 0, "#B2"); Assert.IsTrue(ms.CanWrite, "#B2"); try { writer.Generate(); Assert.Fail("#C1"); } catch (InvalidOperationException ex) { // The resource writer has already been closed // and cannot be edited Assert.AreEqual(typeof(InvalidOperationException), ex.GetType(), "#C2"); Assert.IsNull(ex.InnerException, "#C3"); Assert.IsNotNull(ex.Message, "#C4"); } writer.Close(); }
[Test] // AddResource (string, byte []) public void AddResource0() { byte [] value = new byte [] { 5, 7 }; MemoryStream ms = new MemoryStream(); ResourceWriter writer = new ResourceWriter(ms); writer.AddResource("Name", value); writer.Generate(); try { writer.AddResource("Address", new byte [] { 8, 12 }); Assert.Fail("#A1"); } catch (InvalidOperationException ex) { // The resource writer has already been closed // and cannot be edited Assert.AreEqual(typeof(InvalidOperationException), ex.GetType(), "#A2"); Assert.IsNull(ex.InnerException, "#A3"); Assert.IsNotNull(ex.Message, "#A4"); } ms.Position = 0; ResourceReader rr = new ResourceReader(ms); IDictionaryEnumerator enumerator = rr.GetEnumerator(); Assert.IsTrue(enumerator.MoveNext(), "#B1"); Assert.AreEqual("Name", enumerator.Key, "#B3"); Assert.AreEqual(value, enumerator.Value, "#B4"); Assert.IsFalse(enumerator.MoveNext(), "#B5"); writer.Close(); }
public override object Generate(string formatter, InputArgs inputArgs) { string resxPayload = Plugins.ResxPlugin.GetPayload("binaryformatter", inputArgs); MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(resxPayload)); // TextFormattingRunPropertiesGenerator is the preferred method due to its short length. However, we need to insert it manually into a serialized object as ResourceSet cannot tolerate it // TODO: surgical insertion! // object generatedPayload = TextFormattingRunPropertiesGenerator.TextFormattingRunPropertiesGadget(tempInputArgs); object generatedPayload = TypeConfuseDelegateGenerator.TypeConfuseDelegateGadget(inputArgs); using (ResourceWriter rw = new ResourceWriter(@".\ResourceSetGenerator.resources")) { rw.AddResource("", generatedPayload); rw.Generate(); rw.Close(); } // Payload will be executed once here which is annoying but without surgical insertion or something to parse binaryformatter objects, it is quite hard to prevent this ResourceSet myResourceSet = new ResourceSet(@".\ResourceSetGenerator.resources"); if (formatter.Equals("binaryformatter", StringComparison.OrdinalIgnoreCase) || formatter.Equals("losformatter", StringComparison.OrdinalIgnoreCase) || formatter.Equals("objectstateformatter", StringComparison.OrdinalIgnoreCase) || formatter.Equals("netdatacontractserializer", StringComparison.OrdinalIgnoreCase)) { return(Serialize(myResourceSet, formatter, inputArgs)); } else { throw new Exception("Formatter not supported"); } }
private void createDefaultLanguage() { Assembly a = Assembly.GetExecutingAssembly(); Stream fs = a.GetManifestResourceStream("Engine.en-US.xml"); StreamReader sr = new StreamReader(fs); StreamWriter sw = new StreamWriter(this._lang_home + @"default.xml", false, Encoding.Default); sw.WriteLine(sr.ReadToEnd()); sw.Close(); sr.Close(); fs.Close(); XmlDocument xdoc = new XmlDocument(); xdoc.Load(this._lang_home + @"default.xml"); ResourceWriter rw = new ResourceWriter(this._lang_home + "Languages.resources"); foreach (XmlNode n in xdoc.ChildNodes[1]) { this.generateRessource(rw, n, ""); } rw.Generate(); rw.Close(); }
public void AddResource_Name_Duplicate() { MemoryStream ms = new MemoryStream(); ResourceWriter writer = new ResourceWriter(ms); writer.AddResource("FirstName", "Miguel"); try { writer.AddResource("FirstNaMe", "Chris"); Assert.Fail("#1"); } catch (ArgumentException ex) { // Item has already been added. Key is dictionary: // 'FirstName' Key being added: 'FirstNaMe' Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#2"); Assert.IsNull(ex.InnerException, "#3"); Assert.IsNotNull(ex.Message, "#4"); Assert.IsNull(ex.ParamName, "#5"); } writer.AddResource("Name", "Miguel"); writer.Close(); }
public static int Main(string[] args) { try{ Console.WriteLine("! MakeRes is using .NET version: " + Environment.Version.ToString()); ResourceWriter rw = new ResourceWriter(args[0] + ".resources"); for(int i = 1; i < args.Length; i = i + 2) { using(FileStream fs = File.OpenRead(args[i + 1])) { byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); Console.WriteLine("ID = " + args[i]); rw.AddResource(args[i], buffer); fs.Close(); SHA1 sha = new SHA1CryptoServiceProvider(); byte[] result = sha.ComputeHash(buffer); WriteHash(args[0] + "."+ args[i], result); } } rw.Close(); }catch(Exception ex) { Console.WriteLine("# MareRes Error: " + ex.Message + "\r\n" + ex.StackTrace); return 1; } return 0; }
/// <summary> /// 주의: 현재 시점에서는 참조하는 파일이 없을 수 있으므로 이곳에서는 참조하는 외부 파일을 이용하면 안됨. /// </summary> /// <param name="htRefs"></param> public static void WriteReferencedToResources(Hashtable htRefs) { string ResPathFile = @"..\..\" + Application.ProductName + ".resources"; ResourceWriter rw = new ResourceWriter(ResPathFile); foreach (DictionaryEntry d in htRefs) { string Name = (string)d.Key; string PathFile = (string)d.Value; if (!System.IO.File.Exists(PathFile)) { continue; } FileStream fs = new FileStream(PathFile, FileMode.Open, FileAccess.Read, FileShare.None); int len = Convert.ToInt32(fs.Length); byte[] byt = new byte[len]; fs.Read(byt, 0, len); fs.Close(); rw.AddResource(Name, byt); } rw.Close(); }
static void Main(string[] args) { ResourceWriter myResource = new ResourceWriter("Images.resources"); myResource.AddResource("flash", new Bitmap("flashScreen.png")); Image simpleImage = new Image(); simpleImage.Margin = new Thickness(0); BitmapImage bi = new BitmapImage(); //BitmapImage.UriSource must be in a BeginInit/EndInit block bi.BeginInit(); bi.UriSource = new Uri(@"pack://siteoforigin:,,,/alarm3.png"); bi.EndInit(); //set image source simpleImage.Source = bi; // simpleImage.Stretch = Stretch.None; simpleImage.HorizontalAlignment = HorizontalAlignment.Center; simpleImage.Visibility = Visibility.Hidden; simpleImage.Name = "AlarmIndicator"; simpleImage.Width = 13; myResource.AddResource("alarm", new Image("alarm3.png")); myResource.Close(); }
static void Main() { ResourceWriter writer = new ResourceWriter("test.resources"); writer.AddResource("1", "2"); writer.Generate(); writer.Close(); }
/// <summary> /// 将resx文件转换为resources文件,如果转换成功,返回True /// </summary> /// <param name="strResources">resources文件的路径,注意请保证路径正确无误</param> /// <param name="strResx">resx文件的路径,注意请保证路径正确无误</param> public static bool ConvertResources(string strResx, string strResources) { if (string.IsNullOrEmpty(strResources) || string.IsNullOrEmpty(strResx)) { return(false); } if (File.Exists(strResources) && File.Exists(strResx) == false) { return(false); } //开始转换. try { //ResourceReader reader = new ResourceReader(strResources); ResXResourceSet reader = new ResXResourceSet(strResx); //ResXResourceWriter writer = new ResXResourceWriter(strResx); ResourceWriter writer = new ResourceWriter(strResources); foreach (DictionaryEntry en in reader) { writer.AddResource(en.Key.ToString(), en.Value); } reader.Close(); writer.Close(); } catch { return(false); } return(true); }
static void Main(string[] args) { var write = new ResourceWriter("Resource1.resources"); var jsonfolder = new DirectoryInfo($@"..\..\Completed\json_{args[0]}\"); var masterfolder = new DirectoryInfo($@"..\..\Completed\master_{args[0]}\"); var scenariofolder = new DirectoryInfo($@"..\..\Completed\scenario_{args[0]}\"); foreach (var file in jsonfolder.GetFiles()) { write.AddResource(Path.GetFileNameWithoutExtension(file.FullName), File.ReadAllText(file.FullName)); } foreach (var file in masterfolder.GetFiles()) { write.AddResource(Path.GetFileNameWithoutExtension(file.FullName), File.ReadAllText(file.FullName)); } write.Generate(); write.Close(); var write2 = new ResourceWriter("Resource2.resources"); foreach (var file in scenariofolder.GetFiles()) { write2.AddResource(Path.GetFileNameWithoutExtension(file.FullName), File.ReadAllText(file.FullName)); } write2.Generate(); write2.Close(); }
/// <summary> /// Goes through all the auxillary methods to generate the source code to load the application after it is compressed. /// </summary> /// <returns></returns> private static string GenerateSource() { string result = ""; //usings. result += "using System;\n"; result += "using System.Reflection;\n"; result += "using System.Resources;\n"; result += "using System.Text;\n"; result += "using System.IO;\n"; result += "using System.IO.Compression;\n"; result += GetAssemblyInfo() + "\n"; //create a resource writer, so we can embed the compressed materials. ResourceWriter writer = new ResourceWriter(File.Open("resource.resources", FileMode.Create)); //add the basic structure. result += "namespace CompressedApp\n{\nclass Program\n{\n[STAThread]\nstatic void Main(string[] args)\n{\n" + GetMainMethodCode(writer) + "\n}\n}\n}\n"; //close the resource writer. writer.Close(); return(result); }
static void Assemble(string pattern) { string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), pattern); foreach (string file in files) { if (Path.GetExtension(file).ToUpper() == ".XML") { try { XmlDocument doc = new XmlDocument(); doc.Load(file); string resfilename = "StringResources." + doc.DocumentElement.Attributes["language"].InnerText + ".resources"; ResourceWriter rw = new ResourceWriter(resfilename); foreach (XmlElement el in doc.DocumentElement.ChildNodes) { rw.AddResource(el.Attributes["name"].InnerText, el.InnerText); } rw.Generate(); rw.Close(); } catch (Exception e) { Console.WriteLine("Error while processing " + file + " :"); Console.WriteLine(e.ToString()); } } } }
static void Assemble(string pattern) { string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), pattern); foreach (string file in files) { if (Path.GetExtension(file).ToUpper() == ".XML") { try { XmlDocument doc = new XmlDocument(); doc.Load(file); string resfilename = "StringResources." + doc.DocumentElement.Attributes["language"].InnerText + ".resources"; ResourceWriter rw = new ResourceWriter(resfilename); foreach (XmlElement el in doc.DocumentElement.ChildNodes) { rw.AddResource(el.Attributes["name"].InnerText, el.InnerText); } rw.Generate(); rw.Close(); } catch (Exception e) { Console.WriteLine("Error while processing " + file + " :"); Console.WriteLine(e.ToString()); } } } }
CompilerResults CompileForm(string src, string NamespaceAndClass) { CSharpCodeProvider csc = new CSharpCodeProvider( new Dictionary <string, string>() { { "CompilerVersion", "v4.0" } }); CompilerParameters parameters = new CompilerParameters(); parameters.GenerateInMemory = true; parameters.ReferencedAssemblies.Add("System.dll"); parameters.ReferencedAssemblies.Add("System.Drawing.dll"); parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll"); string binDirectory = Path.GetDirectoryName(Application.ExecutablePath); // reference all dlls in the bin directory string[] dllnames = Directory.GetFiles(binDirectory, "*.dll"); foreach (string dllName in dllnames) { if (!dllName.EndsWith("sqlite3.dll")) { parameters.ReferencedAssemblies.Add(dllName); } } string ResourceXFile = FFilename.Replace(".yaml", "-generated.resx"); //"../../../../tmp/" + string ResourcesFile = NamespaceAndClass + ".resources"; if (File.Exists(ResourceXFile)) { ResXResourceReader ResXReader = new ResXResourceReader(ResourceXFile); FileStream fs = new FileStream(ResourcesFile, FileMode.OpenOrCreate, FileAccess.Write); IResourceWriter writer = new ResourceWriter(fs); foreach (DictionaryEntry d in ResXReader) { writer.AddResource(d.Key.ToString(), d.Value); } writer.Close(); parameters.EmbeddedResources.Add(ResourcesFile); } CompilerResults results = csc.CompileAssemblyFromSource(parameters, src); if (results.Errors.HasErrors) { foreach (CompilerError error in results.Errors) { TLogging.Log(error.ToString()); } } return(results); }
private void ResourceWriter(DateTime dtschedule, string _type) { ResourceWriter rsw = new ResourceWriter(Application.StartupPath + @"\STFCongif"); rsw.AddResource("Schedule", dtschedule.Hour + ":" + dtschedule.Minute); rsw.AddResource("Type", _type); rsw.Close(); }
public void Save() { if (rw != null) { rw.Close(); rw = null; } }
/// <summary> /// 写入 中文 资源文件. /// </summary> public void WriteChinaResource() { // 构造写入器. ResourceWriter rw = new ResourceWriter("China.resource"); rw.AddResource("Hello", "你好"); rw.Close(); }
/// <summary> /// 写入 英文 资源文件. /// </summary> public void WriteEnglishResource() { // 构造写入器. ResourceWriter rw = new ResourceWriter("English.resource"); rw.AddResource("Hello", "Hello"); rw.Close(); }
static void Main() { ResourceWriter writer = new ResourceWriter("test.resources"); writer.AddResource("1", "2"); writer.Generate(); writer.Close(); }
// Read all msgid/msgstr pairs (each string being NUL-terminated and // UTF-8 encoded) and write the .resources file to the given filename. WriteResource(String filename) { Stream input = new BufferedStream(Console.OpenStandardInput()); reader = new StreamReader(input, new UTF8Encoding()); if (filename.Equals("-")) { BufferedStream output = new BufferedStream(Console.OpenStandardOutput()); // A temporary output stream is needed because ResourceWriter.Generate // expects to be able to seek in the Stream. MemoryStream tmpoutput = new MemoryStream(); ResourceWriter rw = new ResourceWriter(tmpoutput); ReadAllInput(rw); #if __CSCC__ // Use the ResourceReader to check against pnet-0.6.0 ResourceWriter // bug. try { ResourceReader rr = new ResourceReader(new MemoryStream(tmpoutput.ToArray())); foreach (System.Collections.DictionaryEntry entry in rr) { ; } } catch (IOException e) { throw new Exception("class ResourceWriter is buggy", e); } #endif tmpoutput.WriteTo(output); rw.Close(); output.Close(); } else { #if __CSCC__ MemoryStream tmpoutput = new MemoryStream(); ResourceWriter rw = new ResourceWriter(tmpoutput); ReadAllInput(rw); // Use the ResourceReader to check against pnet-0.6.0 ResourceWriter // bug. try { ResourceReader rr = new ResourceReader(new MemoryStream(tmpoutput.ToArray())); foreach (System.Collections.DictionaryEntry entry in rr) { ; } } catch (IOException e) { throw new Exception("class ResourceWriter is buggy", e); } BufferedStream output = new BufferedStream(new FileStream(filename, FileMode.Create, FileAccess.Write)); tmpoutput.WriteTo(output); rw.Close(); output.Close(); #else ResourceWriter rw = new ResourceWriter(filename); ReadAllInput(rw); rw.Close(); #endif } }
private void buildButton_Click(object sender, EventArgs e) { //Build an exe String port = portText.Text; String ipAddress = ipOrDns.Text; var assembly = Assembly.GetExecutingAssembly(); Stream stream = assembly.GetManifestResourceStream("PR0T0TYP3.Client.txt"); StreamReader reader = new StreamReader(stream); String clientCode = reader.ReadToEnd(); saveFile.Filter = "exe files (*.exe)|.exe"; saveFile.Title = "Save the .exe File"; saveFile.ShowDialog(); String fileDownName = saveFile.FileName; ResourceWriter resW = new ResourceWriter("temp.resources"); resW.AddResource("port", port); resW.AddResource("ipAddress", ipAddress); resW.Generate(); resW.Close(); CSharpCodeProvider codeProvider = new CSharpCodeProvider(); ICodeCompiler icc = codeProvider.CreateCompiler(); System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(); parameters.ReferencedAssemblies.Add("System.IO.dll"); parameters.ReferencedAssemblies.Add("System.Security.dll"); parameters.ReferencedAssemblies.Add("System.Core.dll"); parameters.ReferencedAssemblies.Add("System.dll"); parameters.ReferencedAssemblies.Add("System.Net.dll"); parameters.ReferencedAssemblies.Add("System.Linq.dll"); parameters.ReferencedAssemblies.Add("System.Reflection.dll"); parameters.ReferencedAssemblies.Add("System.Collections.dll"); parameters.EmbeddedResources.Add("temp.resources"); parameters.GenerateExecutable = true; parameters.OutputAssembly = fileDownName; CompilerResults results = icc.CompileAssemblyFromSource(parameters, clientCode); //Add stuff l8r if (results.Errors.Count > 0) { // Display compilation errors. log.Text += "Errors building file into " + results.PathToAssembly + "\n"; foreach (CompilerError ce in results.Errors) { log.Text += ce.ToString() + "\n"; } } else { // Display a successful compilation message. log.Text = "File built into " + results.PathToAssembly + " successfully."; } }
static void Main() { ResourceWriter rw = new ResourceWriter("MCListBox.resources"); using(Image image = Image.FromFile("../../TRFFC10a.ICO")) { rw.AddResource("StopLight",image); rw.Close(); } }
public static void AddFileAsStringResource(string resourceFile, string resourceName, string inputFile) { ResourceWriter writer = new ResourceWriter(resourceFile); StreamReader reader = new StreamReader(inputFile); string s = reader.ReadToEnd(); reader.Close(); writer.AddResource(resourceName, s); writer.Close(); }
public static void Main() { ResourceWriter rw = new ResourceWriter("English.resources"); rw.AddResource("Name", "Test"); rw.AddResource("Ver", 1.0); rw.AddResource("Author", "www.java2s.com"); rw.Generate(); rw.Close(); }
public static void Main() { ResourceWriter rw = new ResourceWriter("PaDrawImage2016CS.resources"); //Icon ico = new Icon("Demo.ico"); Image imgBg = Image.FromFile("小老虎-2-3-2"); rw.AddResource("bg.gif", imgBg); rw.Generate(); rw.Close(); }
private void APILoginForm_FormClosing(object sender, FormClosingEventArgs e) { if (SaveLogin == true) { IResourceWriter writer = new ResourceWriter("Login.resources"); writer.AddResource("TTUSERNAME", Username); writer.AddResource("TTPASSWORD", Password); writer.Close(); } }
public static void Main(string[] args) { String fileName = "genstrings.resources"; if(File.Exists(Environment.CurrentDirectory+"\\" + fileName)) File.Delete(Environment.CurrentDirectory+"\\" + fileName); ResourceWriter writer = new ResourceWriter(fileName); writer.AddResource("English_Text", ReadTextFile("english.txt")); writer.AddResource("Japanese_Text", ReadTextFile("japanese.txt")); writer.AddResource("German_Text", ReadTextFile("german.txt")); writer.AddResource("Arabic_Text", ReadTextFile("arabic.txt")); writer.AddResource("Korean_Text", ReadTextFile("korean.txt")); writer.AddResource("ChineseTra_Text", ReadTextFile("chinesetra.txt")); writer.AddResource("ChineseSim_Text", ReadTextFile("chinesesim.txt")); writer.AddResource("Spanish_Text", ReadTextFile("spanish.txt")); writer.AddResource("Italian_Text", ReadTextFile("italian.txt")); writer.AddResource("French_Text", ReadTextFile("french.txt")); writer.AddResource("Turkish_Text", ReadTextFile("turkish.txt")); writer.AddResource("NorwegianBok_Text", ReadTextFile("norwegianbok.txt")); writer.AddResource("NorwegianNyn_Text", ReadTextFile("norwegiannyn.txt")); writer.Generate(); writer.Close(); }
public Boolean runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; String strValue = String.Empty; Co5209AddResource_str_ubArr cc = new Co5209AddResource_str_ubArr(); IDictionaryEnumerator idic; try { do { ResourceWriter resWriter; ResourceReader resReader; int statusBits = 0; int resultBits = 0; Byte[] ubArr = null; if(File.Exists(Environment.CurrentDirectory+"\\Co5209.resources")) File.Delete(Environment.CurrentDirectory+"\\Co5209.resources"); strLoc = "Loc_204gh"; resWriter = new ResourceWriter("Co5209.resources"); strLoc = "Loc_209tj"; try { iCountTestcases++; resWriter.AddResource(null, ubArr); iCountErrors++; printerr("Error_20fhs! Expected Exception not thrown"); } catch (ArgumentException) {} catch (Exception exc) { iCountErrors++; printerr("Error_2t0jg! Unexpected exception exc=="+exc.ToString()); } strLoc = "Loc_t4j80"; ubArr = null; iCountTestcases++; try { resWriter.AddResource("key with null value", ubArr); } catch (Exception exc) { iCountErrors++; printerr("Error_59ufd! Unexpected exc=="+exc.ToString()); } Byte[] ubArr1 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'1',}; Byte[] ubArr2 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'2',}; Byte[] ubArr3 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'3',}; Byte[] ubArr4 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'4',}; Byte[] ubArr5 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'5',}; Byte[] ubArr6 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'6',}; strLoc = "Loc_59ugd"; resWriter.AddResource("key 1", ubArr1); resWriter.AddResource("key 2", ubArr2); resWriter.AddResource("key 3", ubArr3); resWriter.AddResource("key 4", ubArr4); resWriter.AddResource("key 5", ubArr5); resWriter.AddResource("key 6", ubArr6); strLoc = "Loc_230rj"; iCountTestcases++; try { resWriter.AddResource("key 1", ubArr6); iCountErrors++; printerr("Error_2th8e! Names are not unique"); } catch (ArgumentException) {} catch (Exception exc) { iCountErrors++; printerr("Error_298hg! Unexpected exception=="+exc.ToString()); } resWriter.Generate(); iCountTestcases++; if(!File.Exists(Environment.CurrentDirectory+"\\Co5209.resources")) { iCountErrors++; printerr("Error_23094! Expected file was not created"); } resWriter.Close(); strLoc = "Loc_30tud"; resReader = new ResourceReader(Environment.CurrentDirectory+"\\Co5209.resources"); strLoc = "Loc_0576cd"; byte[] btTemp; Boolean fNotEqual; IDictionaryEnumerator resEnumerator = resReader.GetEnumerator(); idic = resReader.GetEnumerator(); while(idic.MoveNext()) { if(idic.Key.Equals("key 1")) { btTemp = (byte[])idic.Value; fNotEqual = false; for(int i=0;i<btTemp.Length; i++) { if(btTemp[i]!=ubArr1[i]) fNotEqual = true; } if(!fNotEqual) statusBits = statusBits | 0x1; } else if(idic.Key.Equals("key 2")) { btTemp = (byte[])idic.Value; fNotEqual = false; for(int i=0;i<btTemp.Length; i++) { if(btTemp[i]!=ubArr2[i]) fNotEqual = true; } if(!fNotEqual) statusBits = statusBits | 0x2; } else if(idic.Key.Equals("key 3")) { btTemp = (byte[])idic.Value; fNotEqual = false; for(int i=0;i<btTemp.Length; i++) { if(btTemp[i]!=ubArr3[i]) fNotEqual = true; } if(!fNotEqual) statusBits = statusBits | 0x4; } else if(idic.Key.Equals("key 4")) { btTemp = (byte[])idic.Value; fNotEqual = false; for(int i=0;i<btTemp.Length; i++) { if(btTemp[i]!=ubArr4[i]) fNotEqual = true; } if(!fNotEqual) statusBits = statusBits | 0x8; } else if(idic.Key.Equals("key 5")) { btTemp = (byte[])idic.Value; fNotEqual = false; for(int i=0;i<btTemp.Length; i++) { if(btTemp[i]!=ubArr5[i]) fNotEqual = true; } if(!fNotEqual) statusBits = statusBits | 0x10; } else if(idic.Key.Equals("key 6")) { btTemp = (byte[])idic.Value; fNotEqual = false; for(int i=0;i<btTemp.Length; i++) { if(btTemp[i]!=ubArr6[i]) fNotEqual = true; } if(!fNotEqual) statusBits = statusBits | 0x20; } } resultBits = 0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20; iCountTestcases++; if(statusBits != resultBits) { iCountErrors++; printerr("Error_238fh! The names are incorrect, StatusBits=="+statusBits); } strLoc = "Loc_t0dds"; iCountTestcases++; if(idic.MoveNext()) { iCountErrors++; printerr("Error_2398r! , There shouldn't have been more elementes : GetValue=="+idic.Value); } resReader.Close(); strLoc = "Loc_957fd"; } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
private void DoThings() { String[] bogusHeaders; ResourceWriter resWriter; CultureInfo culture; NumberFormatInfo numInfo; StreamWriter xmlwriter; XmlTextWriter myXmlTextWriter; resWriter = new ResourceWriter(resourceBaseName + ".resources"); resWriter.AddResource(resCultures, cultures); for(int iCul = 0; iCul<cultures.Length; iCul++){ culture = cultures[iCul]; numInfo = NumberFormatInfo.GetInstance(culture); if(verbose) Console.WriteLine(culture); if(verbose) Console.WriteLine("Numerical values and its formats"); bogusHeaders = new String[numericalFormats.Length]; for(int i=0; i<bogusHeaders.Length; i++){ bogusHeaders[i] = "AA_" + i; } if(iCul==0){ GenerateXmlSchema(bogusHeaders, strInt); } xmlwriter = File.CreateText(xmlDataFile + "_" + strInt + "_" + culture.ToString() + ".xml"); myXmlTextWriter = new XmlTextWriter(xmlwriter); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartElement("NewDataSet"); WriteRealHeaders(myXmlTextWriter, bogusHeaders, numericalFormats); WriteValues(myXmlTextWriter, NumberType.Int, bogusHeaders, numericalFormats, numInfo); WriteDataToResourceFile(strInt, resWriter, culture); if(verbose) Console.WriteLine("Decimal values and its formats"); bogusHeaders = new String[decimalFormats.Length]; for(int i=0; i<bogusHeaders.Length; i++){ bogusHeaders[i] = "AA_" + i; } if(iCul==0){ GenerateXmlSchema(bogusHeaders, strDec); } xmlwriter = File.CreateText(xmlDataFile + "_" + strDec + "_" + culture.ToString() + ".xml"); myXmlTextWriter = new XmlTextWriter(xmlwriter); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartElement("NewDataSet"); WriteRealHeaders(myXmlTextWriter, bogusHeaders, decimalFormats); WriteValues(myXmlTextWriter, NumberType.Decimal, bogusHeaders, decimalFormats, numInfo); WriteDataToResourceFile(strDec, resWriter, culture); if(verbose) Console.WriteLine("Double values and its formats"); bogusHeaders = new String[doubleFormats.Length]; for(int i=0; i<bogusHeaders.Length; i++){ bogusHeaders[i] = "AA_" + i; } if(iCul==0){ GenerateXmlSchema(bogusHeaders, strDbl); } xmlwriter = File.CreateText(xmlDataFile + "_" + strDbl + "_" + culture.ToString() + ".xml"); myXmlTextWriter = new XmlTextWriter(xmlwriter); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartElement("NewDataSet"); WriteRealHeaders(myXmlTextWriter, bogusHeaders, doubleFormats); WriteValues(myXmlTextWriter, NumberType.Double, bogusHeaders, doubleFormats, numInfo); WriteDataToResourceFile(strDbl, resWriter, culture); if(verbose) Console.WriteLine("Picture values and its formats"); GoDoPictureFormatting(culture, resWriter); } resWriter.Generate(); resWriter.Close(); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; ResourceWriter writer; ThreadStart tdst1; Thread[] thdPool; Boolean fLoopExit; try { do { iCountTestcases++; if(File.Exists(Environment.CurrentDirectory+"\\Co3878_A.resources")) File.Delete(Environment.CurrentDirectory+"\\Co3878_A.resources"); writer = new ResourceWriter("Co3878_A.resources"); for(int i=0; i<iNumberOfStringsInFile; i++) writer.AddResource("Key " + i, "Value " + i); writer.Generate(); writer.Close(); iThreadsCompleted = 0; thdPool = new Thread[iNumberOfThreads]; for(int i=0; i<iNumberOfThreads; i++){ tdst1 = new ThreadStart(this.RSMangerForEachThread); thdPool[i] = new Thread(tdst1); } for(int i=0; i<iNumberOfThreads; i++){ thdPool[i].Start(); } do { int numberAlive = 0; fLoopExit = false; Thread.Sleep(100); for(int i=0; i<iNumberOfThreads; i++){ if(thdPool[i].IsAlive) { fLoopExit = true; numberAlive ++; } } }while(fLoopExit); if(iThreadsCompleted != iNumberOfThreads){ iCountErrors++; Console.WriteLine("Err_67423csd! All the thrads didn't execute the function. Expected, " + iNumberOfThreads + " completed, " + iThreadsCompleted); } iCountTestcases++; if(File.Exists(Environment.CurrentDirectory+"\\Co3878_B.resources")) File.Delete(Environment.CurrentDirectory+"\\Co3878_B.resources"); writer = new ResourceWriter("Co3878_B.resources"); for(int i=0; i<iNumberOfStringsInFile; i++) writer.AddResource("Key " + i, "Value " + i); writer.Generate(); writer.Close(); manager = ResourceManager.CreateFileBasedResourceManager("Co3878_B", Environment.CurrentDirectory, null); iThreadsCompleted = 0; thdPool = new Thread[iNumberOfThreads]; for(int i=0; i<iNumberOfThreads; i++){ tdst1 = new ThreadStart(this.RSMangerForAllThreads); thdPool[i] = new Thread(tdst1); } for(int i=0; i<iNumberOfThreads; i++){ thdPool[i].Start(); } do { fLoopExit = false; Thread.Sleep(100); for(int i=0; i<iNumberOfThreads; i++){ if(thdPool[i].IsAlive) fLoopExit = true; } }while(fLoopExit); if(iThreadsCompleted != iNumberOfThreads){ iCountErrors++; Console.WriteLine("Err_7539cd! All the threads didn't execute the function. Expected, " + iNumberOfThreads + " completed, " + iThreadsCompleted); } manager.ReleaseAllResources(); } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
private void DoThings() { String[] bogusHeaders; ResourceWriter resWriter; String[] dateInfoCustomFormats; Hashtable dupTable; CultureInfo culture; DateTimeFormatInfo dateInfo; StreamWriter xmlwriter; XmlTextWriter myXmlTextWriter; Calendar otherCalendar; Calendar gregorian; Hashtable calendars; String[] tempFormats; calendars = new Hashtable(); calendars.Add(0x0401, new HijriCalendar()); calendars.Add(0x0404, new TaiwanCalendar()); calendars.Add(0x040D, new HebrewCalendar()); calendars.Add(0x0411, new JapaneseCalendar()); calendars.Add(0x0412, new KoreanCalendar()); calendars.Add(0x041E, new ThaiBuddhistCalendar()); otherCalendar = null; gregorian = new GregorianCalendar(); resWriter = new ResourceWriter(resourceBaseName + ".resources"); resWriter.AddResource(resCultures, cultures); WriteXMLForCultures(cultures); for(int iCul = 0; iCul<cultures.Length; iCul++) { culture = cultures[iCul]; dateInfo = DateTimeFormatInfo.GetInstance(culture); try { otherCalendar = (Calendar)calendars[culture.LCID]; } catch { } bogusHeaders = new String[formalFormats.Length]; for(int i=0; i<bogusHeaders.Length; i++) { bogusHeaders[i] = "AA_" + i; } if(iCul==0) { GenerateXmlSchema(bogusHeaders, fileFormalFormats, false, culture); } if(calendars.ContainsKey(culture.LCID)) { xmlwriter = File.CreateText(xmlDataFile + "_" + fileFormalFormats + "_" + culture.ToString() + "_" + otherCalendarString + ".xml"); myXmlTextWriter = new XmlTextWriter(xmlwriter); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartElement("NewDataSet"); tempFormats = new String[formalFormats.Length]; formalFormats.CopyTo(tempFormats, 0); for(int i=0; i<tempFormats.Length; i++) { if(Char.IsUpper(tempFormats[i][0])) tempFormats[i] = tempFormats[i] + " "; } WriteRealHeaders(myXmlTextWriter, bogusHeaders, tempFormats); WriteValues(myXmlTextWriter, bogusHeaders, formalFormats, culture, otherCalendar); WriteDataToResourceFile(fileFormalFormats, resWriter, culture, false, true); } xmlwriter = File.CreateText(xmlDataFile + "_" + fileFormalFormats + "_" + culture.ToString() + ".xml"); myXmlTextWriter = new XmlTextWriter(xmlwriter); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartElement("NewDataSet"); tempFormats = new String[formalFormats.Length]; formalFormats.CopyTo(tempFormats, 0); for(int i=0; i<tempFormats.Length; i++) { if(Char.IsUpper(tempFormats[i][0])) tempFormats[i] = tempFormats[i] + " "; } WriteRealHeaders(myXmlTextWriter, bogusHeaders, tempFormats); WriteValues(myXmlTextWriter, bogusHeaders, formalFormats, culture, gregorian); WriteDataToResourceFile(fileFormalFormats, resWriter, culture, false, false); dateInfoCustomFormats = DateTimeFormatInfo.GetInstance(culture).GetAllDateTimePatterns(); dupTable = new Hashtable(); for(int i=0; i<dateInfoCustomFormats.Length; i++) { try { dupTable.Add(dateInfoCustomFormats[i], null); } catch { } } dateInfoCustomFormats = new String[dupTable.Count]; Int32 iTemp1=0; foreach(String strN in dupTable.Keys) dateInfoCustomFormats[iTemp1++] = strN; bogusHeaders = new String[dateInfoCustomFormats.Length]; for(int i=0; i<bogusHeaders.Length; i++) { bogusHeaders[i] = "AA_" + i; } GenerateXmlSchema(bogusHeaders, fileDateTimePatterns, true, culture); if(calendars.ContainsKey(culture.LCID)) { xmlwriter = File.CreateText(xmlDataFile + "_" + fileDateTimePatterns + "_" + culture.ToString() + "_" + otherCalendarString + ".xml"); myXmlTextWriter = new XmlTextWriter(xmlwriter); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartElement("NewDataSet"); WriteRealHeaders(myXmlTextWriter, bogusHeaders, dateInfoCustomFormats); WriteValues(myXmlTextWriter, bogusHeaders, dateInfoCustomFormats, culture, otherCalendar); WriteDataToResourceFile(fileDateTimePatterns, resWriter, culture, true, true); } xmlwriter = File.CreateText(xmlDataFile + "_" + fileDateTimePatterns + "_" + culture.ToString() + ".xml"); myXmlTextWriter = new XmlTextWriter(xmlwriter); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartElement("NewDataSet"); WriteRealHeaders(myXmlTextWriter, bogusHeaders, dateInfoCustomFormats); WriteValues(myXmlTextWriter, bogusHeaders, dateInfoCustomFormats, culture, gregorian); WriteDataToResourceFile(fileDateTimePatterns, resWriter, culture, true, false); bogusHeaders = new String[ourOwnCustomFormats.Length]; for(int i=0; i<bogusHeaders.Length; i++) { bogusHeaders[i] = "AA_" + i; } if(iCul==0) { GenerateXmlSchema(bogusHeaders, fileCustomFormats, false, culture); } if(calendars.ContainsKey(culture.LCID)) { xmlwriter = File.CreateText(xmlDataFile + "_" + fileCustomFormats + "_" + culture.ToString() + "_" + otherCalendarString + ".xml"); myXmlTextWriter = new XmlTextWriter(xmlwriter); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartElement("NewDataSet"); tempFormats = new String[ourOwnCustomFormats.Length]; ourOwnCustomFormats.CopyTo(tempFormats, 0); for(int i=0; i<tempFormats.Length; i++) { if(ourOwnCustomFormats[i]=="DD") tempFormats[i] = tempFormats[i] + " "; } WriteRealHeaders(myXmlTextWriter, bogusHeaders, tempFormats); WriteValues(myXmlTextWriter, bogusHeaders, ourOwnCustomFormats, culture, otherCalendar); WriteDataToResourceFile(fileCustomFormats, resWriter, culture, false, true); } xmlwriter = File.CreateText(xmlDataFile + "_" + fileCustomFormats + "_" + culture.ToString() + ".xml"); myXmlTextWriter = new XmlTextWriter(xmlwriter); myXmlTextWriter.Formatting = Formatting.Indented; myXmlTextWriter.WriteStartElement("NewDataSet"); tempFormats = new String[ourOwnCustomFormats.Length]; ourOwnCustomFormats.CopyTo(tempFormats, 0); for(int i=0; i<tempFormats.Length; i++) { if(ourOwnCustomFormats[i]=="DD") tempFormats[i] = tempFormats[i] + " "; } WriteRealHeaders(myXmlTextWriter, bogusHeaders, tempFormats); WriteValues(myXmlTextWriter, bogusHeaders, ourOwnCustomFormats, culture, gregorian); WriteDataToResourceFile(fileCustomFormats, resWriter, culture, false, false); } resWriter.Generate(); resWriter.Close(); }
/// <summary> /// This method generates resource files directly using the ResourceWriter class. /// </summary> public void GenerateResourceFiles() { // Generate the New Zealand resource file. ResourceWriter rw = new ResourceWriter(EN_NZRESFILE); rw.AddResource("promptValidDeg", "Please enter a viable outside temperature (-100 to 60)."); rw.AddResource("dist1", "(in kilometres) ==>"); rw.AddResource("degree1", "in Celsius ==>"); rw.AddResource("degree2", "-100"); rw.AddResource("degree3", "60"); rw.Generate(); rw.Close(); Console.WriteLine("Generating resource file: {0}", EN_NZRESFILE); // Generate the Germand resource file. rw = new ResourceWriter(DERESFILE); rw.AddResource("promptName", "Geben Sie Ihren Namen ein ==>"); rw.AddResource("promptAge", "Geben Sie Ihr Alter ein ==>"); rw.AddResource("promptDegrees", "Geben Sie die aktuelle Temperatur ein,"); rw.AddResource("promptMissing", "Stellen Sie sicher, dass Sie einen gültigen Wert eingeben."); rw.AddResource("promptValidAge", "Geben Sie ein gültiges Alter für einen Erwachsenen ein (15 und älter)."); rw.AddResource("promptDist", "Geben Sie an, wie weit Sie zur Arbeit fahren"); rw.AddResource("promptValidDist", "Geben Sie einen gültigen Abstand ein (größer als Null)."); rw.AddResource("promptValidDeg", "Geben Sie eine Außentemperatur ein (-60C bis 60F)."); rw.AddResource("promptEntries", "Sie trugen die folgenden Informationen ein:"); rw.AddResource("dist1", "(in den Kilometern) ==>"); rw.AddResource("degree1", "in Celsius ==>"); rw.AddResource("degree2", "-60"); rw.AddResource("degree3", "60"); rw.AddResource("outputName", "Name:"); rw.AddResource("outputAge", "Alter:"); rw.AddResource("outputDegrees", "Temperatur:"); rw.AddResource("outputDist", "Abstand Zur Arbeit:"); rw.Generate(); rw.Close(); Console.WriteLine("Generating resource file: {0}", DERESFILE); }//GenerateResourceFiles()
/// <remarks> /// Builds resource files out of the ResAsm format /// </remarks> static void Assemble(string pattern) { string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), pattern); int linenr = 0; foreach (string file in files) { try { StreamReader reader = new StreamReader(file, new UTF8Encoding()); string resfilename = Path.GetFileNameWithoutExtension(file) + ".resources"; ResourceWriter rw = new ResourceWriter(resfilename); linenr = 0; while (true) { string line = reader.ReadLine(); linenr++; if (line == null) { break; } line = line.Trim(); // skip empty or comment lines if (line.Length == 0 || line[0] == '#') { continue; } // search for a = char int idx = line.IndexOf('='); if (idx < 0) { Console.WriteLine("error in file " + file + " at line " + linenr); continue; } string key = line.Substring(0, idx).Trim(); string val = line.Substring(idx + 1).Trim(); object entryval = null; if (val[0] == '"') { // case 1 : string value val = val.Trim(new char[] {'"'}); StringBuilder tmp = new StringBuilder(); for (int i = 0; i < val.Length; ++i) { switch (val[i]) { // handle the \ char case '\\': ++i; if (i < val.Length) switch (val[i]) { case '\\': tmp.Append('\\'); break; case 'n': tmp.Append('\n'); break; case '\"': tmp.Append('\"'); break; } break; default: tmp.Append(val[i]); break; } } entryval = tmp.ToString(); } else { // case 2 : no string value -> load resource entryval = LoadResource(val); } rw.AddResource(key, entryval); } rw.Generate(); rw.Close(); reader.Close(); } catch (Exception e) { Console.WriteLine("Error in line " + linenr); Console.WriteLine("Error while processing " + file + " :"); Console.WriteLine(e.ToString()); } } }
private static void CreateResourceFile( string csFile, string resFile, string outputDir, out string sourceHash, out int viewCount) { viewCount = -1; sourceHash = string.Empty; var codeProvider = new CSharpCodeProvider(); var inMemoryCodeCompiler = codeProvider.CreateCompiler(); var parameters = new CompilerParameters(); parameters.ReferencedAssemblies.Add("System.Data.Entity.dll"); parameters.GenerateInMemory = true; CompilerResults results = inMemoryCodeCompiler.CompileAssemblyFromFile(parameters, csFile); if (results.Errors.Count == 0) { Assembly resultingAssembly = results.CompiledAssembly; Type[] typeList = resultingAssembly.GetTypes(); foreach (Type type in typeList) { if (type.BaseType == typeof(EntityViewContainer)) { MethodInfo[] methodInfo = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance); var instance = (EntityViewContainer)Activator.CreateInstance(type); sourceHash = instance.HashOverAllExtentViews; viewCount = instance.ViewCount; using (var resWriter = new ResourceWriter(Path.Combine(outputDir, resFile))) { foreach (MethodInfo method in methodInfo) { if (char.IsDigit(method.Name, method.Name.Length - 1)) { var result = (KeyValuePair<string, string>)method.Invoke(instance, null); resWriter.AddResource(method.Name.Replace("GetView", string.Empty), result); } } resWriter.Generate(); resWriter.Close(); } } } } else { Console.WriteLine("Unable to Generate Resource File"); } }