Dispose() public method

public Dispose ( ) : void
return void
        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 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();
                         });
                 }
             }
         });
 }
Example #3
0
		static void Main(string[] args) {

			string dataDirectory = args[0];
			string targetFile = args[1];

			XmlDocument map = new XmlDocument();
			XmlNode xFilesNode = map.CreateElement("Files");
			ResourceWriter writer = new ResourceWriter(targetFile);

			foreach (string file in Directory.GetFiles(dataDirectory, "*", SearchOption.AllDirectories)) {

				XmlNode xFile = map.CreateElement("File");
				string id = Guid.NewGuid().ToString();
				string targetDirectory = Path.GetDirectoryName(file).Replace(dataDirectory, "");
				if (targetDirectory.StartsWith("\\"))
					targetDirectory = targetDirectory.Substring(1);

				xFile.AppendChild(createNode(map, "Id", id));
				xFile.AppendChild(createNode(map, "Directory", targetDirectory)); ;
				xFile.AppendChild(createNode(map, "Filename", Path.GetFileName(file)));
				xFilesNode.AppendChild(xFile);

				writer.AddResourceData(id, "setupData", Compress(File.ReadAllBytes(file)));
				
			}

			map.AppendChild(xFilesNode);
			using (MemoryStream msData = new MemoryStream()) {
				using (StreamWriter sw = new StreamWriter(msData, Encoding.UTF8)) {
					map.Save(sw);
					writer.AddResourceData("map", "setupData", msData.ToArray());
				}
			}

			writer.Generate();
			writer.Dispose();
		}
		[Test] // bug #82566
		public void WriteEnum ()
		{
			MemoryStream ms = new MemoryStream ();

			ResourceWriter writer = new ResourceWriter (ms);
			writer.AddResource ("Targets", AttributeTargets.Assembly);
			writer.Generate ();

			ms.Position = 0;

			bool found = false;

			ResourceReader reader = new ResourceReader (ms);
			foreach (DictionaryEntry de in reader) {
				string name = de.Key as string;
				Assert.IsNotNull (name, "#1");
				Assert.AreEqual ("Targets", name, "#2");
				Assert.IsNotNull (de.Value, "#3");
				Assert.AreEqual (AttributeTargets.Assembly, de.Value, "#4");
				found = true;
			}

			Assert.IsTrue (found, "#5");

			writer.Dispose ();
		}
 public static void ExceptionforResWriter05()
 {
     Assert.Throws<InvalidOperationException>(() =>
         {
             byte[] buffer = new byte[_RefBuffer.Length];
             using (var ms2 = new MemoryStream(buffer, true))
             {
                 var rw1 = new ResourceWriter(ms2);
                 rw1.AddResource("key2", "args");
                 rw1.Dispose();
                 rw1.AddResource("key2", "args");
             }
         });
 }
 public static void ExceptionforResWriter06()
 {
     Assert.Throws<ArgumentOutOfRangeException>(() =>
         {
             byte[] buffer = new byte[_RefBuffer.Length];
             using (var ms2 = new MemoryStream(buffer, true))
             {
                 var rw1 = new ResourceWriter(ms2);
                 try
                 {
                     rw1.Generate();
                 }
                 finally
                 {
                     Assert.Throws<NotSupportedException>(() =>
                         {
                             rw1.Dispose();
                         });
                 }
             }
         });
 }
		string CompileResource (AppResourceFileInfo arfi, bool local)
		{
			string path = arfi.Info.FullName;
			string rname = Path.GetFileNameWithoutExtension (path) + ".resources";
			if (!local)
				rname = "Resources." + rname;
			
			string resource = Path.Combine (TempDirectory, rname);
			FileStream source = null, destination = null;
			IResourceReader reader = null;
			ResourceWriter writer = null;

			try {
				source = new FileStream (path, FileMode.Open, FileAccess.Read);
				destination = new FileStream (resource, FileMode.Create, FileAccess.Write);
				reader = GetReaderForKind (arfi.Kind, source, path);
				writer = new ResourceWriter (destination);
				foreach (DictionaryEntry de in reader) {
					object val = de.Value;
					if (val is string)
						writer.AddResource ((string)de.Key, (string)val);
					else
						writer.AddResource ((string)de.Key, val);
				}
			} catch (Exception ex) {
				throw new HttpException ("Failed to compile resource file", ex);
			} finally {
				if (reader != null)
					reader.Dispose ();
				if (source != null)
					source.Dispose ();
				if (writer != null)
					writer.Dispose ();
				if (destination != null)
					destination.Dispose ();
			}
			
			return resource;
		}