Exemple #1
0
        public void Can_Serialize_Without_Error()
        {
            var ss = new SerializationService(new JsonNetSerializer());

            var item = new DictionaryTranslation(new Language("en-AU")
            {
                CreateDate  = DateTime.Now,
                CultureName = "en",
                Id          = 11,
                IsoCode     = "AU",
                Key         = Guid.NewGuid(),
                UpdateDate  = DateTime.Now
            }, "colour")
            {
                CreateDate = DateTime.Now,
                Id         = 88,
                Key        = Guid.NewGuid(),
                UpdateDate = DateTime.Now
            };

            var result = ss.ToStream(item);
            var json   = result.ResultStream.ToJsonString();

            Debug.Print(json);
        }
Exemple #2
0
        public Dictionary <string, bool> CreateDictionaryItems(List <ImportExportDictionaryItem> items)
        {
            Dictionary <string, bool> results = new Dictionary <string, bool>();

            foreach (var item in items)
            {
                var keyString = item.Key;
                var value     = item.Value;
                var parentKey = item.ParentKey;
                var dicItem   = localizationService.GetDictionaryItemByKey(keyString) ?? new DictionaryItem(keyString);

                var lang = localizationService.GetLanguageByIsoCode(item.LanguageCode);
                if (lang == null)
                {
                    lang = new Language(item.LanguageCode);
                    localizationService.Save(lang);
                }

                List <IDictionaryTranslation> translations = new List <IDictionaryTranslation>();
                foreach (var translation in item.Translations ?? new Dictionary <string, string>())
                {
                    var translationLanguage = localizationService.GetLanguageByIsoCode(translation.Key);
                    if (translationLanguage == null)
                    {
                        translationLanguage = new Language(translation.Key);
                        localizationService.Save(translationLanguage);
                    }
                    var trans = new DictionaryTranslation(translationLanguage, translation.Value);
                    translations.Add(trans);
                }

                dicItem.Translations = translations;

                if (!string.IsNullOrEmpty(parentKey))
                {
                    var parentGuid = localizationService.GetDictionaryItemByKey(parentKey)?.GetUdi().Guid;
                    if (parentGuid != null)
                    {
                        dicItem.ParentId = parentGuid;
                    }
                }

                try
                {
                    localizationService.AddOrUpdateDictionaryValue(dicItem, lang, value);
                    localizationService.Save(dicItem);

                    results.Add(dicItem.ItemKey, true);
                }
                catch
                {
                    results.Add(dicItem.ItemKey, false);
                }
            }
            return(results);
        }
        public IDictionaryTranslation BuildEntity(LanguageTextDto dto)
        {
            var item = new DictionaryTranslation(_language, dto.Value, _uniqueId)
            {
                Id = dto.PrimaryKey
            };

            //on initial construction we don't want to have dirty properties tracked
            // http://issues.umbraco.org/issue/U4-1946
            item.ResetDirtyProperties(false);
            return(item);
        }
Exemple #4
0
        public static IDictionaryTranslation BuildEntity(LanguageTextDto dto, Guid uniqueId)
        {
            var item = new DictionaryTranslation(dto.LanguageId, dto.Value, uniqueId);

            try
            {
                item.DisableChangeTracking();

                item.Id = dto.PrimaryKey;

                // reset dirty initial properties (U4-1946)
                item.ResetDirtyProperties(false);
                return(item);
            }
            finally
            {
                item.EnableChangeTracking();
            }
        }
        public IDictionaryTranslation BuildEntity(LanguageTextDto dto)
        {
            var item = new DictionaryTranslation(dto.LanguageId, dto.Value, _uniqueId);

            try
            {
                item.DisableChangeTracking();

                item.Id = dto.PrimaryKey;

                //on initial construction we don't want to have dirty properties tracked
                // http://issues.umbraco.org/issue/U4-1946
                item.ResetDirtyProperties(false);
                return(item);
            }
            finally
            {
                item.EnableChangeTracking();
            }
        }
