Skip to content

Commit

Permalink
- 调整 resources 转换成 static class 静态类;#1917
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Nov 8, 2024
1 parent fa0e5ba commit 01b9ae0
Show file tree
Hide file tree
Showing 228 changed files with 3,422 additions and 4,845 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public Dictionary<string, object[]> CompareState(TEntity newdata)
{
if (newdata == null) return null;
var _table = Orm.CodeFirst.GetTableByEntity(EntityType);
if (_table.Primarys.Any() == false) throw new Exception(DbContextStrings.Incomparable_EntityHasNo_PrimaryKey(Orm.GetEntityString(EntityType, newdata)));
if (_table.Primarys.Any() == false) throw new Exception(DbContextErrorStrings.Incomparable_EntityHasNo_PrimaryKey(Orm.GetEntityString(EntityType, newdata)));
var key = Orm.GetEntityKeyString(EntityType, newdata, false);
if (string.IsNullOrEmpty(key)) throw new Exception(DbContextStrings.Incomparable_PrimaryKey_NotSet(Orm.GetEntityString(EntityType, newdata)));
if (string.IsNullOrEmpty(key)) throw new Exception(DbContextErrorStrings.Incomparable_PrimaryKey_NotSet(Orm.GetEntityString(EntityType, newdata)));
if (_states.TryGetValue(key, out var oldState) == false || oldState == null) throw new Exception($"不可对比,数据未被跟踪:{Orm.GetEntityString(EntityType, newdata)}");
AggregateRootTrackingChangeInfo tracking = new AggregateRootTrackingChangeInfo();
AggregateRootUtils.CompareEntityValue(_boundaryName, Orm, EntityType, oldState, newdata, null, tracking);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async public virtual Task<TEntity> InsertOrUpdateAsync(TEntity entity, Cancellat
var stateKey = Orm.GetEntityKeyString(EntityType, entity, false);
if (entity == null) throw new ArgumentNullException(nameof(entity));
var table = Orm.CodeFirst.GetTableByEntity(EntityType);
if (table.Primarys.Any() == false) throw new Exception(DbContextStrings.CannotAdd_EntityHasNo_PrimaryKey(Orm.GetEntityString(EntityType, entity)));
if (table.Primarys.Any() == false) throw new Exception(DbContextErrorStrings.CannotAdd_EntityHasNo_PrimaryKey(Orm.GetEntityString(EntityType, entity)));

var flagExists = ExistsInStates(entity);
if (flagExists == false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public virtual void BeginEdit(List<TEntity> data)
{
if (data == null) return;
var table = Orm.CodeFirst.GetTableByEntity(EntityType);
if (table.Primarys.Any() == false) throw new Exception(DbContextStrings.CannotEdit_EntityHasNo_PrimaryKey(Orm.GetEntityString(EntityType, data.First())));
if (table.Primarys.Any() == false) throw new Exception(DbContextErrorStrings.CannotEdit_EntityHasNo_PrimaryKey(Orm.GetEntityString(EntityType, data.First())));
_statesEditing.Clear();
_dataEditing = data;
foreach (var item in data)
Expand Down Expand Up @@ -216,7 +216,7 @@ public virtual TEntity InsertOrUpdate(TEntity entity)
var stateKey = Orm.GetEntityKeyString(EntityType, entity, false);
if (entity == null) throw new ArgumentNullException(nameof(entity));
var table = Orm.CodeFirst.GetTableByEntity(EntityType);
if (table.Primarys.Any() == false) throw new Exception(DbContextStrings.CannotAdd_EntityHasNo_PrimaryKey(Orm.GetEntityString(EntityType, entity)));
if (table.Primarys.Any() == false) throw new Exception(DbContextErrorStrings.CannotAdd_EntityHasNo_PrimaryKey(Orm.GetEntityString(EntityType, entity)));

var flagExists = ExistsInStates(entity);
if (flagExists == false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ Expression LocalGetAutoIncludeQuery(Expression queryExp, int depth, Type entityT
void LocalInclude(TableRef tbref, Expression exp)
{
var incMethod = queryExp.Type.GetMethod("Include");
if (incMethod == null) throw new Exception(CoreStrings.RunTimeError_Reflection_IncludeMany.Replace("IncludeMany", "Include"));
if (incMethod == null) throw new Exception(CoreErrorStrings.RunTimeError_Reflection_IncludeMany.Replace("IncludeMany", "Include"));
queryExp = Expression.Call(queryExp, incMethod.MakeGenericMethod(tbref.RefEntityType),
Expression.Lambda(typeof(Func<,>).MakeGenericType(entityType, tbref.RefEntityType), exp, navigateParameterExp));
}
Expand All @@ -508,7 +508,7 @@ void LocalIncludeMany(TableRef tbref, Expression exp, bool isthen)
var funcType = typeof(Func<,>).MakeGenericType(entityType, typeof(IEnumerable<>).MakeGenericType(tbref.RefEntityType));
var navigateSelector = Expression.Lambda(funcType, exp, navigateParameterExp);
var incMethod = queryExp.Type.GetMethod("IncludeMany");
if (incMethod == null) throw new Exception(CoreStrings.RunTimeError_Reflection_IncludeMany);
if (incMethod == null) throw new Exception(CoreErrorStrings.RunTimeError_Reflection_IncludeMany);
LambdaExpression navigateThen = null;
var navigateThenType = typeof(Action<>).MakeGenericType(typeof(ISelect<>).MakeGenericType(tbref.RefEntityType));
var thenParameter = Expression.Parameter(typeof(ISelect<>).MakeGenericType(tbref.RefEntityType), "then");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class BaseEntity
static Func<IFreeSql> _resoleOrm;
internal static Func<IUnitOfWork> _resolveUow;

public static IFreeSql Orm => _resoleOrm?.Invoke() ?? throw new Exception(CoreStrings.S_BaseEntity_Initialization_Error);
public static IFreeSql Orm => _resoleOrm?.Invoke() ?? throw new Exception(CoreErrorStrings.S_BaseEntity_Initialization_Error);

public static void Initialization(IFreeSql fsql, Func<IUnitOfWork> resolveUow) => Initialization(() => fsql, resolveUow);
public static void Initialization(Func<IFreeSql> resoleOrm, Func<IUnitOfWork> resolveUow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IQueryable<T1> AsQueryable<T1>(this ISelect<T1> that) where T1 : c
/// <returns></returns>
public static ISelect<T1> RestoreToSelect<T1>(this IQueryable<T1> that) where T1 : class
{
var queryable = that as QueryableProvider<T1, T1> ?? throw new Exception(CoreStrings.S_CannotBeConverted_To_ISelect(typeof(T1).Name));
var queryable = that as QueryableProvider<T1, T1> ?? throw new Exception(CoreErrorStrings.S_CannotBeConverted_To_ISelect(typeof(T1).Name));
return queryable._select;
}

Expand Down
16 changes: 8 additions & 8 deletions Extensions/FreeSql.Extensions.Linq/QueryableProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object tplOrderBy(string method, bool isDescending)
case "Average": return tplMaxMinAvgSum("Avg");

case "Concat":
return throwCallExp(CoreStrings.Not_Support);
return throwCallExp(CoreErrorStrings.Not_Support);
case "Contains":
if (callExp.Arguments.Count == 2)
{
Expand All @@ -141,7 +141,7 @@ object tplOrderBy(string method, bool isDescending)
_select.Distinct();
break;
}
return throwCallExp(CoreStrings.Not_Support);
return throwCallExp(CoreErrorStrings.Not_Support);

case "ElementAt":
case "ElementAtOrDefault":
Expand Down Expand Up @@ -178,7 +178,7 @@ object tplOrderBy(string method, bool isDescending)
_select.InternalWhere(whereParam);
break;
}
return throwCallExp(CoreStrings.Not_Support);
return throwCallExp(CoreErrorStrings.Not_Support);

case "Skip":
_select.Offset((int)callExp.Arguments[1].GetConstExprValue());
Expand All @@ -190,7 +190,7 @@ object tplOrderBy(string method, bool isDescending)
case "ToList":
if (callExp.Arguments.Count == 1)
return _select.ToList();
return throwCallExp(CoreStrings.Not_Support);
return throwCallExp(CoreErrorStrings.Not_Support);

case "Select":
var selectParam = (callExp.Arguments[1] as UnaryExpression)?.Operand as LambdaExpression;
Expand All @@ -199,7 +199,7 @@ object tplOrderBy(string method, bool isDescending)
_select._selectExpression = selectParam;
break;
}
return throwCallExp(CoreStrings.Not_Support);
return throwCallExp(CoreErrorStrings.Not_Support);

case "Join":
if (callExp.Arguments.Count == 5)
Expand Down Expand Up @@ -241,13 +241,13 @@ object tplOrderBy(string method, bool isDescending)

case "Last":
case "LastOrDefault":
return throwCallExp(CoreStrings.Not_Support);
return throwCallExp(CoreErrorStrings.Not_Support);

case "GroupBy":
return throwCallExp(CoreStrings.Not_Support);
return throwCallExp(CoreErrorStrings.Not_Support);

default:
return throwCallExp(CoreStrings.Not_Support);
return throwCallExp(CoreErrorStrings.Not_Support);
}
}
if (tresult == null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ NativeTuple<string, ColumnInfo> ParseField(ZeroTableInfo firstTable, string firs
var ta = _tableAlias.Where(a => string.Join(".", a.NavPath) == navPath).FirstOrDefault();
if (ta?.Table.ColumnsByCs.TryGetValue(field.Last(), out var col) == true)
return NativeTuple.Create($"{ta.Alias}.{_common.QuoteSqlName(col.Attribute.Name)}", col);
throw new Exception(CoreStrings.Cannot_Match_Property(property));
throw new Exception(CoreErrorStrings.Cannot_Match_Property(property));
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Extensions/FreeSql.Extensions.ZeroEntity/ZeroDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ void TransactionInvoke(Action handler)
_orm.Aop.TraceBeforeHandler?.Invoke(this, transBefore);
handler?.Invoke();
_transaction.Commit();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.Commit, null));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreErrorStrings.Commit, null));
}
catch (Exception ex)
{
_transaction.Rollback();
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreStrings.RollBack, ex));
_orm.Aop.TraceAfterHandler?.Invoke(this, new Aop.TraceAfterEventArgs(transBefore, CoreErrorStrings.RollBack, ex));
throw;
}
finally
Expand Down
10 changes: 5 additions & 5 deletions Extensions/FreeSql.Generator/ConsoleApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public ConsoleApp(string[] args, ManualResetEvent wait)

