Esempio n. 1
0
        /// <summary>
        ///   Update translation
        /// </summary>
        /// <param name="culture"> Culture that the prompt is for </param>
        /// <param name="key"> Unique key, in the specified language only, for the prompt to get) </param>
        /// <param name="translatedText"> Translated text string </param>
        public void Update(CultureInfo culture, TypePromptKey key, string translatedText)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (translatedText == null)
            {
                throw new ArgumentNullException("translatedText");
            }

            var sql = "UPDATE LocalizedTypes SET Value=@value, UpdatedAt=@updat, UpdatedBy=@updby WHERE LocaleId = @lcid AND [Key] = @key";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("value", translatedText);
                cmd.AddParameter("updat", DateTime.Now);
                cmd.AddParameter("updby", Thread.CurrentPrincipal.Identity.Name);
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("key", key.ToString());
                cmd.ExecuteNonQuery();
            }
        }
        /// <summary>
        /// Updates the specified culture.
        /// </summary>
        /// <param name="culture">The culture.</param>
        /// <param name="key">The key.</param>
        /// <param name="translatedText">The translated text.</param>
        public void Update(CultureInfo culture, TypePromptKey key, string translatedText)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (translatedText == null)
            {
                throw new ArgumentNullException("translatedText");
            }

            var language = GetOrCreateLanguage(culture);
            var prompt   = (from p in language.Prompts
                            where p.LocaleId == culture.LCID && p.TextKey == key.ToString()
                            select p).FirstOrDefault();

            if (prompt == null)
            {
                throw new InvalidOperationException("Prompt " + key + " do not exist.");
            }

            prompt.Text = translatedText;
            _logger.Debug("Updating text for " + prompt.TypeName + "." + prompt.TextName + " to " + translatedText);
            _documentSession.Store(language);
            _documentSession.SaveChanges();
        }
        /// <summary>
        /// Create  or update a prompt
        /// </summary>
        /// <param name="culture">Culture that the prompt is for</param>
        /// <param name="fullTypeName">Type.FullName for the type being localized</param>
        /// <param name="name">Property name and any additonal names (such as metadata name, use underscore as delimiter)</param>
        /// <param name="translatedText">Translated text string</param>
        public void Save(CultureInfo culture, string fullTypeName, string name, string translatedText)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (fullTypeName == null)
            {
                throw new ArgumentNullException("fullTypeName");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (translatedText == null)
            {
                throw new ArgumentNullException("translatedText");
            }
            if (fullTypeName.IndexOf(".") == -1)
            {
                throw new ArgumentException("You must use Type.FullName", "fullTypeName");
            }

            var pos      = fullTypeName.LastIndexOf(".");
            var typeName = fullTypeName.Substring(pos + 1);
            var key      = new TypePromptKey(fullTypeName, name);
            var language = GetOrCreateLanguage(culture);
            var prompt   = (from p in language.Prompts
                            where p.LocaleId == culture.LCID && p.TextKey == key.ToString()
                            select p).FirstOrDefault() ?? new TypePromptDocument
            {
                FullTypeName = fullTypeName,
                LocaleId     = culture.LCID,
                TextName     = name,
                Text         = translatedText,
                TextKey      = key.ToString(),
                TypeName     = typeName,
                UpdatedAt    = DateTime.Now,
                UpdatedBy    = Thread.CurrentPrincipal.Identity.Name
            };

            prompt.Text = translatedText;
            _logger.Debug("Updating text for " + prompt.TypeName + "." + prompt.TextName + " to " + translatedText);
            _documentSession.Store(language);
            _documentSession.SaveChanges();
        }