Exemple #6
0
        public void Can_Deep_Clone()
        {
            var item = new DictionaryTranslation(new Language("en-AU")
            {
                CreateDate  = DateTime.Now,
                CultureName = "en",
                Id          = 11,
                IsoCode     = "AU",
                Key         = Guid.NewGuid(),
                UpdateDate  = DateTime.Now
            }, "colour")
            {
                CreateDate = DateTime.Now,
                Id         = 88,
                Key        = Guid.NewGuid(),
                UpdateDate = DateTime.Now
            };

            var clone = (DictionaryTranslation)item.DeepClone();

            Assert.AreNotSame(clone, item);
            Assert.AreEqual(clone, item);
            Assert.AreEqual(clone.CreateDate, item.CreateDate);
            Assert.AreEqual(clone.Id, item.Id);
            Assert.AreEqual(clone.Key, item.Key);
            Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
            Assert.AreNotSame(clone.Language, item.Language);
            //This is null because we are ignoring it from cloning due to caching/cloning issues - we don't really want
            // this entity attached to this item but we're stuck with it for now
            Assert.IsNull(clone.Language);
            Assert.AreEqual(clone.LanguageId, item.LanguageId);
            Assert.AreEqual(clone.Value, item.Value);

            //This double verifies by reflection
            var allProps = clone.GetType().GetProperties();

            foreach (var propertyInfo in allProps.Where(x => x.Name != "Language"))
            {
                Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
            }
        }
Exemple #7
0
        public void CreateDictionaryItem(Type item)
        {
            var keyString = item.GetProperty("Key").Value <string>();
            var value     = item.GetProperty("Value").Value <string>();
            var parentKey = item.GetProperty("ParentKey")?.Value <string>();
            var dicItem   = localizationService.GetDictionaryItemByKey(keyString) ?? new DictionaryItem(keyString);

            var lang = localizationService.GetLanguageByIsoCode(item.GetProperty("LanguageCode").Value <string>());

            if (lang == null)
            {
                lang = new Language(item.GetProperty("LanguageCode").Value <string>());
                localizationService.Save(lang);
            }

            List <IDictionaryTranslation> translations = new List <IDictionaryTranslation>();

            foreach (var translation in item.GetProperty("Translations").Value <Dictionary <string, string> >() ?? new Dictionary <string, string>())
            {
                var translationLanguage = localizationService.GetLanguageByIsoCode(translation.Key);
                if (translationLanguage == null)
                {
                    translationLanguage = new Language(translation.Key);
                    localizationService.Save(translationLanguage);
                }
                var trans = new DictionaryTranslation(translationLanguage, translation.Value);
                translations.Add(trans);
            }
            dicItem.Translations = translations;
            if (!string.IsNullOrEmpty(parentKey))
            {
                var parentGuid = localizationService.GetDictionaryItemByKey(parentKey)?.GetUdi().Guid;
                if (parentGuid != null)
                {
                    dicItem.ParentId = parentGuid;
                }
            }
            localizationService.AddOrUpdateDictionaryValue(dicItem, lang, value);
            localizationService.Save(dicItem);
        }
        public void Can_Serialize_Without_Error()
        {
            var item = new DictionaryTranslation(new Language("en-AU")
            {
                CreateDate  = DateTime.Now,
                CultureName = "en",
                Id          = 11,
                IsoCode     = "AU",
                Key         = Guid.NewGuid(),
                UpdateDate  = DateTime.Now
            }, "colour")
            {
                CreateDate = DateTime.Now,
                Id         = 88,
                Key        = Guid.NewGuid(),
                UpdateDate = DateTime.Now
            };

            var json = JsonConvert.SerializeObject(item);

            Debug.Print(json);
        }
        public void Can_Deep_Clone()
        {
            var item = new DictionaryTranslation(new Language("en-AU")
            {
                CreateDate  = DateTime.Now,
                CultureName = "en",
                Id          = 11,
                IsoCode     = "AU",
                Key         = Guid.NewGuid(),
                UpdateDate  = DateTime.Now
            }, "colour")
            {
                CreateDate = DateTime.Now,
                Id         = 88,
                Key        = Guid.NewGuid(),
                UpdateDate = DateTime.Now
            };

            var clone = (DictionaryTranslation)item.DeepClone();

            Assert.AreNotSame(clone, item);
            Assert.AreEqual(clone, item);
            Assert.AreEqual(clone.CreateDate, item.CreateDate);
            Assert.AreEqual(clone.Id, item.Id);
            Assert.AreEqual(clone.Key, item.Key);
            Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
            Assert.AreNotSame(clone.Language, item.Language);
            Assert.AreEqual(clone.Language, item.Language);
            Assert.AreEqual(clone.Value, item.Value);

            //This double verifies by reflection
            var allProps = clone.GetType().GetProperties();

            foreach (var propertyInfo in allProps)
            {
                Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
            }
        }