コード例 #1
0
        private void CreateCultureHierarchy(IDatabaseStaticTextContext dbContext, Culture culture)
        {
            var cultureHierarchyDao = new CultureHierarchyDao(dbContext.CultureHierarchy);
            var cultureDao          = new CultureDao(dbContext.Culture);

            cultureHierarchyDao.MakeCultureSelfReferencing(culture);

            var defaultCultureName = m_configuration.DefaultCulture.Name;
            var defaultCulture     = cultureDao.FindByName(defaultCultureName);

            var cultureInfo = new CultureInfo(culture.Name);

            if (cultureInfo.IsNeutralCulture) //Just reference to default culture
            {
                cultureHierarchyDao.MakeCultureReference(culture, defaultCulture, 1);
            }
            else
            {
                var parentCultureName = cultureInfo.Parent.Name;
                var parentCulture     = cultureDao.FindByName(parentCultureName);
                if (parentCulture == null)
                {
                    cultureHierarchyDao.MakeCultureReference(culture, defaultCulture, 1);
                }
                else
                {
                    cultureHierarchyDao.MakeCultureReference(culture, parentCulture, 1);
                    cultureHierarchyDao.MakeCultureReference(culture, defaultCulture, 2);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates for given culture self reference in culture hierarchy tree with level 0 (if not already exists).
        /// </summary>
        /// <param name="cultureInfo">Culture</param>
        private async Task CreateCultureHierarchySelfReference(CultureInfo cultureInfo)
        {
            using (var dbContext = m_dbContextFunc.Invoke())
            {
                var cultureDao = new CultureDao(dbContext.Culture);
                var culture    = cultureDao.FindByName(cultureInfo.Name);

                var cultureHierarchyDao = new CultureHierarchyDao(dbContext.CultureHierarchy);

                var isCultureSelfReferencing = await cultureHierarchyDao.IsCultureSelfReferencing(culture);

                if (!isCultureSelfReferencing)
                {
                    cultureHierarchyDao.MakeCultureSelfReferencing(culture);
                    dbContext.SaveChanges();
                }
            }
        }
コード例 #3
0
        private async Task CreateCultureHierarchy(IReadOnlyList <CultureInfo> supportedCultures, CultureInfo defaultCulture)
        {
            using (var dbContext = m_dbContextFunc.Invoke())
            {
                var cultureHierarchyDao = new CultureHierarchyDao(dbContext.CultureHierarchy);
                var cultureDao          = new CultureDao(dbContext.Culture);

                var defaultCultureEntity = cultureDao.FindByName(defaultCulture.Name);

                IList <CultureInfo> supportedCulturesWithoutDefault = supportedCultures.ToList();
                supportedCulturesWithoutDefault.Remove(defaultCulture);

                foreach (var supportedCultureA in supportedCulturesWithoutDefault)
                {
                    var cultureEntityA = cultureDao.FindByName(supportedCultureA.Name);

                    foreach (var supportedCultureB in supportedCultures)
                    {
                        if (supportedCultureA.Name == supportedCultureB.Name)
                        {
                            continue;
                        }

                        var cultureEntityB = cultureDao.FindByName(supportedCultureB.Name);

                        if (supportedCultureB.Parent.Equals(supportedCultureA))
                        {
                            var isCultureBReferencingA =
                                await cultureHierarchyDao.IsCultureReferencing(cultureEntityB, cultureEntityA);

                            if (!isCultureBReferencingA)
                            {
                                cultureHierarchyDao.MakeCultureReference(cultureEntityB, cultureEntityA, 1);
                                dbContext.SaveChanges();
                            }
                        }
                    }
                }

                foreach (var supportedCulture in supportedCulturesWithoutDefault)
                {
                    if (supportedCulture.IsNeutralCulture)
                    {
                        var cultureEntity = cultureDao.FindByName(supportedCulture.Name);

                        var isCultureReferencingDefaultCulture =
                            await cultureHierarchyDao.IsCultureReferencing(cultureEntity, defaultCultureEntity);

                        if (!isCultureReferencingDefaultCulture)
                        {
                            cultureHierarchyDao.MakeCultureReference(cultureEntity, defaultCultureEntity, 1);
                            dbContext.SaveChanges();
                        }
                    }
                }

                //
                foreach (var supportedCultureA in supportedCultures)
                {
                    var cultureEntityA = cultureDao.FindByName(supportedCultureA.Name);

                    foreach (var supportedCultureB in supportedCultures)
                    {
                        if (supportedCultureA.Name == supportedCultureB.Name || supportedCultureB.Name == defaultCultureEntity.Name)
                        {
                            continue;
                        }

                        var cultureEntityB = cultureDao.FindByName(supportedCultureB.Name);
                        if (supportedCultureB.Parent.Equals(supportedCultureA))
                        {
                            if (cultureEntityA.Name != defaultCultureEntity.Name)
                            {
                                var isCultureAReferencingDefaultCulture =
                                    await cultureHierarchyDao.IsCultureReferencing(cultureEntityA, defaultCultureEntity);

                                if (isCultureAReferencingDefaultCulture)
                                {
                                    var isCultureBReferencingDefaultCulture =
                                        await cultureHierarchyDao.IsCultureReferencing(cultureEntityB, defaultCultureEntity);

                                    if (!isCultureBReferencingDefaultCulture)
                                    {
                                        cultureHierarchyDao.MakeCultureReference(cultureEntityB, defaultCultureEntity, 2);
                                        dbContext.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }