public static void ReadResource(int numberOfLeadingBytes)
        {
            var buffer = new byte[4096];
            using (var ms2 = new MemoryStream(buffer, true))
            {
                ms2.Write(new byte[numberOfLeadingBytes], 0, numberOfLeadingBytes);
                using (var rw = GenerateResourceStream(s_dict, ms2))
                {
                    //Rewind to begining of stream

                    ms2.Seek(numberOfLeadingBytes, SeekOrigin.Begin);

                    var reder = new ResourceReader(ms2);

                    var s_found_list = new List<string>();
                    foreach (DictionaryEntry entry in reder)
                    {
                        string key = (string)entry.Key;
                        string value = (string)entry.Value;
                        string found = s_dict[key];
                        Assert.True(string.Compare(value, found) == 0, "expected: " + value + ", but got : " + found);
                        s_found_list.Add(key);
                    }

                    Assert.True(s_found_list.Count == s_dict.Count);
                }
            }
        }
 public static void ReturnNamedResourceAsWebPage(HttpMessage httpMessage, ISocketProxy socketProxy)
 {
     string destinationUrl = httpMessage.Headers.DestinationUrl().Substring(1);
     var resourceStream = new ResourceReader().GetResource(destinationUrl);
     var bytes = resourceStream.ReadFully();
     socketProxy.SendWebPage(Encoding.ASCII.GetString(bytes));
 }
        public void CanBuildTemplate()
        {
            var templateText = new ResourceReader().GetTextResource("CacheList.html");
            var parser = new MainPageTemplateParser(null, templateText, new List<CacheRecord>());

            var message = parser.GenerateContent();

            Console.WriteLine(message);

            Assert.That(message.Length, Is.GreaterThan(0));
        }
