Esempio n. 1
0
  }//public static void ResourceAdd()

  ///<summary>ResourceList</summary>
  public static void ResourceList
  (
   ref UtilityResourceArgument  utilityResourceArgument,
   ref string                   exceptionMessage
  )
  {
   
   HttpContext            httpContext            =  HttpContext.Current;
   IDictionaryEnumerator  iDictionaryEnumerator  =  null;
   ResXResourceReader     resXResourceReader     =  null;
   
   try
   {
    foreach( string filenameCurrent in utilityResourceArgument.resourceFilename )
    {
     // Create a ResXResourceReader for the file items.resx.
     resXResourceReader    =  new ResXResourceReader( filenameCurrent );

     // Create an IDictionaryEnumerator to iterate through the resources.
     iDictionaryEnumerator  =  resXResourceReader.GetEnumerator();       

     // Iterate through the resources and display the contents to the console.
     foreach ( DictionaryEntry  dictionaryEntry in resXResourceReader ) 
     {
      System.Console.WriteLine
      (
       dictionaryEntry.Key.ToString() + ":\t" + dictionaryEntry.Value.ToString()
      );
     }//foreach ( DictionaryEntry  dictionaryEntry in iDictionaryEnumerator )

     //Close the reader.
     resXResourceReader.Close();
    }//foreach( string filenameCurrent in utilityResourceArgument.resourceFilename )
   }//try
   catch( Exception exception )
   {
    exceptionMessage = "Exception: " + exception.Message;   	
   }//catch( Expression expression )
   finally
   {
    if ( resXResourceReader != null )
    {
     resXResourceReader.Close();
    }//if ( resXResourceReader != null ) 
   }//finally   	

   if ( exceptionMessage != null )
   {
    if ( httpContext == null )
    {
     System.Console.WriteLine( exceptionMessage );
    }//if ( httpContext == null )
    else
    {
     //httpContext.Response.Write( exceptionMessage );
    }//else 
   }//if ( exceptionMessage != null )

  }//public static void ResourceList()
        public static Bitmap GetImgFromResource(string name)
        {
            ResXResourceReader resReader = new ResXResourceReader(RESOURCES_FILE_NAME);

            foreach (DictionaryEntry d in resReader)
            {
                if (d.Key.ToString().Equals(name))
                {
                    resReader.Close();
                    return((Bitmap)d.Value);
                }
            }
            resReader.Close();
            return((Bitmap)Resources.ResourceManager.GetObject("defaultImg", Resources.Culture));
        }
