Beispiel #1
0
 /// <summary>
 /// Gets the cultures.
 /// </summary>
 /// <returns>IEnumerable{CultureInfo}.</returns>
 public IEnumerable <CultureInfo> GetCultures()
 {
     if (Directory.Exists(_path))
     {
         string[] files = Directory.GetFiles(_path);
         foreach (var file in files)
         {
             string culture;
             string category;
             ResXResourceFileHelper.Parse(file, out culture, out category);
             if (!string.IsNullOrEmpty(culture))
             {
                 yield return(new CultureInfo(culture));
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Gets the elements.
        /// </summary>
        /// <returns>IQueryable{Element}.</returns>
        public IQueryable <Element> GetElements()
        {
            Locker.EnterReadLock();
            try
            {
                IEnumerable <Element> elements = Enumerable.Empty <Element>();
                if (Directory.Exists(_path))
                {
                    string[] files = Directory.GetFiles(_path);

                    foreach (var fileName in files)
                    {
                        if (!fileName.EndsWith(".resx"))
                        {
                            continue;
                        }

                        var    doc = XDocument.Load(fileName);
                        string culture;
                        string category;
                        ResXResourceFileHelper.Parse(fileName, out culture, out category);

                        if (doc.Root == null)
                        {
                            continue;
                        }
                        var newElements = doc.Root.Elements("data").Select(x =>
                                                                           new Element
                        {
                            Category = category,
                            Culture  = culture,
                            Name     = x.Attribute("name").Value,
                            Value    = x.Element("value") != null ? x.Element("value").Value : null
                        });

                        elements = elements.Union(newElements);
                    }
                }
                return(elements.AsQueryable());
            }
            finally
            {
                Locker.ExitReadLock();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the categories.
        /// </summary>
        /// <returns>IEnumerable{ElementCategory}.</returns>
        public IEnumerable <ElementCategory> GetCategories()
        {
            if (Directory.Exists(_path))
            {
                string[] files = Directory.GetFiles(_path);
                foreach (var file in files)
                {
                    string culture;
                    string category;
                    ResXResourceFileHelper.Parse(file, out culture, out category);

                    if (!string.IsNullOrEmpty(category))
                    {
                        yield return(new ElementCategory {
                            Category = category, Culture = culture
                        });
                    }
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Removes the category.
 /// </summary>
 /// <param name="category">The category.</param>
 /// <param name="culture">The culture.</param>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
 public bool RemoveCategory(string category, string culture)
 {
     Locker.EnterWriteLock();
     try
     {
         string[] files = Directory.GetFiles(_path);
         foreach (var file in files)
         {
             string culture1;
             string category1;
             ResXResourceFileHelper.Parse(file, out culture1, out category1);
             if (category.EqualsOrNullEmpty(category1, StringComparison.CurrentCultureIgnoreCase) && culture1.EqualsOrNullEmpty(culture, StringComparison.CurrentCultureIgnoreCase))
             {
                 File.Delete(file);
             }
         }
         return(true);
     }
     finally
     {
         Locker.ExitWriteLock();
     }
 }