コード例 #1
0
        /// <summary>
        /// [FAE] Obtiene un Listado de recursos por Modulo
        /// </summary>
        /// <param name="filterFileName"></param>
        /// <param name="keyFilter">indicador de subtipo de recurso [Ctrl|Msg|Url]</param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public static Dictionary <string, string> GetResourcesByFilter(string filterFileName, string keyFilter = null, string culture = null)
        {
            CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

            if (string.IsNullOrEmpty(culture))
            {
                culture = currentCulture.Name;
            }
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            var             path          = System.Web.HttpContext.Current.Server.MapPath("~/App_GlobalResources");
            var             directoryInfo = new DirectoryInfo(path);
            List <FileInfo> filesInfo     = new List <FileInfo>();

            if (string.IsNullOrWhiteSpace(filterFileName))
            {
                filesInfo = directoryInfo.GetFiles("*." + culture + ".resx").ToList();
            }
            else
            {
                filesInfo = directoryInfo.GetFiles("*" + filterFileName + "*." + culture + ".resx").ToList();
            }

            foreach (var fileInfo in filesInfo)
            {
                var reader = new ResXResourceReader(fileInfo.FullName);
                dictionary = reader.Cast <DictionaryEntry>().ToDictionary(a => a.Key.ToString(), a => a.Value.ToString());
            }

            if (!string.IsNullOrWhiteSpace(keyFilter))
            {
                dictionary = dictionary.Where(r => r.Key.ToUpper().Contains(keyFilter.ToUpper())).ToDictionary(r => r.Key, r => r.Value);
            }
            return(dictionary);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: splinter21/CeVIO.CN
        public static void AddResource(Dictionary <string, object> res, string inputPath, string outputPath)
        {
            var dic = new Dictionary <string, ResXDataNode>();

            using (var reader = new ResXResourceReader(inputPath)
            {
                UseResXDataNodes = true
            })
            {
                dic = reader.Cast <DictionaryEntry>().ToDictionary(e => e.Key.ToString(), e => e.Value as ResXDataNode);
                foreach (var kv in res)
                {
                    if (!dic.ContainsKey(kv.Key) && !SkipList.Contains(kv.Key))
                    {
                        dic.Add(kv.Key, new ResXDataNode(kv.Key, kv.Value)
                        {
                            Comment = kv.Value.ToString()
                        });
                    }
                }
            }

            using (var writer = new ResXResourceWriter(outputPath))
            {
                foreach (var kv in dic)
                {
                    writer.AddResource(kv.Key, kv.Value);
                }

                writer.Generate();
            }
        }
コード例 #3
0
        public static void Update(string className, string folderPath, List <LanguageModel> languageResources)
        {
            foreach (var languageResource in languageResources)
            {
                XmlDocument document = new XmlDocument();

                var xmlPath = GetResxPath(className, folderPath, languageResource.Name);

                if (!File.Exists(xmlPath))
                {
                    throw new Exception("Cannot find 'Resouce' file");
                }

                var resxItems = new List <DictionaryEntry>();
                using (var reader = new ResXResourceReader(xmlPath))
                {
                    resxItems = reader.Cast <DictionaryEntry>().ToList();
                }

                using (var writer = new ResXResourceWriter(xmlPath))
                {
                    foreach (var item in resxItems)
                    {
                        var value = item.Value;
                        if (languageResource.Values.Any(x => x.Key.Equals(item.Key.ToString())))
                        {
                            value = languageResource.Values.FirstOrDefault(x => x.Key.Equals(item.Key.ToString())).Value;
                        }
                        writer.AddResource(item.Key.ToString(), item.Value);
                    }
                    writer.Generate();
                }
            }
        }
コード例 #4
0
            public override void Write(byte[] buffer, int offset, int count)
            {
                var contentInBuffer = Encoding.UTF8.GetString(buffer);

                // Get localized resource file (or default as fallback)
                string resxFile = null;

                if (HttpContext.Current.Request.Cookies["language"] != null)
                {
                    var resxFileLocalized = HttpContext.Current.Server.MapPath($"~/DesktopModules/DnnDevTools/App_LocalResources/Overlay.{HttpContext.Current.Request.Cookies["language"]?.Value}.resx");
                    if (File.Exists(resxFileLocalized))
                    {
                        resxFile = resxFileLocalized;
                    }
                }
                if (string.IsNullOrWhiteSpace(resxFile))
                {
                    resxFile = HttpContext.Current.Server.MapPath($"~/DesktopModules/DnnDevTools/App_LocalResources/Overlay.resx");
                }

                // Localize content
                var rsxr = new ResXResourceReader(resxFile);

                contentInBuffer = rsxr.Cast <DictionaryEntry>().Aggregate(contentInBuffer, (current, d) => current.Replace($"[res:{d.Key}]", d.Value.ToString()));
                _outputStream.Write(Encoding.UTF8.GetBytes(contentInBuffer), offset, Encoding.UTF8.GetByteCount(contentInBuffer));
            }
コード例 #5
0
        public static ExcelModel ConvertToExcelData(string resxFolder)
        {
            var keys    = new List <string>();
            var columns = new List <ColumnModel>();
            var files   = Directory.GetFiles(resxFolder, "*.resx");

            foreach (var file in files)
            {
                using (var reader = new ResXResourceReader(file))
                {
                    var resxItems    = reader.Cast <DictionaryEntry>();
                    var languageName = GetLanguageName(file);

                    if (string.IsNullOrWhiteSpace(languageName))
                    {
                        languageName = "default";
                    }

                    keys.AddRange(resxItems.Select(x => x.Key.ToString()));
                    keys = keys.Distinct().ToList();

                    columns.Add(new ColumnModel()
                    {
                        LanguageName = languageName,
                        Values       = resxItems.ToList()
                    });
                }
            }

            return(new ExcelModel
            {
                Keys = keys,
                Columns = columns
            });
        }
コード例 #6
0
        static DiscordHelpAttribute()
        {
            string resxFile = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DiscordHelpAttribute)).Location) + @"\Resources.resx";

            using (var resxReader = new ResXResourceReader(resxFile))
                _keys = resxReader.Cast <DictionaryEntry>().Select(x => x.Key.ToString()).ToList();
        }
