public void Clear() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var subarray = new SubArray<int>(array, 1, 6); subarray.Clear(); Assert.IsTrue(Enumerable.SequenceEqual(new int[] { 1, 0, 0, 0, 0, 0, 0, 8, }, array)); }
public TokenType Type; //{ get; set; } #endregion Fields #region Constructors //public Token() //{ //} public Token(char[] source, int start, int end, TokenType type) { Start = start; End = end; Type = type; Content = new SubArray<char>(source, Start, End - Start /*Length*/); }
public void ConstructorArrayEmpty() { int[] array = new int[0]; var subarray = new SubArray<int>(array); Assert.AreSame(array, subarray.Array); Assert.AreEqual(0, subarray.Offset); Assert.AreEqual(0, subarray.Count); }
public void ConstructorArray() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var subarray = new SubArray<int>(array); Assert.AreSame(array, subarray.Array); Assert.AreEqual(0, subarray.Offset); Assert.AreEqual(array.Length, subarray.Count); Assert.AreEqual(1, subarray[0]); Assert.AreEqual(8, subarray[7]); }
public void ConstructorArrayOffsetRefType() { string[] array = new string[] { "1", "2", "3", "4", "5", "6", "7", "8" }; var subarray = new SubArray<string>(array, 1, 6); Assert.AreSame(array, subarray.Array); Assert.AreEqual(1, subarray.Offset); Assert.AreEqual(6, subarray.Count); Assert.AreEqual("2", subarray[0]); Assert.AreEqual("7", subarray[5]); }
public void ConstructorArrayOffset() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var subarray = new SubArray<int>(array, 1, 6); Assert.AreSame(array, subarray.Array); Assert.AreEqual(1, subarray.Offset); Assert.AreEqual(6, subarray.Count); Assert.AreEqual(2, subarray[0]); Assert.AreEqual(7, subarray[5]); }
/// <summary> /// 添加数据 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <typeparam name="modelType">模型类型</typeparam> /// <param name="sqlTool">SQL操作工具</param> /// <param name="connection">SQL连接</param> /// <param name="array">数据数组</param> /// <returns></returns> internal override SubArray <valueType> Insert <valueType, modelType>(Table <valueType, modelType> sqlTool, ref DbConnection connection, ref SubArray <valueType> array) { MemberMap <modelType> memberMap = MemberMap <modelType> .Default; InsertQuery query = new InsertQuery { NotQuery = true }; LeftArray <valueType> newArray = new LeftArray <valueType>(array.Length); foreach (valueType value in array) { insert(sqlTool, value, memberMap, ref query); if (Insert(sqlTool, ref connection, value, ref query)) { newArray.UnsafeAdd(value); } } return(new SubArray <valueType>(ref newArray)); }
Node ReconstructTreeHelper(SubArray<int> preorder, SubArray<int> inorder, Dictionary<int, int> inorderMapTable) { int rootVal = preorder[0]; int rootPos = inorderMapTable[rootVal] - inorder.Offset; Node node = new Node { Id = rootVal }; int nodesToLeft = rootPos; if (nodesToLeft > 0) node.Left = ReconstructTreeHelper(preorder.SubArray(1, nodesToLeft), inorder.SubArray(0, nodesToLeft), inorderMapTable); int nodesToRight = inorder.Count - rootPos - 1; if (nodesToRight > 0) node.Right = ReconstructTreeHelper(preorder.SubArray(rootPos + 1, nodesToRight), inorder.SubArray(rootPos + 1, nodesToRight), inorderMapTable); return node; }
/// <summary> /// 添加数据 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <typeparam name="modelType">模型类型</typeparam> /// <param name="sqlTool">SQL操作工具</param> /// <param name="transaction">事务操作</param> /// <param name="array">数据数组</param> /// <returns></returns> internal override SubArray <valueType> Insert <valueType, modelType>(Sql.Table <valueType, modelType> sqlTool, Transaction transaction, ref SubArray <valueType> array) { if (sqlTool.CallOnInsert(ref array)) { MemberMap <modelType> memberMap = MemberMap <modelType> .Default; InsertQuery query = new InsertQuery(); foreach (valueType value in array) { insert(sqlTool, value, memberMap, ref query); if (executeNonQuery(transaction, query.InsertSql) <= 0) { return(default(SubArray <valueType>)); } } sqlTool.CallOnInserted(transaction, array); return(array); } return(default(SubArray <valueType>)); }
/// <summary> /// 压缩数据 /// </summary> /// <param name="isFastestCompressionLevel"></param> internal void Compress(bool isFastestCompressionLevel) #endif { switch (Type) { case Net.Http.ResponseType.ByteArray: Body.SetFull(); goto SUBBYTEARRAY; case Net.Http.ResponseType.SubByteArray: SUBBYTEARRAY: if (Body.Length > GZipHeaderSize + 256) { SubArray <byte> compressData = default(SubArray <byte>); try { #if DOTNET2 || DOTNET4 if (AutoCSer.IO.Compression.GzipCompressor.Get(Body.Array, Body.Start, Body.Length, ref SubBuffer, ref compressData, 0, GZipHeaderSize)) #else if (AutoCSer.IO.Compression.GzipCompressor.Get(Body.Array, Body.Start, Body.Length, ref SubBuffer, ref compressData, 0, GZipHeaderSize, isFastestCompressionLevel)) #endif { Body = compressData; Type = compressData.Array == SubBuffer.Buffer ? ResponseType.SubBuffer : ResponseType.SubByteArray; ContentEncoding = GZipEncoding; Flag |= ResponseFlag.ContentEncoding; } } finally { if (Type != ResponseType.SubBuffer) { SubBuffer.Free(); } } } return; case Net.Http.ResponseType.SubBuffer: if (Body.Length > GZipHeaderSize + 256) { SubBuffer.PoolBufferFull compressBuffer = default(SubBuffer.PoolBufferFull); SubArray <byte> compressData = default(SubArray <byte>); byte isCompress = 0; try { #if DOTNET2 || DOTNET4 if (AutoCSer.IO.Compression.GzipCompressor.Get(Body.Array, Body.Start, Body.Length, ref compressBuffer, ref compressData, 0, GZipHeaderSize)) #else if (AutoCSer.IO.Compression.GzipCompressor.Get(Body.Array, Body.Start, Body.Length, ref compressBuffer, ref compressData, 0, GZipHeaderSize, isFastestCompressionLevel)) #endif { isCompress = 1; SubBuffer.Free(); Body = compressData; if (compressData.Array == compressBuffer.Buffer) { SubBuffer = compressBuffer; } else { Type = ResponseType.SubByteArray; } ContentEncoding = GZipEncoding; Flag |= ResponseFlag.ContentEncoding; } } finally { if (isCompress == 0 || Type != ResponseType.SubBuffer) { compressBuffer.Free(); } } } return; } }
public bool SendCustomData(SubArray<byte> data) { return Sender.CustomData(ref data); }
private void doCommand(ref SubBuffer.PoolBufferFull buffer) { SubArray<byte> data = new SubArray<byte> { Array = buffer.Buffer, Start = buffer.StartIndex, Length = dataSize }; doCommand(ref data); buffer.PoolBuffer.Free(); }
/// <summary> /// 上传文件 /// </summary> /// <param name="server">文件同步服务端</param> /// <param name="path">文件路径</param> /// <param name="listFileItem">列表文件数据</param> /// <param name="index">当前写入位置</param> /// <param name="data">写入数据</param> /// <param name="onCreated">创建文件回调处理</param> internal ServerUploadFile(Server server, string path, ref ListFileItem listFileItem, long index, ref SubArray <byte> data, Func <ReturnValue <UploadFileIdentity>, bool> onCreated) : base(server, path, ref listFileItem, null) { this.onCreated = onCreated; this.index = index; this.data = data; }
/// <summary> /// 命令处理 /// </summary> /// <param name="index">命令序号</param> /// <param name="sender">TCP 内部服务套接字数据发送</param> /// <param name="data">命令数据</param> public override void DoCommand(int index, AutoCSer.Net.TcpInternalServer.ServerSocketSender sender, ref SubArray <byte> data) { AutoCSer.Net.TcpServer.ReturnType returnType; switch (index - 128) { case 0: returnType = AutoCSer.Net.TcpServer.ReturnType.Unknown; try { _p1 inputParameter = new _p1(); if (sender.DeSerialize(ref data, ref inputParameter, true)) { (_s0 /**/.Pop() ?? new _s0()).Set(sender, Value, AutoCSer.Net.TcpServer.ServerTaskType.Timeout, ref inputParameter); return; } returnType = AutoCSer.Net.TcpServer.ReturnType.ServerDeSerializeError; } catch (Exception error) { returnType = AutoCSer.Net.TcpServer.ReturnType.ServerException; sender.AddLog(error); } sender.Push(returnType); return; default: return; } }
/// <summary> /// ARP数据包 /// </summary> /// <param name="data">数据</param> public Arp(SubArray <byte> data) : this(ref data) { }
/// <summary> /// ARP数据包 /// </summary> /// <param name="data">数据</param> public Arp(ref SubArray <byte> data) { this.data = data.Length >= PacketSize ? data : new SubArray <byte>(); }
/// <summary> /// UDP数据包 /// </summary> /// <param name="data">数据</param> public unsafe Udp(SubArray <byte> data) : this(ref data) { }
internal static bool GetCompress(ref SubArray <byte> data, ref SubArray <byte> compressData, int seek, bool isFastest) { return(data.Length > GZipHeaderSize + 256 && AutoCSer.IO.Compression.GzipCompressor.Get(ref data, ref compressData, seek, GZipHeaderSize, isFastest)); }
public void Contains() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var subarray = new SubArray<int>(array, 1, 6); Assert.IsTrue(subarray.Contains(2) && subarray.Contains(7)); Assert.IsFalse(subarray.Contains(1) || subarray.Contains(8)); }
static void Main(string[] args) { Console.WriteLine(@"http://www.AutoCSer.com/WebView/Index.html "); int clientCountPerCpu = 256, maxClientCount = 256; bool isKeepAlive = true; byte[][] requestDatas = new byte[(byte)TestType.HelloFile + 1][]; requestDatas[(byte)TestType.HelloFile] = createRequestData(@"GET /hello.html HTTP/1.1 Host: 127.0.0.1 Connection: Keep-Alive ", 16); requestDatas[(byte)TestType.Json] = createRequestData(@"GET /json HTTP/1.1 Host: 127.0.0.1 Connection: Keep-Alive ", 16); int[] responseSizes = new int[(byte)TestType.HelloFile + 1]; responseSizes[(byte)TestType.HelloFile] = @"HTTP/1.1 200 OK Content-Length: 10 Connection: Keep-Alive Server: AutoCSer.HTTP/1.1 Date: Mon, 15 May 2017 12:16:35 GMT Hello, World!".Length; responseSizes[(byte)TestType.Json] = @"HTTP/1.1 200 OK Content-Length: 27 Connection: Keep-Alive Server: AutoCSer.HTTP/1.1 Date: Mon, 15 May 2017 12:16:35 GMT {""message"":""Hello, World!""}".Length; int cpuCount = AutoCSer.Common.ProcessorCount, maxSocketCount = Math.Min(cpuCount * clientCountPerCpu, maxClientCount); using (Task task = new Task(maxSocketCount, 1)) { do { for (int pipeline = 16; pipeline != 0; pipeline >>= 1) { int count = maxSocketCount * pipeline * 256, keepAliveCount = isKeepAlive ? ((count <<= 2) + (maxSocketCount - 1)) / maxSocketCount : 1; task.KeepAliveCount = keepAliveCount; loopTestType = TestType.Json; do { Console.WriteLine("Start request " + maxSocketCount.toString() + " / " + count.toString() + (isKeepAlive ? " +KeppAlive" : null) + (pipeline == 1 ? null : (" +pipeline[" + pipeline.toString() + "]"))); task.ErrorCount = task.RefusedCount = 0; requestData = new SubArray <byte>(requestDatas[(byte)loopTestType], 0, requestDatas[(byte)loopTestType].Length / 16 * pipeline); receiveKeepAliveSize = responseSizes[(byte)loopTestType] * pipeline; long time = System.Diagnostics.Stopwatch.GetTimestamp(); task.Add(count / pipeline); task.Wait(); long milliseconds = (long)Date.GetTimestampTimeSpan(time).TotalMilliseconds; task.CloseClient(); Console.WriteLine(@"Finally[" + count.toString() + "] Error[" + (task.ErrorCount * pipeline).toString() + "] Refused[" + task.RefusedCount.toString() + "] " + milliseconds.toString() + "ms" + (milliseconds == 0 ? null : ("[" + ((count - task.RefusedCount) / milliseconds).toString() + "/ms]")) + " " + loopTestType.ToString()); Console.WriteLine(@"Sleep 3000ms "); Thread.Sleep(3000); }while (++loopTestType != TestType.LoopEnd); } }while (true); } }
public void Enumerator() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var subarray = new SubArray<int>(array, 1, 6); Assert.IsTrue(Enumerable.SequenceEqual(subarray, array.Skip(1).Take(6))); }
/// <summary> /// 流合并命令处理 /// </summary> /// <param name="data">输入数据</param> internal void Merge(ref SubArray<byte> data) { int receiveCount = data.Length; if (receiveCount >= (sizeof(int) + sizeof(uint))) { try { byte[] dataArray = data.Array; fixed (byte* dataFixed = dataArray) { int receiveIndex = data.Start, receiveSize; receiveCount += data.Start; do { byte* start = dataFixed + receiveIndex; if (!Server.IsCommand(command = *(int*)start)) break; switch (command - TcpServer.Server.MinCommandIndex) { case TcpServer.Server.CancelKeepCommandIndex - TcpServer.Server.MinCommandIndex: if (*(int*)(start + (sizeof(int) * 2)) != 0 || receiveCount - (receiveIndex += sizeof(int) * 3) < 0) { DisposeSocket(); return; } Sender.CancelKeepCallback(*(int*)(start + sizeof(int))); break; case TcpServer.Server.CustomDataCommandIndex - TcpServer.Server.MinCommandIndex: if ((dataSize = *(int*)(start + (sizeof(uint) + sizeof(int)))) < 0 || dataSize > receiveCount - (receiveIndex += (sizeof(int) * 2 + sizeof(uint))) || (customDataSize = *(int*)(start + sizeof(int))) < 0 || (uint)(dataSize - customDataSize) >= 4) { DisposeSocket(); return; } data.Set(receiveIndex, customDataSize); Server.CustomData(ref data); receiveIndex += dataSize; break; case TcpServer.Server.RemoteExpressionCommandIndex - TcpServer.Server.MinCommandIndex: case TcpServer.Server.RemoteExpressionNodeIdCommandIndex - TcpServer.Server.MinCommandIndex: if (((CommandIndex = *(uint*)(start + sizeof(int))) & (uint)TcpServer.CommandFlags.NullData) != 0 || (dataSize = *(int*)(start + (sizeof(uint) + sizeof(int)))) <= 0 || dataSize > receiveCount - (receiveIndex += (sizeof(int) * 2 + sizeof(uint)))) { DisposeSocket(); return; } data.Set(receiveIndex, dataSize); if (command == TcpServer.Server.RemoteExpressionCommandIndex) Sender.GetRemoteExpression(ref data); else Sender.GetRemoteExpressionNodeId(ref data); receiveIndex += dataSize; break; default: if (((CommandIndex = *(uint*)(start + sizeof(int))) & (uint)TcpServer.CommandFlags.NullData) == 0) { if ((dataSize = *(int*)(start + (sizeof(uint) + sizeof(int)))) <= 0 || dataSize > receiveCount - (receiveIndex += (sizeof(int) * 2 + sizeof(uint)))) { DisposeSocket(); return; } data.Set(receiveIndex, dataSize); Server.DoCommand(command, Sender, ref data); receiveIndex += dataSize; } else { Server.DoCommand(command, Sender, ref SubArray<byte>.Null); receiveIndex += (sizeof(int) + sizeof(uint)); } break; } if ((receiveSize = receiveCount - receiveIndex) == 0) return; } while (receiveSize >= (sizeof(int) + sizeof(uint))); } } catch (Exception error) { Server.Log.Add(AutoCSer.Log.LogType.Error, error); } } DisposeSocket(); }
public void IndexOf() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var subarray = new SubArray<int>(array, 1, 6); Assert.AreEqual(2, subarray.IndexOf(4)); }
/// <summary> /// 连接字符串集合 /// </summary> /// <param name="subArray"></param> /// <param name="join"></param> /// <param name="nullString"></param> /// <returns></returns> internal unsafe static string stringSubArrayJoinChar(SubArray <string> subArray, char join, string nullString) { string[] array = subArray.Array; if (subArray.Length == 1) { string value = array[subArray.StartIndex]; return(value == null ? nullString : value.ToString()); } int startIndex = subArray.Start, length = 0, endIndex = startIndex + subArray.Length; if (nullString.Length == 0) { do { string nextString = array[startIndex++]; if (nextString != null) { length += nextString.Length; } }while (startIndex != endIndex); string value = AutoCSer.Extensions.StringExtension.FastAllocateString(length + subArray.Length - 1); fixed(char *valueFixed = value) { char *write = valueFixed; startIndex = subArray.Start; do { string nextString = array[startIndex++]; if (write != valueFixed) { *write++ = join; } if (nextString != null) { AutoCSer.Extensions.StringExtension.CopyNotNull(nextString, write); write += nextString.Length; } }while (startIndex != endIndex); } return(value); } else { do { length += (array[startIndex++] ?? nullString).Length; }while (startIndex != endIndex); string value = AutoCSer.Extensions.StringExtension.FastAllocateString(length + subArray.Length - 1); fixed(char *valueFixed = value) { char *write = valueFixed; startIndex = subArray.Start; do { string nextString = array[startIndex++] ?? nullString; if (write != valueFixed) { *write++ = join; } AutoCSer.Extensions.StringExtension.CopyNotNull(nextString, write); write += nextString.Length; }while (startIndex != endIndex); } return(value); } }
internal void SetLocation(ref SubArray <byte> data, ResponseState state = ResponseState.Found302) { Location = data; State = state; Flag = (Flag | ResponseFlag.Location | ResponseFlag.State) & (ResponseFlag.All ^ ResponseFlag.AccessControlAllowOrigin); }
public void CopyTo() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var subarray = new SubArray<int>(array, 1, 6); int[] dest = new int[8]; subarray.CopyTo(dest, 1); Assert.IsTrue(Enumerable.SequenceEqual(new int[] { 0, 2, 3, 4, 5, 6, 7, 0, }, dest)); }
/// <summary> /// 命令处理 /// </summary> /// <param name="index">命令序号</param> /// <param name="socket">TCP 内部服务套接字数据发送</param> /// <param name="data">命令数据</param> /// <returns>是否成功</returns> public override bool DoCommand(int index, AutoCSer.Net.TcpInternalSimpleServer.ServerSocket socket, ref SubArray <byte> data) { AutoCSer.Net.TcpServer.ReturnType returnType; switch (index - @CommandStartIndex) { #region LOOP MethodIndexs #region NOT IsNullMethod case @MethodIndex: #region IF Attribute.IsExpired #region IF OutputParameterIndex return(socket.SendOutput(AutoCSer.Net.TcpServer.ReturnType.VersionExpired)); #endregion IF OutputParameterIndex #region NOT OutputParameterIndex return(socket.Send(AutoCSer.Net.TcpServer.ReturnType.VersionExpired)); #endregion NOT OutputParameterIndex #endregion IF Attribute.IsExpired #region NOT Attribute.IsExpired returnType = AutoCSer.Net.TcpServer.ReturnType.Unknown; try { #region IF InputParameterIndex @InputParameterTypeName inputParameter = new @InputParameterTypeName(); if (socket.DeSerialize(ref data, ref inputParameter /*IF:IsSimpleSerializeInputParamter*/, true /*IF:IsSimpleSerializeInputParamter*/)) #endregion IF InputParameterIndex { #region IF IsAsynchronousCallback #region IF MethodIsReturn @OutputParameterTypeName outputParameter = new @OutputParameterTypeName(); /*PUSH:Method*/ Value.@MethodName/*PUSH:Method*/ (/*IF:ClientParameterName*/ socket, /*IF:ClientParameterName*//*LOOP:InputParameters*//*AT:ParameterRef*//*PUSH:Parameter*/ inputParameter.@ParameterName, /*PUSH:Parameter*//*LOOP:InputParameters*//*NOTE*/ (AutoCSer.Net.TcpServer.ServerCallback <MethodReturnType.FullName>)(object) /*NOTE*/ socket.GetCallback <@OutputParameterTypeName /*NOT:IsVerifyMethod*/, @MethodReturnType.FullName /*NOT:IsVerifyMethod*/>(@MethodIdentityCommand, ref outputParameter)); #endregion IF MethodIsReturn #region NOT MethodIsReturn /*PUSH:Method*/ Value.@MethodName/*PUSH:Method*/ (/*IF:ClientParameterName*/ socket, /*IF:ClientParameterName*//*LOOP:InputParameters*//*AT:ParameterRef*//*PUSH:Parameter*/ inputParameter.@ParameterName, /*PUSH:Parameter*//*LOOP:InputParameters*//*NOTE*/ (AutoCSer.Net.TcpServer.ServerCallback <MethodReturnType.FullName>)(object) /*NOTE*/ socket.GetCallback()); #endregion NOT MethodIsReturn return(true); #endregion IF IsAsynchronousCallback #region NOT IsAsynchronousCallback #region IF OutputParameterIndex @OutputParameterTypeName _outputParameter_ = new @OutputParameterTypeName(); #endregion IF OutputParameterIndex /*IF:MethodIsReturn*/ @MethodReturnType.FullName @ReturnName; /*IF:MethodIsReturn*/ #region IF MemberIndex #region IF Method.IsGetMember #region IF Method.PropertyParameter @ReturnName = /*NOTE*/ (MethodReturnType.FullName) /*NOTE*/ Value[/*IF:ClientParameterName*/ socket /*IF:InputParameters.Length*/, /*IF:InputParameters.Length*//*IF:ClientParameterName*//*LOOP:InputParameters*//*AT:ParameterRef*//*PUSH:Parameter*/ inputParameter.@ParameterName /*AT:ParameterJoin*//*PUSH:Parameter*//*LOOP:InputParameters*/]; #endregion IF Method.PropertyParameter #region NOT Method.PropertyParameter @ReturnName = /*NOTE*/ (MethodReturnType.FullName) /*NOTE*/ Value.@PropertyName; #endregion NOT Method.PropertyParameter #endregion IF Method.IsGetMember #region NOT Method.IsGetMember #region IF Method.PropertyParameter Value[/*IF:ClientParameterName*/ socket, /*IF:ClientParameterName*//*LOOP:InputParameters*//*NOT:MethodParameter.IsPropertyValue*//*AT:ParameterRef*//*PUSH:Parameter*/ inputParameter.@ParameterName /*AT:ParameterJoin*//*PUSH:Parameter*//*NOT:MethodParameter.IsPropertyValue*//*LOOP:InputParameters*/] = /*LOOP:InputParameters*//*IF:MethodParameter.IsPropertyValue*//*PUSH:Parameter*/ inputParameter.@ParameterName /*PUSH:Parameter*//*IF:MethodParameter.IsPropertyValue*//*LOOP:InputParameters*/; #endregion IF Method.PropertyParameter #region NOT Method.PropertyParameter Value.@PropertyName = /*LOOP:InputParameters*/ inputParameter./*PUSH:Parameter*/ @ParameterName /*PUSH:Parameter*//*LOOP:InputParameters*/; #endregion NOT Method.PropertyParameter #endregion NOT Method.IsGetMember #endregion IF MemberIndex #region NOT MemberIndex /*IF:MethodIsReturn*/ @ReturnName = /*NOTE*/ (MethodReturnType.FullName) /*NOTE*//*IF:MethodIsReturn*//*PUSH:Method*/ Value.@MethodName/*PUSH:Method*/ (/*IF:ClientParameterName*/ socket /*IF:InputParameters.Length*/, /*IF:InputParameters.Length*//*IF:ClientParameterName*//*LOOP:InputParameters*//*AT:ParameterRef*//*IF:MethodParameter.IsOut*//*PUSH:InputParameter*/ _outputParameter_.@ParameterName /*PUSH:InputParameter*//*IF:MethodParameter.IsOut*//*NOTE*/, /*NOTE*//*NOT:MethodParameter.IsOut*//*PUSH:Parameter*/ inputParameter.@ParameterName /*PUSH:Parameter*//*NOT:MethodParameter.IsOut*//*PUSH:Parameter*//*AT:ParameterJoin*//*PUSH:Parameter*//*LOOP:InputParameters*/); #endregion NOT MemberIndex #region IF OutputParameterIndex #region IF IsVerifyMethod if (/*NOTE*/ (bool)(object)/*NOTE*/ @ReturnName) { socket.SetVerifyMethod(); } #endregion IF IsVerifyMethod #region LOOP OutputParameters #region NOT InputMethodParameter.IsOut /*PUSH:Parameter*/ _outputParameter_.@ParameterName /*PUSH:Parameter*/ = inputParameter./*PUSH:InputParameter*/ @ParameterName /*PUSH:InputParameter*/; #endregion NOT InputMethodParameter.IsOut #endregion LOOP OutputParameters #region IF MethodIsReturn _outputParameter_.@ReturnName = @ReturnName; #endregion IF MethodIsReturn return(socket.Send(@MethodIdentityCommand, ref _outputParameter_)); #endregion IF OutputParameterIndex #region NOT OutputParameterIndex return(socket.Send()); #endregion NOT OutputParameterIndex #endregion NOT IsAsynchronousCallback } #region IF InputParameterIndex returnType = AutoCSer.Net.TcpServer.ReturnType.ServerDeSerializeError; #endregion IF InputParameterIndex } catch (Exception error) { returnType = AutoCSer.Net.TcpServer.ReturnType.ServerException; socket.Log(error); } #region IF OutputParameterIndex return(socket.SendOutput(returnType)); #endregion IF OutputParameterIndex #region NOT OutputParameterIndex return(socket.Send(returnType)); #endregion NOT OutputParameterIndex #endregion NOT Attribute.IsExpired #endregion NOT IsNullMethod #endregion LOOP MethodIndexs default: return(false); } }
public void Indexer() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var subarray = new SubArray<int>(array, 1, 6); Assert.AreEqual(4, subarray[2]); }
public static bool DeSerialize <valueType>(ServerSocket socket, ref SubArray <byte> data, ref valueType value, bool isSimpleSerialize) where valueType : struct { return(socket.DeSerialize(ref data, ref value, isSimpleSerialize)); }
public void IsReadOnly() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var subarray = new SubArray<int>(array, 1, 6); Assert.IsFalse(subarray.IsReadOnly); }
/// <summary> /// 命令处理 /// </summary> /// <param name="index">命令序号</param> /// <param name="socket">TCP 内部服务套接字数据发送</param> /// <param name="data">命令数据</param> /// <returns>是否成功</returns> public override bool DoCommand(int index, AutoCSer.Net.TcpOpenSimpleServer.ServerSocket socket, ref SubArray <byte> data) { AutoCSer.Net.TcpServer.ReturnType returnType; switch (index - 128) { case 0: returnType = AutoCSer.Net.TcpServer.ReturnType.Unknown; try { _p1 inputParameter = new _p1(); if (socket.DeSerialize(ref data, ref inputParameter)) { _p2 outputParameter = new _p2(); Value.addAsynchronous(inputParameter.left, inputParameter.right, socket.GetCallback <_p2, int>(_c0, ref outputParameter)); return(true); } returnType = AutoCSer.Net.TcpServer.ReturnType.ServerDeSerializeError; } catch (Exception error) { returnType = AutoCSer.Net.TcpServer.ReturnType.ServerException; socket.Log(error); } return(socket.SendOutput(returnType)); case 1: returnType = AutoCSer.Net.TcpServer.ReturnType.Unknown; try { _p1 inputParameter = new _p1(); if (socket.DeSerialize(ref data, ref inputParameter)) { (_s1 /**/.Pop() ?? new _s1()).Set(socket, Value, AutoCSer.Net.TcpServer.ServerTaskType.TcpQueue, ref inputParameter); return(true); } returnType = AutoCSer.Net.TcpServer.ReturnType.ServerDeSerializeError; } catch (Exception error) { returnType = AutoCSer.Net.TcpServer.ReturnType.ServerException; socket.Log(error); } return(socket.SendOutput(returnType)); case 2: returnType = AutoCSer.Net.TcpServer.ReturnType.Unknown; try { _p1 inputParameter = new _p1(); if (socket.DeSerialize(ref data, ref inputParameter)) { _p2 _outputParameter_ = new _p2(); int Return; Return = Value.addSynchronous(inputParameter.left, inputParameter.right); _outputParameter_.Return = Return; return(socket.Send(_c2, ref _outputParameter_)); } returnType = AutoCSer.Net.TcpServer.ReturnType.ServerDeSerializeError; } catch (Exception error) { returnType = AutoCSer.Net.TcpServer.ReturnType.ServerException; socket.Log(error); } return(socket.SendOutput(returnType)); case 3: returnType = AutoCSer.Net.TcpServer.ReturnType.Unknown; try { _p1 inputParameter = new _p1(); if (socket.DeSerialize(ref data, ref inputParameter)) { (_s3 /**/.Pop() ?? new _s3()).Set(socket, Value, AutoCSer.Net.TcpServer.ServerTaskType.TcpTask, ref inputParameter); return(true); } returnType = AutoCSer.Net.TcpServer.ReturnType.ServerDeSerializeError; } catch (Exception error) { returnType = AutoCSer.Net.TcpServer.ReturnType.ServerException; socket.Log(error); } return(socket.SendOutput(returnType)); case 4: returnType = AutoCSer.Net.TcpServer.ReturnType.Unknown; try { _p1 inputParameter = new _p1(); if (socket.DeSerialize(ref data, ref inputParameter)) { (_s4 /**/.Pop() ?? new _s4()).Set(socket, Value, AutoCSer.Net.TcpServer.ServerTaskType.ThreadPool, ref inputParameter); return(true); } returnType = AutoCSer.Net.TcpServer.ReturnType.ServerDeSerializeError; } catch (Exception error) { returnType = AutoCSer.Net.TcpServer.ReturnType.ServerException; socket.Log(error); } return(socket.SendOutput(returnType)); case 5: returnType = AutoCSer.Net.TcpServer.ReturnType.Unknown; try { _p1 inputParameter = new _p1(); if (socket.DeSerialize(ref data, ref inputParameter)) { (_s5 /**/.Pop() ?? new _s5()).Set(socket, Value, AutoCSer.Net.TcpServer.ServerTaskType.Timeout, ref inputParameter); return(true); } returnType = AutoCSer.Net.TcpServer.ReturnType.ServerDeSerializeError; } catch (Exception error) { returnType = AutoCSer.Net.TcpServer.ReturnType.ServerException; socket.Log(error); } return(socket.SendOutput(returnType)); default: return(false); } }
public void OutofBoundsOffsetConstructor() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var subarray = new SubArray<int>(array, 8, 6); }
/// <summary> /// 命令处理 /// </summary> /// <param name="index">命令序号</param> /// <param name="sender">TCP 内部服务套接字数据发送</param> /// <param name="data">命令数据</param> public override void DoCommand(int index, AutoCSer.Net.TcpOpenStreamServer.ServerSocketSender sender, ref SubArray <byte> data) { AutoCSer.Net.TcpServer.ReturnType returnType; switch (index - 128) { case 0: returnType = AutoCSer.Net.TcpServer.ReturnType.Unknown; try { _p1 inputParameter = new _p1(); if (sender.DeSerialize(ref data, ref inputParameter)) { _p2 _outputParameter_ = new _p2(); int Return; Return = Value.add(inputParameter.left, inputParameter.right); _outputParameter_.Return = Return; sender.Push(_c0, ref _outputParameter_); return; } returnType = AutoCSer.Net.TcpServer.ReturnType.ServerDeSerializeError; } catch (Exception error) { returnType = AutoCSer.Net.TcpServer.ReturnType.ServerException; sender.AddLog(error); } sender.Push(returnType); return; case 1: returnType = AutoCSer.Net.TcpServer.ReturnType.Unknown; try { _p3 inputParameter = new _p3(); if (sender.DeSerialize(ref data, ref inputParameter)) { _p4 _outputParameter_ = new _p4(); AutoCSer.TestCase.TcpServerPerformance.Add Return; Return = Value.addAsynchronous(inputParameter.left, inputParameter.right); _outputParameter_.Return = Return; sender.Push(_c1, ref _outputParameter_); return; } returnType = AutoCSer.Net.TcpServer.ReturnType.ServerDeSerializeError; } catch (Exception error) { returnType = AutoCSer.Net.TcpServer.ReturnType.ServerException; sender.AddLog(error); } sender.Push(returnType); return; default: return; } }
/// <summary> /// 添加数据 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <typeparam name="modelType">模型类型</typeparam> /// <param name="sqlTool">SQL操作工具</param> /// <param name="connection">SQL连接</param> /// <param name="array">数据数组</param> /// <returns></returns> internal override SubArray <valueType> Insert <valueType, modelType>(Table <valueType, modelType> sqlTool, ref DbConnection connection, ref SubArray <valueType> array) { throw new NotImplementedException(); }
/// <summary> /// 添加数据 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <typeparam name="modelType">模型类型</typeparam> /// <param name="sqlTool">SQL操作工具</param> /// <param name="transaction">事务操作</param> /// <param name="array">数据数组</param> /// <returns></returns> internal override SubArray <valueType> Insert <valueType, modelType>(Sql.Table <valueType, modelType> sqlTool, Transaction transaction, ref SubArray <valueType> array) { throw new InvalidOperationException(); }
public void ConstructorArrayNull() { var subarray = new SubArray<int>(null); }
public unsafe bool DeSerialize <valueType>(ref SubArray <byte> data, ref valueType value, bool isSimpleSerialize = false) where valueType : struct { return(ServerSocket.DeSerialize(ref data, ref value, isSimpleSerialize)); }
public void ConstructorArrayOffsetNull() { var subarray = new SubArray<int>(null, 1, 3); }
private void doCommandMark(ref SubArray<byte> data) { if (MarkData != 0) TcpServer.CommandBuffer.Mark(ref data, MarkData); doCommand(ref data); }
public void ConstructorSubArray() { int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var subarrayOuter = new SubArray<int>(array, 1, 6); var subarrayInner = new SubArray<int>(subarrayOuter); Assert.AreSame(array, subarrayInner.Array); Assert.AreEqual(1, subarrayInner.Offset); Assert.AreEqual(6, subarrayInner.Count); Assert.AreEqual(2, subarrayInner[0]); Assert.AreEqual(5, subarrayInner[3]); }
/// <summary> /// 接收数据回调处理 /// </summary> /// <param name="data">输出数据</param> internal override void OnReceive(ref SubArray <byte> data) { Callback <ReturnValue <outputParameterType> > callback = Callback; if (callback != null) { ReturnValue <outputParameterType> outputParameter = new ReturnValue <outputParameterType>(); if (CommandInfo.TaskType == ClientTaskType.Synchronous) { try { onReceive(ref data, ref outputParameter); } catch (Exception error) { Socket.Log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer); } finally { callback.Call(ref outputParameter); } } else { try { onReceive(ref data, ref outputParameter); } catch (Exception error) { outputParameter.Type = ReturnType.ClientException; outputParameter.Value = default(outputParameterType); Socket.Log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer); } int isOutput = 1; Exception exception = null; OutputLock.Enter(); try { if (outputParameters.FreeCount == 0) { OutputLock.SleepFlag = 1; } outputParameters.Add(outputParameter); isOutput = this.isOutput; this.isOutput = 1; } catch (Exception error) { exception = error; } finally { OutputLock.ExitSleepFlag(); if (exception != null) { Socket.Log.Exception(exception, null, LogLevel.Exception | LogLevel.AutoCSer); } } if (isOutput == 0) { switch (CommandInfo.TaskType) { case ClientTaskType.ThreadPool: if (!System.Threading.ThreadPool.QueueUserWorkItem(threadPoolOnReceive)) { AutoCSer.Threading.TaskSwitchThreadArray.Default.CurrentThread.Add(this); } return; case ClientTaskType.Timeout: AutoCSer.Threading.TaskSwitchThreadArray.Default.CurrentThread.Add(this); return; case ClientTaskType.TcpTask: ClientCallThreadArray.Default.CurrentThread.Add(this); return; case ClientTaskType.TcpQueue: ClientCallQueue.Default.Add(this); return; } } } } }