コード例 #1
0
        public override ResourceSet GetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
        {
            DBResourceSet databaseResourceSet;

            while (true)
            {
                if (ResourceSets.Contains(culture.Name) && (DBResourceSet)ResourceSets[culture.Name] != null)
                {
                    databaseResourceSet = (DBResourceSet)ResourceSets[culture.Name];
                }
                else
                {
                    databaseResourceSet = new DBResourceSet(_fileName, culture);
                    ResourceSets.Add(culture.Name, databaseResourceSet);
                }

                if (databaseResourceSet.TableCount != 0 || culture.Equals(CultureInfo.InvariantCulture))
                {
                    break;
                }

                culture = culture.Parent;
            }

            if (DateTime.UtcNow > _updateDate.AddSeconds(2))
            {
                GetResource.UpdateDBRS(databaseResourceSet, _fileName, culture.Name, _updateDate);
                _updateDate = DateTime.UtcNow;
            }

            return(databaseResourceSet);
        }
コード例 #2
0
        public override ResourceSet GetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
        {
            var baseCulture = culture;

            DBResourceSet databaseResourceSet;

            while (true)
            {
                if (!ResourceSetsTable.TryGetValue(culture.Name, out databaseResourceSet))
                {
                    databaseResourceSet = new DBResourceSet(_fileName, culture);
                    ResourceSetsTable.TryAdd(culture.Name, databaseResourceSet);
                }

                if (!databaseResourceSet.DataIsEmpty)
                {
                    break;
                }

                if (culture.Equals(CultureInfo.InvariantCulture))
                {
                    return(_resManager.GetResourceSet(baseCulture, createIfNotExists, tryParents));
                }

                culture = culture.Parent;
            }

            if (0 < updateSeconds && DateTime.UtcNow > _updateDate.AddSeconds(2))
            {
                GetResource.UpdateDBRS(databaseResourceSet, _fileName, culture.Name, _updateDate);
                _updateDate = DateTime.UtcNow;
            }

            return(databaseResourceSet);
        }
コード例 #3
0
        public override string GetString(string name, CultureInfo culture)
        {
            try
            {
                var pageLink     = string.Empty;
                var resDataTable = LoadData();

                try
                {
                    if (HttpContext.Current != null && HttpContext.Current.Request != null)
                    {
                        var uri = HttpContext.Current.Request.Url;

                        if (uri.Host.Contains("-translator") || uri.Host.Contains("we-translate") || updatePortals.Contains(uri.Host, StringComparer.InvariantCultureIgnoreCase))
                        {
                            resDataTable = LoadDataTrans();
                            if (DateTime.UtcNow > _updateDate.AddSeconds(updateSeconds))
                            {
                                GetResource.UpdateHashTable(ref resDataTable, _updateDate);
                                _updateDate = DateTime.UtcNow;
                            }
                        }

                        if (uri.Host == getPagePortal)
                        {
                            pageLink = uri.AbsolutePath;
                        }
                    }
                }
                catch { }

                var ci = culture ?? CultureInfo.CurrentUICulture;
                while (true)
                {
                    var language = !string.IsNullOrEmpty(ci.Name) ? ci.Name : "Neutral";

                    var resdata = resDataTable[name + _fileName + language];
                    if (resdata != null)
                    {
                        if (!string.IsNullOrEmpty(pageLink))
                        {
                            GetResource.AddLink(name, _fileName, pageLink);
                        }
                        return(resdata.ToString());
                    }

                    if (ci.Equals(CultureInfo.InvariantCulture))
                    {
                        break;
                    }
                    ci = ci.Parent;
                }
            }
            catch { }

            return(_resManager.GetString(name, culture));
        }
