コード例 #1
0
ファイル: StaticTextDao.cs プロジェクト: LightCZ/localization
        public IList <StaticText> FindByNameAndScope(string name, DictionaryScope dictionaryScope,
                                                     DbSet <CultureHierarchy> cultureHierarchies)
        {
            List <StaticText> resultValue = null;

            try
            {
                var hierarchies = cultureHierarchies
                                  .Select(t => t);

                var result = DbSet
                             .Where(w => w.Name == name && w.DictionaryScope == dictionaryScope);
                //.Include(x => x.Culture)
                //.Join(hierarchies,
                //    text => text.Culture.Id,
                //    hierarchy => hierarchy.ParentCulture.Id,
                //    (text, hierarchy) => new {text, hierarchy})
                //.OrderBy(r => r.hierarchy.LevelProperty)
                //.Take(4) Why is this restriction used in FindByNameAndCultureAndScope method?
                //.Select(r => r.text);

                resultValue = result.Distinct().ToList();
            }
            catch (ArgumentNullException e)
            {
                if (Logger.IsWarningEnabled())
                {
                    Logger.LogWarning(new EventId(e.GetHashCode()), e,
                                      "ArgumentNullException in method FindByNameAndScope");
                }
            }

            return(resultValue);
        }
コード例 #2
0
        public ITextBuilder <T> DictionaryScope(DictionaryScope dictionaryScope)
        {
            BuilderGuard.ArgumentAlreadySet(nameof(dictionaryScope), m_baseText.DictionaryScope, Logger);

            m_baseText.DictionaryScopeId = dictionaryScope.Id;
            m_baseText.DictionaryScope   = dictionaryScope;
            return(this);
        }
コード例 #3
0
        /// <summary>
        /// Executes an action on default culture text if it does not exist. Actions include - nothing, create empty string, copy current culture text
        /// </summary>
        /// <param name="actionForDefaultCulture">Specific action</param>
        /// <param name="dynamicText">Current dynamic text entity</param>
        /// <param name="currentCulture">Current culture entity</param>
        /// <param name="dictionaryScope">Current dictionary scope entity</param>
        /// <param name="dbContext">Database context</param>
        /// <param name="dao">DAO of static text entity</param>
        private void ExecuteDefaultCultureAction(IfDefaultNotExistAction actionForDefaultCulture,
                                                 DynamicText dynamicText, Culture currentCulture,
                                                 DictionaryScope dictionaryScope, IDatabaseStaticTextContext dbContext, StaticTextDao dao)
        {
            var defaultCulture = GetDefaultCulture(dbContext);

            if (currentCulture == defaultCulture)
            {
                return;
            }

            var defaultText = dao.FindByNameAndCultureAndScope(
                dynamicText.Name, defaultCulture, dictionaryScope, dbContext.CultureHierarchy
                );

            if (defaultText != null)
            {
                return;
            }

            defaultText = new StaticText
            {
                Format           = dynamicText.Format,
                ModificationTime = DateTime.UtcNow,
                ModificationUser = dynamicText.ModificationUser,
                Name             = dynamicText.Name,
                Culture          = defaultCulture,
                DictionaryScope  = dictionaryScope,
            };

            switch (actionForDefaultCulture)
            {
            case IfDefaultNotExistAction.DoNothing:
                return;

            case IfDefaultNotExistAction.CreateEmpty:
                defaultText.Text = string.Empty;
                dao.Create(defaultText);
                break;

            case IfDefaultNotExistAction.CreateTextCopy:
                defaultText.Text = dynamicText.Text;
                dao.Create(defaultText);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(actionForDefaultCulture), actionForDefaultCulture,
                                                      "Invalid default language save action");
            }
        }
コード例 #4
0
ファイル: StaticTextDao.cs プロジェクト: LightCZ/localization
        public StaticText[] FindAllByCultureAndScope(Culture culture, DictionaryScope dictionaryScope)
        {
            StaticText[] result = null;
            try
            {
                result = DbSet
                         .Where(w => w.Culture == culture && w.DictionaryScope == dictionaryScope)
                         .ToArray();
            }
            catch (ArgumentNullException e)
            {
                if (Logger.IsWarningEnabled())
                {
                    Logger.LogWarning(new EventId(e.GetHashCode()), e,
                                      "ArgumentNullException in method FindAllByCultureAndScope(Culture culture, DictionaryScope dictionaryScope)");
                }
            }

            return(result);
        }
コード例 #5
0
ファイル: StaticTextDao.cs プロジェクト: LightCZ/localization
        public StaticText FindByNameAndCultureAndScope(string name, Culture culture, DictionaryScope dictionaryScope,
                                                       DbSet <CultureHierarchy> cultureHierarchies)
        {
            StaticText resultValue = null;

            try
            {
                var hierarchies = cultureHierarchies
                                  .Select(t => t)
                                  .Where(hierarchyCulture => hierarchyCulture.Culture.Id == culture.Id);

                var result = DbSet
                             .Where(w => w.Name == name && w.DictionaryScope == dictionaryScope)
                             .Include(x => x.Culture)
                             .Join(hierarchies,
                                   text => text.Culture.Id,
                                   hierarchy => hierarchy.ParentCulture.Id,
                                   (text, hierarchy) => new { text, hierarchy })
                             .OrderBy(r => r.hierarchy.LevelProperty)
                             .Take(4)
                             .Select(r => r.text);

                resultValue = result.DefaultIfEmpty().First();
            }
            catch (ArgumentNullException e)
            {
                if (Logger.IsWarningEnabled())
                {
                    Logger.LogWarning(
                        new EventId(e.GetHashCode()), e,
                        "ArgumentNullException in method FindByNameAndCultureAndScope(string name, Culture culture, DictionaryScope dictionaryScope, DbSet < CultureHierarchy > cultureHierarchies)"
                        );
                }
            }

            return(resultValue);
        }
コード例 #6
0
 public ITextBuilder <PluralizedStaticText> DictionaryScope(DictionaryScope dictionaryScope)
 {
     return(m_baseTextBuilder.DictionaryScope(dictionaryScope));
 }
コード例 #7
0
        public PluralizedStaticText FindByNameAndCultureAndScope(string name, Culture culture, DictionaryScope dictionaryScope)
        {
            PluralizedStaticText result = null;

            try
            {
                result = DbSet.First(
                    w => w.Name == name && w.Culture == culture && w.DictionaryScope == dictionaryScope);
            }
            catch (ArgumentNullException e)
            {
                if (Logger.IsWarningEnabled())
                {
                    Logger.LogWarning(new EventId(e.GetHashCode()), e, "ArgumentNullException in method FindByNameAndCultureAndScope(string name, Culture culture, DictionaryScope dictionaryScope)");
                }
            }
            catch (InvalidOperationException e)
            {
                if (Logger.IsWarningEnabled())
                {
                    Logger.LogWarning(new EventId(e.GetHashCode()), e, "InvalidOperationException in method FindByNameAndCultureAndScope(string name, Culture culture, DictionaryScope dictionaryScope)");
                }
            }

            return(result);
        }
コード例 #8
0
 public ITextBuilder <ConstantStaticText> DictionaryScope(DictionaryScope dictionaryScope)
 {
     return(m_baseTextBuilder.DictionaryScope(dictionaryScope));
 }
コード例 #9
0
 public DictionaryScopeBuilder()
 {
     m_dictionaryScope = new DictionaryScope();
 }