Ejemplo n.º 1
0
        public static void SetTranslation(String moduleName, String languagePair, String trnKey, TranslationContract contract)
        {
            if (String.IsNullOrWhiteSpace(moduleName))
            {
                throw new ArgumentNullException("moduleName");
            }

            if (String.IsNullOrWhiteSpace(trnKey))
            {
                throw new ArgumentNullException("trnKey");
            }

            if (String.IsNullOrWhiteSpace(languagePair))
            {
                throw new ArgumentNullException("languagePair");
            }

            if (contract == null)
            {
                throw new ArgumentNullException("contract");
            }

            var session = Hb8Factory.InitSession();

            var entity = (from n in session.Query <CD_Translation>()
                          where n.DateDeleted == null &&
                          n.TrnKey.ToLower() == trnKey.ToLower() &&
                          n.LanguagePair.ToLower() == languagePair.ToLower() &&
                          n.ModuleName.ToLower() == moduleName.ToLower()
                          select n).SingleOrDefault();

            if (entity == null)
            {
                entity = new CD_Translation
                {
                    ID          = Guid.NewGuid(),
                    DateCreated = DateTime.Now
                };

                entity.TrnKey         = trnKey;
                entity.ModuleName     = moduleName;
                entity.LanguagePair   = languagePair;
                entity.DefaultText    = contract.DefaultText;
                entity.TranslatedText = contract.TranslatedText;

                session.SubmitChanges(entity);
            }
            else
            {
                TranslationCache.SetTranslatedText(moduleName, languagePair, trnKey, contract.TranslatedText);
            }
        }
Ejemplo n.º 2
0
        private static void AddOrUpdateInDb(String moduleName, String languagePair, String trnKey, String defaultText, String translatedText)
        {
            try
            {
                using (var db = DcFactory.Create <CommonDataDataContext>())
                {
                    var dbTrn = (from n in db.CD_Translations
                                 where n.ModuleName == moduleName &&
                                 n.TrnKey == trnKey &&
                                 n.LanguagePair == languagePair //&&
                                                                //n.Hashcode == db.GenTrnHashCode(moduleName, trnKey, languagePair)
                                 select n).FirstOrDefault();

                    if (dbTrn == null)
                    {
                        dbTrn = new CD_Translation
                        {
                            ID          = Guid.NewGuid(),
                            DateCreated = DateTime.Now
                        };

                        db.CD_Translations.InsertOnSubmit(dbTrn);
                    }

                    dbTrn.ModuleName     = moduleName;
                    dbTrn.TrnKey         = trnKey;
                    dbTrn.LanguagePair   = languagePair;
                    dbTrn.DefaultText    = defaultText;
                    dbTrn.TranslatedText = translatedText;

                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 3
0
 public static String GenCacheItemKey(CD_Translation trn)
 {
     return(GenCacheItemKey(trn.ModuleName, trn.LanguagePair, trn.TrnKey));
 }