internal NotificationArgs(RequestOutcome outcome, OPSTelegrama response) { if (response != null) { _response = OPSTelegramaFactory.CreateOPSTelegrama(response.FullData); } _outcome = outcome; }
/// <summary> /// Sends a NACK for the received message /// </summary> /// <param name="channel">The channel that received the message</param> private void NackMessage(IChannel channel) { string nackBody = "<ne id=\"0\"/>"; OPSTelegrama t = OPSTelegramaFactory.CreateOPSTelegrama(Correlation.NextId, nackBody); channel.SendMessage(t); FecsMain.Logger.AddLog( string.Format("Message sent to {0} [{1}]", channel.Uri, nackBody), LoggerSeverities.Debug); }
/// <summary> /// Builds a packet containing only the messages that need to be /// retried. The status of the messages is set to Sending /// </summary> /// <param name="msg">The object that receives the packet</param> /// <param name="msgIds">The identifiers of the messages in the packet. Only keys /// are important</param> /// <returns>The number of messages packed</returns> private int PrepareMessagesToSend(out OPSTelegrama msg, out Hashtable msgIds) { msg = null; StringBuilder packet = null; int msgCount = GetMessagesPacket(out packet, out msgIds); Debug.WriteLine("Request - Messages in packet: " + msgCount); if (msgCount > 0 && packet != null) { msg = OPSTelegramaFactory.CreateOPSTelegrama(Correlation.NextId, packet.ToString()); } return(msgCount); }
/// <summary> /// Sends a message immediately and without expecting a response /// </summary> /// <param name="msg">The message to send</param> public void OneWaySend(string msg) { OPSTelegrama packet = OPSTelegramaFactory.CreateOPSTelegrama(Correlation.NextId, msg); try { _channel.SendMessage(packet); } catch (Exception ex) { //Debug.WriteLine("MsgProc OneWaySend error: " + ex.Message); CommMain.Logger.AddLog(ex); } }
/// <summary> /// Sends a NACK for the received message /// </summary> /// <param name="msg">The message to not acknowledge</param> /// <param name="channel">The channel that received the message</param> private void NackMessage(OPSTelegrama msg, IChannel channel) { string[] msgsId = null; if (msg != null) { msgsId = msg.GetMessagesId(); } if (msgsId != null) { for (int i = 0; i < msgsId.Length; i++) { string nackBody = string.Format("<ne id=\"{0}\"/>", msgsId[i]); OPSTelegrama t = OPSTelegramaFactory.CreateOPSTelegrama(Correlation.NextId, nackBody); channel.SendMessage(t); FecsMain.Logger.AddLog( string.Format("Message sent to {0} [{1}]", channel.Uri, msg.XmlData), LoggerSeverities.Debug); } } }
/// <summary> /// Handles received data and manages the eventually fragmented Telegrama /// </summary> /// <param name="rcvData"></param> private void ProcessReceivedData(byte[] rcvData) { int receivedCount = rcvData.Length; int headerSize; System.Configuration.AppSettingsReader appSettings = new System.Configuration.AppSettingsReader(); int iFrameType = (int)appSettings.GetValue("FrameType", typeof(int)); switch (iFrameType) { case OPSTelegramaFactory.FRAMETYPE_NOENCRYPT: headerSize = OPSTelegramaFrame1.Header.ByteSize; break; case OPSTelegramaFactory.FRAMETYPE_ENCRYPT: headerSize = OPSTelegramaFrame2.Header.ByteSize; break; default: headerSize = OPSTelegramaFrame1.Header.ByteSize; break; } if (receivedCount > headerSize) { Debug.WriteLine("Process - Received enough data"); _rcvBufferCount = 0; // At least the header has been received if (_telegram == null) { Debug.WriteLine("Process - Starting new telegram"); // A new telegram must be built _telegram = OPSTelegramaFactory.CreateOPSTelegrama(rcvData); Debug.WriteLine("Process - t: " + _telegram.XmlData); } else { Debug.WriteLine("Process - Still adding data to telegram"); // Still receiving data for the current telegram _telegram.AddData(rcvData); Debug.WriteLine("Process - t: " + _telegram.XmlData); } if (_telegram.Completed) { Debug.WriteLine("Process - Telegram completed"); // Notify the completion of the telegram NotifyReceive(_telegram); // handle eventual extra bytes belonging to a following telegram int extraBytes = _telegram.GetLastExtraBytes(); _telegram = null; if (extraBytes > 0) { Debug.WriteLine("Process - Extra bytes to process"); ProcessExtraBytes(rcvData, receivedCount - extraBytes); } } } else { Debug.WriteLine("Process - Not enough data received"); // It's likely a fragment of a header came at the end of a // previous telegram. Add the partial data to the incoming data // buffer for further processing for (int i = 0; i < receivedCount; i++) { _rcvBuffer[_rcvBufferCount++] = rcvData[i]; } } }
private void OnInQueueReceiveCompleted(FecsBecsHeader header, string body) { if (_channelMgr != null) { string uri = header.ID; IChannel channel = _channelMgr.GetChannel(uri); if (channel == null) { channel = _channelMgr.OpenChannel(uri, ChannelType.BecsQueue); if (channel != null) { MessageProcessorManager.OnNewConnection(channel); } } if (channel != null) { BecsChannel bc = (BecsChannel)channel; StringBuilder packet = new StringBuilder(256); packet.AppendFormat(null, "<{0} {1}=\"{2}\" {3}=\"{4}\">{5}</{0}>", Tags.Packet, Tags.PacketSrcAttr, header.PacketInfo.SourceId, Tags.PacketDateAttr, Dtx.DtxToString(header.PacketInfo.Dtx), body); string xml = packet.ToString(); ILogger localLogger = null; try { Database d = null; CmpUnitsDB cmpUnits = new CmpUnitsDB(); //d = DatabaseFactory.GetDatabase(); localLogger = DatabaseFactory.Logger; if (localLogger != null) { localLogger.AddLog("[OnInQueueReceiveCompleted]: Updating ID: " + header.PacketInfo.SourceId + " IP :" + header.IP, LoggerSeverities.Debug); } if (Convert.ToInt32(header.PacketInfo.SourceId) != -1) { if (cmpUnits.UpdateIP(Convert.ToInt32(header.PacketInfo.SourceId), header.IP) != 1) { if (localLogger != null) { localLogger.AddLog("[OnInQueueReceiveCompleted]: Error Updating IP", LoggerSeverities.Debug); } } else { if (localLogger != null) { localLogger.AddLog("[OnInQueueReceiveCompleted]: Update OK", LoggerSeverities.Debug); } } } } catch { // Do not do nothing?? // Si tenemos un error en realizar un update de la ip // no hacemos nada if (localLogger != null) { localLogger.AddLog("[OnInQueueReceiveCompleted]: Error Updating IP", LoggerSeverities.Debug); } } Interlocked.Increment(ref _packetId); OPSTelegrama opsTel = OPSTelegramaFactory.CreateOPSTelegrama(_packetId, xml); bc.ReceiveMessage(opsTel); } } }
/// <summary> /// Handler for the inbound message queue ReceiveCompleted event /// </summary> /// <param name="header">The header of the incoming message</param> /// <param name="body">The body of the incoming message</param> public void OnQueueReceiveCompleted(BecsFecsHeader header, string body) { /// JLB 2004.07.21 - time sending a message /// Org.Mentalis.Utilities.StopWatch sw = new Org.Mentalis.Utilities.StopWatch(); IChannel channel = _channelMgr.GetChannel(header.Fid); long d = sw.Peek(); if (channel == null) { try { //>> LDRTEST0 //channel = _channelMgr.OpenChannel(header.Fid, ChannelType.FecsQueue); //<< LDRTEST0 } catch (Exception ex) { FecsMain.Logger.AddLog( string.Format("Couldn't open channel to send to {0}.", header.Fid), LoggerSeverities.Error); FecsMain.Logger.AddLog(ex); } if (channel != null) { SetupChannel(channel); } } if (channel != null) { if (d > 100) { FecsMain.Logger.AddLog(string.Format("Delay for GetChannel({1}) {0} ms", d, channel.Uri), LoggerSeverities.Debug); } try { OPSTelegrama t = OPSTelegramaFactory.CreateOPSTelegrama(Correlation.NextId, body); channel.SendMessage(t); FecsMain.Logger.AddLog( string.Format("Message sent to {0} [{1}].", channel.Uri, t.XmlData), LoggerSeverities.Info); } catch (Exception ex) { _channelMgr.CloseChannel(header.Fid); FecsMain.Logger.AddLog( string.Format("Couldn't send to {0}. Closing channel.", header.Fid), LoggerSeverities.Error); FecsMain.Logger.AddLog(ex); } } else { FecsMain.Logger.AddLog(string.Format("Delay for GetChannel({1}) {0} ms", d, header.Fid), LoggerSeverities.Debug); FecsMain.Logger.AddLog( string.Format("Message NOT sent to {0} [{1}].", header.Fid, body), LoggerSeverities.Error); } }