コード例 #7
0
        public static void UpdateResourceFile(string resourceKey, string value, string appConfigKeyForResourceFile)
        {
            var resx = new List <DictionaryEntry>();

            using (var reader = new ResXResourceReader(appConfigKeyForResourceFile))
            {
                resx = reader.Cast <DictionaryEntry>().ToList();
                var existingResource = resx.Where(r => r.Key.ToString() == resourceKey).FirstOrDefault();
                var modifiedResx     = new DictionaryEntry()
                {
                    Key = existingResource.Key, Value = value
                };
                resx.Remove(existingResource); // REMOVING RESOURCE!
                resx.Add(modifiedResx);        // AND THEN ADDING RESOURCE!
            }
            using (var writer = new ResXResourceWriter(appConfigKeyForResourceFile))
            {
                resx.ForEach(r =>
                {
                    // Again Adding all resource to generate with final items
                    writer.AddResource(r.Key.ToString(), r.Value.ToString());
                });
                writer.Generate();
            }
        }
コード例 #8
0
ファイル: ResourceHelper.cs プロジェクト: dovanduy/titan
    public static void AddOrUpdateResource(DictionaryEntry newElement, string resourceFilepath)
    {
        var resx = new List <DictionaryEntry>();

        using (var reader = new ResXResourceReader(resourceFilepath))
        {
            resx = reader.Cast <DictionaryEntry>().ToList();
            var existingResource = resx.Where(r => r.Key == newElement.Key).FirstOrDefault();
            if (existingResource.Key == null && existingResource.Value == null) // NEW!
            {
                resx.Add(newElement);
            }
            else // MODIFIED RESOURCE!
            {
                var modifiedResx = new DictionaryEntry()
                {
                    Key = existingResource.Key, Value = newElement.Value
                };
                resx.Remove(existingResource); // REMOVING RESOURCE!
                resx.Add(modifiedResx);        // AND THEN ADDING RESOURCE!
            }
        }
        using (var writer = new ResXResourceWriter(resourceFilepath))
        {
            resx.ForEach(r =>
            {
                // Again Adding all resource to generate with final items
                writer.AddResource(r.Key.ToString(), r.Value.ToString());
            });
            writer.Generate();
            writer.Close();
        }
    }