Esempio n. 3
0
        public static string GetHelpTooltipText(String path, string ResourceName)
        {
            Hashtable resourceEntries = new Hashtable();
            //Get existing resources
            ResXResourceReader reader = new ResXResourceReader(path);

            if (reader != null)
            {
                IDictionaryEnumerator id = reader.GetEnumerator();
                foreach (DictionaryEntry d in reader)
                {
                    if (d.Value == null)
                    {
                        resourceEntries.Add(d.Key.ToString(), "");
                    }
                    else
                    {
                        resourceEntries.Add(d.Key.ToString(), d.Value.ToString());
                    }
                }
                reader.Close();
            }

            string value = "";

            if (resourceEntries.ContainsKey(ResourceName))
            {
                value = resourceEntries[ResourceName].ToString();
            }

            return(value);
        }
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var dr = openFileDialog.ShowDialog();

            if (dr == DialogResult.OK)
            {
                var dictsList = new List <TranslationDictionary>();
                foreach (var file in openFileDialog.FileNames)
                {
                    // Load resources
                    try
                    {
                        var rr   = new ResXResourceReader(file);
                        var dict = new TranslationDictionary();
                        dict.Name = Path.GetFileNameWithoutExtension(file);
                        foreach (DictionaryEntry d in rr)
                        {
                            dict.Add(d.Key.ToString(), d.Value.ToString());
                        }
                        dictsList.Add(dict);
                        rr.Close();
                    }
                    catch (SecurityException ex)
                    {
                        MessageBox.Show("Security error. Please contact your administrator for details.\n\n" +
                                        "Error message: " + ex.Message + "\n\n" +
                                        "Details (send to Support):\n\n" + ex.StackTrace
                                        );
                    }
                }
        public void WriteRead1()
        {
            serializable ser = new serializable("aaaaa", "bbbbb");
            ResXDataNode dn  = new ResXDataNode("test", ser);

            dn.Comment = "comment";

            string resXFile = GetResXFileWithNode(dn, "resx.resx");

            bool found            = false;
            ResXResourceReader rr = new ResXResourceReader(resXFile);

            rr.UseResXDataNodes = true;
            IDictionaryEnumerator en = rr.GetEnumerator();

            while (en.MoveNext())
            {
                ResXDataNode node = ((DictionaryEntry)en.Current).Value as ResXDataNode;
                if (node == null)
                {
                    break;
                }
                serializable o = node.GetValue((AssemblyName [])null) as serializable;
                if (o != null)
                {
                    found = true;
                    Assert.AreEqual(ser, o, "#A1");
                    Assert.AreEqual("comment", node.Comment, "#A3");
                }
            }
            rr.Close();

            Assert.IsTrue(found, "#A2 - Serialized object not found on resx");
        }
        public ResourceControl(string content)
        {
            InitializeComponent();

            byte[] b = Convert.FromBase64String(content);
            innerContent    = Encoding.UTF8.GetString(b);
            originalContent = innerContent;
            innerType       = Enumerations.WebResourceType.Resx;

            Stream stream = new MemoryStream(b);

            table = new DataTable();
            table.Columns.Add(new DataColumn("Key"));
            table.Columns.Add(new DataColumn("Value"));

            Dictionary <string, string> resourceMap = new Dictionary <string, string>();

            rsxr = new ResXResourceReader(stream);
            foreach (DictionaryEntry d in rsxr)
            {
                if (string.IsNullOrEmpty(d.Key?.ToString()))
                {
                    continue;
                }
                table.Rows.Add(d.Key.ToString(), d.Value?.ToString());
            }
            rsxr.Close();

            dgv.DataSource = table;

            dgv.CellValueChanged += dgv_CellValueChanged;
            dgv.UserDeletedRow   += dgv_UserDeletedRow;;
        }
Esempio n. 7
0
        public void Test()
        {
            Thread.CurrentThread.CurrentCulture       =
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");

            ResXResourceWriter w = new ResXResourceWriter(fileName);

            w.AddResource("point", new Point(42, 43));
            w.Generate();
            w.Close();

            int count = 0;
            ResXResourceReader    r = new ResXResourceReader(fileName);
            IDictionaryEnumerator e = r.GetEnumerator();

            while (e.MoveNext())
            {
                if ((string)e.Key == "point")
                {
                    Assert.AreEqual(typeof(Point), e.Value.GetType(), "#1");
                    Point p = (Point)e.Value;
                    Assert.AreEqual(42, p.X, "#2");
                    Assert.AreEqual(43, p.Y, "#3");
                    count++;
                }
            }
            r.Close();
            Assert.AreEqual(1, count, "#100");
        }
        public override List <string> GetStatesForCountry(string Country)
        {
            List <string> items = null;

            string canadaResourceFile = string.Format("~\\App_GlobalResources\\PuertoRicoStates.{0}.resx", Thread.CurrentThread.CurrentCulture.Name);
            var    resxPath           = HttpContext.Current.Server.MapPath(canadaResourceFile);

            if (!File.Exists(resxPath))
            {
                resxPath = HttpContext.Current.Server.MapPath("~\\App_GlobalResources\\PuertoRicoStates.resx");
            }

            if (File.Exists(resxPath))
            {
                // Get info from resx
                var resxReader     = new ResXResourceReader(resxPath);
                var resxDictionary = resxReader.Cast <DictionaryEntry>().ToDictionary
                                         (r => r.Key.ToString(), r => r.Value.ToString());
                resxReader.Close();

                items = (from s in resxDictionary
                         select string.Format("{0} - {1}", s.Key, s.Value)).ToList <string>();
            }

            return(items);
        }
Esempio n. 9
0
        public void Load(string lang, string filename)
        {
            ResXResourceReader reader = new ResXResourceReader(filename);

            reader.BasePath         = Path.GetDirectoryName(filename);
            reader.UseResXDataNodes = true;

            try
            {
                foreach (DictionaryEntry entry in reader)
                {
                    string key   = entry.Key.ToString();
                    string value = entry.Value.ToString();
                    if (!translatedKey.ContainsKey(key))
                    {
                        translatedKey.Add(key, new TranslatedKey());
                    }
                    translatedKey[key].Add(lang, value);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            reader.Close();

            files[lang] = filename;
        }
Esempio n. 10
0
        public void WriteRead1()
        {
            ResXResourceWriter rw  = new ResXResourceWriter("resx.resx");
            serializable       ser = new serializable("aaaaa", "bbbbb");
            ResXDataNode       dn  = new ResXDataNode("test", ser);

            dn.Comment = "comment";
            rw.AddResource(dn);
            rw.Close();

            bool found = false;
            ResXResourceReader    rr = new ResXResourceReader("resx.resx");
            IDictionaryEnumerator en = rr.GetEnumerator();

            while (en.MoveNext())
            {
                serializable o = ((DictionaryEntry)en.Current).Value as serializable;
                if (o != null)
                {
                    found = true;
                    Assert.AreEqual(ser, o, "#A1");
                }
            }
            rr.Close();

            Assert.IsTrue(found, "#A2 - Serialized object not found on resx");
        }
        public void SaveResxAsTypeScriptFile(string[] resxFiles, string outputTSFilePAth)
        {
            var sb = new StringBuilder();

            sb.AppendLine("// This file is auto generated");
            sb.AppendLine("");
            sb.AppendLine("export class PortalResources");
            sb.AppendLine("{");

            foreach (var resxFile in resxFiles)
            {
                if (File.Exists(resxFile))
                {
                    ResXResourceReader rsxr = new ResXResourceReader(resxFile);
                    foreach (DictionaryEntry d in rsxr)
                    {
                        sb.AppendLine(string.Format("    public static {0}: string = \"{0}\";", d.Key.ToString()));
                    }

                    //Close the reader.
                    rsxr.Close();
                }
            }
            sb.AppendLine("}");

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(outputTSFilePAth))
            {
                file.WriteLine(sb.ToString());
            }
        }
Esempio n. 12
0
        public string ReadResFile(string key)
        {
            string resourceValue = string.Empty;
            string file          = "";

            switch (Employee.TheLanguageCode)
            {
            case "da-DK": file = "Message.da-DK.resx";
                break;

            case "de-DE": file = "Message.de-DE.resx";
                break;

            case "en-US": file = "Message.en-US.resx";
                break;
            }
            ResXResourceReader    r  = new ResXResourceReader(file);
            IDictionaryEnumerator en = r.GetEnumerator();

            while (en.MoveNext())
            {
                if (en.Key.Equals(key))
                {
                    return(resourceValue = en.Value.ToString());
                }
            }
            r.Close();
            return("");
        }
Esempio n. 13
0
    public static List <DictionaryEntry> ReadResourceFile(string path)
    {
        List <DictionaryEntry> resourceEntries = new List <DictionaryEntry>();

        //Get existing resources
        ResXResourceReader reader = new ResXResourceReader(path);

        reader.UseResXDataNodes = true;
        System.ComponentModel.Design.ITypeResolutionService typeres = null;
        if (reader != null)
        {
            IDictionaryEnumerator id = reader.GetEnumerator();
            DictionaryEntry       emptyValue;
            emptyValue.Value = "";

            foreach (DictionaryEntry d in reader)
            {
                //Read from file:
                if (d.Value == null)
                {
                    emptyValue.Key = d.Key;
                    resourceEntries.Add(emptyValue);
                }
                else
                {
                    resourceEntries.Add(d);
                }
            }
            reader.Close();
        }

        return(resourceEntries);
    }
Esempio n. 14
0
        public void Convert(Options options)
        {
            var resourceFiles = resxReader.GetResourceFiles(options.InputFolder);

            var baseResourceFile = resourceFiles.First(x => x.IsBaseResourceType);

            var baseResourceDict = resxReader.GetKeyValuePairsFromResxFile(baseResourceFile);

            foreach (var resourceFile in resourceFiles)
            {
                var jsFileNameWithoutPath = resourceFile.ResourceFilePathName.Substring(resourceFile.ResourceFilePathName.LastIndexOf("\\") + 1) + ".js";
                var outputJsFilePathName  = Path.Combine(options.OutputFolder, jsFileNameWithoutPath);

                if (resourceFile.IsBaseResourceType)
                {
                    WriteOutput(options, baseResourceDict, outputJsFilePathName);
                }
                else
                {
                    var cultureSpecificResourceDict = objectCopier.Copy(baseResourceDict);
                    var rsxr = new ResXResourceReader(resourceFile.ResourceFilePathName);
                    foreach (DictionaryEntry d in rsxr)
                    {
                        var key = d.Key as string;
                        cultureSpecificResourceDict[key] = d.Value.ToString();
                    }
                    //Close the reader.
                    rsxr.Close();

                    WriteOutput(options, cultureSpecificResourceDict, outputJsFilePathName);
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Function which fills the Dictionnary
        /// <param name="_Language">Language chosen for the software</param>
        /// <param name="_File_Handler">Global file handler</param>
        /// <returns>True if the filling has been correctly done, false otherwise</returns>
        /// </summary>
        public bool Fill_Resources(string _Language, Files _File_Handler)
        {
            string fileName = @"Language\Language_" + _Language + ".resx";

            if (_File_Handler.File_Exists(fileName) == false)
            {
                Console.WriteLine("File does not exist - " + fileName);
                return(false);
            }
            try
            {
                ResXResourceReader resourceReader = new ResXResourceReader(fileName);
                m_ResourceMap = new Dictionary <string, string>();
                foreach (DictionaryEntry dico in resourceReader)
                {
                    m_ResourceMap.Add(dico.Key.ToString(), dico.Value.ToString());
                }
                resourceReader.Close();
                return(true);
            }
            catch (Exception e)
            {
                m_Error_Handler.WriteException(System.Reflection.MethodBase.GetCurrentMethod().Name, e);
                return(false);
            }
        }
Esempio n. 16
0
        private void Initialize()
        {
            try
            {
                ResXResourceReader reader = new ResXResourceReader(m_filename);

                IEnumerable <DictionaryEntry> enumerator = reader.OfType <DictionaryEntry>();

                if (enumerator == null)
                {
                    m_entriesInitialized = false;
                }
                else
                {
                    m_entries = (from ent in enumerator
                                 select new ResourceEntry(ent)).ToList();
                    m_totalCharacterCount = (int)m_entries.Sum(w => w.OriginalValue.Length);
                    m_entriesInitialized  = true;
                }

                reader.Close();
            }
            catch
            {
                m_entriesInitialized = false;
            }
        }
Esempio n. 17
0
        private void cargar_menu(String idioma)
        {
            ToolStripMenuItem[] mnuOpcion;
            ToolStripMenuItem   mnuSubOpcion;

            mnuOpcion = new ToolStripMenuItem[100];
            int i = 0;

            menuStrip1.Items.Clear();

            ResXResourceReader rsxr = new ResXResourceReader(".\\RecursosLocalizables\\StringResources" + idioma + ".resx");

            foreach (DictionaryEntry d in rsxr)
            {
                i = int.Parse(d.Key.ToString().Substring(4, 1));
                if (d.Key.ToString().Contains("main"))
                {
                    mnuOpcion[i]     = new ToolStripMenuItem(d.Value.ToString());
                    mnuOpcion[i].Tag = d.Key.ToString();
                    menuStrip1.Items.Add(mnuOpcion[i]);
                }
                if (d.Key.ToString().Contains("sub_"))
                {
                    mnuSubOpcion        = new ToolStripMenuItem(d.Value.ToString());
                    mnuSubOpcion.Tag    = d.Key.ToString();
                    mnuSubOpcion.Click += menuStrip1_Click;
                    mnuOpcion[i].DropDownItems.Add(mnuSubOpcion);
                }
                if (d.Key.ToString().Contains("titu1"))
                {
                    this.Text = d.Value.ToString();
                }
            }
            rsxr.Close();
        }
Esempio n. 18
0
        public void LoadResource( )
        {
            OpenFileDialog ofd = new OpenFileDialog( );

            ofd.CheckFileExists = true;
            ofd.Filter          = "resx files (*.resx)|*.resx|All files (*.*)|*.*";

            if (last_load_resx_directory != String.Empty)
            {
                if (Directory.Exists(last_load_resx_directory))
                {
                    ofd.InitialDirectory = last_load_resx_directory;
                }
            }

            if (DialogResult.OK == ofd.ShowDialog( ))
            {
                ClearResources( );

                resXResourceReader = new ResXResourceReader(ofd.FileName);

                Text = Path.GetFileName(ofd.FileName);

                fullFileName = ofd.FileName;

                last_load_resx_directory = Path.GetDirectoryName(ofd.FileName);

                number_resources = resourceSelectionControl.LoadResource(resXResourceReader);

                resXResourceReader.Close( );

                UpdateStatusBar( );
            }
        }
        public static List <Language> GetLists(String PhysicalApplicationPath, String langage = "langage")
        {
            List <Language> cmblanguages  = new List <Language>();
            string          resourcespath = PhysicalApplicationPath + "App_GlobalResources/" + langage;
            DirectoryInfo   dirInfo       = new DirectoryInfo(resourcespath);

            foreach (FileInfo filInfo in dirInfo.GetFiles())
            {
                string filename = filInfo.Name;
                if (!filename.ToUpper().EndsWith(".designer.cs".ToUpper()))
                {
                    ResXResourceReader    RrX  = new ResXResourceReader(filInfo.Directory.FullName + "\\" + filInfo.Name);
                    IDictionaryEnumerator RrEn = RrX.GetEnumerator();
                    Language language          = new Language();
                    while (RrEn.MoveNext())
                    {
                        if (RrEn.Key.ToString() == "code")
                        {
                            language.Code = RrEn.Value.ToString();
                        }
                        if (RrEn.Key.ToString() == "Language")
                        {
                            language.Name = RrEn.Value.ToString();
                        }
                    }
                    cmblanguages.Add(language);
                    RrX.Close();
                }
            }
            return(cmblanguages);
        }
Esempio n. 20
0
        public static List <ResXEntry> Read(string filename, Option options = Option.None)
        {
            var result = new List <ResXEntry>();

            using (var resx = new ResXResourceReader(filename))
            {
                resx.UseResXDataNodes = true;
                var dict = resx.GetEnumerator();
                while (dict.MoveNext())
                {
                    var node    = dict.Value as ResXDataNode;
                    var comment = options.HasFlag(Option.SkipComments) ? string.Empty : node.Comment.Replace("\r", string.Empty);
                    result.Add(new ResXEntry()
                    {
                        Id      = dict.Key as string,
                        Value   = (node.GetValue((ITypeResolutionService)null) as string).Replace("\r", string.Empty),
                        Comment = comment
                    });
                }

                resx.Close();
            }

            return(result);
        }
Esempio n. 21
0
 /// <summary>
 /// 合并所有来自其他程序集的资源到主资源,前提是资源文件在对应项目的App_Data文件夹下
 /// </summary>
 /// <param name="resNamespaces">资源所在的命名空间名称列表</param>
 /// <param name="overwriteExists">是否覆盖已经定义的资源</param>
 public static void CombinAssemblyResx(IEnumerable <Assembly> assemblys, bool overwriteExists = false)
 {
     foreach (var ns in assemblys)
     {
         foreach (string cultureName in GetUsedCultureNames())
         {
             string resName = "app_data/customstrings." + cultureName.ToLower() + ".resx";
             Stream stream  = GetGResources(ns, resName) as Stream;
             if (stream == null)
             {
                 continue;
             }
             ResXResourceReader reader = new ResXResourceReader(stream);
             var coll = GetCollection(cultureName);
             foreach (DictionaryEntry d in reader)
             {
                 if ((coll[CommOp.ToStr(d.Key)].IsEmpty() || overwriteExists) &&
                     !CommOp.ToStr(d.Value).IsEmpty())
                 {
                     coll[CommOp.ToStr(d.Key)] = CommOp.ToStr(d.Value);
                 }
             }
             reader.Close();
         }
     }
 }
Esempio n. 22
0
        protected void OnSaveClick(object sender, EventArgs e)
        {
            List <string>         resourceNames  = new List <string>();
            ResXResourceReader    resxReader     = new ResXResourceReader(string.Format("{0}/App_Resources/Templates.resx", WebRootPath.Instance.ToString()));
            IDictionaryEnumerator resxEnumerator = resxReader.GetEnumerator();

            while (resxEnumerator.MoveNext())
            {
                resourceNames.Add(resxEnumerator.Key.ToString());
            }
            resxReader.Close();

            ResXResourceWriter resxWriter = new ResXResourceWriter(string.Format("{0}\\App_Resources/Templates.resx", WebRootPath.Instance.ToString()));

            try
            {
                foreach (string name in resourceNames)
                {
                    string value = Request.Form[string.Format("{0}${1}$TxtValue", this.RepResources.UniqueID, name)];
                    resxWriter.AddResource(name, value);
                }
                resxWriter.Close();
            }
            catch (Exception)
            {
            }
        }
Esempio n. 23
0
        public void AddResource_WithComment()
        {
            ResXResourceWriter w    = new ResXResourceWriter(fileName);
            ResXDataNode       node = new ResXDataNode("key", "value");

            node.Comment = "comment is preserved";
            w.AddResource(node);
            w.Generate();
            w.Close();

            ResXResourceReader     r       = new ResXResourceReader(fileName);
            ITypeResolutionService typeres = null;

            r.UseResXDataNodes = true;

            int count = 0;

            foreach (DictionaryEntry o in r)
            {
                string key = o.Key.ToString();
                node = (ResXDataNode)o.Value;
                string value   = node.GetValue(typeres).ToString();
                string comment = node.Comment;

                Assert.AreEqual("key", key, "key");
                Assert.AreEqual("value", value, "value");
                Assert.AreEqual("comment is preserved", comment, "comment");
                Assert.AreEqual(0, count, "too many nodes");
                count++;
            }
            r.Close();

            File.Delete(fileName);
        }
Esempio n. 24
0
        private void DisplayResx()
        {
            if (Resource == null)
            {
                return;
            }

            byte[] b = Convert.FromBase64String(Resource.Content);

            Stream stream = new MemoryStream(b);

            table = new DataTable();
            table.Columns.Add(new DataColumn("Key"));
            table.Columns.Add(new DataColumn("Value"));

            rsxr = new ResXResourceReader(stream);
            foreach (DictionaryEntry d in rsxr)
            {
                if (string.IsNullOrEmpty(d.Key?.ToString()))
                {
                    continue;
                }
                table.Rows.Add(d.Key.ToString(), d.Value?.ToString());
            }
            rsxr.Close();

            dgv.DataSource = table;

            dgv.CellValueChanged += dgv_CellValueChanged;
            dgv.UserDeletedRow   += dgv_UserDeletedRow;
        }
Esempio n. 25
0
            public static void TestReader(string fileName)
            {
                ResXResourceReader r = new ResXResourceReader(fileName);
                Hashtable          h = new Hashtable();

                foreach (DictionaryEntry e in r)
                {
                    h.Add(e.Key, e.Value);
                }
                r.Close();

                Assert.AreEqual("hola", (string)h ["String"], fileName + "#1");
                Assert.AreEqual("hello", (string)h ["String2"], fileName + "#2");
                Assert.AreEqual(42, (int)h ["Int"], fileName + "#3");
                Assert.AreEqual(PlatformID.Win32NT, (PlatformID)h ["Enum"], fileName + "#4");
                Assert.AreEqual(43, ((Point)h ["Convertible"]).X, fileName + "#5");
                Assert.AreEqual(2, (byte)((ArrayList)h ["Serializable"]) [1], fileName + "#6");
                Assert.AreEqual(13, ((byte [])h ["ByteArray"]) [1], fileName + "#7");
                Assert.AreEqual(16, ((byte [])h ["ByteArray2"]) [1], fileName + "#8");
                Assert.AreEqual(1013, ((int [])h ["IntArray"]) [1], fileName + "#9");
                Assert.AreEqual("world", ((string [])h ["StringArray"]) [1], fileName + "#10");
                Assert.IsNull(h ["InvalidMimeType"], "#11");
                Assert.IsNotNull(h ["Image"], fileName + "#12");
                Assert.AreEqual(typeof(Bitmap), h ["Image"].GetType(), fileName + "#13");
            }
	private void RemoveEmptyEntries (string file)
	{
		try {
			var newFile = file + ".out";
			using (ResXResourceWriter resxWriter = new ResXResourceWriter (newFile)) {
				var resxReader = new ResXResourceReader(file);
				resxReader.UseResXDataNodes = true;
				foreach (DictionaryEntry entry in resxReader) {
					var node = (ResXDataNode) entry.Value;
					if (!string.IsNullOrEmpty (node.GetValue((ITypeResolutionService) null).ToString ())) {
						resxWriter.AddResource (node);
					}
				}
				resxReader.Close ();
			}

			if (new FileInfo (newFile).Length < new FileInfo (file).Length) {
				File.Delete (file);
				File.Move (newFile, file);
			}
			else {
				File.Delete (newFile);
			}
		}
		catch (Exception ex) {
			Console.WriteLine ("{0}: {1}", file, ex.Message);
		}
	}
Esempio n. 27
0
        public ResourcesHelper Find(string id)
        {
            ResourcesHelper res = new ResourcesHelper();

            if (Directory.Exists(_path))
            {
                return(null);
            }
            _readerEn = new ResXResourceReader(_path);

            _resourceEn = new Hashtable();

            if (_readerEn != null)
            {
                foreach (DictionaryEntry d in _readerEn)
                {
                    string key = d.Key.ToString();
                    if (key == id)
                    {
                        res.Key     = d.Key.ToString();
                        res.English = d.Value.ToString();
                        res.Nepali  = GetNepaliValue(res.Key);
                    }
                }
                _readerEn.Close();
            }
            return(res);
        }
Esempio n. 28
0
        public void LoadResourceFile(String FileName)
        {
            this.FileName = FileName;
            String x = Path.GetExtension(FileName);

            if ((String.Compare(x, ".xml", true) == 0) || (String.Compare(x, ".resX", true) == 0))
            {
                ResXResourceReader    r = new ResXResourceReader(FileName);
                IDictionaryEnumerator n = r.GetEnumerator();
                while (n.MoveNext())
                {
                    if (!Resource.ContainsKey(n.Key))
                    {
                        Resource.Add(n.Key, n.Value);
                    }
                }
                r.Close();
                Initialize();
            }
            else
            {
                FileStream s = new FileStream(FileName, FileMode.Open);
                LoadResourceStream(s);
                s.Close();
            }
        }
Esempio n. 29
0
        public List <ResourcesHelper> List()
        {
            List <ResourcesHelper> lst = new List <ResourcesHelper>();

            if (Directory.Exists(_path))
            {
                return(null);
            }
            _readerEn = new ResXResourceReader(_path);

            _resourceEn = new Hashtable();

            if (_readerEn != null)
            {
                foreach (DictionaryEntry d in _readerEn)
                {
                    ResourcesHelper res = new ResourcesHelper();
                    res.Key     = d.Key.ToString();
                    res.English = d.Value.ToString();
                    res.Nepali  = GetNepaliValue(res.Key);
                    lst.Add(res);
                }
                _readerEn.Close();
            }

            return(lst);
        }
Esempio n. 30
0
 /// <summary>
 /// read existing resource files
 /// </summary>
 private void ReadResource()
 {
     if (Directory.Exists(_path))
     {
         return;
     }
     _readerEn   = new ResXResourceReader(_path);
     _readerNe   = new ResXResourceReader(_pathNe);
     _resourceEn = new Hashtable();
     _resourceNe = new Hashtable();
     if (_readerEn != null)
     {
         foreach (DictionaryEntry d in _readerEn)
         {
             _resourceEn.Add(d.Key.ToString(), d.Value.ToString());
         }
         _readerEn.Close();
     }
     if (_readerNe != null)
     {
         foreach (DictionaryEntry d in _readerNe)
         {
             _resourceNe.Add(d.Key.ToString(), d.Value.ToString());
         }
         _readerNe.Close();
     }
 }
Esempio n. 31
0
        public int GetCharCountOfFile(string resxFile)
        {
            int count = 0;
            ResXResourceReader reader;

            try
            {
                reader = new ResXResourceReader(resxFile);
            }
            catch (Exception ex)
            {
                return(count);
            }

            foreach (DictionaryEntry d in reader)
            {
                var value = d.Value as string;
                if (value != null)
                {
                    count += d.Value.ToString().Length;
                }
            }

            reader.Close();

            return(count);
        }
Esempio n. 32
0
 protected void cmbResources_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cmbResources.SelectedIndex != 0)
     {
         panelUpdate.Visible = false;
         string filename = Request.PhysicalApplicationPath + "App_GlobalResources\\" + cmbResources.SelectedItem.Text;
         Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
         ResXResourceReader RrX = new ResXResourceReader(stream);
         IDictionaryEnumerator RrEn = RrX.GetEnumerator();
         SortedList slist = new SortedList();
         while (RrEn.MoveNext())
         {
             slist.Add(RrEn.Key, RrEn.Value);
         }
         RrX.Close();
         stream.Dispose();
         gridView1.DataSource = slist;
         gridView1.DataBind();
     }
 }
Esempio n. 33
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();
        }
    }