public override void UpdateSource(IEnumerable <LocalizedContent> localizedContent)
 {
     foreach (LocalizedContent lk in localizedContent)
     {
         TranslationKey      key           = lk.LocalizationKey as TranslationKey;
         TranslationGroupKey groupKey      = TranslationGroupKey.CreateManager(2).Load(key.Translation, lk.Group, lk.Key);
         TranslationValue    existingValue = TranslationValue.CreateManager().Load(lk.LocalizationKey as TranslationKey, groupKey);
         if (existingValue != null)
         {
             if (lk.Value == null)
             {
                 existingValue.Delete();
             }
             else if (!existingValue.Value.Equals(lk.Value))
             {
                 existingValue.Value = lk.Value;
                 existingValue.Update();
             }
         }
         else if (lk.Value != null)
         {
             TranslationValue newValue = new TranslationValue(-1, key, groupKey, lk.Value, DateTime.Now, DateTime.Now);
             newValue.Insert();
         }
     }
 }
Esempio n. 2
0
 public TranslationValue CreateInstance(TranslationGroupKey translationGroupKey)
 {
     if (!this.HasData)
     {
         return(null);
     }
     return(new TranslationValue(this.TranslationValueID, new TranslationKey(this.TranslationKeyID), translationGroupKey ?? new TranslationGroupKey(this.TranslationGroupKeyID), this.Value, this.Updated, this.Created));
 }
 public TranslationValueTemplate(TranslationKey translationKey, TranslationKey fallbackTranslationKey, TranslationGroupKey groupKey)
 {
     this._groupkey       = groupKey;
     this._translationKey = translationKey;
     this._value          = TranslationValue.CreateManager().Load(this._translationKey, groupKey);
     if (fallbackTranslationKey != null)
     {
         this._fallbackValue = TranslationValue.CreateManager().Load(fallbackTranslationKey, groupKey);
     }
 }
Esempio n. 4
0
        public ActionResult ApiUpdateTranslationValue(string translationValueKeyID, string translationKeyID, string translationGroupKeyID, string groupName, string groupKey, string value)
        {
            int tvalueID, tKeyID, tGroupKeyID;

            if (!Int32.TryParse(translationValueKeyID, out tvalueID))
            {
                return(this.Json(new { status = false, message = "Argument error 'translationValueKeyID" }));
            }
            if (!Int32.TryParse(translationKeyID, out tKeyID))
            {
                return(this.Json(new { status = false, message = "Argument error 'translationKeyID" }));
            }
            if (!Int32.TryParse(translationGroupKeyID, out tGroupKeyID))
            {
                return(this.Json(new { status = false, message = "Argument error 'translationGroupKeyID" }));
            }

            string message = "";

            value = HttpUtility.UrlDecode(value);

            TranslationValue translationValue;

            if (tvalueID == -1)
            {
                translationValue = new TranslationValue(-1,
                                                        TranslationKey.CreateManager().Load(tKeyID),
                                                        TranslationGroupKey.CreateManager().Load(tGroupKeyID),
                                                        value,
                                                        DateTime.Now, DateTime.Now);
                translationValue.Insert();
                message = "Translation has been added";
            }
            else
            {
                translationValue = TranslationValue.CreateManager().Load(tvalueID);
                if (translationValue == null)
                {
                    return(this.Json(new { status = false, message = "Translation value does not exists!" }));
                }

                translationValue.Value = value;
                translationValue.Update();
                message = "Translation has been updated";
            }

            Translations.Web.GetGroup(groupName).AssignValue(groupKey, value);
            //MobiContext.Current.UpdateTranslationsWildcars();

            return(this.Json(new { status = true, message = message, id = translationValue.ID, Updated = translationValue.Updated.ToString() }));
        }
        public TranslationTemplateModel(MobiContext context, Translation translation, bool extendedAccess, string groupName)
            : base(context, extendedAccess)
        {
            this._translationKey = TranslationKey.CreateManager().Load(context.Service.ServiceData);
            if (this._translationKey == null)
            {
                this._hasTranslation = false;
                return;
            }

            this.Name              = groupName;
            this._fallbackKey      = this._translationKey.FallbackTranslationKey;
            this._translationGroup = TranslationGroup.CreateManager().Load(translation, groupName);

            this._values = new List <TranslationValueTemplate>();
            List <TranslationGroupKey> groupKeys = TranslationGroupKey.CreateManager().Load(this._translationGroup);

            foreach (TranslationGroupKey groupKey in groupKeys)
            {
                this._values.Add(new TranslationValueTemplate(this._translationKey, this._fallbackKey, groupKey));
            }
        }