コード例 #9
0
        protected void LoadResource(string pluginName)
        {
            string path;

            try
            {
                path = HttpContext.Current.Server.MapPath("/").Replace("IUDICO.LMS", pluginName);
            }
            catch (Exception)
            {
                path = Path.Combine(Assembly.GetExecutingAssembly().CodeBase.Remove(0, 8) + @"\..\..\..\..\", pluginName) + @"\";
            }

            this.resource.Add(pluginName, new Dictionary <string, Dictionary <string, string> >());

            foreach (var culture in Cultures)
            {
                try
                {
                    var resourceReader  = new ResXResourceReader(path + "Resource." + culture + ".resx");
                    var resourceEntries = resourceReader.Cast <DictionaryEntry>().ToDictionary(d => d.Key.ToString(), d => d.Value.ToString());

                    this.resource[pluginName].Add(culture, resourceEntries);
                }
                catch (Exception)
                {
                }
            }
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        public void TestConvertToAndFromResXDataNode()
        {
            List <ResXDataNode> nodes;

            using (var reader = new ResXResourceReader(resxFile)
            {
                UseResXDataNodes = true,
            })
            {
                nodes = reader.Cast <DictionaryEntry>().Select(x => (ResXDataNode)x.Value).ToList();
            }
            foreach (var node in nodes)
            {
                ResXNode     icon  = node;
                ResXDataNode node2 = icon;

                var resolution = default(System.ComponentModel.Design.ITypeResolutionService);
                Assert.AreEqual(node.GetValueTypeName(resolution), node2.GetValueTypeName(resolution));
                Assert.AreEqual(node.Name, node2.Name);
                Assert.AreEqual(node.Comment, node2.Comment);
                Assert.AreEqual(node.FileRef, node2.FileRef);

                if (node.FileRef == null)
                {
                    AreEqual(node.GetValue(resolution), node2.GetValue(resolution));
                }
            }
        }
コード例 #12
0
 public Localiser LoadLocalisations(CultureInfo culture = null)
 {
     using (var stream = loader.OpenLocalisationFile(culture ?? CultureInfo.CurrentUICulture))
     {
         using (var set = new ResXResourceReader(stream))
         {
             return(new Localiser(set.Cast <DictionaryEntry>()
                                  .ToDictionary(kv => kv.Key.ToString(), kv => kv.Value.ToString())));
         }
     }
 }
コード例 #13
0
        private int GetResourceFileKeyCount(Stream stream)
        {
            int keyCount;

            using (var resXResourceReader = new ResXResourceReader(stream))
            {
                keyCount = resXResourceReader.Cast <DictionaryEntry>().Count();
            }

            return(keyCount);
        }
コード例 #14
0
        private List <DictionaryEntry> ReadResource(string ResxFilePath)
        {
            if (string.IsNullOrWhiteSpace(ResxFilePath))
            {
                return(new List <DictionaryEntry>());
            }

            ResXResourceReader     _ResXResourceReader  = new ResXResourceReader(ResxFilePath);
            List <DictionaryEntry> _ResxDictionaryEntry = _ResXResourceReader.Cast <DictionaryEntry>().ToList();

            return(_ResxDictionaryEntry);
        }
コード例 #15
0
        public static Dictionary <string, string> GetResourcesByFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(new Dictionary <string, string>());
            }

            using (var resx = new ResXResourceReader(filePath))
            {
                return(resx.Cast <DictionaryEntry>()
                       .ToDictionary(k => k.Key.ToString(), v => v.Value.ToString()));
            }
        }
コード例 #16
0
        private IEnumerable <string> GetResourceNamesByFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(Enumerable.Empty <string>());
            }

            using (var resx = new ResXResourceReader(filePath))
            {
                resx.UseResXDataNodes = true;
                return(resx.Cast <DictionaryEntry>().Select(x => x.Key as string));
            }
        }