Esempio n. 4
0
 public void DeletePrompt(TypePromptKey key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     Prompts.RemoveAll(k => k.TextKey == key.ToString());
 }
        /// <summary>
        /// Get a specific prompt
        /// </summary>
        /// <param name="culture">Culture to get prompt for</param>
        /// <param name="key">Key which is unique in the current language</param>
        /// <returns>
        /// Prompt if found; otherwise <c>null</c>.
        /// </returns>
        public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key)
        {
            var language = GetOrCreateLanguage(culture);

            return((from p in language.Prompts
                    where p.LocaleId == culture.LCID && p.TextKey == key.ToString()
                    select CreateTextPrompt(p)).FirstOrDefault());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TypePromptDocument"/> class.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="modelType">Type of the model.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="culture">The culture.</param>
        public TypePromptDocument(TypePromptKey key, Type modelType, string propertyName, CultureInfo culture)
        {
            if (key == null) throw new ArgumentNullException("key");
            if (modelType == null) throw new ArgumentNullException("modelType");
            if (propertyName == null) throw new ArgumentNullException("propertyName");

            TextKey = key.ToString();
            FullTypeName = modelType.FullName;
            TypeName = modelType.Name;
            TextName = propertyName;
            LocaleId = culture.LCID;
        }
Esempio n. 7
0
        private bool Exists(CultureInfo culture, TypePromptKey key)
        {
            var sql = @"SELECT count(Id) FROM LocalizedTypes WHERE LocaleId = @lcid AND [Key] = @key";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("key", key.ToString());
                cmd.CommandText = sql;
                return(!cmd.ExecuteScalar().Equals(0));
            }
        }
Esempio n. 8
0
        /// <summary>
        ///   Get a specific prompt
        /// </summary>
        /// <param name="culture"> Culture to get prompt for </param>
        /// <param name="key"> Key which is unique in the current language </param>
        /// <returns> Prompt if found; otherwise <c>null</c> . </returns>
        public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key)
        {
            var sql = "SELECT * FROM LocalizedTypes WHERE LocaleId = @LocaleId AND [Key] = @TextKey";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("LocaleId", culture.LCID);
                cmd.AddParameter("TextKey", key.ToString());

                using (var reader = cmd.ExecuteReader())
                {
                    return(!reader.Read() ? null : MapEntity(reader));
                }
            }
        }
Esempio n. 9
0
        private void Create(CultureInfo culture, string fullTypeName, string name, string translatedText)
        {
            var sql =
                @"INSERT INTO LocalizedTypes (LocaleId, [Key], TypeName, TextName, Value, UpdatedAt, UpdatedBy)
                      VALUES (@lcid, @TextKey, @TypeName, @TextName, @value, @updat, @updby)";

            var key = new TypePromptKey(fullTypeName, name);

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("TextKey", key.ToString());
                cmd.AddParameter("TypeName", fullTypeName);
                cmd.AddParameter("TextName", name);
                cmd.AddParameter("value", translatedText);
                cmd.AddParameter("updat", DateTime.Now);
                cmd.AddParameter("updby", Thread.CurrentPrincipal.Identity.Name);
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();
            }
        }