Esempio n. 6
0
        public TranslationValue Load(ISqlConnectionInfo connection, TranslationKey translationKey, TranslationGroupKey translationGroupKey)
        {
            SqlQueryParameters parameters = new SqlQueryParameters();

            parameters.Where = "[tv].TranslationGroupKeyID = @TranslationGroupKeyID AND [tv].TranslationKeyID = @TranslationKeyID";
            parameters.Arguments.Add("TranslationGroupKeyID", translationGroupKey.ID);
            parameters.Arguments.Add("TranslationKeyID", translationKey.ID);
            return(this.Load(connection, parameters));
        }
Esempio n. 7
0
        public TranslationValue Load(IConnectionInfo connection, TranslationKey translationKey, TranslationGroupKey translationGroupKey)
        {
            ISqlConnectionInfo sqlConnection = connection as ISqlConnectionInfo;

            if (sqlConnection != null)
            {
                return(this.Load(sqlConnection, translationKey, translationGroupKey));
            }
            using (sqlConnection = new SqlConnectionInfo(connection, this.Type))
                return(this.Load(sqlConnection, translationKey, translationGroupKey));
        }
Esempio n. 8
0
 public TranslationValue Load(TranslationKey translationKey, TranslationGroupKey translationGroupKey)
 {
     using (SqlConnectionInfo connection = new SqlConnectionInfo(this.Type))
         return(this.Load(connection, translationKey, translationGroupKey));
 }
        protected override TranslationValue LoadInternal(ISqlConnectionInfo connection, int id)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT " +
                             TranslationValueTable.GetColumnNames("[tv]") +
                             (this.Depth > 0 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationTable.GetColumnNames("[tv_tk_t]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[tv_tk_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[tv_tk_s]") : string.Empty) +
                             (this.Depth > 0 ? "," + TranslationGroupKeyTable.GetColumnNames("[tv_tgk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationGroupTable.GetColumnNames("[tv_tgk_tg]") : string.Empty) +
                             " FROM [core].[TranslationValue] AS [tv] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationKey] AS [tv_tk] ON [tv].[TranslationKeyID] = [tv_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[TranslationKey] AS [tv_tk_tk] ON [tv_tk].[FallbackTranslationKeyID] = [tv_tk_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Translation] AS [tv_tk_t] ON [tv_tk].[TranslationID] = [tv_tk_t].[TranslationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [tv_tk_l] ON [tv_tk].[LanguageID] = [tv_tk_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Service] AS [tv_tk_s] ON [tv_tk].[ServiceID] = [tv_tk_s].[ServiceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationGroupKey] AS [tv_tgk] ON [tv].[TranslationGroupKeyID] = [tv_tgk].[TranslationGroupKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationGroup] AS [tv_tgk_tg] ON [tv_tgk].[TranslationGroupID] = [tv_tgk_tg].[TranslationGroupID] ";
                }
                sqlCmdText += "WHERE [tv].[TranslationValueID] = @TranslationValueID;";

                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                sqlCmd.Parameters.AddWithValue("@TranslationValueID", id);
                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tv", "loadinternal", "notfound"), "TranslationValue could not be loaded by id as it was not found.", sqlCmdText, this, connection, id);
                    if (this.Logger.IsWarnEnabled)
                    {
                        this.Logger.Warn(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                TranslationValueTable    tvTable        = new TranslationValueTable(query);
                TranslationKeyTable      tv_tkTable     = (this.Depth > 0) ? new TranslationKeyTable(query) : null;
                TranslationKeyTable      tv_tk_tkTable  = (this.Depth > 1) ? new TranslationKeyTable(query) : null;
                TranslationTable         tv_tk_tTable   = (this.Depth > 1) ? new TranslationTable(query) : null;
                LanguageTable            tv_tk_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                ServiceTable             tv_tk_sTable   = (this.Depth > 1) ? new ServiceTable(query) : null;
                TranslationGroupKeyTable tv_tgkTable    = (this.Depth > 0) ? new TranslationGroupKeyTable(query) : null;
                TranslationGroupTable    tv_tgk_tgTable = (this.Depth > 1) ? new TranslationGroupTable(query) : null;


                TranslationKey      tv_tk_tkObject  = (this.Depth > 1) ? tv_tk_tkTable.CreateInstance() : null;
                Translation         tv_tk_tObject   = (this.Depth > 1) ? tv_tk_tTable.CreateInstance() : null;
                Language            tv_tk_lObject   = (this.Depth > 1) ? tv_tk_lTable.CreateInstance() : null;
                Service             tv_tk_sObject   = (this.Depth > 1) ? tv_tk_sTable.CreateInstance() : null;
                TranslationKey      tv_tkObject     = (this.Depth > 0) ? tv_tkTable.CreateInstance(tv_tk_tkObject, tv_tk_tObject, tv_tk_lObject, tv_tk_sObject) : null;
                TranslationGroup    tv_tgk_tgObject = (this.Depth > 1) ? tv_tgk_tgTable.CreateInstance() : null;
                TranslationGroupKey tv_tgkObject    = (this.Depth > 0) ? tv_tgkTable.CreateInstance(tv_tgk_tgObject) : null;
                TranslationValue    tvObject        = tvTable.CreateInstance(tv_tkObject, tv_tgkObject);
                sqlReader.Close();

                return(tvObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tv", "loadinternal", "exception"), "TranslationValue could not be loaded by id. See exception for details.", sqlCmdText, ex, this, connection, id);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "TranslationValue", "Exception while loading TranslationValue object from database. See inner exception for details.", ex);
            }
        }
        public List <TranslationValue> LoadMany(ISqlConnectionInfo connection, SqlQueryParameters parameters)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT {0} " +
                             TranslationValueTable.GetColumnNames("[tv]") +
                             (this.Depth > 0 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationKeyTable.GetColumnNames("[tv_tk_tk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationTable.GetColumnNames("[tv_tk_t]") : string.Empty) +
                             (this.Depth > 1 ? "," + LanguageTable.GetColumnNames("[tv_tk_l]") : string.Empty) +
                             (this.Depth > 1 ? "," + ServiceTable.GetColumnNames("[tv_tk_s]") : string.Empty) +
                             (this.Depth > 0 ? "," + TranslationGroupKeyTable.GetColumnNames("[tv_tgk]") : string.Empty) +
                             (this.Depth > 1 ? "," + TranslationGroupTable.GetColumnNames("[tv_tgk_tg]") : string.Empty) +
                             " FROM [core].[TranslationValue] AS [tv] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationKey] AS [tv_tk] ON [tv].[TranslationKeyID] = [tv_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[TranslationKey] AS [tv_tk_tk] ON [tv_tk].[FallbackTranslationKeyID] = [tv_tk_tk].[TranslationKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[Translation] AS [tv_tk_t] ON [tv_tk].[TranslationID] = [tv_tk_t].[TranslationID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Language] AS [tv_tk_l] ON [tv_tk].[LanguageID] = [tv_tk_l].[LanguageID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "LEFT OUTER  JOIN [core].[Service] AS [tv_tk_s] ON [tv_tk].[ServiceID] = [tv_tk_s].[ServiceID] ";
                }
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationGroupKey] AS [tv_tgk] ON [tv].[TranslationGroupKeyID] = [tv_tgk].[TranslationGroupKeyID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[TranslationGroup] AS [tv_tgk_tg] ON [tv_tgk].[TranslationGroupID] = [tv_tgk_tg].[TranslationGroupID] ";
                }


                sqlCmdText = parameters.BuildQuery(sqlCmdText);
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                foreach (KeyValuePair <string, object> argument in parameters.Arguments)
                {
                    sqlCmd.Parameters.AddWithValue("@" + argument.Key, argument.Value);
                }

                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tv", "customloadmany", "notfound"), "TranslationValue list could not be loaded using custom logic as no items were found.", sqlCmdText, this, connection, parameters);
                    if (this.Logger.IsDebugEnabled)
                    {
                        this.Logger.Debug(builder.ToString());
                    }
                    sqlReader.Close();
                    return(new List <TranslationValue>());
                }

                SqlQuery query = new SqlQuery(sqlReader);

                TranslationValueTable    tvTable        = new TranslationValueTable(query);
                TranslationKeyTable      tv_tkTable     = (this.Depth > 0) ? new TranslationKeyTable(query) : null;
                TranslationKeyTable      tv_tk_tkTable  = (this.Depth > 1) ? new TranslationKeyTable(query) : null;
                TranslationTable         tv_tk_tTable   = (this.Depth > 1) ? new TranslationTable(query) : null;
                LanguageTable            tv_tk_lTable   = (this.Depth > 1) ? new LanguageTable(query) : null;
                ServiceTable             tv_tk_sTable   = (this.Depth > 1) ? new ServiceTable(query) : null;
                TranslationGroupKeyTable tv_tgkTable    = (this.Depth > 0) ? new TranslationGroupKeyTable(query) : null;
                TranslationGroupTable    tv_tgk_tgTable = (this.Depth > 1) ? new TranslationGroupTable(query) : null;

                List <TranslationValue> result = new List <TranslationValue>();
                do
                {
                    TranslationKey      tv_tk_tkObject  = (this.Depth > 1) ? tv_tk_tkTable.CreateInstance() : null;
                    Translation         tv_tk_tObject   = (this.Depth > 1) ? tv_tk_tTable.CreateInstance() : null;
                    Language            tv_tk_lObject   = (this.Depth > 1) ? tv_tk_lTable.CreateInstance() : null;
                    Service             tv_tk_sObject   = (this.Depth > 1) ? tv_tk_sTable.CreateInstance() : null;
                    TranslationKey      tv_tkObject     = (this.Depth > 0) ? tv_tkTable.CreateInstance(tv_tk_tkObject, tv_tk_tObject, tv_tk_lObject, tv_tk_sObject) : null;
                    TranslationGroup    tv_tgk_tgObject = (this.Depth > 1) ? tv_tgk_tgTable.CreateInstance() : null;
                    TranslationGroupKey tv_tgkObject    = (this.Depth > 0) ? tv_tgkTable.CreateInstance(tv_tgk_tgObject) : null;
                    TranslationValue    tvObject        = (this.Depth > -1) ? tvTable.CreateInstance(tv_tkObject, tv_tgkObject) : null;
                    result.Add(tvObject);
                } while (sqlReader.Read());
                sqlReader.Close();

                return(result);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("tv", "customloadmany", "exception"), "TranslationValue list could not be loaded using custom logic. See exception for details.", sqlCmdText, ex, this, connection, parameters);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "TranslationValue", "Exception while loading (custom/many) TranslationValue object from database. See inner exception for details.", ex);
            }
        }
 protected override IEnumerable <LocalizationGroupKey> LoadLocalizationGroupKeys()
 {
     return(from TranslationGroupKey t in (TranslationGroupKey.CreateManager(3).Load(this.Translation))
            select new LocalizationGroupKey(t.TranslationGroup.Translation.Name,
                                            t.TranslationGroup.Name, t.Name, t.Comment));
 }