コード例 #17
0
        public void ParseData()
        {
            string path      = Path.Combine(Files.GetExecutingPath(), "Resources\\TestRes.resx");
            var    refReader = new System.Resources.ResXResourceReader(path, new[] { new AssemblyName("System.Drawing"), new AssemblyName("System") });

            refReader.BasePath = Files.GetExecutingPath();
            ResXResourceReader reader = new ResXResourceReader(path);

            Assert.AreNotEqual(
                refReader.Cast <object>().Count(), // this forces immediate enumeration
                reader.Cast <object>().Count());   // this returns duplicates as separated items

            Assert.AreNotEqual(
                refReader.Cast <object>().Count(), // cached
                reader.Cast <object>().Count());   // second enumeration is cached, though still returns duplicates

            reader = new ResXResourceReader(path)
            {
                AllowDuplicatedKeys = false
            };
            Assert.AreEqual(
                refReader.Cast <object>().Count(), // cached
                reader.Cast <object>().Count());   // duplication is off (not lazy now)
        }
コード例 #18
0
        public void Audio_WhenRetrieved_IsCorrect()
        {
            using (var reader = new ResXResourceReader(TestResxFile.File()))
            {
                reader.UseResXDataNodes = true;

                var file = reader
                           .Cast <DictionaryEntry>()
                           .Select(x => (ResXDataNode)x.Value)
                           .First(x => x.FileRef.FileName == "Resources\\cello82.wav");

                var type = typeof(MemoryStream);
                Assert.Equal(type.AssemblyQualifiedName, file.FileRef.TypeName);
            }
        }
コード例 #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //((MasterPages_SiteAdmin)this.Master).SetNavigationItem("ResourcesEdit");

            _4screen.CSB.Extensions.Business.TrackingManager.TrackEventPage(null, null, IsPostBack, LogSitePageType.SiteAdmin);

            // TODO: Get resrouce name from query string

            if (!IsPostBack)
            {
                ResXResourceReader resxReader = new ResXResourceReader(string.Format("{0}/App_Resources/Templates.resx", WebRootPath.Instance.ToString()));

                this.RepResources.DataSource = resxReader.Cast <DictionaryEntry>().OrderBy(x => x.Key.ToString());
                this.RepResources.DataBind();

                resxReader.Close();
            }
        }
コード例 #20
0
        public void String_WhenRetrieved_IsCorrect()
        {
            using (var reader = new ResXResourceReader(TestResxFile.File()))
            {
                reader.UseResXDataNodes = true;

                var str = reader
                          .Cast <DictionaryEntry>()
                          .Select(x => (ResXDataNode)x.Value)
                          .First(x => x.Name == "Example");

                var value = (string)str.GetValue((ITypeResolutionService)null);

                Assert.NotNull(value);
                Assert.Equal("Something", value);
                Assert.Equal("Comment", str.Comment);
            }
        }
コード例 #21
0
ファイル: Form1.cs プロジェクト: prabah/ResourceWriter
        private void button1_Click(object sender, EventArgs e)
        {
            var       resourceFilepath = "..\\..\\ICIS.Resource.test.resx";
            Hashtable data             = new Hashtable();

            data.Add("Item1", "测试");
            data.Add("Item2", "Value3");

            var resx = new List <DictionaryEntry>();

            using (var reader = new ResXResourceReader(resourceFilepath))
            {
                resx = reader.Cast <DictionaryEntry>().ToList();
                foreach (var key in data.Keys)
                {
                    var existingResource = resx.Where(r => r.Key.ToString() == key.ToString()).FirstOrDefault();
                    if (existingResource.Key == null && existingResource.Value == null) // NEW!
                    {
                        resx.Add(new DictionaryEntry()
                        {
                            Key = key, Value = data[key]
                        });
                    }
                    else // MODIFIED RESOURCE!
                    {
                        var modifiedResx = new DictionaryEntry()
                        {
                            Key = existingResource.Key, Value = data[key]
                        };
                        resx.Remove(existingResource); // REMOVING RESOURCE!
                        resx.Add(modifiedResx);        // AND THEN ADDING RESOURCE!
                    }
                }
            }
            using (var writer = new ResXResourceWriter(resourceFilepath))
            {
                resx.ForEach(r =>
                {
                    // Again Adding all resource to generate with final items
                    writer.AddResource(r.Key.ToString(), r.Value.ToString());
                });
                writer.Generate();
            }
        }
