internal static void SetResponseBuffer(TheRequestData pRequestData, TheChannelInfo pChannelInfo, bool pSendPulse, string NopTopic, Guid owner, string pRefreshToken) { if (string.IsNullOrEmpty(NopTopic)) { TheQueuedSender tQ = null; if (pChannelInfo != null && pChannelInfo.cdeMID != Guid.Empty) //Send to Device First { tQ = TheQueuedSenderRegistry.GetSenderByGuid(pChannelInfo.cdeMID); } if (tQ != null) { if (pRequestData.WebSocket != null) { if (tQ.GetQueLength() == 0) { tQ.SendPickupMessage(); } return; } tQ.GetNextBackChannelBuffer(pRequestData); } } if (string.IsNullOrEmpty(NopTopic) && pRequestData.WebSocket != null) { return; //NEW:3.084 && !pSendPulse removed NEW:V3B3:2014-7-22 removed && pRequestData.ResponseBuffer != null } if (pRequestData.ResponseBuffer == null && pChannelInfo != null && (pSendPulse || (pChannelInfo.cdeMID != Guid.Empty || TheQueuedSenderRegistry.IsNodeIdInSenderList(pChannelInfo.cdeMID)))) { TheDeviceMessage tDev = new TheDeviceMessage { CNT = 0 }; //tDev.MET = 0; if (!string.IsNullOrEmpty(NopTopic)) { tDev.MSG = new TSM(); //Can be set without ORG and SID if (owner != Guid.Empty) { tDev.MSG.OWN = owner.ToString(); } if (NopTopic == "CDE_WSINIT") { NopTopic = TheCommCore.SetConnectingBufferStr(pChannelInfo, null); } } if (pChannelInfo.SenderType != cdeSenderType.CDE_JAVAJASON) //4.209: No longer sending SID to Browser; { if (TheBaseAssets.MyServiceHostInfo.EnableFastSecurity) { tDev.SID = pRequestData.SessionState.SScopeID; //SECURITY: All responses will have same Scrambled ScopeID - but ok because this is init telegram or HB } else { tDev.SID = TheBaseAssets.MyScopeManager.GetScrambledScopeID(pRequestData.SessionState.SScopeID, false); //GRSI: high frequency } } else { if (!string.IsNullOrEmpty(pRefreshToken)) { tDev.SID = pRefreshToken; } } tDev.FID = pRequestData.SessionState.GetNextSerial().ToString(); if (TheCommonUtils.IsDeviceSenderType(pChannelInfo.SenderType)) //IDST-OK: Must create RSA for Devices { TheCommonUtils.CreateRSAKeys(pRequestData.SessionState); tDev.RSA = pRequestData.SessionState.RSAPublic; } tDev.NPA = TheBaseAssets.MyScopeManager.GetISBPath(TheBaseAssets.MyServiceHostInfo.RootDir, pChannelInfo.SenderType, TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.SenderType, pRequestData.SessionState.FID, pRequestData.SessionState.cdeMID, pRequestData.WebSocket != null); tDev.CNT = pSendPulse ? 1 : 0; tDev.TOP = NopTopic; tDev.DID = pChannelInfo.SenderType == cdeSenderType.CDE_JAVAJASON ? pChannelInfo.cdeMID.ToString() : TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID.ToString(); //There will be only one Message here - single poke or Mini Command or NOP Pickup List <TheDeviceMessage> tDevList = new List <TheDeviceMessage> { tDev }; if (pChannelInfo.SenderType == cdeSenderType.CDE_JAVAJASON || TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.SenderType == cdeSenderType.CDE_MINI || pChannelInfo.SenderType == cdeSenderType.CDE_MINI || pRequestData.WebSocket != null) { pRequestData.ResponseBuffer = TheCommonUtils.CUTF8String2Array(TheCommonUtils.SerializeObjectToJSONString(tDevList)); pRequestData.ResponseMimeType = "application/json"; } else { pRequestData.ResponseBuffer = TheCommonUtils.cdeCompressString(TheCommonUtils.SerializeObjectToJSONString(tDevList)); pRequestData.ResponseMimeType = "application/x-gzip"; } } if (pRequestData.ResponseBuffer == null && pChannelInfo != null && pChannelInfo.cdeMID != Guid.Empty) { TheBaseAssets.MySYSLOG.WriteToLog(290, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM("CoreComm", $"Nothing to Send Back to {pChannelInfo?.ToMLString()}", eMsgLevel.l7_HostDebugMessage)); } }