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(); }
private static void CreateResource() { FileStream stream = File.OpenWrite(ResourceFile); using (var writer = new ResourceWriter(stream)) { writer.AddResource("Title", "Professional C#"); writer.AddResource("Author", "Christian Nagel"); writer.AddResource("Publisher", "Wrox Press"); writer.Generate(); } }
public static void ExceptionforResWriter04() { Assert.Throws<ArgumentException>(() => { byte[] buffer = new byte[_RefBuffer.Length]; using (var ms2 = new MemoryStream(buffer, true)) { using (var rw1 = new ResourceWriter(ms2)) { rw1.AddResource("key1", "args"); rw1.AddResource("key1", "args"); } } }); }
private static void WriteResourceFile(string resxFilePath) { using (var fs = File.OpenRead(resxFilePath)) { var document = XDocument.Load(fs); var binDirPath = Path.Combine(Path.GetDirectoryName(resxFilePath), "bin"); if (!Directory.Exists(binDirPath)) { Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(resxFilePath), "bin")); } // Put in "bin" sub-folder of resx file var targetPath = Path.Combine(binDirPath, Path.ChangeExtension(Path.GetFileName(resxFilePath), ".resources")); using (var targetStream = File.Create(targetPath)) { var rw = new ResourceWriter(targetStream); foreach (var e in document.Root.Elements("data")) { var name = e.Attribute("name").Value; var value = e.Element("value").Value; rw.AddResource(name, value); } rw.Generate(); } } }
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(); } }
/// <summary> /// Build .resx file to .resource /// </summary> /// <param name="input"></param> /// <param name="output"></param> public static void Build(string input) { var resxs = Directory.GetFiles(input, "*.resx"); foreach (var resxFile in resxs) { var binFile = Path.GetDirectoryName(resxFile) +"\\"+ Path.GetFileNameWithoutExtension(resxFile) + ".resources"; if (File.Exists(binFile)) { var resxFileInfo = new FileInfo(resxFile); var binFileInfo = new FileInfo(binFile); if (resxFileInfo.LastWriteTime > binFileInfo.LastWriteTime) File.Delete(binFile); //Re-complied } if (!File.Exists(binFile)) { using (var reader = new ResXResourceReader(resxFile)) { using (var writer = new ResourceWriter(binFile)) { foreach (DictionaryEntry d in reader) { writer.AddResource(d.Key.ToString(), d.Value); } } } } } }
public void Run() { Catalog catalog = new Catalog(); foreach(string fileName in Options.InputFiles) { Catalog temp = new Catalog(); temp.Load(fileName); catalog.Append(temp); } using (ResourceWriter writer = new ResourceWriter(Options.OutFile)) { foreach (CatalogEntry entry in catalog) { try { writer.AddResource(entry.Key, entry.IsTranslated ? entry.GetTranslation(0) : entry.String); } catch (Exception e) { string message = String.Format("Error adding item {0}", entry.String); if (!String.IsNullOrEmpty(entry.Context)) message = String.Format("Error adding item {0} in context '{1}'", entry.String, entry.Context); throw new Exception(message, e); } } writer.Generate(); } }
public void SystemResourceTests_Should_WriteUpdateValueToResx() { var filename = Path.Combine(TestContext.TestRunDirectory, Guid.NewGuid().ToString() + ".resx"); var inputData = "TheInputData"; using (ResourceWriter w = new ResourceWriter(filename)) { w.AddResource("InvariantName", inputData); w.Generate(); } inputData = "TheUpdatedInputData"; using (ResourceWriter w = new ResourceWriter(filename)) { w.AddResource("InvariantName", inputData); w.Generate(); } var data = string.Empty; using( var r = new ResourceReader(filename)) { var rr = r.GetEnumerator(); rr.MoveNext(); data = rr.Value as string; } Assert.IsTrue(inputData == data); }
/// <summary> /// 写入 英文 资源文件. /// </summary> public void WriteEnglishResource() { // 构造写入器. ResourceWriter rw = new ResourceWriter("English.resource"); rw.AddResource("Hello", "Hello"); rw.Close(); }
/// <summary> /// 写入 中文 资源文件. /// </summary> public void WriteChinaResource() { // 构造写入器. ResourceWriter rw = new ResourceWriter("China.resource"); rw.AddResource("Hello", "你好"); rw.Close(); }
public void BuildResource(string outputPath) { using (ResourceWriter w1 = new ResourceWriter(outputPath)) { foreach (Item item in _items) w1.AddResource(item.Name, item.Value); } }
private static Stream MakeResourceStream() { var stream = new MemoryStream(); var resourceWriter = new ResourceWriter(stream); resourceWriter.AddResource("TestName", "value"); resourceWriter.Generate(); stream.Position = 0; return stream; }
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(); }
static void Main(string[] args) { var getopt = new Getopt(Assembly.GetExecutingAssembly().GetName().Name, args, "i:o:") { Opterr = false }; string input = null; string output = null; int option; while (-1 != (option = getopt.getopt())) { switch (option) { case 'i': input = getopt.Optarg; break; case 'o': output = getopt.Optarg; break; default: PrintUsage(); return; } } if (input == null || output == null) { PrintUsage(); return; } try { if (!File.Exists(input)) { Console.WriteLine("File {0} not found", input); return; } Dictionary<string, string> entries; var parser = new PoParser(); using (var reader = new StreamReader(input)) { entries = parser.ParseIntoDictionary(reader); } using (var writer = new ResourceWriter(output)) { foreach (var kv in entries) { try { writer.AddResource(kv.Key, kv.Value); } catch (Exception e) { Console.WriteLine("Error adding item {0}: {1}", kv.Key, e.Message); } } writer.Generate(); } } catch (Exception ex) { Console.WriteLine("Error during execution: {0}", ex.Message); return; } }
public static void InsertEmployee(ResourceObj emp) { l.Add(emp); ResourceWriter rsxw = new ResourceWriter(path); for (int i = 0; i < l.Count; i++) { rsxw.AddResource("obj" + i.ToString(), l[i]); } rsxw.Close(); }
public void AddItem(string entity, string key, string value, string culture) { var filename = GetResourceFilename(entity, culture); using (var writer = new ResourceWriter(filename)) { writer.AddResource(key, value); writer.Generate(); } }
void GenerationData(int countOfObj) { Random rand = new Random(); ResourceWriter rsxw = new ResourceWriter(Server.MapPath("~/Resources/") + "res.resx"); for (int i = 0; i < countOfObj; i++) { rsxw.AddResource("obj" + i.ToString(), new ResourceObj(rand)); } rsxw.Close(); }
public bool Process(AssemblyDefinition containingAssembly, Res resource, ResReader resourceReader, ResourceWriter resourceWriter) { if (!resource.IsString) return false; string content = (string)resourceReader.GetObject(resource); content = _repackContext.FixStr(content); resourceWriter.AddResource(resource.name, content); return true; }
// Read all msgid/msgstr pairs, register them in the ResourceWriter, // and write the binary contents to the output stream. private void ReadAllInput (ResourceWriter rw) { for (;;) { String msgid = ReadString(); if (msgid == null) break; String msgstr = ReadString(); if (msgstr == null) break; rw.AddResource(msgid, msgstr); } rw.Generate(); }
Process( string filename, ResourceWriter writer ) { string name = this.GetLocalFilename( filename ); byte[] data = ReadAllBytes( filename ); WriteLine( String.Format( "Adding as byte[] named '{0}'", name ) ); writer.AddResource( name, data ); return true; }
public static ResourceWriter GenerateResourceStream(Dictionary<string, string> inp_dict, MemoryStream ms) { ResourceWriter rw = new ResourceWriter(ms); foreach (KeyValuePair<string, string> e in inp_dict) { string name = e.Key; string values = e.Value; rw.AddResource(name, values); } rw.Generate(); ms.Seek(0L, SeekOrigin.Begin); return rw; }
/// <summary> /// Creates a resources file with an image /// </summary> /// <param name="imageSourcePath"></param> /// <param name="outputPath"></param> public static void WriteImageResource(string imageSourcePath, string outputPath) { Debug.Assert(imageSourcePath.EndsWith(".png")); Debug.Assert(outputPath.EndsWith(".resources")); FileInfo fileInfo = new FileInfo(imageSourcePath); FileStream fsSource = fileInfo.OpenRead(); byte[] bytes = new byte[fileInfo.Length + 1]; int bytesRead = fsSource.Read(bytes, 0, bytes.Length); Debug.Assert(bytesRead == fileInfo.Length); MemoryStream memoryStream = new MemoryStream(bytes, 0, bytesRead); ResourceWriter resw = new ResourceWriter(outputPath); resw.AddResource(imageSourcePath.ToLowerInvariant(), memoryStream); resw.Close(); }
private static void WriteResourcesFile(Stream outfs, IEnumerable<XElement> data) { var rw = new ResourceWriter(outfs); foreach (var e in data) { var name = e.Attribute("name").Value; var value = e.Element("value").Value; rw.AddResource(name, value); } rw.Generate(); }
public static void UpdateEmployee(ASP_ex5.ResourceObj emp) { ResourceWriter rsxw = new ResourceWriter(path); for (int i = 0; i < l.Count; i++) { if (l[i].key == emp.key) { l[i].comment = emp.comment; l[i].key = emp.key; l[i].value = emp.value; } rsxw.AddResource("obj" + i.ToString(), l[i]); } rsxw.Close(); }
public static void GenerateResources(string filePath) { // Create a resource writer. using (IResourceWriter rw = new ResourceWriter("app.resources")) { // Add resources to the file. var imageFiles = Directory.GetFiles(filePath); foreach (var imageFile in imageFiles) { var image = System.Drawing.Image.FromFile(imageFile) as Bitmap; var fileInfo = new FileInfo(imageFile); var name = fileInfo.Name.Split('.')[0]; rw.AddResource(name, image); } } }
Process( string filename, ResourceWriter writer ) { string name; string local = this.GetLocalFilename( filename ); if( !local.EndsWith( SUFFIX ) ) return false; name = local.Substring( 0, (local.Length-SUFFIX.Length) ); string data = ReadAllText( filename ); WriteLine( String.Format( "Adding as string named '{0}'", name ) ); writer.AddResource( name, data ); return true; }
private static IEnumerable<string> GenerateEmbeddedResources(IEnumerable<ScaffoldedMigration> scaffoldedMigrations, string @namespace) { foreach (var scaffoldedMigration in scaffoldedMigrations) { var className = GetClassName(scaffoldedMigration.MigrationId); var embededResource = Path.Combine( Path.GetTempPath(), @namespace + "." + className + ".resources"); using (var writer = new ResourceWriter(embededResource)) { scaffoldedMigration .Resources .Each(e => writer.AddResource(e.Key, e.Value)); } yield return embededResource; } }
private static void WriteResourcesFile(string resxFilePath, string outputFile) { using (var fs = File.OpenRead(resxFilePath)) using (var outfs = File.Create(outputFile)) { var document = XDocument.Load(fs); var rw = new ResourceWriter(outfs); foreach (var e in document.Root.Elements("data")) { string name = e.Attribute("name").Value; string value = e.Element("value").Value; rw.AddResource(name, value); } rw.Generate(); } }
public static void InsertEmployee(string key, string value, string comment) { bool temp = false; for (int i = 0; i < l.Count; i++) { if (l[i].key == key) { temp = true; } } if(temp ==false) l.Add(new ResourceObj(key, value, comment)); ResourceWriter rsxw = new ResourceWriter(path); for (int i = 0; i < l.Count; i++) { rsxw.AddResource("obj" + i.ToString(), l[i]); } rsxw.Close(); }
private void Comp() { if (radioButton1.Checked == true) { System.Resources.ResourceWriter w = new System.Resources.ResourceWriter("res.resources"); //Declaration du nouvelle ressource w.AddResource("file", Cryptoclass.DexEncrypt(System.IO.File.ReadAllBytes(textBox1.Text), this.key)); // lit tout les bytes du fichier source, les encrypt, et les ajout dans la ressource w.Close(); } if (radioButton2.Checked == true) { System.Resources.ResourceWriter w = new System.Resources.ResourceWriter("res.resources"); //Declaration du nouvelle ressource w.AddResource("file", Cryptoclass.RC4EncryptDecrypt(System.IO.File.ReadAllBytes(textBox1.Text), this.key)); // lit tout les bytes du fichier source, les encrypt, et les ajout dans la ressource w.Close(); } if (radioButton4.Checked == true) { System.Resources.ResourceWriter w = new System.Resources.ResourceWriter("res.resources"); //Declaration du nouvelle ressource w.AddResource("file", Cryptoclass.RijndaelEncrypt(System.IO.File.ReadAllBytes(textBox1.Text), this.key)); // lit tout les bytes du fichier source, les encrypt, et les ajout dans la ressource w.Close(); } }
private void InitBarManager() { //string[] strMenus = { "系统管理", "会员管理", "财务管理", "报表管理", "基础资料", "货品管理", "客户管理", "物流管理" }; //Utils.ImageCollection largeImgs; var query = CacheInfo.listMenuInfoModel().Where(p => p.MenuBig == true).ToList(); if (query == null || query.Count() == 0) { return; } string imagePath = Application.StartupPath + "\\TempImage"; int imgindex = 0; string fileName = string.Empty; foreach (var model in query) { if (model.MenuBigImage == null) { return; } //添加图标到资源文件 fileName = string.Format("{0}.png", model.MenuFrmName); ImageTools.CreateImage(imagePath, fileName, model.MenuBigImage); System.Resources.IResourceWriter rw = new System.Resources.ResourceWriter("Resource.resx"); rw.AddResource(model.MenuFrmName, (Image)Image.FromStream(new MemoryStream(model.MenuBigImage)).Clone());//Image.FromFile( imagePath + "\\" + fileName) rw.Close(); //把资源文件中的图像添加到largeImgs中 this.largeImgs.Images.Add((Image)Image.FromStream(new MemoryStream(model.MenuBigImage)).Clone(), model.MenuFrmName); //this.largeImgs.Images.SetKeyName(imgindex, fileName); //创建大图标菜单 DevExpress.XtraBars.BarLargeButtonItem barLargeItem = new DevExpress.XtraBars.BarLargeButtonItem(barMain, model.MenuName); barLargeItem.LargeGlyph = largeImgs.Images[imgindex];//也可以设置 barLargeItem.LargeImageIndex,但是效果不是很好,可以试试 barLargeItem.Hint = model.MenuName; barLargeItem.Tag = model.MenuName; barTop.LinksPersistInfo.Add(new DevExpress.XtraBars.LinkPersistInfo(barLargeItem, true)); barMain.Items.Add(barLargeItem); imgindex++; } }
public static void ExceptionforResWriter03() { Assert.Throws<ArgumentNullException>(() => { byte[] buffer = new byte[_RefBuffer.Length]; using (var ms2 = new MemoryStream(buffer, true)) { var rw1 = new ResourceWriter(ms2); try { rw1.AddResource(null, "args"); } finally { Assert.Throws<ArgumentOutOfRangeException>(() => { rw1.Dispose(); }); } } }); }
public void writeToUnknownSink3(string pattern, string str) { System.Resources.ResourceWriter writer = new System.Resources.ResourceWriter(str); writer.AddResource(pattern, str); }
public void writeToUnknownSink(string key, string str) { System.Resources.ResourceWriter writer = new System.Resources.ResourceWriter(key); writer.AddResource(key, str); }