コード例 #22
0
        /// <summary>
        /// The get JSON from the resource.
        /// </summary>
        /// <param name="resourceItem">
        /// The resource item.
        /// </param>
        /// <param name="cultureInfo">
        /// The culture Info.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string GetJson(string resourceItem, CultureInfo cultureInfo)
        {
            Dictionary <string, object> strings;

            using (var rsxr = new ResXResourceReader(resourceItem))
            {
                rsxr.UseResXDataNodes = true;
                strings = rsxr.Cast <DictionaryEntry>()
                          .ToDictionary(
                    x => x.Key.ToString(),
                    x => ((ResXDataNode)x.Value).GetValue((ITypeResolutionService)null));
            }

            strings.Add("lcid", cultureInfo == null ? 0 : cultureInfo.LCID);
            strings.Add("lang", cultureInfo == null ? string.Empty : cultureInfo.Name);
            strings.Add("r2jng", timestamp);

            return(new JavaScriptSerializer().Serialize(strings));
        }
コード例 #23
0
        private void TestWrite(
            Func <System.Data.Entity.Migrations.Utilities.MigrationWriter, ScaffoldedMigration, string> action,
            bool skipUserCodeVerification = false)
        {
            var command             = CreateCommand(_projectDir);
            var writer              = new System.Data.Entity.Migrations.Utilities.MigrationWriter(command);
            var scaffoldedMigration = new ScaffoldedMigration
            {
                MigrationId  = MigrationId,
                Language     = Language,
                Directory    = MigrationsDirectory,
                UserCode     = "The user code.",
                DesignerCode = "The designer code.",
                Resources    =
                {
                    { ResourceName, "The resource." }
                }
            };

            var relativeUserCodePath = action(writer, scaffoldedMigration);

            Assert.Equal(UserCodePath, relativeUserCodePath);

            if (!skipUserCodeVerification)
            {
                var userCodePath = Path.Combine(_projectDir, UserCodePath);
                Assert.Equal("The user code.", File.ReadAllText(userCodePath));
            }

            var designerCodePath = Path.Combine(_projectDir, DesignerCodePath);

            Assert.Equal("The designer code.", File.ReadAllText(designerCodePath));

            var resourcesPath = Path.Combine(_projectDir, ResourcesPath);

            using (var reader = new ResXResourceReader(resourcesPath))
            {
                var resources = reader.Cast <DictionaryEntry>();

                Assert.Equal(1, resources.Count());
                Assert.Contains(new DictionaryEntry(ResourceName, "The resource."), resources);
            }
        }
コード例 #24
0
        public void Photo_WhenRetrieved_IsCorrect()
        {
            using (var reader = new ResXResourceReader(TestResxFile.File()))
            {
                reader.UseResXDataNodes = true;

                var photo = reader
                            .Cast <DictionaryEntry>()
                            .Select(x => (ResXDataNode)x.Value)
                            .First(x => x.Name == "Flowers");

                var value    = (Bitmap)photo.GetValue((ITypeResolutionService)null);
                var typeName = photo.GetValueTypeName((ITypeResolutionService)null);

                Assert.NotNull(value);
                Assert.False(value.Size.IsEmpty);
                Assert.Equal(typeof(Bitmap).AssemblyQualifiedName, typeName);
            }
        }
コード例 #25
0
 private void WriteResource(string path, bool ru)
 {
     using (ResXResourceReader reader = new ResXResourceReader(path))
     {
         var dictionary = reader.Cast <DictionaryEntry>();
         using (ResXResourceWriter writer = new ResXResourceWriter(path))
         {
             foreach (DictionaryEntry dictionaryEntry in dictionary)
             {
                 writer.AddResource(dictionaryEntry.Key.ToString(), dictionaryEntry.Value.ToString());
             }
             foreach (WebPageBaseViewModel webPageBaseViewModel in RootPanel.Children.Flatten(i => i.Children))
             {
                 writer.AddResource(webPageBaseViewModel.FieldInDb, ru ? webPageBaseViewModel.RuDescription : webPageBaseViewModel.EnDescription);
             }
             writer.Generate();
         }
     }
 }
