GetEnumerator() private method

private GetEnumerator ( ) : IDictionaryEnumerator
return IDictionaryEnumerator
Esempio n. 1
0
        public MyResourceDataFile(string fileName)
        {
#if DOTNETCORE
            var reader = new System.Resources.Extensions.DeserializingResourceReader(fileName);
#else
            var reader = new System.Resources.ResourceReader(fileName);
#endif

            this.FileName = fileName;
            this.Name     = Path.GetFileNameWithoutExtension(fileName);
            var  objValues   = new Dictionary <string, object>();
            var  strValues   = new Dictionary <string, string>();
            var  resouceSet  = new System.Resources.ResourceSet(reader);
            var  enumer      = resouceSet.GetEnumerator();
            var  lstData     = new List <byte>();
            bool hasBmpValue = false;
            while (enumer.MoveNext())
            {
                string itemName = (string)enumer.Key;
                var    item     = new MyResourceDataItem();
                item.Name       = itemName;
                item.StartIndex = lstData.Count;
                item.Key        = _Random.Next(1000, int.MaxValue - 1000);
                item.Value      = enumer.Value;
                if (enumer.Value is string)
                {
                    item.IsBmp = false;
                    string str = (string)item.Value;
                    int    key = item.Key;
                    for (int iCount = 0; iCount < str.Length; iCount++, key++)
                    {
                        var v = str[iCount] ^ key;
                        lstData.Add((byte)(v >> 8));
                        lstData.Add((byte)(v & 0xff));
                    }
                }
                else if (enumer.Value is System.Drawing.Bitmap)
                {
                    item.IsBmp  = true;
                    hasBmpValue = true;
                    var ms = new System.IO.MemoryStream();
                    ((System.Drawing.Bitmap)item.Value).Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                    var  bs2 = ms.ToArray();
                    byte key = (byte)item.Key;
                    for (int iCount = 0; iCount < bs2.Length; iCount++, key++)
                    {
                        bs2[iCount] = (byte)(bs2[iCount] ^ key);
                    }
                    lstData.AddRange(bs2);
                }
                else
                {
                    throw new NotSupportedException(item.Value.GetType().FullName);
                }
                item.BsLength = lstData.Count - item.StartIndex;
                this.Items.Add(item);
            }
            resouceSet.Close();
            this.Datas = lstData.ToArray();
        }
        private List <string> ResolveKeys()
        {
            List <string> keys = new List <string>(100);

            System.IO.Stream fs = _assembly.GetManifestResourceStream(_baseName + ".resources");

            using (var streamResx = new System.Resources.ResourceSet(fs))
            {
                IDictionaryEnumerator enumerator = streamResx.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    keys.Add(enumerator.Key.ToString());
                }
            }

            keys.Sort();

            return(keys);
        }
        public string CreateClassFromResourceSet(ResourceSet resourceSet, string nameSpace, string classname, string fileName)
        {
            IsVb = IsFileVb(fileName);

            StringBuilder sbClass = new StringBuilder();

            CreateClassHeader(classname, nameSpace, IsVb, sbClass);

            string indent = "\t\t";

            // Any resource set that contains a '.' is considered a Local Resource
            bool IsGlobalResource = !classname.Contains(".");

            // We'll enumerate through the Recordset to get all the resources
            IDictionaryEnumerator Enumerator = resourceSet.GetEnumerator();

            // We have to turn into a concrete Dictionary            
            while (Enumerator.MoveNext())
            {
                DictionaryEntry item = (DictionaryEntry)Enumerator.Current;
                if (item.Value == null)
                    item.Value = string.Empty;

                string typeName = item.Value.GetType().FullName;
                string key = item.Key as string;
                if (string.IsNullOrEmpty(key))
                    continue;

                string varName = SafeVarName(key);

                // It's a string
                if (!IsVb)
                {
                    sbClass.Append(indent + "public static " + typeName + " " + varName + "\r\n" + indent + "{\r\n");
                    sbClass.AppendFormat(indent + "\tget\r\n" +
                                         indent + "\t{{\r\n" +
                                         indent +
                                         (string.IsNullOrEmpty(typeName) || typeName == "System.String"
                                         ? "\t\t" + @"return GeneratedResourceHelper.GetResourceString(""{0}"",""{1}"",ResourceManager,GeneratedResourceSettings.ResourceAccessMode);" + "\r\n"
                                         : "\t\t" + @"return ({2}) GeneratedResourceHelper.GetResourceObject(""{0}"",""{1}"",ResourceManager,GeneratedResourceSettings.ResourceAccessMode);" + "\r\n")
                                         +
                                         indent + "\t}}\r\n",
                                         classname, key, typeName);
                    sbClass.Append(indent + "}\r\n\r\n");
                }
                else
                {
                    sbClass.Append(indent + "Public Shared Property " + varName + "() as " + typeName + "\r\n");
                    sbClass.AppendFormat(indent + "\tGet\r\n" + indent + "\t\treturn CType( HttpContext.GetGlobalResourceObject(\"{0}\",\"{1}\"), {2})\r\n",
                                         classname, key, typeName);
                    sbClass.Append(indent + "\tEnd Get\r\n");
                    sbClass.Append(indent + "End Property\r\n\r\n");
                }
            }

            if (!IsVb)
                sbClass.Append("\t}\r\n\r\n");
            else
                sbClass.Append("End Class\r\n\r\n");

            string Output = CreateNameSpaceWrapper(nameSpace, IsVb, sbClass.ToString());

            if (!string.IsNullOrEmpty(fileName))
            {
                File.WriteAllText(fileName, Output);
                return Output;
            }

            return sbClass.ToString();
        }
        /// <summary>
        /// Creates a strongly typed resource from a ResourceSet object. The ResourceSet passed should always
        /// be the invariant resourceset that contains all the ResourceIds.
        /// 
        /// Creates strongly typed keys for each of the keys/values.
        /// </summary>
        /// <param name="ResourceSet"></param>
        /// <param name="Namespace">Namespace of the generated class. Pass Null or string.Empty to not generate a namespace</param>
        /// <param name="Classname">Name of the class to generate. Pass null to use the ResourceSet name</param>
        /// <param name="FileName">Output filename for the CSharp class. If null no file is generated and only the class is returned</param>
        /// <returns></returns>
        public string CreateClassFromResourceSet(ResourceSet ResourceSet, string Namespace, string Classname, string FileName)
        {
            this.IsVb = this.IsFileVb(FileName);

            StringBuilder sbClass = new StringBuilder();

            this.CreateClassHeader(Classname, IsVb, sbClass);

            string Indent = "\t\t";

            // Any resource set that contains a '.' is considered a Local Resource
            bool IsGlobalResource = !Classname.Contains(".");

            // We'll enumerate through teh Recordset to get all the resources
            IDictionaryEnumerator Enumerator = ResourceSet.GetEnumerator();

            // We have to turn into a concrete Dictionary            
            while (Enumerator.MoveNext())
            {
                DictionaryEntry Item = (DictionaryEntry)Enumerator.Current;

                string TypeName = Item.Value.GetType().FullName;
                string Key = Item.Key as string;
                Key = Key.Replace(".", "_");
                if (string.IsNullOrEmpty(Key))
                    continue;

                // It's a string
                if (!IsVb)
                {
                    sbClass.Append(Indent + "public static " + TypeName + " " + Key + "\r\n" + Indent + "{\r\n");
                    sbClass.AppendFormat(Indent + "\tget {{ return ({2}) HttpContext.GetGlobalResourceObject(\"{0}\",\"{1}\"); }}\r\n",
                                         Classname, Key,TypeName);
                    sbClass.Append(Indent + "}\r\n\r\n");                    
                }
                else
                {
                    sbClass.Append(Indent + "Public Shared Property " + Key + "() as " + TypeName + "\r\n");
                    sbClass.AppendFormat(Indent + "\tGet\r\n" + Indent + "\t\treturn CType( HttpContext.GetGlobalResourceObject(\"{0}\",\"{1}\"), {2})\r\n",
                                         Classname, Key,TypeName);
                    sbClass.Append(Indent + "\tEnd Get\r\n");
                    sbClass.Append(Indent + "End Property\r\n\r\n");
                }
            }

            if (!this.IsVb)
                sbClass.Append("\t}\r\n\r\n");
            else
                sbClass.Append("End Class\r\n\r\n");

            string Output = this.CreateNameSpaceWrapper(Namespace,this.IsVb,sbClass.ToString() );

            if (!string.IsNullOrEmpty(FileName))
            {
                File.WriteAllText(FileName, Output);
                return Output;
            }
                
            return sbClass.ToString();
        }
        // 
        // Add all the availabe resource names in ResourceSet to ArrayList
        //
        private void AddResourceNameToList(ResourceSet rs, ref ArrayList resourceList)
        {
            IDictionaryEnumerator deResources;

            deResources = rs.GetEnumerator();

            if (deResources != null)
            {
                while (deResources.MoveNext())
                {
                    string resName = deResources.Key as string;

                    resourceList.Add(resName);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Loads all strings found in the resource
        /// </summary>
        /// <param name="path">The path of the resource from where to load the data.</param>
        public bool LoadFromResource(string path)
        {
            if(path == null) {
                throw new ArgumentNullException("path");
            }

            try {
                ResourceSet set = new ResourceSet(path);

                if(set == null) {
                    return false;
                }

                // extract the string resources
                IDictionaryEnumerator id = set.GetEnumerator();

                while(id.MoveNext()) {
                    if(id.Key is string && id.Value is string) {
                        AddString((string)id.Key, (string)id.Value);
                    }
                }
            }
            catch(Exception e) {
                Console.WriteLine(e.Message);
                return false;
            }

            return true;
        }