//============================================================== // Copyright (C) 2020 Inc. All rights reserved. // //============================================================== // Create by 种道洋 at 2020/5/27 9:02:43. // Version 1.0 // 种道洋 //============================================================== using Cdy.Tag; using DotNetty.Buffers; using System; using System.Collections.Generic; using System.Text; namespace SpiderDriver { /// /// /// public class DataService: SocketServer { #region ... Variables ... private TagInfoServerProcess mInfoProcess; private RealDataServerProcess mRealProcess; private HisDataServerProcess mHisProcess; //private IByteBuffer mAsyncCalldata; #endregion ...Variables... #region ... Events ... #endregion ...Events... #region ... Constructor... /// /// /// public DataService() { RegistorInit(); } #endregion ...Constructor... #region ... Properties ... /// /// /// public override string Name => "SpiderDriveDataService"; #endregion ...Properties... #region ... Methods ... /// /// /// private void RegistorInit() { this.RegistorFunCallBack(APIConst.TagInfoRequestFun, TagInfoRequest); this.RegistorFunCallBack(APIConst.RealValueFun, RealDataRequest); this.RegistorFunCallBack(APIConst.HisValueFun, HisDataRequest); } /// /// /// /// protected override void OnClientConnected(string id) { mRealProcess.OnClientConnected(id); mInfoProcess.OnClientConnected(id); mHisProcess.OnClientConnected(id); base.OnClientConnected(id); } /// /// /// /// protected override void OnClientDisConnected(string id) { mRealProcess.OnClientDisconnected(id); mInfoProcess.OnClientDisconnected(id); mHisProcess.OnClientDisconnected(id); base.OnClientDisConnected(id); } /// /// /// public void PushRealDatatoClient(string clientId, byte[] value) { this.SendData(clientId, APIConst.PushDataChangedFun, value, value.Length); } /// /// /// /// /// public void PushRealDatatoClient(string clientId, IByteBuffer value) { this.SendData(clientId, value); } /// /// /// /// /// /// public void AsyncCallback(string clientId, byte fun, byte[] value, int len) { this.SendData(clientId, fun, value, len); } /// /// /// /// /// public void AsyncCallback(string clientId, IByteBuffer data) { this.SendData(clientId, data); } /// /// /// /// /// /// /// public void AsyncCallback(string clientId, byte fun, IntPtr value, int len) { this.SendData(clientId, fun, value, len); } ///// ///// ///// ///// //private IByteBuffer GetAsyncData() //{ // mAsyncCalldata = BufferManager.Manager.Allocate(APIConst.AysncReturn, 4); // mAsyncCalldata.WriteInt(0); // return mAsyncCalldata; //} /// /// /// private IByteBuffer TagInfoRequest(string clientId, IByteBuffer memory) { mInfoProcess?.ProcessData(clientId, memory); return null; } /// /// /// /// /// /// private IByteBuffer RealDataRequest(string clientId, IByteBuffer memory) { this.mRealProcess?.ProcessData(clientId, memory); return null; } /// /// /// /// /// /// private IByteBuffer HisDataRequest(string clientid,IByteBuffer memory) { this.mHisProcess?.ProcessData(clientid, memory); return null; } /// /// /// /// protected override void StartInner(int port) { mRealProcess = new RealDataServerProcess() { Parent = this }; mRealProcess.Init(); mInfoProcess = new TagInfoServerProcess() { Parent = this }; mHisProcess = new HisDataServerProcess() { Parent = this }; mRealProcess.Start(); mInfoProcess.Start(); mHisProcess.Start(); base.StartInner(port); } /// /// /// public override void Stop() { base.Stop(); if (mRealProcess != null) { mRealProcess.Stop(); mRealProcess.Dispose(); mRealProcess = null; } if (mInfoProcess != null) { mInfoProcess.Stop(); mInfoProcess.Dispose(); mInfoProcess = null; } if (mHisProcess != null) { mHisProcess.Stop(); mHisProcess.Dispose(); mHisProcess = null; } } #endregion ...Methods... #region ... Interfaces ... #endregion ...Interfaces... } }