Beispiel #4
0
Datei: test.cs Projekt: mono/gert
	static int Main ()
	{
		string resXFile = Path.Combine (AppDomain.CurrentDomain.BaseDirectory,
			"Resources.resources");
		ResourceReader rr = new ResourceReader (resXFile);
		int i = 0;
		foreach (DictionaryEntry de in rr) {
			Bitmap bmp = null;
			switch (i) {
			case 0:
				if ("VIA vzw" != (string) de.Key)
					return 1;
				bmp = (Bitmap) de.Value;
#if NET_2_0
				if (bmp.Height != 32)
					return 2;
				if (bmp.Width != 32)
					return 3;
#else
				if (bmp.Height != 96)
					return 2;
				if (bmp.Width != 96)
					return 3;
#endif
				break;
			case 1:
				if ("dbs" != (string) de.Key)
					return 4;
				bmp = (Bitmap) de.Value;
				if (bmp.Height != 16)
					return 5;
				if (bmp.Width != 16)
					return 6;
				break;
			default:
				return 1;
			}
			i++;
		}
		if (i != 2)
			return 2;
		return 0;
	}
        private IHttpHandler FindHandler(HttpContext context)
        {
            var reader = new ResourceReader();
            var requestTypeName = GetRequestTypeName(context).ToLowerInvariant();
            var requestResourceName = GetRequestResourceName(requestTypeName, context.Request);

            switch (requestTypeName)
            {
                case "js":
                    return new JavaScriptHandler(reader, requestResourceName);
                case "css":
                    return new CssHandler(reader);
                case "jpg":
                case "gif":
                case "png":
                case "anyimage":    //testing only
                    return new ImageHandler(reader, requestResourceName);
                case "delete":
                    return new DeleteItemHandler(requestResourceName, new MainPageHandler(reader)); //not too happy about a GET doing this, but ok for now.
                default:
                    return new MainPageHandler(reader);
                    //return new DefaultHttpHandler(); TODO: when you get bored, wtf is DefaultHttpHandler
            }
        }
        public static void Exception_Corrupted_resources()
        {
            byte[] _RefBuffer12 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 16, 0, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 1, 6, 118, 97, 108, 117, 101, 50 };
            using (var ms2 = new MemoryStream(_RefBuffer12))
            {
                using (var reader = new ResourceReader(ms2))
                {

                    var s_found_list = new List<string>();
                    Assert.Throws<FormatException>(() =>
                    {
                        foreach (DictionaryEntry entry in reader)
                        {
                            string key = (string)entry.Key;
                            s_found_list.Add(key);
                        }
                    });
                }
            }
        }
        public static void Exception_incorrect_magic_number()
        {
            using (var ms2 = new MemoryStream())
            {
                using (var rw = GenerateResourceStream(s_dict, ms2))
                {
                    ms2.Seek(0L, SeekOrigin.Begin);
                    using (var bw = new BinaryWriter(ms2))
                    {
                        bw.Write(2000);//Our resource reader expects the ResourceManager magic number here

                        //  ms2.Seek(0L, SeekOrigin.Begin);
                        Assert.Throws<ArgumentException>(() =>
                        {
                            var resReader = new ResourceReader(ms2);
                        });
                    }
                }
            }
        }
        public static void ReadV1Resources()
        {
            //NOte: The below ByteStream was generated by V1 framework resource writer from the below dictionary
            byte[] _RefBuffer1 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 88, 0, 0, 0, 41, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 45, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 1, 0, 0, 0, 12, 0, 0, 0, 1, 0, 0, 0, 23, 83, 121, 115, 116, 101, 109, 46, 83, 116, 114, 105, 110, 103, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 129, 56, 148, 171, 124, 133, 198, 205, 9, 176, 129, 210, 193, 133, 199, 216, 245, 127, 11, 239, 60, 90, 212, 15, 202, 130, 229, 15, 241, 187, 198, 30, 88, 117, 120, 32, 253, 221, 196, 54, 242, 213, 88, 62, 206, 25, 176, 106, 0, 0, 0, 0, 47, 0, 0, 0, 108, 0, 0, 0, 153, 0, 0, 0, 216, 0, 0, 0, 255, 0, 0, 0, 76, 1, 0, 0, 155, 1, 0, 0, 186, 1, 0, 0, 251, 1, 0, 0, 62, 2, 0, 0, 129, 2, 0, 0, 146, 3, 0, 0, 42, 65, 0, 114, 0, 103, 0, 95, 0, 73, 0, 110, 0, 118, 0, 97, 0, 108, 0, 105, 0, 100, 0, 77, 0, 101, 0, 109, 0, 98, 0, 101, 0, 114, 0, 73, 0, 110, 0, 102, 0, 111, 0, 0, 0, 0, 0, 56, 73, 0, 110, 0, 118, 0, 97, 0, 108, 0, 105, 0, 100, 0, 79, 0, 112, 0, 95, 0, 71, 0, 101, 0, 116, 0, 73, 0, 100, 0, 68, 0, 105, 0, 102, 0, 102, 0, 70, 0, 114, 0, 111, 0, 109, 0, 77, 0, 101, 0, 109, 0, 73, 0, 100, 0, 59, 0, 0, 0, 40, 65, 0, 114, 0, 103, 0, 95, 0, 69, 0, 110, 0, 117, 0, 109, 0, 78, 0, 111, 0, 116, 0, 67, 0, 108, 0, 111, 0, 110, 0, 101, 0, 97, 0, 98, 0, 108, 0, 101, 0, 136, 0, 0, 0, 58, 65, 0, 114, 0, 103, 0, 95, 0, 84, 0, 97, 0, 114, 0, 103, 0, 101, 0, 116, 0, 78, 0, 111, 0, 116, 0, 86, 0, 97, 0, 108, 0, 105, 0, 100, 0, 70, 0, 111, 0, 114, 0, 73, 0, 82, 0, 101, 0, 102, 0, 108, 0, 101, 0, 99, 0, 116, 0, 170, 0, 0, 0, 34, 65, 0, 114, 0, 103, 0, 95, 0, 71, 0, 101, 0, 116, 0, 77, 0, 101, 0, 116, 0, 104, 0, 78, 0, 111, 0, 116, 0, 70, 0, 110, 0, 100, 0, 214, 0, 0, 0, 72, 78, 0, 111, 0, 116, 0, 83, 0, 117, 0, 112, 0, 112, 0, 111, 0, 114, 0, 116, 0, 101, 0, 100, 0, 95, 0, 65, 0, 100, 0, 100, 0, 105, 0, 110, 0, 103, 0, 77, 0, 101, 0, 116, 0, 104, 0, 115, 0, 78, 0, 111, 0, 116, 0, 83, 0, 117, 0, 112, 0, 112, 0, 111, 0, 114, 0, 116, 0, 101, 0, 100, 0, 35, 1, 0, 0, 74, 78, 0, 111, 0, 116, 0, 83, 0, 117, 0, 112, 0, 112, 0, 111, 0, 114, 0, 116, 0, 101, 0, 100, 0, 95, 0, 65, 0, 100, 0, 100, 0, 105, 0, 110, 0, 103, 0, 70, 0, 105, 0, 101, 0, 108, 0, 100, 0, 115, 0, 78, 0, 111, 0, 116, 0, 83, 0, 117, 0, 112, 0, 112, 0, 111, 0, 114, 0, 116, 0, 101, 0, 100, 0, 81, 1, 0, 0, 26, 77, 0, 105, 0, 115, 0, 115, 0, 105, 0, 110, 0, 103, 0, 77, 0, 101, 0, 109, 0, 98, 0, 101, 0, 114, 0, 126, 1, 0, 0, 60, 73, 0, 110, 0, 118, 0, 97, 0, 108, 0, 105, 0, 100, 0, 67, 0, 97, 0, 115, 0, 116, 0, 95, 0, 81, 0, 73, 0, 70, 0, 111, 0, 114, 0, 69, 0, 110, 0, 117, 0, 109, 0, 86, 0, 97, 0, 114, 0, 70, 0, 97, 0, 105, 0, 108, 0, 101, 0, 100, 0, 145, 1, 0, 0, 62, 73, 0, 110, 0, 118, 0, 97, 0, 108, 0, 105, 0, 100, 0, 79, 0, 112, 0, 95, 0, 73, 0, 110, 0, 118, 0, 97, 0, 108, 0, 105, 0, 100, 0, 78, 0, 101, 0, 119, 0, 69, 0, 110, 0, 117, 0, 109, 0, 86, 0, 97, 0, 114, 0, 105, 0, 97, 0, 110, 0, 116, 0, 198, 1, 0, 0, 62, 65, 0, 114, 0, 103, 0, 95, 0, 79, 0, 98, 0, 106, 0, 101, 0, 99, 0, 116, 0, 78, 0, 111, 0, 116, 0, 86, 0, 97, 0, 108, 0, 105, 0, 100, 0, 70, 0, 111, 0, 114, 0, 77, 0, 101, 0, 116, 0, 104, 0, 111, 0, 100, 0, 73, 0, 110, 0, 102, 0, 111, 0, 11, 2, 0, 0, 32, 65, 0, 114, 0, 103, 0, 95, 0, 78, 0, 111, 0, 65, 0, 99, 0, 99, 0, 101, 0, 115, 0, 115, 0, 83, 0, 112, 0, 101, 0, 99, 0, 58, 2, 0, 0, 0, 57, 84, 104, 101, 32, 115, 112, 101, 99, 105, 102, 105, 101, 100, 32, 109, 101, 109, 98, 101, 114, 32, 105, 110, 102, 111, 32, 105, 115, 32, 110, 111, 116, 32, 118, 97, 108, 105, 100, 32, 102, 111, 114, 32, 116, 104, 105, 115, 32, 73, 82, 101, 102, 108, 101, 99, 116, 46, 0, 75, 84, 104, 101, 32, 68, 73, 83, 80, 73, 68, 32, 114, 101, 116, 117, 114, 110, 101, 100, 32, 102, 114, 111, 109, 32, 71, 101, 116, 73, 68, 115, 79, 102, 78, 97, 109, 101, 115, 32, 105, 115, 32, 100, 105, 102, 102, 101, 114, 101, 110, 116, 32, 102, 114, 111, 109, 32, 116, 104, 101, 32, 99, 97, 99, 104, 101, 100, 32, 68, 73, 83, 80, 73, 68, 46, 0, 32, 84, 104, 101, 32, 101, 110, 117, 109, 101, 114, 97, 116, 111, 114, 32, 105, 115, 32, 110, 111, 116, 32, 99, 108, 111, 110, 101, 97, 98, 108, 101, 46, 0, 42, 84, 104, 101, 32, 116, 97, 114, 103, 101, 116, 32, 105, 115, 32, 110, 111, 116, 32, 118, 97, 108, 105, 100, 32, 102, 111, 114, 32, 116, 104, 105, 115, 32, 73, 82, 101, 102, 108, 101, 99, 116, 46, 0, 75, 67, 97, 110, 110, 111, 116, 32, 103, 101, 116, 32, 116, 104, 101, 32, 118, 97, 108, 117, 101, 32, 102, 111, 114, 32, 116, 104, 101, 32, 112, 114, 111, 112, 101, 114, 116, 121, 32, 105, 110, 102, 111, 32, 115, 105, 110, 99, 101, 32, 105, 116, 32, 100, 111, 101, 115, 32, 110, 111, 116, 32, 104, 97, 118, 101, 32, 97, 32, 103, 101, 116, 116, 101, 114, 46, 0, 44, 73, 68, 105, 115, 112, 97, 116, 99, 104, 69, 120, 32, 100, 111, 101, 115, 32, 110, 111, 116, 32, 115, 117, 112, 112, 111, 114, 116, 32, 97, 100, 100, 105, 110, 103, 32, 109, 101, 116, 104, 111, 100, 115, 46, 0, 43, 73, 68, 105, 115, 112, 97, 116, 99, 104, 69, 120, 32, 100, 111, 101, 115, 32, 110, 111, 116, 32, 115, 117, 112, 112, 111, 114, 116, 32, 97, 100, 100, 105, 110, 103, 32, 102, 105, 101, 108, 100, 115, 46, 0, 17, 77, 101, 109, 98, 101, 114, 32, 110, 111, 116, 32, 102, 111, 117, 110, 100, 46, 0, 51, 81, 73, 32, 102, 111, 114, 32, 73, 69, 110, 117, 109, 86, 65, 82, 73, 65, 78, 84, 32, 102, 97, 105, 108, 101, 100, 32, 111, 110, 32, 116, 104, 101, 32, 117, 110, 109, 97, 110, 97, 103, 101, 100, 32, 115, 101, 114, 118, 101, 114, 46, 0, 67, 86, 97, 114, 105, 97, 110, 116, 32, 114, 101, 116, 117, 114, 110, 101, 100, 32, 102, 114, 111, 109, 32, 73, 110, 118, 111, 107, 101, 40, 41, 32, 111, 110, 32, 109, 101, 109, 98, 101, 114, 32, 68, 73, 83, 80, 73, 68, 95, 78, 69, 87, 69, 78, 85, 77, 32, 105, 115, 32, 105, 110, 118, 97, 108, 105, 100, 46, 0, 45, 84, 104, 101, 32, 111, 98, 106, 101, 99, 116, 32, 105, 115, 32, 110, 111, 116, 32, 118, 97, 108, 105, 100, 32, 102, 111, 114, 32, 116, 104, 105, 115, 32, 109, 101, 116, 104, 111, 100, 32, 105, 110, 102, 111, 46, 0, 68, 77, 117, 115, 116, 32, 115, 112, 101, 99, 105, 102, 121, 32, 98, 105, 110, 100, 105, 110, 103, 32, 102, 108, 97, 103, 115, 32, 100, 101, 115, 99, 114, 105, 98, 105, 110, 103, 32, 116, 104, 101, 32, 105, 110, 118, 111, 107, 101, 32, 111, 112, 101, 114, 97, 116, 105, 111, 110, 32, 114, 101, 113, 117, 105, 114, 101, 100, 46, };

            Dictionary<string, string> s_dictv1 = new Dictionary<string, string>
             {
                { "Arg_InvalidMemberInfo","The specified member info is not valid for this IReflect."},
                {"InvalidOp_GetIdDiffFromMemId","The DISPID returned from GetIDsOfNames is different from the cached DISPID."},
                {"Arg_EnumNotCloneable","The enumerator is not cloneable."},
                {"Arg_TargetNotValidForIReflect","The target is not valid for this IReflect."},
                {"Arg_GetMethNotFnd","Cannot get the value for the property info since it does not have a getter."},
                {"NotSupported_AddingMethsNotSupported","IDispatchEx does not support adding methods."},
                {"NotSupported_AddingFieldsNotSupported","IDispatchEx does not support adding fields."},
                {"MissingMember","Member not found."},
                {"InvalidCast_QIForEnumVarFailed","QI for IEnumVARIANT failed on the unmanaged server."},
                {"InvalidOp_InvalidNewEnumVariant","Variant returned from Invoke() on member DISPID_NEWENUM is invalid."},
                {"Arg_ObjectNotValidForMethodInfo","The object is not valid for this method info."},
                {"Arg_NoAccessSpec","Must specify binding flags describing the invoke operation required."}

             };

            using (var ms2 = new MemoryStream(_RefBuffer1))
            {
                using (var rw = new ResourceReader(ms2))
                {
                    //Rewind to begining of stream

                    ms2.Seek(0L, SeekOrigin.Begin);

                    var reder = new ResourceReader(ms2);

                    var s_found_list = new List<string>();
                    foreach (DictionaryEntry entry in reder)
                    {
                        string key = (string)entry.Key;
                        string value = (string)entry.Value;
                        string found = s_dictv1[key];
                        Assert.True(string.Compare(value, found) == 0, "expected: " + value + ", but got : " + found);
                        s_found_list.Add(key);
                    }

                    Assert.True(s_found_list.Count == s_dictv1.Count);
                }

            }
        }
