Beispiel #1
0
        private void build_page_1()
        {
            TextView tv1 = new TextView();

            try
            {
                string         rez          = "Adeptus.Resources.resources";
                string         key          = "mystring1";
                string         resourceType = "";
                byte[]         resourceData;
                ResourceReader r = new ResourceReader(rez);
                r.GetResourceData(key, out resourceType, out resourceData);
                r.Close();
                System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                tv1.Buffer.Text = enc.GetString(resourceData);
            }
            catch (Exception exp)
            {
                tv1.Buffer.Text = exp.Message;
            }

            tv1.WrapMode = WrapMode.Word;
            tv1.Editable = false;

            this.AppendPage(tv1);
            this.SetPageTitle(tv1, "Introduction");
            this.SetPageType(tv1, AssistantPageType.Intro);
            this.SetPageComplete(tv1, true);
        }
        public void GetResourceData2()
        {
            byte [] expected = new byte [] {
                0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
                0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x0C, 0x02, 0x00, 0x00, 0x00, 0x51, 0x53,
                0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x72,
                0x61, 0x77, 0x69, 0x6E, 0x67, 0x2C, 0x20, 0x56,
                0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3D, 0x32,
                0x2E, 0x30, 0x2E, 0x30, 0x2E, 0x30, 0x2C, 0x20,
                0x43, 0x75, 0x6C, 0x74, 0x75, 0x72, 0x65, 0x3D,
                0x6E, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6C, 0x2C,
                0x20, 0x50, 0x75, 0x62, 0x6C, 0x69, 0x63, 0x4B,
                0x65, 0x79, 0x54, 0x6F, 0x6B, 0x65, 0x6E, 0x3D,
                0x62, 0x30, 0x33, 0x66, 0x35, 0x66, 0x37, 0x66,
                0x31, 0x31, 0x64, 0x35, 0x30, 0x61, 0x33, 0x61,
                0x05, 0x01, 0x00, 0x00, 0x00, 0x13, 0x53, 0x79,
                0x73, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x72, 0x61,
                0x77, 0x69, 0x6E, 0x67, 0x2E, 0x53, 0x69, 0x7A,
                0x65, 0x02, 0x00, 0x00, 0x00, 0x05, 0x77, 0x69,
                0x64, 0x74, 0x68, 0x06, 0x68, 0x65, 0x69, 0x67,
                0x68, 0x74, 0x00, 0x00, 0x08, 0x08, 0x02, 0x00,
                0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00,
                0x00, 0x00, 0x0B
            };
            ResourceReader r = new ResourceReader("Test/resources/bug81759.resources");
            string         type;

            byte [] bytes;
            r.GetResourceData("imageList.ImageSize", out type, out bytes);
            // Note that const should not be used here.
            Assert.AreEqual("System.Drawing.Size, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", type, "#1");
            Assert.AreEqual(expected, bytes, "#2");
            r.Close();
        }
        /// <summary>
        /// Loads the resources.
        /// </summary>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="ci">The ci.</param>
        public static void LoadResources(string resourceName, System.Globalization.CultureInfo ci)
        {
            string resFileName = System.Web.HttpRuntime.BinDirectory + resourceName + "." + ci.ToString() + ".resources";

            if (System.IO.File.Exists(resFileName))
            {
                lock (stringResources)
                {
                    if (!stringResources.ContainsKey(ci.ToString()))
                    {
                        stringResources.Add(ci.ToString(), new Hashtable());

                        try
                        {
                            ResourceReader        reader = new ResourceReader(resFileName);
                            IDictionaryEnumerator en     = reader.GetEnumerator();
                            while (en.MoveNext())
                            {
                                stringResources[ci.ToString()].Add(en.Key, en.Value);
                            }
                            reader.Close();
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 将resources文件转换为resx文件,如果转换成功,返回True
        /// </summary>
        /// <param name="strResources">resources文件的路径,注意请保证路径正确无误</param>
        /// <param name="strResx">res文件的路径,注意请保证路径正确无误</param>
        public static bool ConvertRes(string strResources, string strResx)
        {
            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);
                ResXResourceWriter writer = new ResXResourceWriter(strResx);

                foreach (DictionaryEntry en in reader)
                {
                    writer.AddMetadata(en.Key.ToString(), en.Value);
                }
                reader.Close();
                writer.Close();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        public AccountForm()
        {
            InitializeComponent();

            IResourceReader             reader         = null;
            Dictionary <string, string> loginResources = new Dictionary <string, string>();

            try
            {
                reader = new ResourceReader("Account.resources");
                IDictionaryEnumerator dict = reader.GetEnumerator();
                gridAccounts.Rows.Clear();
                while (dict.MoveNext())
                {
                    string   key         = dict.Key.ToString();
                    string   valueString = dict.Value.ToString();
                    string[] values      = valueString.Split(',');
                    gridAccounts.Rows.Add(key, values[0], values[1], values[2]);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            ResourceReader        res  = new ResourceReader("Resources.resources");//该文件放到bin
            IDictionaryEnumerator dics = res.GetEnumerator();

            while (dics.MoveNext())
            {
                Stream s           = (Stream)dics.Value;
                int    fileSize    = (int)s.Length;
                byte[] fileContent = new byte[fileSize];
                s.Read(fileContent, 0, fileSize);
                FileStream fs;
                string     filepath = dics.Key.ToString();
                filepath = Path.Combine("C://", filepath); //保存到指定目录
                filepath = Path.GetFullPath(filepath);
                var p = Path.GetDirectoryName(filepath);   //要创建的目录
                if (!Directory.Exists(p))
                {
                    Directory.CreateDirectory(p);
                }

                FileInfo fi = new System.IO.FileInfo(filepath);
                fs = fi.OpenWrite();
                fs.Write(fileContent, 0, fileSize);
                fs.Close();
            }

            res.Close();
        }
        /// <summary>
        /// 默认构造函数
        /// </summary>
        /// <param name="filepath">资源文件路径</param>
        public ResourceHelper(string filepath)
        {
            this.m_FilePath  = filepath;
            this.m_Hashtable = new Hashtable();

            //如果存在
            if (File.Exists(filepath))
            {
                string tempFile = HConst.TemplatePath + "\\decryptFile.resx";

                //解密文件
                //System.Net.Security tSecurity = new Security();
                //tSecurity.DecryptDES(filepath, tempFile);
                File.Copy(filepath, tempFile);

                using (ResourceReader ResReader = new ResourceReader(tempFile))
                {
                    IDictionaryEnumerator tDictEnum = ResReader.GetEnumerator();
                    while (tDictEnum.MoveNext())
                    {
                        this.m_Hashtable.Add(tDictEnum.Key, tDictEnum.Value);
                    }

                    ResReader.Close();
                }

                //删除临时文件
                File.Delete(tempFile);
            }
        }
Beispiel #8
0
		public void Stream ()
		{
			Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
			ResourceReader r = new ResourceReader (stream);
			Assert.IsNotNull (r, "ResourceReader");
			r.Close ();
		}
        public void GetResourceData()
        {
            byte [] t1 = new byte [] { 0x16, 0x00, 0x00, 0x00, 0x76, 0x65, 0x72, 0x69, 0x74, 0x61, 0x73, 0x20, 0x76, 0x6F, 0x73, 0x20, 0x6C, 0x69, 0x62, 0x65, 0x72, 0x61, 0x62, 0x69, 0x74, 0x0A };
            byte [] t2 = new byte [] { 0x0A, 0x73, 0x6F, 0x6D, 0x65, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67 };
            byte [] t3 = new byte [] { 0x0E, 0x00, 0x00, 0x00, 0x73, 0x68, 0x61, 0x72, 0x64, 0x65, 0x6E, 0x66, 0x72, 0x65, 0x75, 0x64, 0x65, 0x0A };

            ResourceReader r     = new ResourceReader("Test/resources/StreamTest.resources");
            Hashtable      items = new Hashtable();

            foreach (DictionaryEntry de in r)
            {
                string  type;
                byte [] bytes;
                r.GetResourceData((string)de.Key, out type, out bytes);
                items [de.Key] = new DictionaryEntry(type, bytes);
            }

            DictionaryEntry p = (DictionaryEntry)items ["test"];

            Assert.AreEqual("ResourceTypeCode.Stream", p.Key as string, "#1-1");
            Assert.AreEqual(t1, p.Value as byte [], "#1-2");

            p = (DictionaryEntry)items ["test2"];
            Assert.AreEqual("ResourceTypeCode.String", p.Key as string, "#2-1");
            Assert.AreEqual(t2, p.Value as byte [], "#2-2");

            p = (DictionaryEntry)items ["test3"];
            Assert.AreEqual("ResourceTypeCode.ByteArray", p.Key as string, "#3-1");
            Assert.AreEqual(t3, p.Value as byte [], "#3-2");

            r.Close();
        }
Beispiel #10
0
        public void GetResourceDataNullName()
        {
            ResourceReader r = new ResourceReader("Test/resources/StreamTest.resources");
            string         type;

            byte [] bytes;

            try
            {
                r.GetResourceData(null, out type, out bytes);
                Assert.Fail("#1");
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual(typeof(ArgumentNullException), ex.GetType(), "#2");
                Assert.IsNull(ex.InnerException, "#3");
                Assert.IsNotNull(ex.Message, "#4");
                Assert.IsNotNull(ex.ParamName, "#5");
                Assert.AreEqual("resourceName", ex.ParamName, "#6");
            }
            finally
            {
                r.Close();
            }
        }
Beispiel #11
0
        /// <summary>
        /// Gets the icon set for the given index, using the given list for missing icons.
        /// </summary>
        /// <param name="defaultResourcesPath">The default resources path.</param>
        /// <param name="groupResourcesPath">The group resources path.</param>
        /// <returns></returns>
        private static ImageList GetCustomIconSet(string defaultResourcesPath, string groupResourcesPath)
        {
            ImageList customIconSet;
            ImageList tempImageList = null;

            try
            {
                tempImageList = new ImageList();
                IDictionaryEnumerator basicx;
                IResourceReader       defaultGroupReader = null;
                tempImageList.ColorDepth = ColorDepth.Depth32Bit;
                try
                {
                    defaultGroupReader = new ResourceReader(defaultResourcesPath);

                    basicx = defaultGroupReader.GetEnumerator();

                    while (basicx.MoveNext())
                    {
                        tempImageList.Images.Add(basicx.Key.ToString(), (Icon)basicx.Value);
                    }
                }
                finally
                {
                    defaultGroupReader?.Close();
                }

                IResourceReader groupReader = null;
                try
                {
                    groupReader = new ResourceReader(groupResourcesPath);

                    basicx = groupReader.GetEnumerator();

                    while (basicx.MoveNext())
                    {
                        if (tempImageList.Images.ContainsKey(basicx.Key.ToString()))
                        {
                            tempImageList.Images.RemoveByKey(basicx.Key.ToString());
                        }

                        tempImageList.Images.Add(basicx.Key.ToString(), (Icon)basicx.Value);
                    }
                }
                finally
                {
                    groupReader?.Close();
                }

                customIconSet = tempImageList;
                tempImageList = null;
            }
            finally
            {
                tempImageList?.Dispose();
            }

            return(customIconSet);
        }
Beispiel #12
0
        /// <summary>
        /// Static method to return an OrderRoute for a given instrument and market
        /// </summary>
        /// <param name="instrument">TTInstrument for this order route</param>
        /// <param name="marketName">Market for this order route (i.e. "CME", "CBOT", etc.)</param>
        /// <returns>OrderRoute object to use when sending orders for the specified instrument</returns>
        public static EZOrderRoute GetOrderRoute(EZInstrument instrument, string marketName)
        {
            string                      accountInfoString = null;
            IResourceReader             reader            = null;
            Dictionary <string, string> loginResources    = new Dictionary <string, string>();

            try
            {
                reader = new ResourceReader("Account.resources");
                IDictionaryEnumerator dict = reader.GetEnumerator();
                while (dict.MoveNext())
                {
                    string key = dict.Key.ToString();
                    if (key.Equals(marketName))
                    {
                        accountInfoString = dict.Value.ToString();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            EZOrderRoute route = null;

            if (accountInfoString != null)
            {
                route = new EZOrderRoute();

                string[] values      = accountInfoString.Split(',');
                string   feedName    = values[0];
                string   accountName = values[1];
                string   accountType = values[2];
                ReadOnlyCollection <ezOrderFeed> feeds = instrument.EnabledOrderFeeds;
                foreach (ezOrderFeed feed in feeds)
                {
                    if (feed.Name.Equals(feedName))
                    {
                        route.OrderFeed = feed;
                        break;
                    }
                }
                route.AccountName = accountName;
                route.AccountType = (zAccountType)Enum.Parse(typeof(zAccountType), accountType);
            }

            return(route);
        }
Beispiel #13
0
		public void ConstructorString ()
		{
			if (!File.Exists (m_ResourceFile)) {
				Assert.Fail ("Resource file is not where it should be:" + Path.Combine (Directory.GetCurrentDirectory (), m_ResourceFile));
			}
			ResourceReader r = new ResourceReader (m_ResourceFile);
			Assert.IsNotNull (r, "ResourceReader");
			r.Close ();
		}
 public void Close()
 {
     if (_reader != null)
     {
         _reader.Close();
         _reader     = null;
         _enumerator = null;
     }
 }
        public void LoadFile(FileName filename, Stream stream)
        {
            resources.Clear();
            metadata.Clear();
            switch (Path.GetExtension(filename).ToLowerInvariant())
            {
            case ".resx":
                ResXResourceReader     rx           = new ResXResourceReader(stream);
                ITypeResolutionService typeResolver = null;
                rx.BasePath         = Path.GetDirectoryName(filename);
                rx.UseResXDataNodes = true;
                IDictionaryEnumerator n = rx.GetEnumerator();
                while (n.MoveNext())
                {
                    if (!resources.ContainsKey(n.Key.ToString()))
                    {
                        ResXDataNode node = (ResXDataNode)n.Value;
                        resources.Add(n.Key.ToString(), new ResourceItem(node.Name, node.GetValue(typeResolver), node.Comment));
                    }
                }

                n = rx.GetMetadataEnumerator();
                while (n.MoveNext())
                {
                    if (!metadata.ContainsKey(n.Key.ToString()))
                    {
                        ResXDataNode node = (ResXDataNode)n.Value;
                        metadata.Add(n.Key.ToString(), new ResourceItem(node.Name, node.GetValue(typeResolver)));
                    }
                }

                rx.Close();
                break;

            case ".resources":
                ResourceReader rr = null;
                try {
                    rr = new ResourceReader(stream);
                    foreach (DictionaryEntry entry in rr)
                    {
                        if (!resources.ContainsKey(entry.Key.ToString()))
                        {
                            resources.Add(entry.Key.ToString(), new ResourceItem(entry.Key.ToString(), entry.Value));
                        }
                    }
                }
                finally {
                    if (rr != null)
                    {
                        rr.Close();
                    }
                }
                break;
            }
            InitializeListView();
        }
Beispiel #16
0
        /// <summary>Close underlying <see cref="ResourceReader"/></summary>
        public void Dispose()
        {
            ResourceReader reader = this._reader;

            this._reader = null;
            if (reader != null)
            {
                reader.Close();
            }

            GC.SuppressFinalize(this);
        }
Beispiel #17
0
    public static void Main()
    {
        Console.WriteLine("Resources in ApplicationResources.resources:");
        ResourceReader        res  = new ResourceReader(@".\ApplicationResources.resources");
        IDictionaryEnumerator dict = res.GetEnumerator();

        while (dict.MoveNext())
        {
            Console.WriteLine("   {0}: '{1}' (Type {2})",
                              dict.Key, dict.Value, dict.Value.GetType().Name);
        }
        res.Close();
    }
Beispiel #18
0
    public static void Deserialize(TextBox data)
    {
        // GOOD
        var ds   = new ResourceReader(new MemoryStream(Encoding.UTF8.GetBytes("hardcoded")));
        var dict = ds.GetEnumerator();

        while (dict.MoveNext())
        {
            Console.WriteLine("   {0}: '{1}' (Type {2})",
                              dict.Key, dict.Value, dict.Value.GetType().Name);
        }
        ds.Close();
    }
Beispiel #19
0
    public static void Deserialize(Stream s)
    {
        var ds = new ResourceReader(s);
        // BAD
        var dict = ds.GetEnumerator();

        while (dict.MoveNext())
        {
            Console.WriteLine("   {0}: '{1}' (Type {2})",
                              dict.Key, dict.Value, dict.Value.GetType().Name);
        }
        ds.Close();
    }
Beispiel #20
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <ListViewItem> lvitem = new List <ListViewItem>();

            while (myEnumerator.MoveNext())
            {
                lvitem.Add((ListViewItem)myEnumerator.Current);
            }

            if (!File.Exists(LISTNAME))
            {
                ResourceWriter rw = new ResourceWriter(LISTNAME);

                rw.AddResource(textBox1.Text, lvitem);

                rw.Generate();

                rw.Close();
            }
            else
            {
                ResourceReader rr = new ResourceReader(LISTNAME);

                IDictionaryEnumerator ide = rr.GetEnumerator();

                Hashtable ht = new Hashtable();

                while (ide.MoveNext())
                {
                    ht.Add(ide.Key.ToString(), ide.Value);
                }

                rr.Close();

                ResourceWriter rw = new ResourceWriter(LISTNAME);

                rw.AddResource(textBox1.Text, lvitem);

                foreach (DictionaryEntry de in ht)
                {
                    rw.AddResource(de.Key.ToString(), de.Value);
                }

                rw.Generate();

                rw.Close();
            }


            this.Dispose();
        }
Beispiel #21
0
        /// <summary>
        /// Bietet Zugriff auf die Resourcen in einem Updatepaket.
        /// </summary>
        /// <param name="packagePath">Der Pfad zu dem Updatepaket.</param>
        /// <param name="resID">Die ID der Resource die ausgelesen werden soll.</param>
        /// <returns>Gibt die Resource in Form eines ByteArrays zurück.</returns>
        protected byte[] accessUpdatePackage(string packagePath, string resID)
        {
            var resReader = new ResourceReader(packagePath);

            try {
                byte[] outData;
                string outType;
                resReader.GetResourceData(resID, out outType, out outData);
                return(outData);
            }
            finally {
                resReader.Close();
            }
        }
Beispiel #22
0
    public static void Main()
    {
        var rr = new ResourceReader("PatientForm.resources");
        IDictionaryEnumerator dict = rr.GetEnumerator();
        int ctr = 0;

        while (dict.MoveNext())
        {
            ctr++;
            Console.WriteLine("{0:00}: {1} = {2}", ctr, dict.Key, dict.Value);
        }

        rr.Close();
    }
Beispiel #23
0
 private static void AddBitmapResource(string fileName)
 {
     if (File.Exists(fileName))
     {
         ResourceReader reader = new ResourceReader(fileName);
         foreach (DictionaryEntry entry in reader)
         {
             if (!_bitmapRes.ContainsKey(entry.Key.ToString()))
             {
                 _bitmapRes.Add(entry.Key.ToString(), entry.Value);
             }
         }
         reader.Close();
     }
 }
Beispiel #24
0
        public void LoadResourceStream(Stream Stream)
        {
            ResourceReader        r = new ResourceReader(Stream);
            IDictionaryEnumerator n = r.GetEnumerator();

            while (n.MoveNext())
            {
                if (!Resource.ContainsKey(n.Key))
                {
                    Resource.Add(n.Key, n.Value);
                }
            }
            r.Close();
            Initialize();
        }
 static Hashtable Load(string fileName)
 {
     if (File.Exists(fileName))
     {
         Hashtable      resources = new Hashtable();
         ResourceReader rr        = new ResourceReader(fileName);
         foreach (DictionaryEntry entry in rr)
         {
             resources.Add(entry.Key, entry.Value);
         }
         rr.Close();
         return(resources);
     }
     return(null);
 }
Beispiel #26
0
    public static void Main()
    {
        var assem = typeof(Example).Assembly;
        var fs    = assem.GetManifestResourceStream("PatientForm.resources");
        var rr    = new ResourceReader(fs);
        IDictionaryEnumerator dict = rr.GetEnumerator();
        int ctr = 0;

        while (dict.MoveNext())
        {
            ctr++;
            Console.WriteLine("{0:00}: {1} = {2}", ctr, dict.Key, dict.Value);
        }
        rr.Close();
    }
Beispiel #27
0
        private int WriteResource(IResource resource)
        {
            IEmbeddedResource embeddedResource = resource as IEmbeddedResource;

            if (embeddedResource != null)
            {
                try
                {
                    byte[] buffer   = embeddedResource.Value;
                    string fileName = Path.Combine(_outputDirectory, resource.Name);

                    if (resource.Name.EndsWith(".resources"))
                    {
                        fileName = Path.ChangeExtension(fileName, ".resx");
                        using (MemoryStream ms = new MemoryStream(embeddedResource.Value))
                        {
                            ResXResourceWriter    resxw  = new ResXResourceWriter(fileName);
                            IResourceReader       reader = new ResourceReader(ms);
                            IDictionaryEnumerator en     = reader.GetEnumerator();
                            while (en.MoveNext())
                            {
                                resxw.AddResource(en.Key.ToString(), en.Value);
                            }
                            reader.Close();
                            resxw.Close();
                        }
                    }
                    else                     // other embedded resource
                    {
                        if (buffer != null)
                        {
                            using (Stream stream = File.Create(fileName))
                            {
                                stream.Write(buffer, 0, buffer.Length);
                            }
                        }
                    }
                    AddToProjectFiles(fileName);
                    return(0);
                }
                catch (Exception ex)
                {
                    WriteLine("Error in " + resource.Name + " : " + ex.Message);
                }
            }

            return(WriteOtherResource(resource));
        }
        public void PerformanceTest()
        {
            _resourceManager    = new ResourceManager("PerfResource", c_resDir);
            using var rwGerman  = new ResourceWriter(_resourceManager, s_german);
            using var rwEnglish = new ResourceWriter(_resourceManager, s_english);
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            for (int i = 0; i < 2048; i++)
            {
                rwEnglish.AddResource("ResNr_" + i, StringHelper.RandomString(4196));
            }
            rwEnglish.Close();
            for (int i = 0; i < 2048; i++)
            {
                rwGerman.AddResource("ResNr_" + i, StringHelper.RandomString(4196));
            }
            rwGerman.Close();
            sw.Stop();
            Console.WriteLine("Write: " + sw.Elapsed);
            _resourceManager.Dispose();
            _resourceManager = new ResourceManager("PerfResource", c_resDir);
            sw.Reset();
            using var rrGerman  = new ResourceReader(_resourceManager, s_german);
            using var rrEnglish = new ResourceReader(_resourceManager, s_english);
            var germanSet  = new ResourceSet(rrGerman);
            var englishSet = new ResourceSet(rrEnglish);

            rrGerman.Close();
            rrEnglish.Close();
            sw.Stop();
            Console.WriteLine("Read: " + sw.Elapsed);
            foreach ((string key, object value) in germanSet)
            {
                if (!(value is string str && str.Length == 4196))
                {
                    Assert.Fail();
                }
            }
            foreach ((string key, object value) in englishSet)
            {
                if (!(value is string str && str.Length == 4196))
                {
                    Assert.Fail();
                }
            }
            Assert.Pass();
        }
Beispiel #29
0
		public void Enumerator ()
		{
			Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
			ResourceReader reader = new ResourceReader (stream);

			IDictionaryEnumerator en = reader.GetEnumerator ();
			// Goes through the enumerator, printing out the key and value pairs.
			while (en.MoveNext ()) {
				DictionaryEntry de = (DictionaryEntry) en.Current;
				Assert.IsTrue (String.Empty != (string) de.Key, "Current.Key should not be empty");
				Assert.IsTrue (String.Empty != (string) de.Value, "Current.Value should not be empty");
				Assert.IsTrue (String.Empty != (string) en.Key, "Entry.Key should not be empty");
				Assert.IsTrue (String.Empty != (string) en.Value, "Entry.Value should not be empty");
			}
			reader.Close ();
		}
Beispiel #30
0
    public static void Main()
    {
        // Create a ResourceReader for the file items.resources.
        ResourceReader rr = new ResourceReader("items.resources");

        // Create an IDictionaryEnumerator to iterate through the resources.
        IDictionaryEnumerator id = rr.GetEnumerator();

        // Iterate through the resources and display the contents to the console.
        while (id.MoveNext())
        {
            Console.WriteLine("\n[{0}] \t{1}", id.Key, id.Value);
        }

        rr.Close();
    }
    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;
    }
Beispiel #32
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 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;
     }
   }