/// <summary> /// 格式化数据类型 /// </summary> /// <param name="typeString">数据类型字符串</param> /// <param name="size">列长</param> /// <returns>数据类型</returns> public unsafe static SqlDbType FormatDbType(string typeString, out int size) { fixed(char *typeFixed = typeString) { char * end = typeFixed + typeString.Length, typeEnd = *(end - 1) == ')' ? unsafer.String.Find(typeFixed, end, '(') : end; sqlTypeName typeName = new sqlTypeName { TypeName = typeString, Length = (int)(typeEnd - typeFixed) }; keyValue <SqlDbType, int> value = sqlTypes.Get(typeName, new keyValue <SqlDbType, int>((SqlDbType)(-1), int.MinValue)); if (value.Value == int.MinValue) { size = 0; if (typeEnd != end) { for (--end; ++typeEnd != end; size += *typeEnd - '0') { size *= 10; } } } else { size = value.Value; } return(value.Key); } }
/// <summary> /// 移除TCP调用服务端 /// </summary> /// <param name="host">TCP调用服务端端口信息</param> /// <returns>是否移除成功</returns> private bool removeServer(ref host host) { if (isDisposed == 0) { Monitor.Enter(clientLock); for (int index = 0; index != currentCount; ++index) { keyValue <clientType, int> removeClient = this.clients[index].Remove(ref host); if (removeClient.Key != null) { callCount -= removeClient.Value; try { freeIndexs.Add(index); } finally { Monitor.Exit(clientLock); pub.Dispose(ref removeClient.Key); } log.Default.Add("移除TCP调用服务端 " + host.Host + ":" + host.Port.toString(), new System.Diagnostics.StackFrame(), false); return(true); } } Monitor.Exit(clientLock); } return(false); }
/// <summary> /// 线程池任务 /// </summary> internal void Run() { Monitor.Enter(taskLock); try { while (taskHeap.Count != 0) { keyValue <long, taskInfo> task = taskHeap.UnsafeTop(); if (task.Key <= date.Now.Ticks) { taskHeap.RemoveTop(); task.Value.Run(); } else { if (task.Key != nearTime) { nearTime = task.Key; timer.Interval = Math.Min(Math.Max(new TimeSpan(task.Key - date.Now.Ticks).TotalMilliseconds + 1, 1), int.MaxValue); timer.Start(); } return; } } nearTime = long.MaxValue; } finally { Monitor.Exit(taskLock); } }
/// <summary> /// 添加字段 /// </summary> /// <param name="field">字段信息</param> public void Push(FieldInfo field) { keyValue <FieldInfo, MethodInfo> fieldInvoke = getEqualsFieldInvoke(field.FieldType); Label next = generator.DefineLabel(); generator.Emit(OpCodes.Ldsfld, fieldInvoke.Key); if (isValueType) { generator.Emit(OpCodes.Ldarga_S, 0); } else { generator.Emit(OpCodes.Ldarg_0); } generator.Emit(OpCodes.Ldfld, field); if (isValueType) { generator.Emit(OpCodes.Ldarga_S, 1); } else { generator.Emit(OpCodes.Ldarg_1); } generator.Emit(OpCodes.Ldfld, field); generator.Emit(OpCodes.Callvirt, fieldInvoke.Value); generator.Emit(OpCodes.Brtrue_S, next); generator.Emit(OpCodes.Ldc_I4_0); generator.Emit(OpCodes.Ret); generator.MarkLabel(next); }
static file() { keyValue <encodingBom, bom>[] bomList = new keyValue <encodingBom, bom> [4]; int count = 0; bomList[count++] = new keyValue <encodingBom, bom>(Encoding.Unicode, new bom { Bom = 0xfeffU, Length = 2 }); bomList[count++] = new keyValue <encodingBom, bom>(Encoding.BigEndianUnicode, new bom { Bom = 0xfffeU, Length = 2 }); bomList[count++] = new keyValue <encodingBom, bom>(Encoding.UTF8, new bom { Bom = 0xbfbbefU, Length = 3 }); bomList[count++] = new keyValue <encodingBom, bom>(Encoding.UTF32, new bom { Bom = 0xfeffU, Length = 4 }); boms = new uniqueDictionary <encodingBom, bom>(bomList, 4); DefaultBytesPerCluster = bytesPerCluster(fastCSharp.pub.ApplicationPath); if (DefaultBytesPerCluster == 0) { DefaultBytesPerCluster = 1 << 12; } }
/// <summary> /// 用户注销 /// </summary> /// <param name="user">用户名</param> public void Logout(string user) { if (user.length() != 0) { RemoveSession(); int version = 0; userInfo userInfo; keyValue <list <Action <poll.message> >, string[]> onPolls = default(keyValue <list <Action <poll.message> >, string[]>); Action <poll.message> onPoll = null; hashString userHash = user; Monitor.Enter(userLock); try { if (userInfos.TryGetValue(userHash, out userInfo)) { onPoll = userInfo.OnPoll; userInfos.Remove(userHash); version = ++userVersion; onPolls = getOnPolls(userInfo, false); userInfo.OnPoll = null; } } finally { Monitor.Exit(userLock); } if (onPolls.Key != null) { threadPool.TinyPool.Start(onUserChange, new keyValue <list <Action <poll.message> >, poll.message>(onPolls.Key, new poll.message { UserVersion = version, Users = onPolls.Value })); } remove(onPoll); } }
static type() { #region 初始化 类型名称集合 keyValue <hashCode <Type>, string>[] types = new keyValue <hashCode <Type>, string>[] { new keyValue <hashCode <Type>, string>(typeof(bool), "bool"), new keyValue <hashCode <Type>, string>(typeof(byte), "byte"), new keyValue <hashCode <Type>, string>(typeof(sbyte), "sbyte"), new keyValue <hashCode <Type>, string>(typeof(short), "short"), new keyValue <hashCode <Type>, string>(typeof(ushort), "ushort"), new keyValue <hashCode <Type>, string>(typeof(int), "int"), new keyValue <hashCode <Type>, string>(typeof(uint), "uint"), new keyValue <hashCode <Type>, string>(typeof(long), "long"), new keyValue <hashCode <Type>, string>(typeof(ulong), "ulong"), new keyValue <hashCode <Type>, string>(typeof(float), "float"), new keyValue <hashCode <Type>, string>(typeof(double), "double"), new keyValue <hashCode <Type>, string>(typeof(decimal), "decimal"), new keyValue <hashCode <Type>, string>(typeof(char), "char"), new keyValue <hashCode <Type>, string>(typeof(string), "string"), new keyValue <hashCode <Type>, string>(typeof(object), "object"), new keyValue <hashCode <Type>, string>(typeof(void), "void") }; typeNames = new staticDictionary <hashCode <Type>, string>(types); #endregion }
/// <summary> /// 查询条件 /// </summary> /// <param name="sqlTable">数据库表格操作工具</param> /// <param name="sqlStream">SQL表达式流</param> /// <param name="expression">查询条件表达式</param> /// <param name="isCreatedIndex">是否已经创建查询索引</param> /// <returns></returns> internal static unsafe bool WriteWhere(fastCSharp.emit.sqlTable.sqlToolBase sqlTable, charStream sqlStream, Expression <Func <valueType, bool> > expression, ref bool isCreatedIndex) { if (expression == null) { return(true); } sqlStream.PrepLength(6); sqlStream.UnsafeAddLength(6); int length = sqlStream.Length; bool logicConstantWhere = false; keyValue <string, string> name = sqlTable.Client.GetWhere(expression, sqlStream, ref logicConstantWhere); if (length == sqlStream.Length) { sqlStream.UnsafeFreeLength(6); return(logicConstantWhere); } if (name.Key != null) { byte *where = (byte *)(sqlStream.Char + length); *(uint *)(where - sizeof(uint)) = 'e' + (' ' << 16); *(uint *)(where - sizeof(uint) * 2) = 'e' + ('r' << 16); *(uint *)(where - sizeof(uint) * 3) = 'w' + ('h' << 16); isCreatedIndex = true; sqlTable.CreateIndex(name.Key, name.Value); } return(true); }
public async Task <IHttpActionResult> PostNewProperty(string id, keyValue info) { var g = new GremlinHelper(); string qry = $"g.V('{id}').property('{info.key.Replace("'", "''")}','{info.value.Replace("'", "''")}')"; await g.getResultAsync(qry); return(Ok()); }
/// <summary> /// Set, the latest one one the top. /// </summary> /// <param name="key"></param> /// <param name="value"></param> public void Set(int key, int value) { Console.WriteLine("set(" + key + " " + value + ")"); ListNode p = header.next; // once key is hit, move key up to top while (p != tail) { if (p.val.key == key) { p.val.value = value; p.prev.next = p.next; p.next.prev = p.prev; ListNode p1 = header.next; header.next = p; p.prev = header; p.next = p1; p1.prev = p; return; } p = p.next; } current = null; // delete last item when counter is same as capacity if (counter >= capacity) { ListNode p2 = tail.prev.prev; p2.next = tail; tail.prev = p2; counter--; } keyValue kv = new keyValue(key, value); ListNode listNode = new ListNode(kv); current = header; ListNode p3 = header.next; current.next = listNode; listNode.prev = current; p3.prev = listNode; listNode.next = p3; counter++; }
/// <summary> /// 命令序号记忆数据 /// </summary> private static keyValue<hashString, int>[] _identityCommandNames_() { keyValue<hashString, int>[] names = new keyValue<hashString, int>[4]; names[0].Set(@"(string)verify", 0); names[1].Set(@"(fastCSharp.diagnostics.processCopyServer.copyer)guard", 1); names[2].Set(@"(fastCSharp.diagnostics.processCopyServer.copyer)copyStart", 2); names[3].Set(@"(fastCSharp.diagnostics.processCopyServer.copyer)remove", 3); return names; }
/// <summary> /// 加载日志删除对象 /// </summary> /// <param name="key">关键字</param> /// <returns>日志字节长度</returns> protected override int loadDelete(int key) { if (array != null && (uint)key < (uint)array.Length) { keyValue <int, int> logSize = array[key].Clear(); count -= logSize.Key; return(logSize.Value); } return(0); }
/// <summary> /// 添加数据 /// </summary> /// <param name="value">数据对象</param> public void onInserted(valueType value) { keyValue <keyType, list <valueType> > list; keyType key = getKey(value); if (!groups.TryGetValue(key, out list)) { groups.Add(key, list = new keyValue <keyType, list <valueType> >(key, new list <valueType>())); } list.Value.Add(value); }
/// <summary> /// 添加数据 /// </summary> /// <param name="value">数据对象</param> /// <param name="cache">缓存对象</param> public void onInserted(valueType value, dictionaryList <valueType, memberType, keyType> cache) { keyValue <keyType, list <valueType> > list; keyType key = getKey(value); if (!groups.TryGetValue(key, out list)) { groups.Add(key, list = new keyValue <keyType, list <valueType> >(key, new list <valueType>())); ++cache.keyVersion; } list.Value.Add(value); }
/// <summary> /// 命令序号记忆数据 /// </summary> private static keyValue<hashString, int>[] _identityCommandNames_() { keyValue<hashString, int>[] names = new keyValue<hashString, int>[7]; names[0].Set(@"(string)verify", 0); names[1].Set(@"(fastCSharp.net.tcp.host)setForward", 1); names[2].Set(@"(fastCSharp.net.tcp.http.domain[])stop", 2); names[3].Set(@"(fastCSharp.net.tcp.http.domain)stop", 3); names[4].Set(@"(string,string,fastCSharp.net.tcp.http.domain[],bool)start", 4); names[5].Set(@"(string,string,fastCSharp.net.tcp.http.domain,bool)start", 5); names[6].Set(@"()removeForward", 6); return names; }
/// <summary> /// 安装下一个类型 /// </summary> protected override void nextCreate() { keyValue <methodInfo, fastCSharp.code.cSharp.webSocket> loadMethod = fastCSharp.code.cSharp.webSocket.GetLoadMethod(type.Type); LoadMethod = loadMethod.Key; LoadAttribute = loadMethod.Value; sockets.Add(new socketType { type = type, Attribute = Attribute, DefaultNamespace = AutoParameter.DefaultNamespace + ".", Index = sockets.Count, IgnoreCase = AutoParameter.WebConfig.IgnoreCase }); IsServer = false; create(true); }
public void Add(K key, V value) { int position = GetArrayPosition(key); LinkedList <keyValue <K, V> > linkedList = GetLinkedList(position); keyValue <K, V> item = new keyValue <K, V>() { Key = key, Value = value }; linkedList.AddLast(item); }
/// <summary> /// Reads the ini file line by line and finds sections "[section name]" and the values of that section "key=value". /// </summary> private void storeINIdata() { string[] fileLines = File.ReadAllLines(iniPath, Encoding.Default); data.allSections = new List <section>(); for (int i = 0; i < fileLines.Length; i++) { string sectionSearch = fileLines[i]; if (sectionSearch.StartsWith("[")) { section newSection = new section(); string noBrackets = sectionSearch.Replace("[", ""); noBrackets = noBrackets.Replace("]", ""); newSection.secName = noBrackets; newSection.kvPairs = new List <keyValue>(); //Get Key=Value lines for (int j = i + 1; j < fileLines.Length; j++) { string getLine = fileLines[j]; if (!getLine.StartsWith("[") && !getLine.StartsWith("\\r\\n")) { string[] splitPairs = getLine.Split('='); //length is 1 or 2 keyValue kv = new keyValue(); kv.key = splitPairs[0]; if (splitPairs.Length == 2) { kv.value = splitPairs[1]; } else { kv.value = ""; } newSection.kvPairs.Add(kv); } else { break; } } data.allSections.Add(newSection); } else { continue; } } }
/// <summary> /// 排序字符串 /// </summary> /// <param name="sqlTable">数据库表格操作工具</param> /// <param name="sqlStream">SQL表达式流</param> internal void WriteOrder(fastCSharp.emit.sqlTable.sqlToolBase sqlTable, charStream sqlStream) { if (Orders != null) { int isNext = 0; sqlStream.SimpleWriteNotNull(" order by "); foreach (keyValue <LambdaExpression, bool> order in Orders) { if (isNext == 0) { isNext = 1; } else { sqlStream.Write(','); } keyValue <string, string> name = sqlTable.Client.GetSql(order.Key, sqlStream); if (order.Value) { sqlStream.SimpleWriteNotNull(" desc"); } if (!isCreatedIndex && name.Key != null) { isCreatedIndex = true; sqlTable.CreateIndex(name.Key, name.Value); } } } else if (SqlFieldOrders != null) { int isNext = 0; sqlStream.SimpleWriteNotNull(" order by "); foreach (keyValue <sqlModel.fieldInfo, bool> order in SqlFieldOrders) { if (isNext == 0) { isNext = 1; } else { sqlStream.Write(','); } sqlStream.SimpleWriteNotNull(order.Key.SqlFieldName); if (order.Value) { sqlStream.SimpleWriteNotNull(" desc"); } } } }
///// <summary> ///// 更新数据 ///// </summary> ///// <param name="value">更新后的数据</param> ///// <param name="oldValue">更新前的数据</param> ///// <param name="memberMap">更新成员位图</param> //private void onUpdated(valueType cacheValue, valueType value, valueType oldValue, fastCSharp.code.memberMap<modelType> memberMap) //{ // targetType memberCache = getValue(cacheValue); // keyValue<valueType, int> cache = GetMember(memberCache); // if (cache.Key != null) update(cache.Key, value, memberMap); // if (OnUpdated != null) OnUpdated(cache.Key, value, oldValue); //} /// <summary> /// 更新数据 /// </summary> /// <param name="value">更新后的数据</param> /// <param name="oldValue">更新前的数据</param> /// <param name="memberMap">更新成员位图</param> private void onUpdated(valueType value, valueType oldValue, fastCSharp.code.memberMap <modelType> memberMap) { targetType memberCache = GetByKey(GetKey(value)); keyValue <valueType, int> cache = GetMember(memberCache); if (cache.Key != null) { update(cache.Key, value, oldValue, memberMap); } if (OnUpdated != null) { OnUpdated(cache.Key, value, oldValue, memberMap); } }
/// <summary> /// 删除数据 /// </summary> /// <param name="value">被删除的数据</param> private void onDeleted(valueType value) { targetType cache = GetValue(value); keyValue <valueType, int> cacheValue = GetMember(cache); if (cacheValue.Key != null) { if (OnDeleted != null) { OnDeleted(value); } setMember(cache, new keyValue <valueType, int>(null, cacheValue.Value)); --Count; } }
/// <summary> /// 用户登录 /// </summary> /// <param name="user">用户名</param> /// <param name="version">用户版本</param> /// <returns>用户集合</returns> public string[] Login(string user, ref int version) { if (user.length() != 0) { keyValue <list <Action <poll.message> >, string[]> onPolls = default(keyValue <list <Action <poll.message> >, string[]>); userInfo userInfo = new userInfo(), removeUserInfo = null; Action <poll.message> onPoll = null; hashString userHash = user; bool isLogin = false; Monitor.Enter(userLock); try { if (userInfos.TryGetValue(userHash, out removeUserInfo)) { if (removeUserInfo.LastTime.AddMinutes(2) <= date.NowSecond) { onPoll = removeUserInfo.OnPoll; removeUserInfo.OnPoll = null; isLogin = true; version = ++userVersion; userInfos[userHash] = userInfo; onPolls = getOnPolls(userInfo, true); } } else { isLogin = true; version = ++userVersion; userInfos.Add(userHash, userInfo); onPolls = getOnPolls(userInfo, true); } } finally { Monitor.Exit(userLock); } if (onPolls.Key != null) { threadPool.TinyPool.Start(onUserChange, new keyValue <list <Action <poll.message> >, poll.message>(onPolls.Key, new poll.message { UserVersion = version, Users = onPolls.Value })); } remove(onPoll); if (isLogin) { return(onPolls.Value ?? nullValue <string> .Array); } } return(null); }
/// <summary> /// TCP调用客户端调用结束 /// </summary> /// <param name="client">TCP调用服务器信息</param> /// <param name="returnType">是否回调成功</param> protected void _end_(ref clientIdentity client, fastCSharp.net.returnValue.type returnType) { if (isDisposed == 0) { if (returnType == fastCSharp.net.returnValue.type.Success) { Monitor.Enter(clientLock); callCount -= clients[client.Index].End(client.Identity); Monitor.Exit(clientLock); } else { Monitor.Enter(clientLock); keyValue <clientType, keyValue <host, int> > errorClient = clients[client.Index].Error(client.Identity); if (errorClient.Key == null) { Monitor.Exit(clientLock); } else { callCount -= errorClient.Value.Value; try { freeIndexs.Add(client.Index); } finally { Monitor.Exit(clientLock); pub.Dispose(ref errorClient.Key); host host = errorClient.Value.Key; bool isCreate = newServer(ref host); if (isCreate) { tryCheck(); log.Default.Add("恢复TCP调用服务端[调用错误] " + host.Host + ":" + host.Port.toString(), new System.Diagnostics.StackFrame(), false); } else { log.Default.Add("移除TCP调用服务端[调用错误] " + host.Host + ":" + host.Port.toString(), new System.Diagnostics.StackFrame(), false); } } } } } client.Identity = int.MinValue; client.Client = null; }
/// <summary> /// 基类调用 /// </summary> public void Base() { if (!isValueType && (type = type.BaseType) != typeof(object)) { keyValue <FieldInfo, MethodInfo> fieldInvoke = getEqualsFieldInvoke(type); generator.Emit(OpCodes.Ldsfld, fieldInvoke.Key); generator.Emit(OpCodes.Ldarg_0); generator.Emit(OpCodes.Ldarg_1); generator.Emit(OpCodes.Callvirt, fieldInvoke.Value); } else { generator.Emit(OpCodes.Ldc_I4_1); } generator.Emit(OpCodes.Ret); }
public void addAbility() { int index = ab.value; int m = fu.value; string key = ""; string value = ""; switch (index) { case 0: key = "amenity"; value = "restaurant"; break; case 1: key = "emergency"; value = "fire_hydrant"; break; case 2: key = "natural"; value = "tree"; break; case 3: key = "bicycle_parking"; value = "stands"; break; } keyValue kv = new keyValue(key, value); if (m == 0) { kv.isMax = true; } else { kv.isMax = false; } zadania.Add(kv); string oooo = kv.isMax ? "MAX" : "MIN"; wyswietlaczZadan.text += key + " " + value + " " + oooo + "\n"; }
/// <summary> /// 删除对象 /// </summary> /// <param name="key">关键字</param> /// <returns>被删除对象+日志字节长度,失败返回null</returns> protected override keyValue <valueType, int> delete(int key) { keyValue <valueType, int> value = default(keyValue <valueType, int>); if ((uint)key < (uint)array.Length) { Monitor.Enter(cacheLock); try { if (array != null && (value = array[key].Remove()).Key != null) { --count; } } finally { Monitor.Exit(cacheLock); } } return(value); }
///// <summary> ///// 获取缓存数据 ///// </summary> ///// <param name="value">查询数据</param> ///// <returns>缓存数据</returns> //[MethodImpl((MethodImplOptions)fastCSharp.pub.MethodImplOptionsAggressiveInlining)] //internal valueType Get(valueType value) //{ // return Get(GetKey(value)); //} /// <summary> /// 添加缓存数据 /// </summary> /// <param name="value">缓存数据</param> /// <returns>缓存数据</returns> internal valueType Add(valueType value) { targetType cache = GetByKey(GetKey(value)); keyValue <valueType, int> valueCount = GetMember(cache); if (valueCount.Key != null) { ++valueCount.Value; setMember(cache, valueCount); return(valueCount.Key); } valueType copyValue = fastCSharp.emit.constructor <valueType> .New(); fastCSharp.emit.memberCopyer <modelType> .Copy(copyValue, value, memberMap); setMember(cache, new keyValue <valueType, int>(copyValue, 0)); ++Count; return(copyValue); }
public void addAbility(string value, int m) { keyValue kv = new keyValue("amenity", value); if (m == 0) { kv.isMax = true; } else { kv.isMax = false; } zadania.Add(kv); string oooo = kv.isMax ? "MAX" : "MIN"; heatCache.Clear(); minvalue = float.PositiveInfinity; maxvalue = float.NegativeInfinity; //wyswietlaczZadan.text += key + " " + value + " " + oooo + "\n"; //jakos to zastapic }
public void Remove(K key) { int position = GetArrayPosition(key); LinkedList <keyValue <K, V> > linkedList = GetLinkedList(position); bool itemFound = false; keyValue <K, V> foundItem = default(keyValue <K, V>); foreach (keyValue <K, V> item in linkedList) { if (item.Key.Equals(key)) { itemFound = true; foundItem = item; } } //if item is found, it is removed if (itemFound) { linkedList.Remove(foundItem); } }
/// <summary> /// 查询条件 /// </summary> /// <param name="sqlTable">数据库表格操作工具</param> /// <param name="sqlStream">SQL表达式流</param> /// <returns></returns> internal unsafe bool WriteWhereOnly(fastCSharp.emit.sqlTable.sqlToolBase sqlTable, charStream sqlStream) { if (Where == null) { return(true); } int length = sqlStream.Length; bool logicConstantWhere = false; keyValue <string, string> name = sqlTable.Client.GetWhere(Where, sqlStream, ref logicConstantWhere); if (length == sqlStream.Length) { return(logicConstantWhere); } if (name.Key != null) { isCreatedIndex = true; sqlTable.CreateIndex(name.Key, name.Value); } return(true); }
/// <summary> /// 删除缓存数据 /// </summary> /// <param name="value">缓存数据</param> internal void Remove(targetType cache) { keyValue <valueType, int> valueCount = GetMember(cache); if (valueCount.Key != null) { if (valueCount.Value == 0) { setMember(cache, new keyValue <valueType, int>()); --Count; } else { --valueCount.Value; setMember(cache, valueCount); } } else { log.Error.Add(typeof(valueType).FullName + " 缓存同步错误", null, true); } }
/// <summary> /// 获取泛型类型函数信息 /// </summary> /// <param name="remoteType">调用代理类型</param> /// <param name="methodName">调用函数名称</param> /// <returns>泛型类型函数信息</returns> public static MethodInfo getGenericTypeMethod(fastCSharp.setup.remoteType remoteType, string methodName) { Type type = remoteType.Type; if (type.Name == genericTypeServerName && type.DeclaringType.IsGenericType) { tcpCall tcpCall = type.customAttribute <tcpCall>(); if (tcpCall != null && tcpCall.IsGenericTypeServerMethod && tcpCall.IsIgnore) { tcpCall = type.DeclaringType.customAttribute <tcpCall>(false, cSharp.Default.IsInheritAttribute); if (tcpCall != null && tcpCall.IsSetup) { keyValue <Type, staticDictionary <string, MethodInfo> > methods; int version = genericTypeMethodVersion; hashCode <Type> hashType = type; if (!genericTypeMethods.TryGetValue(hashType, out methods) || methods.Key != type) { while (Interlocked.CompareExchange(ref genericTypeMethodLock, 1, 0) != 0) { Thread.Sleep(1); } try { if (version == genericTypeMethodVersion || !genericTypeMethods.TryGetValue(hashType, out methods)) { methods = new keyValue <Type, staticDictionary <string, MethodInfo> >(type, new staticDictionary <string, MethodInfo>(type.GetMethods(BindingFlags.Static | BindingFlags.Public), value => value.Name)); genericTypeMethods.Add(hashType, methods); ++genericTypeMethodVersion; } } finally { genericTypeMethodLock = 0; } } return(methods.Value.Get(methodName, null)); } } } log.Default.Throw(type.fullName() + " 不符合泛型类型服务器端调用", false, false); return(null); }
/// <summary> /// 命令序号记忆数据 /// </summary> private static keyValue<hashString, int>[] _identityCommandNames_() { keyValue<hashString, int>[] names = new keyValue<hashString, int>[7]; names[0].Set(@"(string)verify", 0); names[1].Set(@"(fastCSharp.net.tcp.tcpRegister.clientId,fastCSharp.net.tcp.tcpRegister.service)register", 1); names[2].Set(@"(fastCSharp.net.tcp.tcpRegister.clientId,System.Func<fastCSharp.code.cSharp.asynchronousMethod.returnValue<fastCSharp.net.tcp.tcpRegister.pollResult>,bool>)poll", 2); names[3].Set(@"(fastCSharp.net.tcp.tcpRegister.clientId,string)removeRegister", 3); names[4].Set(@"(out int)getServices", 4); names[5].Set(@"()register", 5); names[6].Set(@"(fastCSharp.net.tcp.tcpRegister.clientId)removeRegister", 6); return names; }
/// <summary> /// 命令序号记忆数据 /// </summary> private static keyValue<hashString, int>[] _identityCommandNames_() { keyValue<hashString, int>[] names = new keyValue<hashString, int>[11]; names[0].Set(@"(string)verify", 0); names[1].Set(@"(string)open", 1); names[2].Set(@"(fastCSharp.memoryDatabase.physicalServer.timeIdentity)close", 2); names[3].Set(@"(fastCSharp.code.cSharp.tcpBase.subByteUnmanagedStream)create", 3); names[4].Set(@"(fastCSharp.memoryDatabase.physicalServer.timeIdentity)load", 4); names[5].Set(@"(fastCSharp.memoryDatabase.physicalServer.timeIdentity,bool)loaded", 5); names[6].Set(@"(fastCSharp.code.cSharp.tcpBase.subByteUnmanagedStream)append", 6); names[7].Set(@"(fastCSharp.memoryDatabase.physicalServer.timeIdentity)waitBuffer", 7); names[8].Set(@"(fastCSharp.memoryDatabase.physicalServer.timeIdentity)flush", 8); names[9].Set(@"(fastCSharp.memoryDatabase.physicalServer.timeIdentity,bool)flushFile", 9); names[10].Set(@"(fastCSharp.memoryDatabase.physicalServer.timeIdentity)loadHeader", 10); return names; }
/// <summary> /// 获取泛型类型函数信息 /// </summary> /// <param name="remoteType">调用代理类型</param> /// <param name="methodName">调用函数名称</param> /// <returns>泛型类型函数信息</returns> private static MethodInfo getGenericTypeMethod(fastCSharp.code.remoteType remoteType, string methodName) { Type type = remoteType.Type; if (type.Name == GenericTypeServerName && type.DeclaringType.IsGenericType) { tcpCall tcpCall = fastCSharp.code.typeAttribute.GetAttribute<tcpCall>(type, false, false); if (tcpCall != null && tcpCall.IsGenericTypeServerMethod) { tcpCall = fastCSharp.code.typeAttribute.GetAttribute<tcpCall>(type.DeclaringType, false, true);//cSharp.Default.IsInheritAttribute if (tcpCall != null && tcpCall.IsSetup) { keyValue<Type, fastCSharp.stateSearcher.ascii<MethodInfo>> methods; int version = genericTypeMethodVersion; if (!genericTypeMethods.TryGetValue(type, out methods) || methods.Key != type) { interlocked.CompareSetSleep(ref genericTypeMethodLock); try { if (version == genericTypeMethodVersion || !genericTypeMethods.TryGetValue(type, out methods)) { MethodInfo[] methodInfos = type.GetMethods(BindingFlags.Static | BindingFlags.Public); methods = new keyValue<Type, fastCSharp.stateSearcher.ascii<MethodInfo>>(type, new fastCSharp.stateSearcher.ascii<MethodInfo>(methodInfos.getArray(value => value.Name), methodInfos)); genericTypeMethods.Add(type, methods); ++genericTypeMethodVersion; } } finally { genericTypeMethodLock = 0; } } return methods.Value.Get(methodName); } } } log.Error.Throw(type.fullName() + " 不符合泛型类型服务器端调用", false, false); return null; }
static void Main(string[] args) { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); #if true const int MaxNum = 1024*100; keyValue[] keyvalues = new keyValue[MaxNum]; System.Random random = new Random(); for(int i=0; i<MaxNum; ++i){ int len = random.Next()%12+4; int notAlnum = len/3; keyvalues[i].key_ = System.Web.Security.Membership.GeneratePassword(len, notAlnum); keyvalues[i].value_ = string.Format("{0}", i); } for(int count = 0; count < 2; ++count) { { //TinyCollections TinyCollections.Hopscotch<string, string> strToStr = new TinyCollections.Hopscotch<string, string>(); stopwatch.Reset(); stopwatch.Start(); for(int i = 0; i < MaxNum; ++i) { strToStr.Overwrite(keyvalues[i].key_, keyvalues[i].value_); } for(int i = MaxNum - 2; 0 <= i; i -= 2) { strToStr.Remove(keyvalues[i].key_); } for(int i = 0; i < MaxNum; i += 2) { strToStr.Overwrite(keyvalues[i].key_, keyvalues[i].value_); } stopwatch.Stop(); System.Console.WriteLine("Tiny:InsertRemove " + stopwatch.Elapsed); stopwatch.Reset(); stopwatch.Start(); for(int i = 0; i < MaxNum; ++i) { string value; if(strToStr.TryGetValue(keyvalues[i].key_, out value) && value == keyvalues[i].value_) { } else { System.Console.WriteLine("error"); } } stopwatch.Stop(); System.Console.WriteLine("Tiny:Find {0} Memory {1}", stopwatch.Elapsed, GC.GetTotalMemory(true)); } { //System.Collections.Generic.Dictionary Dictionary<string, string> direcionary = new Dictionary<string, string>(); stopwatch.Reset(); stopwatch.Start(); for(int i = 0; i < MaxNum; ++i) { direcionary[keyvalues[i].key_] = keyvalues[i].value_; } for(int i = MaxNum - 2; 0 <= i; i -= 2) { direcionary.Remove(keyvalues[i].key_); } for(int i = 0; i < MaxNum; i += 2) { direcionary[keyvalues[i].key_] = keyvalues[i].value_; } stopwatch.Stop(); System.Console.WriteLine("Dictionary:InsertRemove " + stopwatch.Elapsed); stopwatch.Reset(); stopwatch.Start(); for(int i = 0; i < MaxNum; ++i) { string value; if(direcionary.TryGetValue(keyvalues[i].key_, out value) && value == keyvalues[i].value_) { } else { System.Console.WriteLine("error"); } } stopwatch.Stop(); System.Console.WriteLine("Dictionary:Find {0} Memory {1}", stopwatch.Elapsed, GC.GetTotalMemory(true)); } } #else const int MaxNum = 1024*100; keyValueInt[] keyvalues = new keyValueInt[MaxNum]; System.Random random = new System.Random(); for(int i=0; i<MaxNum; ++i){ keyvalues[i].key_ = random.Next(); keyvalues[i].value_ = i; } for(int count=0; count<2; ++count) { { //TinyCollections TinyCollections.HashMap<int, int> strToStr = new HashMap<int, int>(); stopwatch.Reset(); stopwatch.Start(); for(int i = 0; i < MaxNum; ++i) { strToStr.Overwrite(keyvalues[i].key_, keyvalues[i].value_); } for(int i = MaxNum - 2; 0 <= i; i -= 2) { strToStr.Remove(keyvalues[i].key_); } for(int i = 0; i < MaxNum; i += 2) { strToStr.Overwrite(keyvalues[i].key_, keyvalues[i].value_); } stopwatch.Stop(); System.Console.WriteLine("Tiny:InsertRemove " + stopwatch.Elapsed); stopwatch.Reset(); stopwatch.Start(); for(int i = 0; i < MaxNum; ++i) { int value; if(strToStr.TryGetValue(keyvalues[i].key_, out value) && value == keyvalues[i].value_) { } else { System.Console.WriteLine("error"); } } stopwatch.Stop(); System.Console.WriteLine("Tiny:Find " + stopwatch.Elapsed); } { //System.Collections.Generic.Dictionary Dictionary<int, int> direcionary = new Dictionary<int, int>(); stopwatch.Reset(); stopwatch.Start(); for(int i = 0; i < MaxNum; ++i) { direcionary[keyvalues[i].key_] = keyvalues[i].value_; } for(int i = MaxNum - 2; 0 <= i; i -= 2) { direcionary.Remove(keyvalues[i].key_); } for(int i = 0; i < MaxNum; i += 2) { direcionary[keyvalues[i].key_] = keyvalues[i].value_; } stopwatch.Stop(); System.Console.WriteLine("Dictionary:InsertRemove " + stopwatch.Elapsed); stopwatch.Reset(); stopwatch.Start(); for(int i = 0; i < MaxNum; ++i) { int value; if(direcionary.TryGetValue(keyvalues[i].key_, out value) && value == keyvalues[i].value_) { } else { System.Console.WriteLine("error"); } } stopwatch.Stop(); System.Console.WriteLine("Dictionary:Find " + stopwatch.Elapsed); } System.GC.Collect(); } #endif }
/// <summary> /// 命令序号记忆数据 /// </summary> private static keyValue<hashString, int>[] _identityCommandNames_() { keyValue<hashString, int>[] names = new keyValue<hashString, int>[5]; names[0].Set(@"(string)verify", 0); names[1].Set(@"(fastCSharp.io.fileBlockStream.index,ref fastCSharp.code.cSharp.tcpBase.subByteArrayEvent,System.Func<fastCSharp.code.cSharp.asynchronousMethod.returnValue<fastCSharp.code.cSharp.tcpBase.subByteArrayEvent>,bool>)read", 1); names[2].Set(@"(fastCSharp.code.cSharp.tcpBase.subByteUnmanagedStream)write", 2); names[3].Set(@"()waitBuffer", 3); names[4].Set(@"(bool)flush", 4); return names; }
/// <summary> /// 子节点筛选 /// </summary> /// <param name="path">筛选器</param> /// <param name="value">筛选节点集合</param> /// <returns>匹配的HTML节点集合</returns> private static keyValue<list<htmlNode>, bool> filterChild(filter path, keyValue<list<htmlNode>, bool> value) { if (path.index < 0) { if (path.indexs == null) { if (path.values == null) { if (path.value != null) { string tagName = path.value; list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer; foreach (htmlNode nodes in value.Key) { if (nodes.children.count() > 0) { foreach (htmlNode node in nodes.children) { if (node.TagName == tagName) newValues.Add(node); } } } return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1); } else { int index = 0; foreach (htmlNode nodes in value.Key) if (nodes.children != null) index += nodes.children.Count; if (index != 0) { htmlNode[] newValues = new htmlNode[index]; index = 0; foreach (htmlNode nodes in value.Key) { if (nodes.children != null) { nodes.children.CopyTo(newValues, index); index += nodes.children.Count; } } return new keyValue<list<htmlNode>, bool>(new list<htmlNode>(newValues, true), value.Value && newValues.Length != 1); } return new keyValue<list<htmlNode>, bool>(null, false); } } else { staticHashSet<string> tagNames = path.values; list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer; foreach (htmlNode nodes in value.Key) { if (nodes.children.count() != 0) { foreach (htmlNode node in nodes.children) { if (tagNames.Contains(node.TagName)) newValues.Add(node); } } } return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1); } } else { list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer; if (path.value != null) { string tagName = path.value; staticHashSet<int> indexs = path.indexs; foreach (htmlNode nodes in value.Key) { if (nodes.children.count() != 0) { int index = 0; foreach (htmlNode node in nodes.children) { if (node.TagName == tagName) { if (indexs.Contains(index)) newValues.Add(node); ++index; } } } } } else { int[] indexs = path.indexs.GetList().ToArray(); foreach (htmlNode nodes in value.Key) { int count = nodes.children.count(); if (count > 0) { list<htmlNode> children = nodes.children; for (int index = indexs.Length; --index >= 0; ) { if (index < count) newValues.Add(children[index]); } } } } return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1); } } else { list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer; if (path.value != null) { string tagName = path.value; int index = path.index; foreach (htmlNode nodes in value.Key) { if (nodes.children.count() != 0) { int count = 0; foreach (htmlNode node in nodes.children) { if (node.TagName == tagName) { if (count == index) { newValues.Add(node); break; } ++count; } } } } } else { int index = path.index; foreach (htmlNode nodes in value.Key) { if (index < nodes.children.count()) newValues.List.Add(nodes.children[index]); } } return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1); } }
/// <summary> /// 属性值筛选 /// </summary> /// <param name="path">筛选器</param> /// <param name="value">筛选节点集合</param> /// <returns>匹配的HTML节点集合</returns> private static keyValue<list<htmlNode>, bool> filterValue(filter path, keyValue<list<htmlNode>, bool> value) { string name = path.name; list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer; if (path.values == null && path.value == null) { foreach (htmlNode node in value.Key) { if (node.attributes != null && node.attributes.ContainsKey(name)) newValues.Add(node); } } else { if (path.values == null) { string nameValue = path.value; foreach (htmlNode node in value.Key) { if (node[name] == nameValue) newValues.Add(node); } } else { staticHashSet<string> values = path.values; foreach (htmlNode node in value.Key) { if (values.Contains(node[name])) newValues.Add(node); } } } return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1); }
/// <summary> /// 获取匹配HTML节点集合 /// </summary> /// <param name="value">筛选节点集合</param> /// <returns>匹配的HTML节点集合</returns> private list<htmlNode> get(keyValue<list<htmlNode>, bool> value) { value = filterMethod(this, value); return nextFilter == null || value.Key == null ? value.Key : nextFilter.get(value); }
/// <summary> /// 检测SQL表格 /// </summary> /// <param name="table">SQL表格</param> private static void checkSqlTable(keyValue<Type, keyValue<Type, sqlTable>> table) { table memberTable = setup.cSharp.sqlTable.cSharp.GetTable(table.Key, table.Value.Value, setup.cSharp.sqlTable.cSharp.GetMembers(table.Value.Key, table.Value.Value)); client sqlClient = GetConnection(table.Value.Value.ConnectionType).Client; table sqlTable = sqlClient.GetTable(memberTable.Columns.Name); if (sqlTable == null) { if (!sqlClient.CreateTable(memberTable)) fastCSharp.log.Default.Real("表格 " + memberTable.Columns.Name + " 创建失败", false, false); } else { staticDictionary<string, column> sqlColumnNames = new staticDictionary<string, column>(sqlTable.Columns.Columns, value => value.Name); list<column> newColumns = memberTable.Columns.Columns.getFind(value => !sqlColumnNames.ContainsKey(value.Name)); if (newColumns.count() != 0) { if (sqlClient.AddFields(new columnCollection { Name = memberTable.Columns.Name, Columns = newColumns.toArray() })) { sqlTable.Columns.Columns = newColumns.add(sqlTable.Columns.Columns).toArray(); } else { fastCSharp.log.Default.Real("表格 " + memberTable.Columns.Name + " 字段添加失败 : " + newColumns.joinString(',', value => value.Name), false, false); } } newColumns = memberTable.Columns.Columns.getFind(value => !value.IsMatch(sqlColumnNames.Get(value.Name, null))); if (newColumns.count() != 0) { fastCSharp.log.Default.Real("表格 " + memberTable.Columns.Name + " 字段类型不匹配 : " + newColumns.joinString(',', value => value.Name), false, false); } } }
/// <summary> /// class样式筛选 /// </summary> /// <param name="path">筛选器</param> /// <param name="value">筛选节点集合</param> /// <returns>匹配的HTML节点集合</returns> private static keyValue<list<htmlNode>, bool> filterClass(filter path, keyValue<list<htmlNode>, bool> value) { list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer; if (path.values == null) { string name = path.value; foreach (htmlNode node in value.Key) { string className = node["class"]; if (className != null && className.Split(' ').indexOf(name) != -1) newValues.Add(node); } } else { staticHashSet<string> names = path.values; foreach (htmlNode node in value.Key) { string className = node["class"]; if (className != null) { foreach(string name in className.Split(' ')) { if (names.Contains(name)) { newValues.Add(node); break; } } } } } return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1); }
/// <summary> /// 子孙节点筛选 /// </summary> /// <param name="path">筛选器</param> /// <param name="value">筛选节点集合</param> /// <returns>匹配的HTML节点集合</returns> private static keyValue<list<htmlNode>, bool> filterNode(filter path, keyValue<list<htmlNode>, bool> value) { list<nodeIndex> values = new list<nodeIndex>(); nodeIndex index = new nodeIndex { Values = value.Key.getList() }; if (index.Values.Count != 0) { if (value.Value) { HashSet<htmlNode> newValues = new HashSet<htmlNode>(), historyNodes = new HashSet<htmlNode>(); if (path.values == null) { if (path.value != null) { string tagName = path.value; while (true) { if (index.Values == null) { if (values.Count == 0) break; else index = values.Pop(); } htmlNode node = index.Values[index.Index]; if (node.TagName == tagName) newValues.Add(node); if (node.children.count() == 0 || historyNodes.Contains(node)) { if (++index.Index == index.Values.Count) index.Values = null; } else { if (++index.Index != index.Values.Count) values.Add(index); historyNodes.Add(node); index.Values = node.children; index.Index = 0; } } } else { while (true) { if (index.Values == null) { if (values.Count == 0) break; else index = values.Pop(); } htmlNode node = index.Values[index.Index]; newValues.Add(node); if (node.children.count() == 0 || historyNodes.Contains(node)) { if (++index.Index == index.Values.Count) index.Values = null; } else { if (++index.Index != index.Values.Count) values.Add(index); historyNodes.Add(node); index.Values = node.children; index.Index = 0; } } } } else { staticHashSet<string> tagNames = path.values; while (true) { if (index.Values == null) { if (values.Count == 0) break; else index = values.Pop(); } htmlNode node = index.Values[index.Index]; if (tagNames.Contains(node.TagName)) newValues.Add(node); if (node.children.count() == 0 || historyNodes.Contains(node)) { if (++index.Index == index.Values.Count) index.Values = null; } else { if (++index.Index != index.Values.Count) values.Add(index); historyNodes.Add(node); index.Values = node.children; index.Index = 0; } } } if (newValues.Count != 0) { return new keyValue<list<htmlNode>, bool>(new list<htmlNode>(newValues), newValues.Count > 1); } } else { list<htmlNode> newValues = new list<htmlNode>(); if (path.values == null) { if (path.value != null) { string tagName = path.value; while (true) { if (index.Values == null) { if (values.Count == 0) break; else index = values.Pop(); } htmlNode node = index.Values[index.Index]; if (node.TagName == tagName) newValues.Add(node); if (node.children.count() == 0) { if (++index.Index == index.Values.Count) index.Values = null; } else { if (++index.Index != index.Values.Count) values.Add(index); index.Values = node.children; index.Index = 0; } } } else { while (true) { if (index.Values == null) { if (values.Count == 0) break; else index = values.Pop(); } htmlNode node = index.Values[index.Index]; newValues.Add(node); if (node.children.count() == 0) { if (++index.Index == index.Values.Count) index.Values = null; } else { if (++index.Index != index.Values.Count) values.Add(index); index.Values = node.children; index.Index = 0; } } } } else { staticHashSet<string> tagNames = path.values; while (true) { if (index.Values == null) { if (values.Count == 0) break; else index = values.Pop(); } htmlNode node = index.Values[index.Index]; if (tagNames.Contains(node.TagName)) newValues.Add(node); if (node.children.count() == 0) { if (++index.Index == index.Values.Count) index.Values = null; } else { if (++index.Index != index.Values.Count) values.Add(index); index.Values = node.children; index.Index = 0; } } } if (newValues.Count != 0) { return new keyValue<list<htmlNode>, bool>(newValues, newValues.Count > 1); } } } return new keyValue<list<htmlNode>, bool>(null, false); }