Beispiel #9
0
Datei: View.cs Projekt: dfr0/moon
	public override Widget GetView ()
	{
		if (box != null)
			return box;

		// Create ui
		box = new VBox (false, 10);
		store = new ListStore (typeof (string), typeof (string), typeof (object));
		tree = new TreeView ();
		tree.Model = store;
		tree.AppendColumn ("Name", new CellRendererText (), "text", 0);
		tree.AppendColumn ("Type", new CellRendererText (), "text", 1);
		tree.HeadersVisible = true;
		tree.CursorChanged += HandleCursorChanged;
		scrolled_tree = new ScrolledWindow ();
		scrolled_tree.Add (tree);
		box.PackStart (scrolled_tree, true, true, 0);

		// Load resources
		EmbeddedResource embed = resource as EmbeddedResource;
		if (embed != null) {
			using (MemoryStream stream = new MemoryStream (embed.GetResourceData ())) {
				using (ResourceReader reader = new ResourceReader (stream)) {
					foreach (DictionaryEntry obj in reader) {
						store.AppendValues (obj.Key.ToString (), obj.Value.GetType ().FullName, obj.Value);
					}
				}
			}
		} else {
			Console.WriteLine ("Don't know how to handle a resource whose type is {0}", resource.GetType ().FullName);
		}

		return box;
	}
        /**
         * Standard procedure to compile resources:
         * 1. Get an AppDomain correspondint to the Classloader.
         * 2. Create an assembly in the given appdomain
         * 3. Create a type for each resource, given the className (resourceName), contents
              (pReader.getBytes(resourceName)), and the AppDomain.
         * 4.  Write the compiled types to the store.
         */
        public override CompilationResult compile(
            string[] pResourceNames,
            ResourceReader pReader,
            ResourceStore pStore,
            ClassLoader pClassLoader
            )
        {
            int OFFSETCONSTANT = 8;
            Type[] types = new Type[pResourceNames.Length];
            string[] contents = new string[pResourceNames.Length];
            CodeSnippetCompileUnit[] units = new CodeSnippetCompileUnit[pResourceNames.Length];
            for (int i = 0; i < types.Length; i++)
            {
                string resourceName = pResourceNames[i].Replace('.','/')+".java";
                byte[] byteArray = pReader.getBytes(resourceName);
                string fileContents = this.StringFromBytes(byteArray);
                units[i] = new CodeSnippetCompileUnit(fileContents.Replace("cli.", ""));
                if (fileContents.Contains("public static void consequence"))
                {
                    object[] info = this.GetLinePragmaInfo(fileContents,OFFSETCONSTANT);
                    if(info != null)
                        units[i].LinePragma = new CodeLinePragma(info[0] as string, (int)info[1]);
                }
            }

            CodeDomProvider provider = GetProvider();
            CompilerParameters compilerParameters = new CompilerParameters();
            compilerParameters.GenerateInMemory = true;
            compilerParameters.IncludeDebugInformation = true;

            //            compilerParameters.OutputAssembly = pResourceNames[i].Substring(pResourceNames[i].LastIndexOf('.') + 1);

            int count = 0;
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {

               if (assembly.FullName.StartsWith("CompiledRules"))
                {
                    try
                    {
                        File.Delete(assembly.Location);
                    }
                    catch (System.Exception e)
                    {
                        count++;
                    }
                }
                else
                {
                    compilerParameters.ReferencedAssemblies.Add(assembly.Location);
                }

            }

            compilerParameters.OutputAssembly = "CompiledRules" + count + ".dll";

            CompilerResults results = provider.CompileAssemblyFromDom
                //(compilerParameters, contents);
                (compilerParameters, units);

            Collection problems = new ArrayList();

            DotnetPackageCompilationData pcData = (DotnetPackageCompilationData)
                ((PackageStore)pStore).getPackageCompilationData();

            MemoryStream stream = new MemoryStream(1024);
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream, results.CompiledAssembly);

            for (int i = 0; i < types.Length; i++)
            {
                string resourceName = pResourceNames[i];
                pcData.write(resourceName, new object[]{results.CompiledAssembly, stream.GetBuffer()});

            }
            CompilationProblem[] result = new CompilationProblem[problems.size()];
            return new CompilationResult(result);
        }
 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;
     }
   }
 public void CanGetEmbeddedResourceFromAssembly()
 {
     var reader = new ResourceReader();
     var text = reader.GetTextResource("CacheList.html");
     Assert.That(text, Is.Not.Empty);
 }
        public static void Read_resources_withobject()
        {
            //The following byte array corresponds to  
            //rw.AddResource("name1", "value1");
            //rw.AddResource("name2", (object)bytearray);
            //rw.AddResource("name3", "value3");

            byte[] _RefBuffer12 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 30, 1, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 32, 17, 1, 0, 0, 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 16, 0, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 1, 6, 118, 97, 108, 117, 101, 50, 1, 6, 118, 97, 108, 117, 101, 51, 1, 6, 118, 97, 108, 117, 101, 51 };

            
           Dictionary<string, string> s_dict_expected = new Dictionary<string, string>{
                                                                           { "name1", "value1"},
                                                                           { "name2", null},
                                                                           { "name3", "value3"}
                                                                         };
            using (var ms2 = new MemoryStream(_RefBuffer12))
            {
                using (var rw = new ResourceReader(ms2))
                {

                    ms2.Seek(0L, SeekOrigin.Begin);

                    var reader = new ResourceReader(ms2);

                    var s_found_list = new List<string>();

                    foreach (DictionaryEntry entry in reader)
                    {
                        string key = (string)entry.Key;
                        string found = (string)entry.Value;
                        string value = s_dict_expected[key];
                        Assert.True(string.Compare(value, found) == 0, "expected: " + value + ", but got : " + found);
                        s_found_list.Add(key);
                    }
                

                }
            }
        }
        public static void Exception_Corrupted_resources1()
        {
            byte[] _RefBuffer12 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 16, 0, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 1, 6, 118, 97, 108, 117, 101, 50, 1};
            using (var ms2 = new MemoryStream(_RefBuffer12))
            {
                using (var reader = new ResourceReader(ms2))
                {
                    var s_found_list = new List<DictionaryEntry>();
                    Assert.Throws<BadImageFormatException>(() =>
                    {
                        var enume = reader.GetEnumerator();

                        while (enume.MoveNext())
                        {
                            s_found_list.Add(enume.Entry);
                        }

                    });
                }
            }
        }
 protected AbstractEmbeddedResourceHandler(ResourceReader resourceReader)
 {
     _ResourceReader = resourceReader;
 }
 public MainPageHandler(ResourceReader resourceReader)
     : base(resourceReader)
 {
 }
    private static bool ValidateResourceFile(string resFile, string outputDir, string sourceHash, int viewCount)
    {
        IDictionary<int, KeyValuePair<string, string>> resourceDictionary =
            new Dictionary<int, KeyValuePair<string, string>>();
        using (var resourceReader = new ResourceReader(Path.Combine(outputDir, resFile)))
        {
            // Create an IDictionaryEnumerator to iterate through the resources.
            IDictionaryEnumerator IDEnumerator = resourceReader.GetEnumerator();

            // Iterate through the resources and store it in dictionary
            foreach (DictionaryEntry d in resourceReader)
            {
                //The KeyValuePair to be Inserted into the dictionary, NEEDS TO BE CASTED!
                var valueToInsert = (KeyValuePair<string, string>)d.Value;

                //Populating Dictionary, Item, the key in the dictionary is turn into an integer
                resourceDictionary.Add(Int32.Parse(d.Key.ToString()), valueToInsert);
            }
            resourceReader.Close();
        }

        /*
         * This is commented out in the public file because this class is an internal MS class that EF uses to create it's hash.
         * I reflected on it, made it a public class, and included it in our internal process to validate that the views were
         * created correctly and the view hash matched the original EF hash.
         * I will not distribute MS source code so the simplest approach is to comment this section out.
         *
         * This code being commented out does not affect the output file, it's just a validation step.
         * */

        //var resourceHaser = new CompressingHashBuilder(new SHA256CryptoServiceProvider());
        //for (int i = 0; i < viewCount; i++)
        //{
        //   KeyValuePair<string, string> resourceValue = resourceDictionary[i];
        //   resourceHaser.AppendLine(resourceValue.Key);
        //   resourceHaser.AppendLine(resourceValue.Value);
        //}
        //string fileHash = resourceHaser.ComputeHash();
        //return sourceHash == fileHash;
        return true;
    }
        public static void Exception_EOF()
        {
            byte[] _RefBuffer12 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109};
            using (var ms2 = new MemoryStream(_RefBuffer12))
            {
                Assert.Throws<BadImageFormatException>(() =>
                {
                    using (var rw = new ResourceReader(ms2))
                    {

                    }
                });
               
            }
        }
 public 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";
   String strValue = String.Empty;
   IDictionaryEnumerator idic;
   try
     {
     ResourceWriter resWriter;
     ResourceReader resReader;
     Stream stream = null;
     MemoryStream ms;
     FileStream fs;
     if(File.Exists(Environment.CurrentDirectory+"\\Co5445.resources"))
       File.Delete(Environment.CurrentDirectory+"\\Co5445.resources");
     strLoc = "Loc_20xcy";
     stream = null;
     iCountTestcases++;
     try {
     resWriter = new ResourceWriter(stream);
     iCountErrors++;
     printerr( "Error_29vc8! ArgumentNullException expected");
     } catch ( ArgumentNullException aExc) {
     } catch ( Exception exc) {
     iCountErrors++;
     printerr( "Error_10s9x! ArgumentNullException expected , got exc=="+exc.ToString());
     }
     strLoc = "Loc_3f98d";
     new FileStream("Co5445.resources", FileMode.Create).Close();
     fs = new FileStream("Co5445.resources", FileMode.Open, FileAccess.Read, FileShare.None);
     iCountTestcases++;
     try {
     resWriter = new ResourceWriter(fs);
     iCountErrors++;
     printerr( "Error_2c88s! ArgumentException expected");
     } catch (ArgumentException aExc) {
     } catch ( Exception exc) {
     iCountErrors++;
     printerr( "Error_2x0zu! ArgumentException expected, got exc=="+exc.ToString());
     }
     strLoc = "Loc_f0843";
     ms = new MemoryStream();
     resWriter = new ResourceWriter(ms);
     resWriter.AddResource("Harrison", "Ford");
     resWriter.AddResource("Mark", "Hamill");
     resWriter.Generate();
     ms.Position = 0;
     resReader = new ResourceReader(ms);
     idic = resReader.GetEnumerator();
     idic.MoveNext();
     iCountTestcases++;
     if(!idic.Value.Equals("Ford"))
       {
       iCountErrors++;
       printerr( "Error_2d0s9 Expected==Ford, value=="+idic.Value.ToString());
       }
     idic.MoveNext();
     iCountTestcases++;
     if(!idic.Value.Equals("Hamill"))
       {
       iCountErrors++;
       printerr( "Error_2ce80 Expected==Hamill, value=="+idic.Value.ToString());
       }
     strLoc = "Loc_20984";
     iCountTestcases++;
     if(idic.MoveNext())
       {
       iCountErrors++;
       printerr( "Error_f4094! Should have hit the end of the stream already");
       }
     fs.Close();
     strLoc = "Loc_04853fd";
     if(File.Exists(Environment.CurrentDirectory+"\\Co5445.resources"))
       File.Delete(Environment.CurrentDirectory+"\\Co5445.resources");
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 )
     {
     Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
     return true;
     }
   else
     {
     Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
        public static void Exception_opening_opened_resources()
        {
            byte[] _RefBuffer12 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 16, 0, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 1, 6, 118, 97, 108, 117, 101, 50 };
            using (var ms2 = new MemoryStream(_RefBuffer12))
            {
                using (var rw = new ResourceReader(ms2))
                {

                   
                    Assert.Throws<ArgumentException>(() =>
                    {
                        var rr = new ResourceReader(ms2);
                    });
                }
            }
        }