Esempio n. 10
0
        /// <summary>
        ///   Delete a prompt.
        /// </summary>
        /// <param name="culture"> Culture to delete prompt in </param>
        /// <param name="key"> Prompt key </param>
        public void Delete(CultureInfo culture, TypePromptKey key)
        {
            if (culture == null)
            {
                throw new ArgumentNullException("culture");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var sql = "DELETE FROM LocalizedTypes WHERE [Key]=@textKey AND LocaleId = @lcid";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("textKey", key.ToString());
                cmd.ExecuteNonQuery();
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TypePromptDocument"/> class.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="modelType">Type of the model.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="culture">The culture.</param>
        public TypePromptDocument(TypePromptKey key, Type modelType, string propertyName, CultureInfo culture)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (modelType == null)
            {
                throw new ArgumentNullException("modelType");
            }
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }

            TextKey      = key.ToString();
            FullTypeName = modelType.FullName;
            TypeName     = modelType.Name;
            TextName     = propertyName;
            LocaleId     = culture.LCID;
        }
 public void DeletePrompt(TypePromptKey key)
 {
     if (key == null) throw new ArgumentNullException("key");
     Prompts.RemoveAll(k => k.TextKey == key.ToString());
 }
        private bool Exists(CultureInfo culture, TypePromptKey key)
        {
            var sql = @"SELECT count(Id) FROM LocalizedTypes WHERE LocaleId = @lcid AND [Key] = @key";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("key", key.ToString());
                cmd.CommandText = sql;
                return !cmd.ExecuteScalar().Equals(0);
            }
        }
        private void Create(CultureInfo culture, string fullTypeName, string name, string translatedText)
        {
            var sql =
                @"INSERT INTO LocalizedTypes (LocaleId, [Key], TypeName, TextName, Value, UpdatedAt, UpdatedBy)
                      VALUES (@lcid, @TextKey, @TypeName, @TextName, @value, @updat, @updby)";

            var key = new TypePromptKey(fullTypeName, name);
            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("TextKey", key.ToString());
                cmd.AddParameter("TypeName", fullTypeName);
                cmd.AddParameter("TextName", name);
                cmd.AddParameter("value", translatedText);
                cmd.AddParameter("updat", DateTime.Now);
                cmd.AddParameter("updby", Thread.CurrentPrincipal.Identity.Name);
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();
            }
        }
        /// <summary>
        ///   Delete a prompt.
        /// </summary>
        /// <param name="culture"> Culture to delete prompt in </param>
        /// <param name="key"> Prompt key </param>
        public void Delete(CultureInfo culture, TypePromptKey key)
        {
            if (culture == null) throw new ArgumentNullException("culture");
            if (key == null) throw new ArgumentNullException("key");

            var sql = "DELETE FROM LocalizedTypes WHERE [Key]=@textKey AND LocaleId = @lcid";
            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("textKey", key.ToString());
                cmd.ExecuteNonQuery();
            }
        }
        /// <summary>
        ///   Update translation
        /// </summary>
        /// <param name="culture"> Culture that the prompt is for </param>
        /// <param name="key"> Unique key, in the specified language only, for the prompt to get) </param>
        /// <param name="translatedText"> Translated text string </param>
        public void Update(CultureInfo culture, TypePromptKey key, string translatedText)
        {
            if (culture == null) throw new ArgumentNullException("culture");
            if (key == null) throw new ArgumentNullException("key");
            if (translatedText == null) throw new ArgumentNullException("translatedText");

            var sql = "UPDATE LocalizedTypes SET Value=@value, UpdatedAt=@updat, UpdatedBy=@updby WHERE LocaleId = @lcid AND [Key] = @key";

            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("value", translatedText);
                cmd.AddParameter("updat", DateTime.Now);
                cmd.AddParameter("updby", Thread.CurrentPrincipal.Identity.Name);
                cmd.AddParameter("lcid", culture.LCID);
                cmd.AddParameter("key", key.ToString());
                cmd.ExecuteNonQuery();
            }
        }
        /// <summary>
        ///   Get a specific prompt
        /// </summary>
        /// <param name="culture"> Culture to get prompt for </param>
        /// <param name="key"> Key which is unique in the current language </param>
        /// <returns> Prompt if found; otherwise <c>null</c> . </returns>
        public TypePrompt GetPrompt(CultureInfo culture, TypePromptKey key)
        {
            var sql = "SELECT * FROM LocalizedTypes WHERE LocaleId = @LocaleId AND [Key] = @TextKey";
            using (var cmd = _db.Connection.CreateCommand())
            {
                cmd.CommandText = sql;
                cmd.AddParameter("LocaleId", culture.LCID);
                cmd.AddParameter("TextKey", key.ToString());

                using (var reader = cmd.ExecuteReader())
                {
                    return !reader.Read() ? null : MapEntity(reader);
                }
            }
        }
Esempio n. 18
0
 internal void Update(TypePromptKey key, string translatedText, CultureInfo culture)
 {
     Update(key.ToString(), translatedText, culture);
 }
 private LocalizedType getLocalizedType(CultureInfo culture, TypePromptKey key)
 {
     return getLocalizedType(culture.LCID, key.ToString());
 }
 private LocalizedType getLocalizedType(CultureInfo culture, TypePromptKey key)
 {
     return(getLocalizedType(culture.LCID, key.ToString()));
 }
Esempio n. 21
0
 internal void Update(TypePromptKey key, string translatedText, CultureInfo culture)
 {
     Update(key.ToString(), translatedText, culture);
 }