public object RemoteInvoke(string receiver, string serviceObjectName, MethodBase method, params object[] parameters) { if (receiver == _communicationProxy.GetName()) { return(NativeInvoke(serviceObjectName, method, parameters)); } RemoteMethodInvokeArgument args = new RemoteMethodInvokeArgument(serviceObjectName, method, parameters); BinaryFormatter formatter = new BinaryFormatter(); using (MemoryStream outStream = new MemoryStream()) { CommandContext cmdContext = new CommandContext(); _communicationProxy.GetName(); formatter.Serialize(outStream, args); cmdContext.iCommandId = COMMUNICATION_ID; cmdContext.sReceiver = receiver; cmdContext.sSender = _communicationProxy.GetName(); cmdContext.sSerializeObject = outStream.GetBuffer(); cmdContext.iWaitTime = WAIT_TIME; ISyncResult result = _communicationProxy.SyncSendCommand(cmdContext); if (result.GetCallResult() != 0) { throw new CommunicationException(result.GetCallResult(), "fail to sync send command to " + receiver); } using (MemoryStream replyStream = new MemoryStream(result.GetSerializedObject())) { return(formatter.Deserialize(replyStream)); } } }//EndMethod
private DicomAttributeCollection _dataHead;//session模块的tag应该需要申请,防止tag号相同 /// <summary> /// send command to session to set the dataHead /// </summary> /// <returns></returns> public bool Commit() { byte[] aa = SessionUtility.SerializeDataHead(_dataHead); byte[] buf = SessionUtility.RequestCommandProtoBuffer(SessionManagerFuncID.StoreSessionDataID, new ByteString[] { ByteString.CopyFrom(aa) }); CommandContext context = SessionUtility.CreateCommandContext(CommunicationNode.SystemSessionManager, CommunicationCommandID.XA_SYSTEMSESSION_DATA_CACHE, buf); ISyncResult result = _systemCommunicationProxy.SyncSendCommand(context); return((0 == result.GetCallResult()) ? true : false); }
/// <summary> /// send command to sessionmanager to get the dataHead /// </summary> /// <returns></returns> public bool Refresh() { byte[] buf = SessionUtility.RequestCommandProtoBuffer(SessionManagerFuncID.QuerySessionDataID, new ByteString[] { }); CommandContext context = SessionUtility.CreateCommandContext(CommunicationNode.SystemSessionManager, CommunicationCommandID.XA_SYSTEMSESSION_DATA_CACHE, buf); ISyncResult result = _systemCommunicationProxy.SyncSendCommand(context); CLRLogger.GetInstance().LogDevInfo(string.Format("Commit result:{0},proxyName:{1}", result.GetCallResult().ToString(), _systemCommunicationProxy.GetName())); _dataHead = SessionUtility.DeserializeDataHead(result.GetSerializedObject()); return((0 == result.GetCallResult()) ? true : false); }
public void Commit() { byte[] serilizedDataHead = SessionUtility.SerializeDataHead(_dataHead); byte[] buf = SessionUtility.RequestCommandProtoBuffer(SessionManagerFuncID.UpdateProcessStatusID, new ByteString[] { ByteString.CopyFromUtf8(_proxyName), ByteString.CopyFrom(serilizedDataHead) }); CommandContext context = SessionUtility.CreateCommandContext(CommunicationNode.SystemSessionManager, CommunicationCommandID.XA_SYSTEMSESSION_PROCESS_CACHE, buf); ISyncResult result = _processCommunicationProxy.SyncSendCommand(context); if (result.GetCallResult() != 0) { CLRLogger.GetInstance().LogDevError(string.Format("ProcessCacheProxy Commit failed, proxyName is {0},GetCallResult is {1}.", _proxyName, result.GetCallResult())); } }
/// <summary> /// Get datahead form session manager,this datahead is process's status /// </summary> public bool Refresh() { byte[] buf = SessionUtility.RequestCommandProtoBuffer(SessionManagerFuncID.QueryProcessStatusID, new ByteString[] { ByteString.CopyFromUtf8(_proxyName) }); CommandContext context = SessionUtility.CreateCommandContext(CommunicationNode.SystemSessionManager, CommunicationCommandID.XA_SYSTEMSESSION_PROCESS_CACHE, buf); ISyncResult result = _processCommunicationProxy.SyncSendCommand(context); if (0 == result.GetCallResult()) { _dataHead = DicomAttributeCollection.Deserialize(result.GetSerializedObject()); return(true); } CLRLogger.GetInstance().LogDevError(string.Format("ProcessCacheProxy Refresh failed, proxyName is {0},GetCallResult is {1}.", _proxyName, result.GetCallResult())); return(false); }
public byte[] SyncSendCommand(int cmdID, string receiver, byte[] content, uint waitTime = 0, string contentAsString = null) { CommandContext cmdContext = new CommandContext(); cmdContext.iCommandId = cmdID; cmdContext.sReceiver = receiver; cmdContext.sSerializeObject = content; cmdContext.sStringObject = contentAsString; if (waitTime != 0) { cmdContext.iWaitTime = waitTime; } ISyncResult result = _communicationProxy.SyncSendCommand(cmdContext); if (result.GetCallResult() != NO_ERROR) { string msg = string.Format("{0} fails to sync send command with command id = {1}, errorCode = {2}, content = {3}", _communicationProxy.GetName(), cmdID, result.GetCallResult(), content); throw new CommunicationException(result.GetCallResult(), msg); } return(result.GetSerializedObject()); }
/// <summary> /// Call this method send command to other containees. /// </summary> /// <returns>null or -1: send command failed.Otherwise, it is a ISyncResult object that included detail info.</returns> public static object SendCommand(ICommunicationProxy commProxy, CommandContext cmdCtx, CommandType cmdType) { GlobalDefinition.LoggerWrapper.LogDevInfo("enter ContaineeUtility.SendCommand"); if (null == commProxy) { GlobalDefinition.LoggerWrapper.LogDevError("Containee CommunicationProxy is null."); return(null); } try { if (null != cmdCtx) { string content = String.Format("CommandID: {0} ||| Receiver: {1} ||| Sender: {2}", cmdCtx.iCommandId.ToString(), //cmdCtx.sStringObject, cmdCtx.sReceiver, cmdCtx.sSender); GlobalDefinition.LoggerWrapper.LogDevInfo(content); ISyncResult pResult = null; int result = -1; switch (cmdType) { case CommandType.AsyncCommand: GlobalDefinition.LoggerWrapper.LogDevInfo("case CommandType.AsyncCommand"); result = commProxy.AsyncSendCommand(cmdCtx); break; case CommandType.SyncCommand: GlobalDefinition.LoggerWrapper.LogDevInfo("case CommandType.SyncCommand"); pResult = commProxy.SyncSendCommand(cmdCtx); result = pResult.GetCallResult(); break; default: GlobalDefinition.LoggerWrapper.LogDevError("case default"); result = commProxy.AsyncSendCommand(cmdCtx); break; } if (result == 0) { GlobalDefinition.LoggerWrapper.LogDevInfo("Send command " + cmdCtx.iCommandId.ToString() + " to " + cmdCtx.sReceiver + " successfully."); if (cmdType == CommandType.SyncCommand) { return(pResult); } else { return(result); } } else { ContaineeUtility._feCmdCallbackList.Remove(cmdCtx.pCommandCallback as FECommandCallbackHandler); GlobalDefinition.LoggerWrapper.LogDevError( string.Format("Send command {0} to {1} failed. Result = {2}", cmdCtx.iCommandId.ToString(), cmdCtx.sReceiver, result.ToString())); return(null); } } else { GlobalDefinition.LoggerWrapper.LogDevError("Command param is error."); return(null); } } catch (Exception ex) { GlobalDefinition.LoggerWrapper.LogDevError(ex.Message); GlobalDefinition.LoggerWrapper.LogDevError(ex.StackTrace); } return(null); }