Beispiel #21
0
    /// <remarks>
    /// Builds ResAsm files out of resource files
    /// </remarks>
    static void Disassemble(string pattern)
    {
        string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), pattern);
        foreach (string file in files) {

            Hashtable resources = new Hashtable();
            int       length    = 0;
            // read resource files into the hashtable
            switch (Path.GetExtension(file).ToUpper()) {
                case ".RESX":
                    ResXResourceReader rx = new ResXResourceReader(file);
                    IDictionaryEnumerator n = rx.GetEnumerator();
                    while (n.MoveNext())
                        if (!resources.ContainsKey(n.Key)) {
                            length = Math.Max(length, n.Key.ToString().Length);
                            resources.Add(n.Key, n.Value);
                        }

                    rx.Close();
                break;
                case ".RESOURCES":
                    ResourceReader rr = new ResourceReader(file);
                    foreach (DictionaryEntry entry in rr) {
                        if (!resources.ContainsKey(entry.Key)) {
                            length = Math.Max(length, entry.Key.ToString().Length);
                            resources.Add(entry.Key, entry.Value);
                        }
                    }
                    rr.Close();
                break;
            }

            // write the hashtable to the resource file
            string fname  = Path.GetFileNameWithoutExtension(file);
            string path   = fname + "-data";
            StreamWriter writer = File.CreateText(fname + ".res");

            writer.Write("# this file was automatically generated by ResAsm\r\n\r\n");
            foreach (DictionaryEntry entry in resources) {
                // strings are put directly into the resasm format
                if (entry.Value is string) {
                    writer.Write(entry.Key.ToString() + "=\"" + ConvertIllegalChars(entry.Value.ToString()) + "\"\r\n");
                } else {
                    // all other files are referenced as a file and the filename
                    // is saved in the resasm format, the files need to be generated.
                    string extension  = "";
                    string outputname = path + '\\' + entry.Key.ToString();
                    if (entry.Value is Icon) {
                        extension = ".ico";
                        if (!Directory.Exists(path))
                            Directory.CreateDirectory(path);
                        ((Icon)entry.Value).Save(File.Create(outputname + extension));
                    } else if (entry.Value is Image) {
                        // all bitmaps are saved in the png format
                        extension = ".png";
                        if (!Directory.Exists(path))
                            Directory.CreateDirectory(path);
                        ((Image)entry.Value).Save(outputname + extension, ImageFormat.Png);
                    } else {
                        Console.WriteLine("can't save " + entry.Key + " unknown format.");
                        continue;
                    }
                    writer.Write(entry.Key.ToString().PadRight(length) + " = " + outputname + extension + "\r\n");
                }
            }
            writer.Close();
        }
    }
        public static void ReadResource1()
        {

            using (var ms2 = new MemoryStream())
            {
                using (var rw = GenerateResourceStream(s_dict, ms2))
                {
                    //Rewind to begining of stream

                    ms2.Seek(0L, SeekOrigin.Begin);

                    var reader = new ResourceReader(ms2);

                    var s_found_key = new List<string>();
                    var s_found_value = new List<string>();
                    var enume = reader.GetEnumerator();

                    while (enume.MoveNext())
                    {
                        s_found_key.Add((string)enume.Key);
                        s_found_value.Add((string)enume.Value);
                    }
                    enume.Reset();
                    int i = 0;
                    while (enume.MoveNext())
                    {
                        string key = s_found_key[i];
                        string found_key = (string)enume.Key;

                        string value = s_found_key[i];
                        string found_value = (string)enume.Key;
                        i++;
                        Assert.True(string.Compare(key, found_key) == 0, "expected: " + key + ", but got : " + found_key);
                        Assert.True(string.Compare(value, found_value) == 0, "expected: " + value + ", but got : " + found_value);
                    }


                    Assert.True(s_found_key.Count == s_dict.Count);
                }
            }

        }
 public static void ExceptionforResourceReaderNull()
 {
     Assert.Throws<ArgumentNullException>(() =>
     {
         MemoryStream ms2 = null;
         var rw = new ResourceReader(ms2);
     });
 }
 public JavaScriptHandler(ResourceReader reader, string resourceName)
     : base(reader)
 {
     _resourceName = resourceName;
 }
        public static void ExceptionforResourceReaderDispose01()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                using (var ms2 = new MemoryStream())
                {
                    using (var rw = GenerateResourceStream(s_dict, ms2))
                    {
                        ms2.Seek(0L, SeekOrigin.Begin);
                        var rr1 = new ResourceReader(ms2);

                        rr1.Dispose();
                        var s_found_list = new List<string>();
                        foreach (DictionaryEntry entry in rr1)
                        {
                            string key = (string)entry.Key;
                            string value = (string)entry.Value;
                            string found = s_dict[key];
                            Assert.True(string.Compare(value, found) == 0, "expected: " + value + ", but got : " + found);
                            s_found_list.Add(key);
                        }

                    }
                }
            });
        }