コード例 #26
0
        public void Other_WhenRetrieved_IsCorrect()
        {
            using (var reader = new ResXResourceReader(TestResxFile.File()))
            {
                reader.UseResXDataNodes = true;

                var other = reader
                            .Cast <DictionaryEntry>()
                            .Select(x => (ResXDataNode)x.Value)
                            .First(x => x.FileRef.FileName == "Resources\\cello82.mp3");

                var value    = (byte[])other.GetValue((ITypeResolutionService)null);
                var typeName = other.GetValueTypeName((ITypeResolutionService)null);

                Assert.NotNull(value);
                Assert.Equal(@"Resources\cello82.mp3", other.FileRef.FileName);
                Assert.True(value.Length > 0);
                Assert.Equal(typeof(byte[]).AssemblyQualifiedName, typeName);
            }
        }
コード例 #27
0
        public void Bitmap_WhenIsFile_IsCorrect()
        {
            using (var reader = new ResXResourceReader(TestResxFile.File()))
            {
                reader.UseResXDataNodes = true;

                var file = reader
                           .Cast <DictionaryEntry>()
                           .Select(x => (ResXDataNode)x.Value)
                           .First(x => x.FileRef.FileName == "Resources\\Image1.bmp");

                var value = (Bitmap)file.GetValue((ITypeResolutionService)null);

                var typeName = file.GetValueTypeName((ITypeResolutionService)null);

                Assert.NotNull(value);
                Assert.False(value.Size.IsEmpty);
                Assert.Equal(typeof(Bitmap).AssemblyQualifiedName, typeName);
            }
        }
コード例 #28
0
        private void AddOrUpdateResource(string key, string value)
        {
            var resx = new List <DictionaryEntry>();

            using (var reader = new ResXResourceReader(ResXFilePath))
            {
                resx = reader.Cast <DictionaryEntry>().OrderBy(i => i.Key).ToList();
                var existingResource = resx.Where(r => r.Key.ToString() == key).FirstOrDefault();
                if (existingResource.Key == null && value != null) // NEW!
                {
                    resx.Add(new DictionaryEntry()
                    {
                        Key = key, Value = value
                    });
                }
                else // MODIFIED RESOURCE!
                {
                    if (value == null)
                    {
                        resx.Remove(existingResource);
                    }
                    else
                    {
                        var modifiedResx = new DictionaryEntry {
                            Key = existingResource.Key, Value = value
                        };
                        resx.Remove(existingResource); // REMOVING RESOURCE!
                        resx.Add(modifiedResx);        // AND THEN ADDING RESOURCE!
                    }
                }
            }
            using (var writer = new ResXResourceWriter(ResXFilePath))
            {
                resx.ForEach(r =>
                {
                    // Again Adding all resource to generate with final items
                    writer.AddResource(r.Key.ToString(), r.Value.ToString());
                });
                writer.Generate();
            }
        }
コード例 #29
0
ファイル: ResourceTests.cs プロジェクト: pitchcontrol/Atom
        public void AddDoubleKey()
        {
            PanelViewModel panelViewModel = new PanelViewModel(_model.RootPanel)
            {
                RuDescription = "Комент", FieldInDb = "Key1"
            };

            _model.RootPanel.Children.Add(panelViewModel);
            //Добавляем ключь, должны добавится в оба словаря
            _model.WriteResourses();
            //Проверяем
            ResXResourceReader reader = new ResXResourceReader(_model.ResourceFilePath);
            var dictionary            = reader.Cast <DictionaryEntry>();

            Assert.AreEqual(1, dictionary.Count());
            reader.Close();

            reader     = new ResXResourceReader(_model.ResourceFilePath.Replace(".resx", ".ru-RU.resx"));
            dictionary = reader.Cast <DictionaryEntry>();
            Assert.AreEqual(1, dictionary.Count());
            reader.Close();
        }
コード例 #30
0
        public static Dictionary <string, ResxItem> GetResourcesByFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return(new Dictionary <string, ResxItem>());
            }

            using (var reader = new ResXResourceReader(filePath))
            {
                reader.UseResXDataNodes = true;
                ITypeResolutionService typeres = null;

                return(reader
                       .Cast <DictionaryEntry>()
                       .ToDictionary(k => k.Key.ToString(), v => new ResxItem
                {
                    Name = v.Key.ToString(),
                    Text = ((ResXDataNode)v.Value).GetValue(typeres).ToString(),
                    Comment = ((ResXDataNode)v.Value).Comment,
                }));
            }
        }