/// <summary> Initialize the protocol handler for a zone</summary> public virtual void Open(ZoneImpl zone) { fZone = zone; fKeepAliveOnSend = ((HttpProperties)fTransport.Properties).KeepAliveOnSend; try { // Ensure the ZIS URL is http/https fZoneUrl = fZone.ZoneUrl; string check = fZoneUrl.Scheme.ToLower(); if (!check.Equals("http") && !check.Equals("https")) { throw new AdkException ("HttpProtocolHandler cannot handle URL: " + fZone.ZoneUrl, fZone); } // Prepare headers later used to send messages fHttpUserAgent = fZone.Agent.Id + " (Adk/" + Adk.AdkVersion + ")"; } catch (Exception thr) { throw new AdkException ("HttpProtocolHandler could not parse URL \"" + fZone.ZoneUrl + "\": " + thr, fZone); } }
public IProtocolHandler Activate( ZoneImpl zone ) { // Activate the transport used by the zone ITransport trans = GetTransport( zone.Properties.TransportProtocol ); trans.Activate( zone ); return trans.CreateProtocolHandler( zone.Properties.MessagingMode ); }
/// <summary> /// Commits the writing of all objects and sends the objects /// </summary> public override void Commit() { try { if (fDeferResponses) { Abort(); } else { // If no objects or SIF_Errors have been written to the stream, we still // need to return an empty SIF_Response to the ZIS. if (fCurrentOutputStream == null) { try { NewPacket(); Close(); } catch (IOException ioe) { throw new AdkException ( "Could not commit the stream because of an IO error writing an empty SIF_Response packet: " + ioe, fZone); } } String responseFileName = ResponseDelivery.SerializeResponseHeaderFileName(fDestId, fReqId, fMorePackets); // Write out "destId.requestId." file to signal the Publisher has finished // writing all responses successfully. This file will hang around until // all "requestId.{packet}.pkt" files have been sent to the ZIS by the Adk, // a process that could occur over several agent sessions if the agent // is abruptly terminated. // String fileName = fWorkDir + Path.DirectorySeparatorChar + responseFileName; try { FileInfo publisherFile = new FileInfo(fileName); using (Stream publisherFileStream = publisherFile.Create()) { publisherFileStream.Close(); } } catch (IOException ioe) { fZone.Log.Warn("Unable to create SIF_Response header file: " + fileName + ". " + ioe.Message, ioe); } OnCommitted(); } } finally { fZone = null; } }
/** * SIF_Unregister */ public SIF_Ack SifUnregister(IZone zone) { ZoneImpl AdkZone = (ZoneImpl)zone; SifVersion effectiveZISVersion = AdkZone.HighestEffectiveZISVersion; SifMessagePayload message = new SIF_Unregister(effectiveZISVersion); return(AdkZone.Dispatcher.send(message)); }
public IProtocolHandler Activate(ZoneImpl zone) { // Activate the transport used by the zone ITransport trans = GetTransport(zone.Properties.TransportProtocol); trans.Activate(zone); return(trans.CreateProtocolHandler(zone.Properties.MessagingMode)); }
/// <summary> Constructor. /// /// </summary> /// <param name="zone">The zone /// /// </param> /// <param name="source">Identifies the source of pending SIF_Response packets to /// be processed: <c>RSPTYPE_GENERIC</c> to process files in the default /// 'responses' directory, or <c>RSPTYPE_SIFREPORTOBJECT</c> to process /// SIF_ReportObject files in the 'responses/reports' directory /// </param> public ResponseDelivery(IZone zone, ResponseDeliveryType source) { fZone = (ZoneImpl)zone; fParser = SifParser.NewInstance(); fSrc = source; fWorkDir = GetSourceDirectory(source, fZone); }
private SIF_Ack SifSystemControl(SifElement command, ZoneImpl zone) { SIF_SystemControl msg = new SIF_SystemControl(zone.HighestEffectiveZISVersion); SIF_SystemControlData cmd = new SIF_SystemControlData(); cmd.AddChild(command); msg.SIF_SystemControlData = cmd; return(zone.Dispatcher.send(msg)); }
/// <summary> /// Aborts the current write, closes the string, and deletes all files created during this operations /// </summary> public override void Abort() { Close(); string filter = fDestId + "." + fReqId + "*"; DirectoryInfo dir = new DirectoryInfo(fWorkDir); foreach (FileInfo file in dir.GetFiles(filter)) { file.Delete(); } fZone = null; }
/** * SIF_Unsubscribe */ public SIF_Ack SifUnsubscribe(IZone zone, String[] objectType) { ZoneImpl AdkZone = (ZoneImpl)zone; SIF_Unsubscribe msg = new SIF_Unsubscribe(AdkZone.HighestEffectiveZISVersion); for (int i = 0; i < objectType.Length; i++) { SIF_Object obj = new SIF_Object(); obj.ObjectName = objectType[i]; msg.AddSIF_Object(obj); } return(AdkZone.Dispatcher.send(msg)); }
/// <summary> Initialize the output stream. This method must be called after creating /// a new instance of this class and before writing any SIFDataObjects to /// the stream. /// </summary> /// <param name="zone">The Zone associated with messages that will be written to the stream /// </param> /// <param name="queryRestrictions">The fields that should be returned according to the Query /// that was specified in the SIF_Request message /// </param> /// <param name="requestSourceId">The SourceId of the associated SIF_Request message /// </param> /// <param name="requestMsgId">The MsgId of the associated SIF_Request message /// </param> /// <param name="requestSIFVersion">The version of the SIF_Message envelope of the /// SIF_Request message (if specified and different than the SIF_Message /// version, the SIF_Request/SIF_Version element takes precedence). /// SIF_Responses will be encapsulated in a message envelope matching /// this version and SifDataObject contents will be rendered in this /// version /// </param> /// <param name="maxSize">The maximum size of rendered SifDataObject that will be /// accepted by this stream. If a SifDataObject is written to the stream /// and its size exceeds this value after rendering the object to an XML /// stream, an ObjectTooLargeException will be thrown by the <i>write</i> /// method /// </param> public override void Initialize( IZone zone, IElementDef[] queryRestrictions, String requestSourceId, String requestMsgId, SifVersion requestSIFVersion, int maxSize) { fZone = (ZoneImpl)zone; fQueryRestrictions = queryRestrictions; fReqId = requestMsgId; fDestId = requestSourceId; fMaxSize = maxSize; fCurPacket = 0; fRenderAsVersion = requestSIFVersion; // // Messages written to this stream are stored in the directory // "%adk.home%/work/%zoneId%_%zoneHost%/responses". One or more files // are written to this directory, where each file has the name // "destId.requestId.{packet}.pkt". As messages are written to the // stream, the maxSize property is checked to determine if the size of // the current file will be larger than the maxSize. If so, the file is // closed and the packet number incremented. A new file is then created // for the message and all subsequent messages until maxSize is again // exceeded. // Ensure work directory exists fWorkDir = ResponseDelivery.GetSourceDirectory(DeliveryType, zone); DirectoryInfo dir = new DirectoryInfo(fWorkDir); if (!dir.Exists) { dir.Create(); } // Get the size of the SIF_Message envelope to determine the actual // packet size we're producing fEnvSize = CalcEnvelopeSize(fZone); }
/// <summary> /// Attempts to parse attributes out of the source message enough to make a valid /// SIF_Ack with a SIF_Error. This is useful in conditions where the source message cannot /// be parsed by the ADK /// </summary> /// <param name="sourceMessage"> The original message as a string</param> /// <param name="error">The error to place in the SIF_Ack/SIF_Error</param> /// <param name="zone">The zone associated with this message</param> /// <returns></returns> /// <exception cref="AdkMessagingException"></exception> public static SIF_Ack ackError(String sourceMessage, SifException error, ZoneImpl zone) { SifMessageInfo parsed = null; try { StringReader reader = new StringReader(sourceMessage); parsed = SifMessageInfo.Parse(reader, false, zone); reader.Close(); } catch (Exception e) { zone.Log.Error(e, e); } SIF_Ack errorAck = new SIF_Ack(zone.HighestEffectiveZISVersion); if (parsed != null) { // Set SIFVersion, OriginalSourceId, and OriginalMsgId; if (parsed.SifVersion != null) { errorAck.SifVersion = parsed.SifVersion; } errorAck.SIF_OriginalMsgId = parsed.GetAttribute("SIF_MsgId"); errorAck.SIF_OriginalSourceId = parsed.GetAttribute("SIF_SourceId"); } SetRequiredAckValues(errorAck); SIF_Error newErr = new SIF_Error(); newErr.SIF_Category = (int)error.ErrorCategory; newErr.SIF_Code = error.ErrorCode; newErr.SIF_Desc = error.ErrorDesc; newErr.SIF_ExtendedDesc = error.ErrorExtDesc; errorAck.SIF_Error = newErr; return(errorAck); }
/// <summary> /// Attempts to parse attributes out of the source message enough to make a valid /// SIF_Ack with a SIF_Error. This is useful in conditions where the source message cannot /// be parsed by the ADK /// </summary> /// <param name="sourceMessage"> The original message as a string</param> /// <param name="error">The error to place in the SIF_Ack/SIF_Error</param> /// <param name="zone">The zone associated with this message</param> /// <returns></returns> /// <exception cref="AdkMessagingException"></exception> public static SIF_Ack ackError(String sourceMessage, SifException error, ZoneImpl zone) { SifMessageInfo parsed = null; try { StringReader reader = new StringReader(sourceMessage); parsed = SifMessageInfo.Parse(reader, false, zone); reader.Close(); } catch (Exception e) { zone.Log.Error(e, e); } SIF_Ack errorAck = new SIF_Ack(zone.HighestEffectiveZISVersion ); if (parsed != null) { // Set SIFVersion, OriginalSourceId, and OriginalMsgId; if (parsed.SifVersion != null) { errorAck.SifVersion = parsed.SifVersion; } errorAck.SIF_OriginalMsgId = parsed.GetAttribute("SIF_MsgId"); errorAck.SIF_OriginalSourceId = parsed.GetAttribute("SIF_SourceId"); } SetRequiredAckValues(errorAck); SIF_Error newErr = new SIF_Error(); newErr.SIF_Category = (int)error.ErrorCategory; newErr.SIF_Code = error.ErrorCode; newErr.SIF_Desc = error.ErrorDesc; newErr.SIF_ExtendedDesc = error.ErrorExtDesc; errorAck.SIF_Error = newErr; return errorAck; }
/// <summary> Calculate the size of a SIF_Response minus the SIF_ObjectData content.</summary> protected virtual long CalcEnvelopeSize(ZoneImpl zone) { long size = 400; try { SIF_Response rsp = new SIF_Response(); rsp.SIF_MorePackets = "Yes"; rsp.SIF_RequestMsgId = fReqId; rsp.SIF_PacketNumber = 100000000; SIF_ObjectData data = new SIF_ObjectData(); data.TextValue = " "; rsp.SIF_ObjectData = data; SIF_Header hdr = rsp.Header; hdr.SIF_Timestamp = DateTime.Now; hdr.SIF_MsgId = "012345678901234567890123456789012"; hdr.SIF_SourceId = zone.Agent.Id; hdr.SIF_Security = zone.Dispatcher.secureChannel(); hdr.SIF_DestinationId = fDestId; using (MemoryStream buffer = new MemoryStream()) { SifWriter writer = new SifWriter(buffer); writer.Write(rsp); writer.Flush(); size = buffer.Length + 10; writer.Close(); buffer.Close(); } } catch (Exception ex) { zone.Log.Warn("Error calculating packet size: " + ex, ex); } return(size); }
/// <summary> /// Aborts the current write, closes the string, and deletes all files created during this operations /// </summary> public override void Abort() { Close(); string filter = fDestId + "." + fReqId + "*"; DirectoryInfo dir = new DirectoryInfo( fWorkDir ); foreach ( FileInfo file in dir.GetFiles( filter ) ) { file.Delete(); } fZone = null; }
public void Open( ZoneImpl zone ) { zone.Log.Info( "TestProtocolHandler openned" ); fZone = zone; }
/// <summary> Initialize the protocol handler for a zone</summary> public virtual void Open( ZoneImpl zone ) { fZone = zone; fKeepAliveOnSend = ((HttpProperties) fTransport.Properties).KeepAliveOnSend; try { // Ensure the ZIS URL is http/https fZoneUrl = fZone.ZoneUrl; string check = fZoneUrl.Scheme.ToLower(); if ( !check.Equals( "http" ) && !check.Equals( "https" ) ) { throw new AdkException ( "HttpProtocolHandler cannot handle URL: " + fZone.ZoneUrl, fZone ); } // Prepare headers later used to send messages fHttpUserAgent = fZone.Agent.Id + " (Adk/" + Adk.AdkVersion + ")"; } catch ( Exception thr ) { throw new AdkException ( "HttpProtocolHandler could not parse URL \"" + fZone.ZoneUrl + "\": " + thr, fZone ); } }
/// <summary> /// Returns true if the protocol and underlying transport are currently active /// for this zone /// </summary> /// <param name="zone"></param> /// <returns>True if the protocol handler and transport are active</returns> public override bool IsActive( ZoneImpl zone ) { return fTransport.IsActive( zone ) && fServer != null && fServer.IsStarted; }
public void Close( IZone zone ) { zone.Log.Info( "TestProtocolHandler closed" ); fZone = null; }
private void AssertExceptionHandling(ErrorMessageHandler handler, SifMessagePayload payload, ZoneImpl zone, Type expectedExceptionType) { Exception exc = null; try { assertNormalHandling(handler, payload, zone); } catch (Exception ex) { exc = ex; Assert.IsTrue(handler.wasCalled(), "Handler was not called"); AdkMessagingException adkme = ex as AdkMessagingException; Assert.IsNotNull(adkme, "Expected an ADKMessagingException, but was " + ex.GetType().Name + ":" + ex.ToString()); Exception source = adkme; Exception innerEx = null; while( source.InnerException != null ) { innerEx = source.InnerException; source = innerEx; } Assert.IsNotNull(innerEx, "AdkMessaginException was thrown but inner exception was not set"); if (innerEx.GetType() != expectedExceptionType) { Assert.Fail("Exception thrown was not a " + expectedExceptionType.Name + ", but was " + innerEx.GetType().Name + ":" + innerEx.ToString()); } } Assert.IsNotNull(exc, "An exception was not thrown by the handler"); AssertThreadIsOK(); }
private void AssertRetryHandling(ErrorMessageHandler handler, SifMessagePayload payload, ZoneImpl zone) { try { assertNormalHandling(handler, payload, zone); } catch (SifException ex) { Assert.IsTrue(handler.wasCalled(), "Handler was not called"); Assert.AreEqual(SifErrorCategoryCode.Transport, ex.ErrorCategory, "SIF Error category should be 10: " + ex.Message); } Assert.IsTrue(handler.wasCalled(), "Handler was not called"); AssertThreadIsOK(); }
/// <summary> /// Returns true if the protocol and underlying transport are currently active /// for this zone /// </summary> /// <param name="zone"></param> /// <returns>True if the protocol handler and transport are active</returns> public override bool IsActive( ZoneImpl zone ) { return fRunning; }
/// <summary> /// Returns true if the protocol and underlying transport are currently active /// for this zone /// </summary> /// <param name="zone"></param> /// <returns>True if the protocol handler and transport are active</returns> public abstract bool IsActive(ZoneImpl zone);
private void assertNormalHandling(ErrorMessageHandler handler, SifMessagePayload payload, ZoneImpl zone) { MessageDispatcher testDispatcher = new MessageDispatcher(zone); int result = testDispatcher.dispatch(payload); Assert.IsTrue(handler.wasCalled(), "Handler was not called"); Assert.AreEqual(1, result, "Result code should always be 1 because this version does not support SMB"); }
private void AssertExceptionHandling(ErrorMessageHandler handler, SifMessagePayload payload, ZoneImpl zone, Type expectedExceptionType) { Exception exc = null; try { assertNormalHandling(handler, payload, zone); } catch (Exception ex) { exc = ex; Assert.IsTrue(handler.wasCalled(), "Handler was not called"); AdkMessagingException adkme = ex as AdkMessagingException; Assert.IsNotNull(adkme, "Expected an ADKMessagingException, but was " + ex.GetType().Name + ":" + ex.ToString()); Exception source = adkme; Exception innerEx = null; while (source.InnerException != null) { innerEx = source.InnerException; source = innerEx; } Assert.IsNotNull(innerEx, "AdkMessaginException was thrown but inner exception was not set"); if (innerEx.GetType() != expectedExceptionType) { Assert.Fail("Exception thrown was not a " + expectedExceptionType.Name + ", but was " + innerEx.GetType().Name + ":" + innerEx.ToString()); } } Assert.IsNotNull(exc, "An exception was not thrown by the handler"); AssertThreadIsOK(); }
/// <summary> Find the MessagingListenerImpl objects to notify when a message is /// received or sent on this zone. /// </summary> internal static ICollection<IMessagingListener> GetMessagingListeners(ZoneImpl zone) { List<IMessagingListener> listeners = new List<IMessagingListener>(); // Contribute the Zone's listeners to the group listeners.AddRange(zone.fMessagingListeners); listeners.AddRange(zone.Agent.MessagingListeners); return listeners; }
/// <summary> Wakes up the thread, dispatches the event to Subscriber.onEvent, /// then returns the appropriate SIF_Ack code. If onEvent() completes /// processing without invoking SMB, this method returns once onEvent() /// is finished. If, however, onEvent() invokes SMB by instantiating a /// TrackQueryResults object, this method returns at the time the /// TrackQueryResults constructor is called. /// </summary> internal virtual int dispatch(ISubscriber target, Event evnt, ZoneImpl zone, ITopic topic, IMessageInfo msgInfo) { _target = target; _event = evnt; _zone = zone; _topic = topic; _msgInfo = msgInfo; // TODO: Implement SMB //_smb = null; _state._ack = -1; _state._exception = null; this.Run(); return waitForAckCode(); }
/// <summary> Constructs a MessageDispatcher for a zone</summary> public MessageDispatcher(ZoneImpl zone) { fRequestCache = RequestCache.GetInstance(zone.Agent); fZone = zone; fQueue = zone.fQueue; if (fQueue != null) { if (!fQueue.Ready) { throw new AdkQueueException ( "Agent Queue is not ready for agent \"" + zone.Agent.Id + "\" zone \"" + zone.ZoneId + "\"", fZone); } Thread thread = new Thread(new ThreadStart(this.Run)); thread.Name = zone.Agent.Id + "@" + zone.ZoneId + ".MessageDispatcher"; thread.Start(); } fSourceId = zone.Agent.Id; fKeepMsg = zone.Agent.Properties.KeepMessageContent; fAckAckOnPull = zone.Agent.Properties.PullAckAck; try { fParser = SifParser.NewInstance(); } catch (AdkException adke) { throw new ApplicationException(adke.ToString()); } }
/// <summary> /// Commits the writing of all objects and sends the objects /// </summary> public override void Commit() { try { if ( fDeferResponses ) { Abort(); } else { // If no objects or SIF_Errors have been written to the stream, we still // need to return an empty SIF_Response to the ZIS. if ( fCurrentOutputStream == null ) { try { NewPacket(); Close(); } catch ( IOException ioe ) { throw new AdkException ( "Could not commit the stream because of an IO error writing an empty SIF_Response packet: " + ioe, fZone ); } } String responseFileName = ResponseDelivery.SerializeResponseHeaderFileName(fDestId, fReqId, fMorePackets); // Write out "destId.requestId." file to signal the Publisher has finished // writing all responses successfully. This file will hang around until // all "requestId.{packet}.pkt" files have been sent to the ZIS by the Adk, // a process that could occur over several agent sessions if the agent // is abruptly terminated. // String fileName = fWorkDir + Path.DirectorySeparatorChar + responseFileName; try { FileInfo publisherFile = new FileInfo( fileName ); using ( Stream publisherFileStream = publisherFile.Create() ) { publisherFileStream.Close(); } } catch ( IOException ioe ) { fZone.Log.Warn("Unable to create SIF_Response header file: " + fileName + ". " + ioe.Message, ioe); } OnCommitted(); } } finally { fZone = null; } }
/// <summary> /// Returns true if the protocol and underlying transport are currently active /// for this zone /// </summary> /// <param name="zone"></param> /// <returns>True if the protocol handler and transport are active</returns> public abstract bool IsActive( ZoneImpl zone );
/// <summary> Initialize the output stream. This method must be called after creating /// a new instance of this class and before writing any SIFDataObjects to /// the stream. /// </summary> /// <param name="zone">The Zone associated with messages that will be written to the stream /// </param> /// <param name="queryRestrictions">The fields that should be returned according to the Query /// that was specified in the SIF_Request message /// </param> /// <param name="requestSourceId">The SourceId of the associated SIF_Request message /// </param> /// <param name="requestMsgId">The MsgId of the associated SIF_Request message /// </param> /// <param name="requestSIFVersion">The version of the SIF_Message envelope of the /// SIF_Request message (if specified and different than the SIF_Message /// version, the SIF_Request/SIF_Version element takes precedence). /// SIF_Responses will be encapsulated in a message envelope matching /// this version and SifDataObject contents will be rendered in this /// version /// </param> /// <param name="maxSize">The maximum size of rendered SifDataObject that will be /// accepted by this stream. If a SifDataObject is written to the stream /// and its size exceeds this value after rendering the object to an XML /// stream, an ObjectTooLargeException will be thrown by the <i>write</i> /// method /// </param> public override void Initialize( IZone zone, IElementDef[] queryRestrictions, String requestSourceId, String requestMsgId, SifVersion requestSIFVersion, int maxSize ) { fZone = (ZoneImpl) zone; fQueryRestrictions = queryRestrictions; fReqId = requestMsgId; fDestId = requestSourceId; fMaxSize = maxSize; fCurPacket = 0; fRenderAsVersion = requestSIFVersion; // // Messages written to this stream are stored in the directory // "%adk.home%/work/%zoneId%_%zoneHost%/responses". One or more files // are written to this directory, where each file has the name // "destId.requestId.{packet}.pkt". As messages are written to the // stream, the maxSize property is checked to determine if the size of // the current file will be larger than the maxSize. If so, the file is // closed and the packet number incremented. A new file is then created // for the message and all subsequent messages until maxSize is again // exceeded. // Ensure work directory exists fWorkDir = ResponseDelivery.GetSourceDirectory( DeliveryType, zone ); DirectoryInfo dir = new DirectoryInfo( fWorkDir ); if ( !dir.Exists ) { dir.Create(); } // Get the size of the SIF_Message envelope to determine the actual // packet size we're producing fEnvSize = CalcEnvelopeSize( fZone ); }
/// <summary> /// Returns true if the protocol and underlying transport are currently active /// for this zone /// </summary> /// <param name="zone"></param> /// <returns>True if the protocol handler and transport are active</returns> public override bool IsActive(ZoneImpl zone) { return(fRunning); }
private void assertNormalHandling(ErrorMessageHandler handler, SifMessagePayload payload, ZoneImpl zone) { MessageDispatcher testDispatcher = new MessageDispatcher(zone); int result = testDispatcher.dispatch(payload); Assert.IsTrue(handler.wasCalled(), "Handler was not called"); Assert.AreEqual(1, result, "Result code should always be 1 because this version does not support SMB"); }
/** * SIF_Register */ public SIF_Ack SifRegister(IZone zone) { ZoneImpl AdkZone = (ZoneImpl)zone; AgentProperties props = zone.Properties; SifVersion effectiveZISVersion = AdkZone.HighestEffectiveZISVersion; SIF_Register msg = new SIF_Register(effectiveZISVersion); msg.SIF_MaxBufferSize = props.MaxBufferSize; msg.SIF_Mode = props.MessagingMode == AgentMessagingMode.Pull ? "Pull" : "Push"; // Set the agent's name and version Agent agent = zone.Agent; msg.SIF_Name = agent.Name; String vendor = props.AgentVendor; if (vendor != null) { msg.SIF_NodeVendor = vendor; } String version = props.AgentVersion; if (version != null) { msg.SIF_NodeVersion = version; } SIF_Application applicationInfo = new SIF_Application(); String appName = props.ApplicationName; if (appName != null) { applicationInfo.SIF_Product = appName; } String appVersion = props.ApplicationVersion; if (appVersion != null) { applicationInfo.SIF_Version = appVersion; } String appVendor = props.ApplicationVendor; if (appVendor != null) { applicationInfo.SIF_Vendor = appVendor; } if (applicationInfo.FieldCount > 0) { // All three fields under SIF_Application are required by the // SIF_Specification. Determine if any are missing. If so, // create the field with an empty value if (applicationInfo.SIF_Product == null) { applicationInfo.SIF_Product = string.Empty; } if (applicationInfo.SIF_Version == null) { applicationInfo.SIF_Version = string.Empty; } if (applicationInfo.SIF_Vendor == null) { applicationInfo.SIF_Vendor = string.Empty; } msg.SIF_Application = applicationInfo; } String propVal = props.AgentIconUrl; if (propVal != null) { msg.SIF_Icon = propVal; } // // SIF_Version handling: // // * If the "Adk.provisioning.zisVersion" property is set to > SIF 1.1 // (the default), use SIF 1.1+ registration where multiple SIF_Version // elements are included in the SIF_Register message. Otherwise use // SIF 1.0 registration where only a single SIF_Version is included in // the SIF_Register message. // // For SIF 1.1 registrations: // // * If the "Adk.sifRegister.sifVersions" System property is set, // enumerate its comma-delimited list of SIF_Version values and use // those instead of building a list. This is primarily used for // testing wildcards (which the Adk doesn't normally use) or when an // agent wants to connect to a ZIS where wildcarding works better for // some reason. // // * Otherwise, build a list of SIF_Versions: Set the first SIF_Version // element to the version initialized by the Adk, then add a SIF_Version // element for each additional version of SIF supported by the Adk // String forced = zone.Properties.OverrideSifVersions; if (forced != null) { ((ZoneImpl)zone).Log.Debug("Using custom SIF_Register/SIF_Version: " + forced); foreach (String token in forced.Split(',')) { msg.AddSIF_Version(new SIF_Version(token.Trim())); } } else { SifVersion zisVer = SifVersion.Parse(zone.Properties.ZisVersion); if (zisVer.CompareTo(SifVersion.SIF11) >= 0) { // Add the Adk version first. This is the "default" // agent version, which has special meaning to the // ZIS msg.AddSIF_Version(new SIF_Version(effectiveZISVersion)); // TT 2007 // If the Adk Version is set to 1.1 or 1.5r1, only send those two // versions in the SIF_Register message. The downside to this is // that we can't connect to a 2.0 ZIS using SIF 1.5r1 and still // receive 2.0 events. However, this seems to be the best approach // because it ensures greater compatibility with older ZIS's that will // otherwise fail if they get a 2.0 version in the SIF_Register message SifVersion[] supported = Adk.SupportedSIFVersions; for (int i = 0; i < supported.Length; i++) { // Exclude the version added above if (supported[i].CompareTo(effectiveZISVersion) < 0) { msg.AddSIF_Version(new SIF_Version(supported[i])); } } } else { msg.AddSIF_Version(new SIF_Version(Adk.SifVersion)); } } // // Set the SIF_Protocol object as supplied by the Transport. Depending // on the transport protocol and the messaging mode employed by the // zone we may or may not get a SIF_Protocol object back // SIF_Protocol po = ((ZoneImpl)zone).ProtocolHandler.MakeSIF_Protocol(zone); if (po != null) { msg.SIF_Protocol = po; } return(AdkZone.Dispatcher.send(msg)); }
/// <summary> /// Returns true if the protocol and underlying transport are currently active /// for this zone /// </summary> /// <param name="zone"></param> /// <returns>True if the protocol handler and transport are active</returns> public bool IsActive( ZoneImpl zone ) { return true; }
/// <summary> Calculate the size of a SIF_Response minus the SIF_ObjectData content.</summary> protected virtual long CalcEnvelopeSize( ZoneImpl zone ) { long size = 400; try { SIF_Response rsp = new SIF_Response(); rsp.SIF_MorePackets = "Yes"; rsp.SIF_RequestMsgId = fReqId; rsp.SIF_PacketNumber = 100000000; SIF_ObjectData data = new SIF_ObjectData(); data.TextValue = " "; rsp.SIF_ObjectData = data; SIF_Header hdr = rsp.Header; hdr.SIF_Timestamp = DateTime.Now; hdr.SIF_MsgId = "012345678901234567890123456789012"; hdr.SIF_SourceId = zone.Agent.Id; hdr.SIF_Security = zone.Dispatcher.secureChannel(); hdr.SIF_DestinationId = fDestId; using ( MemoryStream buffer = new MemoryStream() ) { SifWriter writer = new SifWriter( buffer ); writer.Write( rsp ); writer.Flush(); size = buffer.Length + 10; writer.Close(); buffer.Close(); } } catch( Exception ex ) { zone.Log.Warn( "Error calculating packet size: " + ex, ex ); } return size; }
private SIF_Ack SifSystemControl(SifElement command, ZoneImpl zone) { SIF_SystemControl msg = new SIF_SystemControl(zone.HighestEffectiveZISVersion); SIF_SystemControlData cmd = new SIF_SystemControlData(); cmd.AddChild(command); msg.SIF_SystemControlData = cmd; return zone.Dispatcher.send(msg); }
public void Close( IZone zone ) { zone.Log.Info( "TestProtocolHandler closed" ); fZone = null; }
/// <summary> /// Returns true if the protocol and underlying transport are currently active /// for this zone /// </summary> /// <param name="zone"></param> /// <returns>True if the protocol handler and transport are active</returns> public bool IsActive( ZoneImpl zone ) { return true; }
public void Open( ZoneImpl zone ) { zone.Log.Info( "TestProtocolHandler openned" ); fZone = zone; }
private void AssertRetryHandling(ErrorMessageHandler handler, SifMessagePayload payload, ZoneImpl zone) { try { assertNormalHandling(handler, payload, zone); } catch (SifException ex) { Assert.IsTrue(handler.wasCalled(), "Handler was not called"); Assert.AreEqual(SifErrorCategoryCode.Transport, ex.ErrorCategory, "SIF Error category should be 10: " + ex.Message); } Assert.IsTrue(handler.wasCalled(), "Handler was not called"); AssertThreadIsOK(); }
/// <summary> /// Returns true if the protocol and underlying transport are currently active /// for this zone /// </summary> /// <param name="zone"></param> /// <returns>True if the protocol handler and transport are active</returns> public override bool IsActive(ZoneImpl zone) { return(fTransport.IsActive(zone) && fServer != null && fServer.IsStarted); }