Beispiel #26
0
	public static int Unpack (string assembly, string pattern)
	{
		Assembly asm = null;
		try {
			asm = Assembly.LoadFile (assembly);
		} catch (Exception e) {
			Console.Error.WriteLine ("Unable to load assembly: {0}.", assembly);
			Console.Error.WriteLine (e);
			return 1;
		}

		string [] resources = asm.GetManifestResourceNames ();
	
		foreach (string resource in resources) {
			if (verbose)
				Console.WriteLine ("decompressing '{0}'", resource);

			ResourceReader reader = null;

			try {
				using (reader = new ResourceReader (asm.GetManifestResourceStream (resource))) {
				
					IDictionaryEnumerator id = reader.GetEnumerator (); 

					while (id.MoveNext ()) {
						string key = (string) id.Key;
						if (!Regex.IsMatch (key, pattern))
							continue;

						if (verbose)
							Console.WriteLine ("  stream: {0}", key);

						MemoryStream stream = id.Value as MemoryStream;
						if (stream == null) {
							Console.Error.WriteLine ("Item not stored as a MemoryStream. {0}", key);
							continue;
						}

						byte [] data = new byte [stream.Length];
						stream.Read (data, 0, data.Length);

						string dir = Path.GetDirectoryName (key);
						if (!String.IsNullOrEmpty (dir))
							Directory.CreateDirectory (dir);

						using (FileStream fs = File.OpenWrite (key)) {
							fs.Write (data, 0, data.Length);
						}
									      
					}
				}
			} catch (Exception e) {
				Console.WriteLine ("failed to decompress {0}, exception '{1}'.. skipping", resource, e.Message);
			}
		}

		return 0;
	}
        public static void Exception_Enumerator_Value()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                using (var ms2 = new MemoryStream())
                {
                    using (var rw = GenerateResourceStream(s_dict, ms2))
                    {
                        ms2.Seek(0L, SeekOrigin.Begin);
                        var rr1 = new ResourceReader(ms2);

                        IDictionaryEnumerator enumarator = rr1.GetEnumerator();
                        rr1.Dispose();
                        var shouldnotgethere = enumarator.Value;


                    }
                }
            });
        }