/// <inheritdoc/> public sealed override string ToString() { // Expressions are immutable, so it's always safe to return a cached string representation. return(_expressionStringCache != null ? _expressionStringCache : _expressionStringCache = Simplified.CreateExpressionString()); }
/// <summary> /// 获取文本分词结果 /// </summary> /// <param name="text"></param> /// <param name="result">分词结果</param> internal void Get(Simplified text, ref LeftArray <KeyValue <HashString, QueryResult> > result) { this.result = result; foramtLength = (formatText = text.FormatText).Length - 1; fixed(char *textFixed = formatText) get(textFixed); result = this.result; }
/// <summary> /// 获取文本分词结果 /// </summary> /// <param name="text"></param> /// <param name="result">分词结果</param> internal void Get(string text, ref LeftArray <KeyValue <HashString, QueryResult> > result) { this.result = result; formatText = AutoCSer.Extension.StringExtension.FastAllocateString((foramtLength = text.Length) + 1); fixed(char *textFixed = formatText) { Simplified.FormatNotEmpty(text, textFixed, foramtLength); get(textFixed); } result = this.result; }
/// <summary> /// 获取文本分词结果 /// </summary> /// <param name="text"></param> /// <param name="isAllMatch">是否要求关键字全匹配</param> /// <param name="result">分词结果</param> internal void Get(ref Simplified text, bool isAllMatch, ref LeftArray <KeyValue <HashString, QueryResult> > result) { this.result = result; formatText = text.FormatText; formatLength = text.Size - 1; fixed(char *textFixed = formatText) { if (get(textFixed, isAllMatch)) { result = this.result; } } }
/// <summary> /// 获取文本分词结果 /// </summary> /// <param name="text"></param> /// <param name="isAllMatch">是否要求关键字全匹配</param> /// <param name="result">分词结果</param> internal void Get(string text, bool isAllMatch, ref LeftArray <KeyValue <HashString, QueryResult> > result) { this.result = result; formatLength = text.Length; formatText = AutoCSer.Extension.StringExtension.FastAllocateString(formatLength + 1); fixed(char *textFixed = formatText) { Simplified.FormatNotEmpty(text, textFixed, formatLength); if (get(textFixed, isAllMatch)) { result = this.result; } } }
/// <summary> /// 获取文本分词结果 /// </summary> /// <param name="text"></param> /// <param name="matchType"></param> /// <param name="result">分词结果</param> /// <param name="lessWords"></param> internal void Get(ref Simplified text, MatchType matchType, ref LeftArray <KeyValue <HashString, QueryResult> > result, ref LeftArray <SubString> lessWords) { this.result = result; this.lessWords = lessWords; formatText = text.FormatText; formatLength = text.Size - 1; fixed(char *textFixed = formatText) { this.matchType = matchType; this.lessWords.Length = 0; if (get(textFixed)) { result = this.result; lessWords = this.lessWords; } } }
/// <summary> /// 获取文本分词结果 /// </summary> /// <param name="text"></param> /// <param name="matchType"></param> /// <param name="result">分词结果</param> /// <param name="lessWords"></param> internal void Get(string text, MatchType matchType, ref LeftArray <KeyValue <HashString, QueryResult> > result, ref LeftArray <SubString> lessWords) { this.result = result; this.lessWords = lessWords; formatLength = text.Length; formatText = AutoCSer.Extensions.StringExtension.FastAllocateString(formatLength + 1); fixed(char *textFixed = formatText) { Simplified.FormatNotEmpty(text, textFixed, formatLength); this.matchType = matchType; this.lessWords.Length = 0; if (get(textFixed)) { result = this.result; lessWords = this.lessWords; } } }
static StringTrieGraph() { DefaultCharTypeData = new Pointer { Data = Unmanaged.GetStatic64(1 << 16, true) }; byte *start = DefaultCharTypeData.Byte, end = DefaultCharTypeData.Byte + (1 << 16); for (char code = (char)0; start != end; ++start, ++code) { UnicodeCategory category = CharUnicodeInfo.GetUnicodeCategory(code); switch (category) { case UnicodeCategory.LowercaseLetter: case UnicodeCategory.UppercaseLetter: case UnicodeCategory.TitlecaseLetter: case UnicodeCategory.ModifierLetter: *start = (byte)WordType.Letter; break; case UnicodeCategory.DecimalDigitNumber: case UnicodeCategory.LetterNumber: case UnicodeCategory.OtherNumber: *start = (byte)WordType.Number; break; case UnicodeCategory.OtherLetter: *start = (byte)WordType.OtherLetter; break; default: if (code == '&' || code == '.' || code == '+' || code == '#' || code == '-' || code == '_') { *start = (byte)WordType.Keep; } break; } } Simplified.SetChinese(DefaultCharTypeData.Byte); DefaultCharTypeData.Byte[' '] = 0; DefaultCharTypeData.Byte['0'] |= (byte)WordType.Number; }
/// <summary> /// Add System User as a Member of a SystemUserGroup /// </summary> /// <param name="user"></param> /// <param name="group"></param> public static void AddSystemUserToSystemUserGroup(Simplified.Ring3.SystemUser user, Simplified.Ring3.SystemUserGroup group) { Simplified.Ring3.SystemUserGroupMember systemUserGroupMember = new Simplified.Ring3.SystemUserGroupMember(); systemUserGroupMember.WhatIs = user; systemUserGroupMember.ToWhat = group; //systemUserGroupMember.SetSystemUser(user); //systemUserGroupMember.SetToWhat(group); //group.AddMember(systemUser); }
/// <summary> /// Gets simplified Customers for filters. /// </summary> /// <returns>Returns an IEnumerable of Simplified Customers.</returns> public IEnumerable <Simplified <Customer> > GetSimplifiedCustomers() { return(Simplified <Customer> .FromEnum(Context.Customers.AsEnumerable(), c => c.Name)); }
/// <summary> /// 获取文本分词结果 /// </summary> /// <param name="text"></param> private void getRemoveResult(string text) { removeResult.Clear(); formatLength = text.Length; formatText = AutoCSer.Extension.StringExtension.FastAllocateString(formatLength + 1); fixed(char *textFixed = formatText) { Simplified.FormatNotEmpty(text, textFixed, formatLength); matchs.Length = 0; char *start = textFixed, end = textFixed + formatLength; if (charTypeData != StringTrieGraph.DefaultCharTypeData.Byte) { StaticStringTrieGraph trieGraph = searcher.trieGraph; int count, index, startIndex; char trieGraphHeadChar = trieGraph.AnyHeadChar; byte type, nextType; bool isMatchMap = false; do { if (((type = charTypeData[*start]) & StringTrieGraph.TrieGraphHeadFlag) == 0) { *end = trieGraphHeadChar; do { if ((type & ((byte)WordType.Chinese | (byte)WordType.TrieGraph)) == ((byte)WordType.Chinese | (byte)WordType.TrieGraph)) { removeResult.Add(new SubString((int)(start - textFixed), 1, formatText)); } if (((nextType = charTypeData[*++start]) & StringTrieGraph.TrieGraphHeadFlag) != 0) { if (start == end) { goto TRIEGRAPHEND; } if ((nextType & (byte)WordType.Chinese) != 0 || (type & nextType & ((byte)WordType.OtherLetter | (byte)WordType.Letter | (byte)WordType.Number | (byte)WordType.Keep)) == 0) { goto TRIEGRAPH; } } type = nextType; }while (true); } TRIEGRAPH: *end = ' '; char *segment = start, segmentEnd = (type & StringTrieGraph.TrieGraphEndFlag) == 0 ? start++ : ++start; while (((type = charTypeData[*start]) & (byte)WordType.TrieGraph) != 0) { ++start; if ((type & StringTrieGraph.TrieGraphEndFlag) != 0) { segmentEnd = start; } } if ((int)(start - segment) == 1) { if ((type & (byte)WordType.Chinese) != 0) { removeResult.Add(new SubString((int)(segment - textFixed), 1, formatText)); } } else { if (segment != segmentEnd) { matchs.Length = 0; trieGraph.LeftRightMatchs(segment, segmentEnd, ref matchs); if ((count = matchs.Length) == 0) { segmentEnd = segment; goto CHINESE; } if (!isMatchMap) { checkMatchMap(); isMatchMap = true; } startIndex = (int)(segment - textFixed); foreach (KeyValue <int, int> value in matchs.Array) { removeResult.Add(new SubString(index = value.Key + startIndex, value.Value, formatText)); matchMap.Set(index, value.Value); if (--count == 0) { break; } } index = (int)(segmentEnd - textFixed); do { if (matchMap.Get(startIndex) == 0 && (charTypeData[textFixed[startIndex]] & (byte)WordType.Chinese) != 0) { removeResult.Add(new SubString(startIndex, 1, formatText)); } }while (++startIndex != index); } CHINESE: while (segmentEnd != start) { if ((charTypeData[*segmentEnd] & (byte)WordType.Chinese) != 0) { removeResult.Add(new SubString((int)(segmentEnd - textFixed), 1, formatText)); } ++segmentEnd; } } }while (start != end); TRIEGRAPHEND: start = textFixed; } do { byte type = charTypeData[*start]; if ((type &= ((byte)WordType.Chinese | (byte)WordType.OtherLetter | (byte)WordType.Letter | (byte)WordType.Number | (byte)WordType.Keep)) == 0) { *end = '0'; do { type = charTypeData[*++start]; if ((type &= ((byte)WordType.Chinese | (byte)WordType.OtherLetter | (byte)WordType.Letter | (byte)WordType.Number | (byte)WordType.Keep)) != 0) { if (start == end) { return; } goto OTHER; } }while (true); } OTHER: *end = ' '; if ((type & (byte)WordType.Chinese) != 0) { do { if ((type & (byte)WordType.TrieGraph) == 0) { removeResult.Add(new SubString((int)(start - textFixed), 1, formatText)); } }while (((type = charTypeData[*++start]) & (byte)WordType.Chinese) != 0); } else { char *segment = start; if ((type & (byte)WordType.OtherLetter) == 0) { char *word = start; for (byte newType = charTypeData[*++start]; (newType &= ((byte)WordType.Letter | (byte)WordType.Number | (byte)WordType.Keep)) != 0; newType = charTypeData[*++start]) { if (type != newType) { if (type != (byte)WordType.Keep) { removeResult.Add(new SubString((int)(word - textFixed), (int)(start - word), formatText)); } type = newType; word = start; } } } else { while ((charTypeData[*++start] & (byte)WordType.OtherLetter) != 0) { ; } } removeResult.Add(new SubString((int)(segment - textFixed), (int)(start - segment), formatText)); } }while (start != end); } }
/// <summary> /// Set password /// </summary> /// <param name="user"></param> /// <param name="password"></param> public static void SetPassword(Simplified.Ring3.SystemUser user, string password) { string hashedPassword; Helper.GeneratePasswordHash(user.Username.ToLower(), password, out hashedPassword); user.Password = hashedPassword; }
/// <summary> /// 获取文本分词结果 /// </summary> /// <param name="text"></param> protected void getResult(string text) { result.Clear(); formatText = AutoCSer.Extension.StringExtension.FastAllocateString((foramtLength = text.Length) + 1); fixed(char *textFixed = formatText) { Simplified.FormatNotEmpty(text, textFixed, foramtLength); words.Length = matchs.Length = 0; char *start = textFixed, end = textFixed + foramtLength; byte type, nextType, wordType; bool isMatchMap = false; if (charTypeData != StringTrieGraph.DefaultCharTypeData.Byte) { StaticStringTrieGraph trieGraph = searcher.trieGraph; int count, index, startIndex; char trieGraphHeadChar = trieGraph.AnyHeadChar; do { if (((type = charTypeData[*start]) & StringTrieGraph.TrieGraphHeadFlag) == 0) { *end = trieGraphHeadChar; do { if ((type & ((byte)WordType.Chinese | (byte)WordType.TrieGraph)) == ((byte)WordType.Chinese | (byte)WordType.TrieGraph)) { addWord((int)(start - textFixed), 1, WordType.Chinese); } if (((nextType = charTypeData[*++start]) & StringTrieGraph.TrieGraphHeadFlag) != 0) { if (start == end) { goto TRIEGRAPHEND; } if ((nextType & (byte)WordType.Chinese) != 0 || (type & nextType & ((byte)WordType.OtherLetter | (byte)WordType.Letter | (byte)WordType.Number | (byte)WordType.Keep)) == 0) { goto TRIEGRAPH; } } type = nextType; }while (true); } TRIEGRAPH: *end = ' '; char *segment = start, segmentEnd = (type & StringTrieGraph.TrieGraphEndFlag) == 0 ? start++ : ++start; while (((type = charTypeData[*start]) & (byte)WordType.TrieGraph) != 0) { ++start; if ((type & StringTrieGraph.TrieGraphEndFlag) != 0) { segmentEnd = start; } } if ((int)(start - segment) == 1) { if ((type & (byte)WordType.Chinese) != 0) { addWord((int)(segment - textFixed), 1, (type & (byte)WordType.TrieGraph) != 0 ? WordType.TrieGraph : WordType.Chinese); } } else { if (segment != segmentEnd) { matchs.Length = 0; trieGraph.LeftRightMatchs(segment, segmentEnd, ref matchs); if ((count = matchs.Length) == 0) { segmentEnd = segment; goto CHINESE; } if (!isMatchMap) { checkMatchMap(); isMatchMap = true; } startIndex = (int)(segment - textFixed); foreach (KeyValue <int, int> value in matchs.Array) { addWord(index = value.Key + startIndex, value.Value, WordType.TrieGraph); matchMap.Set(index, value.Value); if (--count == 0) { break; } } index = (int)(segmentEnd - textFixed); do { if (matchMap.Get(startIndex) == 0 && (charTypeData[textFixed[startIndex]] & (byte)WordType.Chinese) != 0) { addWord(startIndex, 1, WordType.Chinese); } }while (++startIndex != index); } CHINESE: while (segmentEnd != start) { if ((charTypeData[*segmentEnd] & (byte)WordType.Chinese) != 0) { addWord((int)(segmentEnd - textFixed), 1, WordType.Chinese); } ++segmentEnd; } } }while (start != end); TRIEGRAPHEND: start = textFixed; } do { type = charTypeData[*start]; if ((type &= ((byte)WordType.Chinese | (byte)WordType.OtherLetter | (byte)WordType.Letter | (byte)WordType.Number | (byte)WordType.Keep)) == 0) { *end = '0'; do { type = charTypeData[*++start]; if ((type &= ((byte)WordType.Chinese | (byte)WordType.OtherLetter | (byte)WordType.Letter | (byte)WordType.Number | (byte)WordType.Keep)) != 0) { if (start == end) { goto END; } goto OTHER; } }while (true); } OTHER: *end = ' '; if ((type & (byte)WordType.Chinese) != 0) { do { if ((type & (byte)WordType.TrieGraph) == 0) { addWord((int)(start - textFixed), 1, WordType.Chinese); } }while (((type = charTypeData[*++start]) & (byte)WordType.Chinese) != 0); } else { char *segment = start; if ((type & (byte)WordType.OtherLetter) == 0) { char *word = start; wordType = type; for (nextType = charTypeData[*++start]; (nextType &= ((byte)WordType.Letter | (byte)WordType.Number | (byte)WordType.Keep)) != 0; nextType = charTypeData[*++start]) { if (type != nextType) { if (type != (byte)WordType.Keep) { addWord((int)(word - textFixed), (int)(start - word), (WordType)type); } wordType |= nextType; type = nextType; word = start; } } if (word != segment && type != (byte)WordType.Keep) { addWord((int)(word - textFixed), (int)(start - word), (WordType)type); } addWord((int)(segment - textFixed), (int)(start - segment), (WordType)wordType); } else { while ((charTypeData[*++start] & (byte)WordType.OtherLetter) != 0) { ; } addWord((int)(segment - textFixed), (int)(start - segment), WordType.OtherLetter); } } }while (start != end); END: if (words.Length != 0) { int count = words.Length, textLength = text.Length; if ((searcher.flags & SearchFlags.ResultIndexs) == 0) { foreach (KeyValue <SubString, WordType> word in words.Array) { result[word.Key] = new ResultIndexLeftArray { WordType = word.Value, TextLength = textLength }; if (--count == 0) { break; } } } else { ResultIndexLeftArray indexs; foreach (KeyValue <SubString, WordType> word in words.Array) { HashString wordKey = word.Key; if (result.TryGetValue(wordKey, out indexs)) { indexs.Indexs.Add(word.Key.Start); result[wordKey] = indexs; } else { indexs.Set(textLength, word.Value); if (indexArrays.Length != 0) { indexs.Indexs.Set(indexArrays.UnsafePopOnly(), 0); } indexs.Indexs.Add(word.Key.Start); result.Add(wordKey, indexs); } if (--count == 0) { break; } } foreach (ResultIndexLeftArray indexArray in result.Values) { indexArray.Indexs.sort(); } } } } }
/// <summary> /// Remove System User as a Member of a SystemUserGroup /// </summary> /// <param name="user"></param> /// <param name="group"></param> public static void RemoveSystemUserFromSystemUserGroup(Simplified.Ring3.SystemUser user, Simplified.Ring3.SystemUserGroup group) { var removeGroup = Db.SQL<Simplified.Ring3.SystemUserGroupMember>("SELECT o FROM Simplified.Ring3.SystemUserGroupMember o WHERE o.WhatIs=? AND o.ToWhat=?", user, group).First; if (removeGroup != null) { removeGroup.Delete(); } //group.RemoveMember(user); }
/// <summary> /// Delete System User Group and it's relationships /// </summary> /// <param name="group"></param> public static void DeleteSystemUserGroup(Simplified.Ring3.SystemUserGroup group) { // Remove System user member's Db.SlowSQL("DELETE FROM Simplified.Ring3.SystemUserGroupMember WHERE SystemUserGroup=?", group); group.Delete(); }
/// <summary> /// Delete System user /// </summary> /// <param name="user"></param> public static void DeleteSystemUser(Simplified.Ring3.SystemUser user) { if (user == null) { throw new ArgumentNullException("user"); } // Remove Email adresses associated to the system user // Db.SlowSQL("DELETE FROM Simplified.Ring3.EmailAddress WHERE ToWhat=?", user); // Remove ResetPassword associated to the system user Sombody Db.SlowSQL("DELETE FROM Simplified.Ring6.ResetPassword WHERE User=?", user); // TODO: Should we also delete the Somebody (Person/Company)? // Remove system user group member (If system user is member of a system user group) Db.SlowSQL("DELETE FROM Simplified.Ring3.SystemUserGroupMember WHERE SystemUser=?", user); user.Delete(); }
/// <summary> /// Get Simplified User for the filters /// </summary> /// <returns></returns> public IEnumerable <Simplified <User> > GetSimplifiedUsers() { return(Simplified <User> .FromEnum(Context.Users.AsEnumerable(), u => u.FirstName + " " + u.LastName)); }
/// <inheritdoc/> protected override string CreateExpressionString() => Simplified.ToString();