case "-nameoptions":
ArgsNameOptions = args[a + 1].Split(',').Select(opt => opt == "1").ToArray();
if (ArgsNameOptions.Length != 4) throw new ArgumentException(CoreStrings.S_NameOptions_Incorrect);
if (ArgsNameOptions.Length != 4) throw new ArgumentException(CoreErrorStrings.S_NameOptions_Incorrect);
a++;
break;
case "-namespace":
Expand All @@ -172,7 +172,7 @@ public ConsoleApp(string[] args, ManualResetEvent wait)
break;
case "-db":
var dbargs = args[a + 1].Split(',', 2);
if (dbargs.Length != 2) throw new ArgumentException(CoreStrings.S_DB_ParameterError);
if (dbargs.Length != 2) throw new ArgumentException(CoreErrorStrings.S_DB_ParameterError);

switch (dbargs[0].Trim().ToLower())
{
Expand All @@ -186,7 +186,7 @@ public ConsoleApp(string[] args, ManualResetEvent wait)
case "kingbasees": ArgsDbType = DataType.KingbaseES; break;
case "shentong": ArgsDbType = DataType.ShenTong; break;
case "clickhouse": ArgsDbType = DataType.ClickHouse; break;
default: throw new ArgumentException(CoreStrings.S_DB_ParameterError_UnsupportedType(dbargs[0]));
default: throw new ArgumentException(CoreErrorStrings.S_DB_ParameterError_UnsupportedType(dbargs[0]));
}
ArgsConnectionString = dbargs[1].Trim();
a++;
Expand Down Expand Up @@ -225,11 +225,11 @@ public ConsoleApp(string[] args, ManualResetEvent wait)
a++;
break;
default:
throw new ArgumentException(CoreStrings.S_WrongParameter(args[a]));
throw new ArgumentException(CoreErrorStrings.S_WrongParameter(args[a]));
}
}

