/// <summary> /// 获取所有还未处理的结果 /// </summary> /// <returns></returns> public AgentTaskResult[] GetResults() { if (ResultQueue == null) { throw new InvalidOperationException(); } return(ResultQueue.ToArrayAndClear()); }
public Server(int port) { Version = 1; Methods = new Methods(); Subscriptions = new Subscriptions(); Publications = new Publications(); new PublicationMethods(this).AttachMethods(); var messageMethods = new MessageMethods(this).GetMethods(); var messageProcessor = new MessageProcessor(messageMethods); _messageQueue = new ResultQueue<KeyValuePair<IWebSocketConnection, string>>(messageProcessor); _connector = new Connector(this, "127.0.0.1", port); }
/// <summary> /// 等待直到资源被释放 /// </summary> public void WaitDispose() { if (Scheduler != null) { Scheduler.StopWait(); } if (ResultQueue != null) { ResultQueue.Clear(); } if (IOAgent != null) { IOAgent.Dispose(); } }
protected override void DoWorkImpl() { while (true) { var block = InputQueue.Dequeue(); if (block == null) { break; } using (var inStream = new MemoryStream(block.Bytes)) using (var gzipStream = new GZipStream(inStream, CompressionMode.Decompress)) using (var outStream = new MemoryStream()) { gzipStream.CopyTo(outStream); var decompressedBlock = new ByteBlock(block.ID, outStream.ToArray()); ResultQueue.Enqueue(decompressedBlock, true); } } }
protected override void DoWorkImpl() { while (true) { var block = InputQueue.Dequeue(); if (block == null) { break; } using (var memoryStream = new MemoryStream()) { using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress)) { gzipStream.Write(block.Bytes, 0, block.Bytes.Length); } var compressedArray = memoryStream.ToArray(); var compressedBlock = new ByteBlock(block.ID, compressedArray); ResultQueue.Enqueue(compressedBlock, true); } } }
protected void ExecueJob(Job4Agent job) { var result = new AgentTaskResult(job.Identity); result.Action = job.Content.Action; try { switch (job.Content.Action) { case "Send": this.IOAgent.Send(job.Content.SendPacket); result.Successed = true; break; case "Read": result.ExecuteResult = this.IOAgent.Read(job.Content.ReadFilter, 0x00); result.Successed = true; break; case "SendAndRead": result.ExecuteResult = this.IOAgent.SendAndRead(job.Content.SendPacket, job.Content.ReadFilter); result.Successed = true; break; default: if (CustomActionExecute != null) { CustomActionContext caContext = new CustomActionContext(); caContext.Agent = this; caContext.IO = this.IOAgent; caContext.Job = job; result.ExecuteResult = CustomActionExecute(caContext); result.Successed = true; } else { result.Exception = new ArgumentException("未能识别的Action"); result.Successed = false; } break; } } catch (Exception e) { System.Diagnostics.Debug.Write("Exception Catch On AgentAsync.ExecueJob"); System.Diagnostics.Debug.WriteLine(String.Format("{0}:{1}", e.GetType(), e.Message)); System.Diagnostics.Debug.WriteLine(e.StackTrace); result.Exception = e; result.Successed = false; } result.Context = job.Content.Context; if (Scheduler.ScheduleState != ScheduleStates.Running) { return; } ResultGot(result); if (EnableResultQueue) { ResultQueue.Enqueue(result); } }