public virtual void WriteWhitespace(string ws) { if (ws != null) { TkDebug.Assert(StringUtil.IsWhiteSpace(ws), "只有空白字符才能使用", this); } }
public void Start() { TkDebug.AssertNotNull(fThreadObj, "线程对象没有初始化", this); TkDebug.Assert(!fThreadObj.IsAlive, "当前工作线程已经激活,不能再调用Start", this); fThreadObj.Start(); }
public void AddButton(MenuButton button) { TkDebug.AssertArgumentNull(button, "button", this); TkDebug.Assert(Buttons.Count <= 3, "当前的菜单数已经超过3个,这是微信允许的最大数量", this); Buttons.Add(button); }
public void SetHandled(TableResolver resolver, bool value) { TkDebug.Assert(fResolvers.ContainsKey(resolver), string.Format( ObjectUtil.SysCulture, "在Resolver集合中,没有找到({0})的Resolver。" + "请确认是否使用AddResolvers增加对应的Resolver", resolver), resolver); fResolvers[resolver] = value; }
protected internal BaseSchemeEasySearch(ITableScheme scheme, string idField, string nameField, bool canCache) { TkDebug.AssertArgumentNull(scheme, "scheme", null); TkDebug.AssertArgument(scheme is IDisplayObject, "scheme", "scheme需要支持IDisplayObject接口", scheme); fDisplay = scheme.Convert <IDisplayObject>(); TkDebug.Assert(fDisplay.SupportDisplay, "scheme的SupportDisplay必须为true,当前是false", scheme); SourceScheme = scheme; fDisplay = new TempDisplay(fDisplay, scheme, idField, nameField); if (canCache) { canCache = idField == null && nameField == null; } if (canCache) { fScheme = new EasySearchProxyScheme(scheme, fDisplay); } else { fScheme = new NoCacheEasySearchProxyScheme(scheme, fDisplay); } ValueField = fDisplay.Id; NameField = fDisplay.Name; }
private static string CreateWhereSql(TableResolver resolver, IDbCommand command, List <FieldInfoEventArgs> list, bool isOrigin) { StringBuilder whereSql = new StringBuilder(BUFFER_SIZE); int i = 0; TkDbContext context = resolver.Context; foreach (FieldInfoEventArgs item in list) { if ((item.Position & SqlPosition.Where) == SqlPosition.Where) { string fieldName = item.FieldInfo.FieldName; JoinStringItem(whereSql, i++, string.Format(ObjectUtil.SysCulture, "{0} = {1}", context.EscapeName(fieldName), context.GetSqlParamName(fieldName, isOrigin)), " AND "); command.Parameters.Add(CreateDataParameter(context, item.FieldInfo, isOrigin)); } } string sql = whereSql.ToString(); TkDebug.Assert(!string.IsNullOrEmpty(sql), string.Format(ObjectUtil.SysCulture, "表{0}在设置提交SQL的Where部分时,没有找到对应的字段,请确认主键是否设置,或者SetFieldInfo事件是否正确", resolver.TableName), resolver); return("WHERE " + sql); }
private void ValidateEnd(JsonToken endToken) { JsonTokenType currentObject = Pop(); TkDebug.Assert(currentObject == GetTypeForCloseToken(endToken), string.Format(ObjectUtil.SysCulture, "JsonToken {0} 不是 JsonType {1} 的合法闭合标志", endToken, currentObject), this); }
private void JudgeListContainCurrentException(ListNode <T> current) { TkDebug.AssertNotNull(fHead, "该链表为空!", this); //判断当前节点是否为当前链表中 //传送LinkList<T>对象给ListNode<T>构造函数,是为了确定不同的节点对应到各自不同的类节点链表里面 //判断当前节点是否在this链表中 TkDebug.Assert(current.List == this, "您插入的当前链表不匹配!", this); }
public KeyData CreateKeyData() { DataTable table = HostTable; TkDebug.Assert(table.Rows.Count > 0, "当前表中的记录不能为0", this); return(CreateKeyData(table.Rows[0])); }
private void AutoCompleteClose(JsonToken tokenBeingClosed) { // write closing symbol and calculate new state int levelsToComplete = 0; for (int i = 0; i < fTop; i++) { int currentLevel = fTop - i; if (fStack[currentLevel] == GetTypeForCloseToken(tokenBeingClosed)) { levelsToComplete = i + 1; break; } } TkDebug.Assert(levelsToComplete != 0, "No token to close.", this); //if (levelsToComplete == 0) // throw new JsonWriterException(""); for (int i = 0; i < levelsToComplete; i++) { JsonToken token = GetCloseTokenForType(Pop()); if (fCurrentState != State.ObjectStart && fCurrentState != State.ArrayStart) { WriteIndent(); } WriteEnd(token); } JsonTokenType currentLevelType = Peek(); switch (currentLevelType) { case JsonTokenType.Object: fCurrentState = State.Object; break; case JsonTokenType.Array: fCurrentState = State.Array; break; case JsonTokenType.Constructor: fCurrentState = State.Array; break; case JsonTokenType.None: fCurrentState = State.Start; break; default: TkDebug.ThrowToolkitException("非期望的JSON类型: " + currentLevelType, this); break; } }
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); }
internal static void AssertType(object source, OutputData data, params SourceOutputType[] types) { bool found = Array.Exists(types, type => type == data.OutputType); TkDebug.Assert(found, string.Format(ObjectUtil.SysCulture, "当前的PageMaker只支持{0}数据类型,而传入的WebOutputData的数据类型为{1},无法兼容", GetTypeString(types), data.OutputType), source); }
/// <summary> /// Initializes a new instance of the SourceRedirectorAttribute class. /// </summary> public RegRedirectorAttribute(Type objectType) { TkDebug.AssertArgumentNull(objectType, "objectType", null); ObjectType = objectType; TkDebug.Assert(ObjectUtil.IsSubType(typeof(IRedirector), objectType), string.Format(ObjectUtil.SysCulture, "对象{0}必须完成IRedirector接口,现在不是", objectType), null); }
public override OutputData DoAction(IInputData input) { TkDebug.Assert(input.IsPost, "此Source支持Post状态,当前是Get", this); QueryConditionObject obj = input.PostObject.Convert <QueryConditionObject>(); CalcResult(obj); return(OutputData.Create(DataSet)); }
public void ParseExpr(string format) { StringBuilder result = new StringBuilder(); int ptr = 0; int start = ptr; int length = format.Length; int marcoCount = 0; while (ptr < length) { char c = format[ptr++]; if (c == '*') { result.Append(format, start, ptr - start - 1); // check for escaped open bracket //if (format[ptr] == '{') //{ // start = ptr++; // result.Append("{"); // continue; //} // parse specifier int marcoStart = ptr; while (format[ptr++] != '*') { if (ptr >= length) { break; } } TkDebug.Assert(ptr <= length, string.Format(ObjectUtil.SysCulture, "扫描字符串{0}发现,存在只有*而没有与之匹配的*结束的字符串", format), format); string marco = format.Substring(marcoStart, ptr - marcoStart - 1); TkDebug.Assert(!string.IsNullOrEmpty(marco), string.Format(ObjectUtil.SysCulture, "字符串{0}中存在*与*之间没有任何宏名称,空宏是不被允许的", format), format); fParamArray.Add(marco); result.Append("{").Append(marcoCount++).Append("}"); start = ptr; } } if (start < length) { result.Append(format.Substring(start)); } FormatString = result.ToString(); }
public void SetMainResolver(TableResolver resolver) { TkDebug.AssertArgumentNull(resolver, "resolver", this); TkDebug.Assert(MainResolver == null, string.Format(ObjectUtil.SysCulture, "MainResolver已经设置,当前MainResolver的表名是{0}", MainResolver == null ? string.Empty : MainResolver.TableName), this); MainResolver = resolver; }
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 void UpdateTableResolvers(IEnumerable <TkDbContext> contexts, Action <Transaction> applyData, bool sort, IEnumerable <TableResolver> resolvers) { TkDebug.AssertEnumerableArgumentNull(contexts, "contexts", null); TkDebug.AssertArgumentNull(resolvers, "resolvers", null); List <DbConnectionStatus> contextItems = new List <DbConnectionStatus>(contexts.Count()); foreach (TkDbContext context in contexts) { TkDebug.Assert(context.DbConnection is DbConnection, string.Format(ObjectUtil.SysCulture, "名称为{0}的DbContext中的DbConnection不是从System.Data.Common.DbConnection继承的,无法支持事务", context.ContextConfig.Name), null); contextItems.Add(new DbConnectionStatus(context.DbConnection)); } CommittableTransaction transaction = CreateTransaction(); using (transaction) { foreach (DbConnectionStatus item in contextItems) { item.AttachTransaction(transaction); } try { ApplyUpdates(transaction, applyData, sort, resolvers); } catch (DBConcurrencyException ex) { transaction.Rollback(); if (ex.Message.IndexOf("UpdateCommand 影响 0 个记录", StringComparison.CurrentCulture) > 0) { throw new ConcurrencyException(ex); } else { throw; } } catch (Exception) { transaction.Rollback(); throw; } finally { foreach (DbConnectionStatus item in contextItems) { item.DetachTransaction(); } } } }
public TValue this[TKey regName] { get { TkDebug.AssertArgumentNull(regName, "regName", this); TkDebug.Assert(fHashtable.ContainsKey(regName), string.Format( ObjectUtil.SysCulture, "集合中不含注册名为{0}的对象", regName), this); return(fHashtable[regName]); } }
protected BaseSchemeCodeTable(ITableScheme scheme) { TkDebug.AssertArgumentNull(scheme, "scheme", null); TkDebug.AssertArgument(scheme is IDisplayObject, "scheme", "scheme需要支持IDisplayObject接口", scheme); fScheme = scheme; fDisplay = scheme.Convert <IDisplayObject>(); TkDebug.Assert(fDisplay.SupportDisplay, "scheme的SupportDisplay必须为true,当前是false", scheme); }
public InternalTableScheme(string tableName, DataTable table) { DataColumn[] keys = table.PrimaryKey; TkDebug.Assert(keys != null && keys.Length > 0, string.Format(ObjectUtil.SysCulture, "没有从表{0}中获取主键信息,请去数据库确认该表是否设置了主键", tableName), this); string[] keyFieldArray = Array.ConvertAll(keys, column => column.ColumnName); Array.Sort(keyFieldArray); Initialize(tableName, table, keyFieldArray); }
public void IgnoreSection(string sectionName) { TkDebug.AssertArgumentNull(sectionName, nameof(sectionName), this); TkDebug.Assert(PageContext.IsSectionDefined(sectionName), $"Section {sectionName} is not defined", this); if (fIgnoredSections == null) { fIgnoredSections = new HashSet <string>(StringComparer.OrdinalIgnoreCase); } fIgnoredSections.Add(sectionName); }
private string GetFieldDbType(IFieldInfoEx field) { var index = (int)field.DataType; TkDebug.Assert(index >= 0 && index < CONVET_ARR.Length , string.Format(ObjectUtil.SysCulture, "给定枚举值{0}越界了", field.DataType), this); var result = string.Format(ObjectUtil.SysCulture, CONVET_ARR[index] , field.Length, field.Precision); TkDebug.AssertNotNullOrEmpty(result , string.Format(ObjectUtil.SysCulture, "字段:{0}找不到相匹配的数据库的数据类型", field.FieldName), this); return(result); }
public ParamExpressionAttribute(string regName) { TkDebug.AssertArgumentNullOrEmpty(regName, "regName", null); TkDebug.Assert(regName.Length == 1, string.Format(ObjectUtil.SysCulture, "ParamExpression的注册名只能是一个字符,现在的注册名{0}不是", regName), null); TkDebug.Assert(!char.IsLetterOrDigit(regName[0]), string.Format(ObjectUtil.SysCulture, "ParamExpression的注册名要求不是字母或数字,现在的注册名{0}不是", regName), null); RegName = regName; }
internal static DataRow SelectRow(Action action, DataSet dataSet, string tableName) { DataTable table = dataSet.Tables[tableName]; int count = table == null ? 0 : table.Rows.Count; action(); table = dataSet.Tables[tableName]; TkDebug.AssertNotNull(table, string.Format(ObjectUtil.SysCulture, "DataSet中没有表{0},请检查是否填充了数据", tableName), null); TkDebug.Assert(table.Rows.Count > count, string.Format(ObjectUtil.SysCulture, "数据表{0}应该至少选出一条记录,但实际一条都没有。", tableName), null); return(table.Rows[count]); }
internal void InternalExecute(ISqlDataAdapter selector) { TkDebug.AssertArgumentNull(selector, "selector", this); CreateStoredProc(); TkDebug.Assert(fConnection.State == ConnectionState.Closed, string.Format(ObjectUtil.SysCulture, "存储过程{0}在填充模式下,数据库连接必须是关闭的,请检查数据库连接的状态", ProcName), this); selector.DataAdapter.SelectCommand = Command; DbUtil.FillDataSet(this, selector.DataAdapter, selector.DataSet, ProcName); SetOutputValues(); }
public void SelectWithKeys(params object[] values) { TkDebug.AssertEnumerableArgumentNull(values, "values", this); TkDebug.Assert(KeyCount == values.Length, string.Format(ObjectUtil.SysCulture, "参数values的个数和表的主键字段个数不匹配,主键的个数为{0},而values的个数为{1}", KeyCount, values.Length), this); IParamBuilder[] builders = new IParamBuilder[KeyCount]; for (int i = 0; i < KeyCount; ++i) { builders[i] = SqlParamBuilder.CreateEqualSql(Context, fKeyFieldArray[i], values[i]); } Select(ParamBuilder.CreateParamBuilder(builders)); }
public IMetaData CreateObject(params object[] args) { IInputData input = ObjectUtil.ConfirmQueryObject <IInputData>(this, args); ITableSchemeEx scheme; ISingleMetaData masterMeta; switch (input.Style.Style) { case PageStyle.Insert: case PageStyle.Update: case PageStyle.Detail: masterMeta = Master.CreateSingleMetaData(); IEnumerable <ISingleMetaData> oneToOneMeta; if (OneToOneTables == null) { oneToOneMeta = null; } else { oneToOneMeta = (from item in OneToOneTables select item.CreateSingleMetaData()); } var data = new Tk5MultipleMetaData(input, EnumUtil.Convert(masterMeta, oneToOneMeta), OneToManyTables); return(data); case PageStyle.List: masterMeta = Master.CreateSingleMetaData(); scheme = masterMeta.CreateSourceScheme(input); return(new Tk5ListMetaData(scheme, input, masterMeta)); case PageStyle.Custom: if (MetaDataUtil.StartsWith(input.Style, "DetailList")) { int index = input.QueryString["Index"].Value <int>(); TkDebug.Assert(OneToManyTables != null && OneToManyTables.Count > index, string.Format(ObjectUtil.SysCulture, "第{0}项metaData配置不存在", index + 1), this); var config = OneToManyTables[index]; var detailMetaData = config.CreateSingleMetaData(); scheme = detailMetaData.CreateSourceScheme(input); InputDataProxy proxy = new InputDataProxy(input, (PageStyleClass)PageStyle.List); Tk5ListMetaData meta = new Tk5ListMetaData(scheme, proxy, detailMetaData, config.TableOutput?.CreateObject()); return(meta); } break; } return(null); }
protected internal IContent WritePage(IPageData pageData, OutputData outputData) { PageMakerUtil.AssertType(this, outputData, SourceOutputType.XmlReader, SourceOutputType.String, SourceOutputType.DataSet, SourceOutputType.ToolkitObject); string xsltFile = GetRealXsltFile(pageData); // Path.Combine(AppSetting.Current.XmlPath, XsltFile); TkDebug.AssertNotNullOrEmpty(xsltFile, "没有设置XsltFile属性,该值为空", this); TkDebug.Assert(File.Exists(xsltFile), string.Format(ObjectUtil.SysCulture, "系统中并不存在文件名为{0}的文件,请检查路径!", xsltFile), this); XsltArgumentList args = null; if (UseXsltArgs) { args = new XsltArgumentList(); AddXsltParam(args, pageData); } string content = string.Empty; XmlReader reader = null; switch (outputData.OutputType) { case SourceOutputType.XmlReader: reader = outputData.Data.Convert <XmlReader>(); break; case SourceOutputType.String: reader = XmlTransformUtil.GetXmlReader(outputData.Data.Convert <string>()); break; case SourceOutputType.ToolkitObject: XDocument doc = outputData.Data.CreateXDocument(null, ObjectUtil.WriteSettings, QName.ToolkitNoNS); reader = doc.CreateReader(); break; case SourceOutputType.DataSet: reader = new XmlDataSetReader(outputData.Data.Convert <DataSet>()); break; default: TkDebug.ThrowImpossibleCode(this); break; } content = XmlTransformUtil.Transform(reader, xsltFile, args, TransformSetting.All); Encoding encoding = Encoding ?? (pageData.IsPost ? Encoding.UTF8 : null); return(CreateContent(pageData, content, encoding)); }
public static DataRow GetPostRow(IInputData input, string tableName) { TkDebug.AssertArgumentNull(input, "input", null); TkDebug.AssertArgumentNullOrEmpty(tableName, "tableName", null); DataSet postDataSet = input.PostObject.Convert <DataSet>(); DataTable table = postDataSet.Tables[tableName]; TkDebug.AssertNotNull(table, string.Format(ObjectUtil.SysCulture, "PostDataSet中没有表{0}", tableName), null); TkDebug.Assert(table.Rows.Count > 0, string.Format(ObjectUtil.SysCulture, "Post表{0}中的没有数据", tableName), null); return(table.Rows[0]); }