if (string.IsNullOrEmpty(ArgsConnectionString)) throw new ArgumentException(CoreStrings.S_DB_Parameter_Error_NoConnectionString);
if (string.IsNullOrEmpty(ArgsConnectionString)) throw new ArgumentException(CoreErrorStrings.S_DB_Parameter_Error_NoConnectionString);

RazorEngine.Engine.Razor = RazorEngineService.Create(new RazorEngine.Configuration.TemplateServiceConfiguration
{
Expand Down
6 changes: 3 additions & 3 deletions FreeSql.DbContext/DbContext/DbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ namespace FreeSql
public abstract partial class DbContext : IDisposable
{
internal DbContextScopedFreeSql _ormScoped;
internal IFreeSql OrmOriginal => _ormScoped?._originalFsql ?? throw new ArgumentNullException(DbContextStrings.ConfigureUseFreeSql);
internal IFreeSql OrmOriginal => _ormScoped?._originalFsql ?? throw new ArgumentNullException(DbContextErrorStrings.ConfigureUseFreeSql);

/// <summary>
/// 该对象 Select/Delete/Insert/Update/InsertOrUpdate 与 DbContext 事务保持一致,可省略传递 WithTransaction
/// </summary>
public IFreeSql Orm => _ormScoped ?? throw new ArgumentNullException(DbContextStrings.ConfigureUseFreeSql);
public IFreeSql Orm => _ormScoped ?? throw new ArgumentNullException(DbContextErrorStrings.ConfigureUseFreeSql);

#region Property UnitOfWork
internal bool _isUseUnitOfWork = true; //是否创建工作单元事务
Expand Down Expand Up @@ -135,7 +135,7 @@ public virtual IDbSet Set(Type entityType)
void CheckEntityTypeOrThrow(Type entityType)
{
if (OrmOriginal.CodeFirst.GetTableByEntity(entityType) == null)
throw new ArgumentException(DbContextStrings.ParameterDataTypeError(entityType.FullName));
throw new ArgumentException(DbContextErrorStrings.ParameterDataTypeError(entityType.FullName));
}
/// <summary>
/// 添加
Expand Down
Loading

0 comments on commit 01b9ae0

Please sign in to comment.