public object GetCacheItem(string cacheName, string key, params object[] args) { TkDebug.AssertArgumentNullOrEmpty(cacheName, "cacheName", this); TkDebug.AssertArgumentNullOrEmpty(key, "key", this); ICache cache = GetCache(cacheName); BaseCacheItemCreator creator = PlugInFactoryManager.CreateInstance <BaseCacheItemCreator>( CacheItemCreatorPlugInFactory.REG_NAME, cacheName); TkDebug.AssertNotNull(creator, $"{cacheName}不存在", this); if (cache == null) { ICacheCreator cacheCreator = creator.CacheCreator; if (cacheCreator == null) { cacheCreator = creator.SupportDistributed ? DefaultDistributedCreator : DefaultCreator; } cache = cacheCreator.CreateCache(cacheName); CacheLock.WriteLockAction(() => { if (!fCaches.ContainsKey(cacheName)) { fCaches.Add(cacheName, cache); return(true); } return(false); }); } return(cache.GetItem(creator.TransformCacheKey(key), creator, args)); }
public object GetItem(string key, BaseCacheItemCreator creator, params object[] args) { object result = null; ICacheDataConverter converter = GetDataConverter(creator); var distributeKey = GetDistributeKey(creator, key); if (GetCacheInstance(distributeKey, converter, out var cacheObject)) { return(cacheObject); } try { result = creator.Create(key, args); TkDebug.AssertNotNull(result, string.Format(ObjectUtil.SysCulture, "类型为{0}缓存对象创建者没有创建缓存对象,请确认", creator.GetType()), creator); } catch (Exception ex) { TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture, "类型为{0}缓存对象创建者在创建对象时发生例外,请检查原因", creator.GetType()), ex, creator); } ICacheDependency dependency = CacheUtil.SearchDependency(result); IDistributeCacheDependency distributeDependency = dependency as IDistributeCacheDependency; TkDebug.AssertNotNull(distributeDependency, $"附着的ICacheDependency(类型为{dependency.GetType()})不支持IDistributeCacheDependency", dependency); AddCacheInstance(distributeKey, result, converter, distributeDependency, creator.Attribute.ForceCache); return(result); }
public static void SetSafeValue(DataRow row, string fieldName, string value, bool throwOnError) { TkDebug.AssertArgumentNull(row, "row", null); TkDebug.AssertArgumentNull(fieldName, "fieldName", null); if (string.IsNullOrEmpty(value)) { row[fieldName] = DBNull.Value; } else { TkDebug.AssertNotNull(row.Table, "row没有放在Table下,无法获取", null); DataColumn column = row.Table.Columns[fieldName]; try { row[column] = ObjectUtil.GetValue(null, column.DataType, value, null, ObjectUtil.ReadSettings); } catch { if (throwOnError) { throw; } } } }
private static string InternalInput(this Tk5FieldInfoEx field, string name, string value, bool needId, bool isSearchCtrl) { TkDebug.AssertArgumentNull(field, "field", null); HtmlAttributeBuilder builder = new HtmlAttributeBuilder(); TkDebug.AssertNotNull(field.InternalControl, "field的InternalControl不能为空", field); builder.Add("type", field.InternalControl.Control); builder.Add("value", value); AddInputAttribute(field, builder, isSearchCtrl); AddNormalAttribute(field, builder, name, needId); if (field.HintPosition == HintPosition.PlaceHolder || string.IsNullOrEmpty(field.Hint)) { return(string.Format(ObjectUtil.SysCulture, "<input {0}/>{1}", builder.CreateAttribute(), ERROR_LABEL)); } else { string format; if (field.HintPosition == HintPosition.Front) { format = Html.InputHintBefore; } else { format = Html.InputHintAfter; } return(string.Format(ObjectUtil.SysCulture, format, builder.CreateAttribute(), ERROR_LABEL, field.Hint)); } }
public object GetItem(string key, BaseCacheItemCreator creator, params object[] args) { object result = null; object cacheObject; if (GetCacheInstance(key, out cacheObject)) { return(cacheObject); } try { result = creator.Create(key, args); TkDebug.AssertNotNull(result, string.Format(ObjectUtil.SysCulture, "类型为{0}缓存对象创建者没有创建缓存对象,请确认", creator.GetType()), creator); } catch (Exception ex) { TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture, "类型为{0}缓存对象创建者在创建对象时发生例外,请检查原因", creator.GetType()), ex, creator); } AddCacheInstance(key, result, CacheUtil.SearchDependency(result), creator.Attribute.ForceCache); return(result); }
internal static ICacheDataConverter GetDataConverter(BaseCacheItemCreator creator) { ICacheDataConverter converter = creator as ICacheDataConverter; TkDebug.AssertNotNull(converter, $"{nameof(creator)}需要支持ICacheDataConverter接口", creator); return(converter); }
public void Start() { TkDebug.AssertNotNull(fThreadObj, "线程对象没有初始化", this); TkDebug.Assert(!fThreadObj.IsAlive, "当前工作线程已经激活,不能再调用Start", this); fThreadObj.Start(); }
protected virtual IHtmlContent RenderBody() { TkDebug.AssertNotNull(BodyContent, "Method can not be called", this); //fRenderedBody = true; return(BodyContent); }
public async Task IncludeAsync(string key, object model = null) { TkDebug.AssertArgumentNull(key, nameof(key), this); TkDebug.AssertNotNull(IncludeFunc, nameof(IncludeFunc) + "is not set", this); await IncludeFunc(key, model); }
public static TkDbContext CreateDefault() { ISupportDbContext support = GetSupport(); DbContextConfig config = support.Default; TkDebug.AssertNotNull(config, "AppSetting中没有配置Default的DbContext", support); return(config.CreateDbContext()); }
public IEnumerable <string> GetOperator(OperateRightEventArgs e) { IFunctionRight funcRight = WebGlobalVariable.SessionGbl.AppRight.FunctionRight; TkDebug.AssertNotNull(funcRight, "系统没有配置功能权限", this); return(funcRight.GetSubFunctions(FunctionKey)); }
public override IRedirector CreateRedirector(IPageData pageData) { IRedirector redirector = ObjectUtil.CreateObject(ObjectType).Convert <IRedirector>(); TkDebug.AssertNotNull(redirector, string.Format( ObjectUtil.SysCulture, "无法根据类型{0}创建实例", ObjectType), this); return(redirector); }
private static Stream GetResourceStream(Assembly assembly, string partName) { Stream stream = ResourceUtil.GetEmbeddedResource(assembly, partName); TkDebug.AssertNotNull(stream, string.Format(ObjectUtil.SysCulture, "程序集{0}中没有名称包含{1}的资源", assembly, partName), null); return(stream); }
private void JudgeListContainCurrentException(ListNode <T> current) { TkDebug.AssertNotNull(fHead, "该链表为空!", this); //判断当前节点是否为当前链表中 //传送LinkList<T>对象给ListNode<T>构造函数,是为了确定不同的节点对应到各自不同的类节点链表里面 //判断当前节点是否在this链表中 TkDebug.Assert(current.List == this, "您插入的当前链表不匹配!", this); }
string IParamExpression.Execute(string parameter) { Match match = fExpr.Match(parameter); TkDebug.AssertNotNull(match, string.Format(ObjectUtil.SysCulture, "参数{0}格式不正确,正确格式为TableName.FieldName[.(number | n [ - number])]" + "[#EasySearchRegName],请检查", parameter), this); string tableName = match.Groups["Table"].Value; string fieldName = match.Groups["Column"].Value; string regName = match.Groups["RegName"].Value; int count = 0; bool isLast = true; string first = match.Groups["First"].Value; if (!string.IsNullOrEmpty(first)) { isLast = false; count = int.Parse(first, ObjectUtil.SysCulture); } else { string lastCount = match.Groups["Count"].Value; if (!string.IsNullOrEmpty(lastCount)) { try { count = int.Parse(lastCount, ObjectUtil.SysCulture); } catch { TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture, "[n - number]格式中number必须是数字,但是现在不是,它的值是{0}", lastCount), this); } } } DataTable table = fDataSet.Tables[tableName]; TkDebug.AssertNotNull(table, string.Format(ObjectUtil.SysCulture, "宏{0}中定义的表{1}在DataSet中不存在", parameter, tableName), this); TkDebug.Assert(table.Columns.Contains(fieldName), string.Format(ObjectUtil.SysCulture, "宏{0}中定义的字段{1}在表中不存在", parameter, fieldName), this); int rowCount = table.Rows.Count; int rowNumber = isLast ? rowCount - 1 - count : count; TkDebug.Assert(rowNumber >= 0 && rowNumber < rowCount, string.Format(ObjectUtil.SysCulture, "行号定义错误,当前表中有{0}行记录,而现在行号为{1}", rowCount, rowNumber), this); string value = table.Rows[rowNumber][fieldName].ToString(); if (!string.IsNullOrEmpty(regName)) { //EasySearch easySearch = PlugInFactoryManager.CreateInstance<EasySearch>( // "EasySearch", regName); //TkDebug.AssertNotNull(fContext, // "参数宏($)需要Context对象,但是没有从外部对象中找到", this); //value = easySearch.Decode(fContext, value); } return(value); }
private static CorpDepartment FindDept(string id, out CorpDepartmentCollection deptList) { deptList = WeDataUtil.GetCacheData <CorpDepartmentCollection>(WeCorpConst.CORP_DEPT_NAME); CorpDepartment result = deptList.Department[id]; TkDebug.AssertNotNull(result, string.Format(ObjectUtil.SysCulture, "数据有错误,无法找到Id为{0}的Department", id), null); return(result); }
public override ITableSchemeEx CreateSourceScheme(IInputData input) { TypeTableScheme schema = MetaDataUtil.CreateTypeTableScheme(ClassRegName); TkDebug.AssertNotNull(schema, string.Format(ObjectUtil.SysCulture, "没有找到标记了TypeTableSchemeAttribute的注册类{0}", ClassRegName), this); return(schema); }
internal static CorpTag FindTag(string id, out CorpTagList tagList) { tagList = WeDataUtil.GetCacheData <CorpTagList>(WeDataConst.CORP_TAG_NAME); CorpTag result = tagList.TagList[id]; TkDebug.AssertNotNull(result, string.Format(ObjectUtil.SysCulture, "数据有错误,无法找到Id为{0}的Tag", id), null); return(result); }
/// <summary> /// Initializes a new instance of the ParamExpressionItem class. /// </summary> /// <param name="expression"></param> /// <param name="parameter"></param> public ParamExpressionItem(IParamExpression expression, string parameter) { fExpression = expression; Name = parameter; fAttribute = Attribute.GetCustomAttribute(expression.GetType(), typeof(ParamExpressionAttribute)) as ParamExpressionAttribute; TkDebug.AssertNotNull(fAttribute, string.Format(ObjectUtil.SysCulture, "此处错误不该发生,因为插件{0}应该附着了相应的Attribute", expression.GetType()), expression); SqlInject = fAttribute.SqlInject; }
public IDataRight CreateObject(params object[] args) { IFieldInfoIndexer indexer = ObjectUtil.ConfirmQueryObject <IFieldInfoIndexer>(this, args); IFieldInfo ownerField = indexer[NickName]; TkDebug.AssertNotNull(ownerField, string.Format(ObjectUtil.SysCulture, "没有找到昵称为{0}的字段", NickName), indexer); return(CreateDataRight(ownerField).SetErrorText(ErrorMessage)); }
void IReadObjectCallBack.OnReadObject() { TkDebug.AssertNotNull(MasterFields, "没有配置MasterFields内容", this); TkDebug.AssertNotNull(DetailFields, "没有配置DetailFields内容", this); TkDebug.Assert(MasterFields.Length == DetailFields.Length, string.Format( ObjectUtil.SysCulture, "MasterFields和DetailFields中含有的字段个数不匹配," + "现在MasterField中有{0}个字段,DetailField有{1}个字段", MasterFields.Length, DetailFields.Length), this); }
public static Tk5UploadConfig AssertUpload(this IFieldInfoEx field) { TkDebug.AssertArgumentNull(field, "field", null); Tk5UploadConfig upload = field.Upload.Convert <Tk5UploadConfig>(); TkDebug.AssertNotNull(upload, "非法调用,Field没有配置Upload单元", field); return(upload); }
public static IFieldInfo GetFieldInfo(object[] args) { TkDebug.AssertArgumentNull(args, "args", null); //TkDebug.Assert(args.Length == 1, string.Format(ObjectUtil.SysCulture, // "args中的参数只能有一个,现在是{0}个", args.Length), null); IFieldInfo result = ObjectUtil.QueryObject <IFieldInfo>(args); TkDebug.AssertNotNull(result, "创建参数中缺乏IFieldInfo类型", null); return(result); }
private static ISupportDbContext GetSupport() { TkDebug.ThrowIfNoAppSetting(); ISupportDbContext support = BaseAppSetting.Current as ISupportDbContext; TkDebug.AssertNotNull(support, "AppSetting不支持ISupportDbContext接口,无法创建DbContext", BaseAppSetting.Current); return(support); }
public bool ContainsKey(string key, string cacheName) { BaseCacheItemCreator creator = PlugInFactoryManager.CreateInstance <BaseCacheItemCreator>( CacheItemCreatorPlugInFactory.REG_NAME, cacheName); TkDebug.AssertNotNull(creator, $"{cacheName}不存在", this); ICacheDataConverter converter = GetDataConverter(creator); return(GetCacheInstance(key, converter, out _)); }
private IEnumerable <IFieldInfo> GetFieldInfoList(IFieldInfoIndexer indexer) { foreach (var nickName in NickNameList) { IFieldInfo field = indexer[nickName]; TkDebug.AssertNotNull(field, string.Format(ObjectUtil.SysCulture, "{0}不存在,请确认配置是否正确", nickName), this); yield return(field); } }
private void Initialize() { Type type = GetType(); var attr = global::System.Attribute.GetCustomAttribute(type, typeof(CacheItemCreatorAttribute)); TkDebug.AssertNotNull(attr, string.Format(ObjectUtil.SysCulture, "类型{0}没有附着CacheItemCreatorAttribute", type), null); Attribute = attr.Convert <CacheItemCreatorAttribute>(); }
public static object ReadConfig(string sectionName) { TkDebug.AssertArgumentNullOrEmpty(sectionName, nameof(sectionName), null); var config = InternalReadConfig(sectionName); TkDebug.AssertNotNull(config, $"Config.xml中没有{sectionName}的配置,请确认", null); return(config); }
private WeixinCorpConfig GetCorpConfig(int appId) { AssertCorpMode(); WeixinCorpConfig config = fCorpApps[appId.ToString()]; TkDebug.AssertNotNull(config, string.Format(ObjectUtil.SysCulture, "配置中不存在AppId为{0}的CorpApp,请确认", appId), this); return(config); }
private static string InternalCombo(Tk5FieldInfoEx field, string name, IFieldValueProvider row, bool needId) { HtmlAttributeBuilder builder = new HtmlAttributeBuilder(); AddNormalAttribute(field, builder, name, needId); TkDebug.AssertNotNull(field.Decoder, "Combo控件需要配置Decoder", field); DecoderAdditionInfo[] additions = null; if (field.Decoder.Additions != null) { additions = field.Decoder.Additions.ToArray(); builder.Add("data-addition", additions.WriteJson()); } //DataTable codeTable = model.Tables[field.Decoder.RegName]; IEnumerable <IDecoderItem> codeTable = row.GetCodeTable(field.Decoder.RegName); StringBuilder options = new StringBuilder(); if (field.IsEmpty) { string emptyTitle; if (field.Extension != null && field.Extension.EmptyTitle != null) { emptyTitle = field.Extension.EmptyTitle; } else { emptyTitle = string.Empty; } options.Append("<option value=\"\">").Append(emptyTitle).AppendLine("</option>"); } string value = row[name].ToString(); if (codeTable != null) { string addition = string.Empty; foreach (IDecoderItem codeRow in codeTable) { string codeValue = codeRow.Value; if (additions != null) { DecoderAdditionData data = new DecoderAdditionData(); data.AddData(codeRow, additions); addition = " " + data.ToJson(); } options.AppendFormat(ObjectUtil.SysCulture, "<option value=\"{0}\"{1}{3}>{2}</option>\r\n", codeValue, codeValue == value ? " selected" : string.Empty, codeRow.Name, addition); } } return(string.Format(ObjectUtil.SysCulture, "<select {0}>{1}</select>{2}", builder.CreateAttribute(), options, ERROR_LABEL)); }