Esempio n. 1
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));
        }
        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));
        }