コード例 #4
0
        public static string ExportJson(string project, string module, List <string> languages, string exportPath)
        {
            using (var fastZip = new ZipFile())
            {
                var filter = new ResCurrent
                {
                    Project = new ResProject {
                        Name = project
                    },
                    Module = new ResModule {
                        Name = module
                    }
                };

                var zipDirectory = Directory.CreateDirectory(exportPath + module);
                foreach (var language in languages)
                {
                    filter.Language = new ResCulture {
                        Title = language
                    };

                    var words = GetResource.GetListResWords(filter, string.Empty).GroupBy(x => x.ResFile.FileID).ToList();
                    if (!words.Any())
                    {
                        Console.WriteLine("Error!!! Can't find appropriate project and module. Possibly wrong names!");
                        return(null);
                    }

                    foreach (var fileWords in words)
                    {
                        var wordsDictionary = new Dictionary <string, string>();
                        foreach (var word in fileWords.OrderBy(x => x.Title).Where(word => !wordsDictionary.ContainsKey(word.Title)))
                        {
                            wordsDictionary[word.Title] = word.ValueTo ?? word.ValueFrom;
                        }

                        var firstWord = fileWords.FirstOrDefault();
                        var fileName  = firstWord == null ? module : Path.GetFileNameWithoutExtension(firstWord.ResFile.FileName);

                        var zipFileName = zipDirectory.FullName + "\\" + fileName
                                          + (language == "Neutral" ? string.Empty : "." + language) + ".json";
                        using (TextWriter writer = new StreamWriter(zipFileName))
                        {
                            var obj = JsonConvert.SerializeObject(wordsDictionary, Formatting.Indented);
                            writer.Write(obj);
                        }
                    }
                }

                var zipPath = exportPath + "\\" + module + ".zip";
                fastZip.AddDirectory(zipDirectory.FullName);
                fastZip.Save(zipPath);

                zipDirectory.Delete(true);
                return(zipPath);
            }
        }
コード例 #5
0
 private Hashtable LoadDataTrans()
 {
     if (_resDataForTrans == null)
     {
         lock (lockObject)
         {
             if (_resDataForTrans == null)
             {
                 _resDataForTrans = GetResource.GetAllData("tmresourceTrans");
             }
         }
     }
     return(_resDataForTrans);
 }
コード例 #6
0
 private Hashtable LoadData()
 {
     if (_resData == null)
     {
         lock (lockObject)
         {
             if (_resData == null)
             {
                 _resData = GetResource.GetAllData("tmresource");
             }
         }
     }
     return(_resData);
 }
コード例 #7
0
        public override string GetString(string name, CultureInfo culture)
        {
            try
            {
                var pageLink     = string.Empty;
                var resDataTable = LoadData();

                try
                {
                    if (0 < updateSeconds && DateTime.UtcNow > _updateDate.AddSeconds(updateSeconds) &&
                        HttpContext.Current != null && HttpContext.Current.Request != null)
                    {
                        _updateDate = DateTime.UtcNow;

                        var uri = HttpContext.Current.Request.Url;

                        if (uri.Host.Contains("-translator") || uri.Host.Contains("we-translate") || updatePortals.Contains(uri.Host, StringComparer.InvariantCultureIgnoreCase))
                        {
                            resDataTable = LoadDataTrans();
                            GetResource.UpdateHashTable(ref resDataTable, _updateDate);
                        }

                        if (uri.Host == getPagePortal)
                        {
                            pageLink = uri.AbsolutePath;
                        }
                    }
                }
                catch (ArgumentException)
                {
                    // ignore System.ArgumentException: Value does not fall within the expected range.
                }
                catch (Exception err)
                {
                    log4net.LogManager.GetLogger("ASC.DbRes").Error(err);
                }

                var ci = culture ?? CultureInfo.CurrentUICulture;
                while (true)
                {
                    var language = !string.IsNullOrEmpty(ci.Name) ? ci.Name : "Neutral";

                    var resdata = resDataTable[name + _fileName + language];
                    if (resdata != null)
                    {
                        if (!string.IsNullOrEmpty(pageLink))
                        {
                            GetResource.AddLink(name, _fileName, pageLink);
                        }
                        return(resdata.ToString());
                    }

                    if (ci.Equals(CultureInfo.InvariantCulture))
                    {
                        break;
                    }
                    ci = ci.Parent;
                }
            }
            catch (Exception err)
            {
                log4net.LogManager.GetLogger("ASC.DbRes").Error(err);
            }

            return(_resManager.GetString(name, culture));
        }