/// <summary> /// Sends a GetResourcesResponse message to a customer. /// </summary> /// <param name="request">The request.</param> /// <param name="resources">The list of <see cref="Resource" /> objects.</param> /// <returns>The message identifier.</returns> public virtual long GetResourcesResponse(IMessageHeader request, IList <Resource> resources) { if (!resources.Any()) { return(Acknowledge(request.MessageId, MessageFlags.NoData)); } long messageId = 0; for (int i = 0; i < resources.Count; i++) { var messageFlags = i < resources.Count - 1 ? MessageFlags.MultiPart : MessageFlags.MultiPartAndFinalPart; var header = CreateMessageHeader(Protocols.Discovery, MessageTypes.Discovery.GetResourcesResponse, request.MessageId, messageFlags); var getResourcesResponse = new GetResourcesResponse() { Resource = resources[i] }; messageId = Session.SendMessage(header, getResourcesResponse); } return(messageId); }
/// <summary> /// Sends a GetResourcesResponse message to a customer. /// </summary> /// <param name="request">The request.</param> /// <param name="resources">The list of <see cref="Resource" /> objects.</param> /// <returns>The message identifier.</returns> public virtual long GetResourcesResponse(IMessageHeader request, IList <Resource> resources) { if (!resources.Any()) { return(Acknowledge(request.MessageId, MessageFlags.NoData)); } long messageId = 0; for (var i = 0; i < resources.Count; i++) { var messageFlags = i < resources.Count - 1 ? MessageFlags.MultiPart : MessageFlags.MultiPartAndFinalPart; var header = CreateMessageHeader(Protocols.Discovery, MessageTypes.Discovery.GetResourcesResponse, request.MessageId, messageFlags); // TODO: Optimize reponse by sending multiple Resource at a time var response = new GetResourcesResponse { Resources = new[] { resources[i] } }; messageId = Session.SendMessage(header, response); } return(messageId); }
/// <summary> /// Handles the GetResourcesResponse message from a store. /// </summary> /// <param name="header">The message header.</param> /// <param name="getResourcesResponse">The GetResourcesResponse message.</param> protected virtual void HandleGetResourcesResponse(IMessageHeader header, GetResourcesResponse getResourcesResponse) { var uri = GetRequestedUri(header); var args = Notify(OnGetResourcesResponse, header, getResourcesResponse, uri); HandleGetResourcesResponse(args); }
/// <summary> /// Sends a GetResourcesResponse message to a customer. /// </summary> /// <param name="correlatedHeader">The message header that the messages to send are correlated with.</param> /// <param name="resources">The list of <see cref="Resource"/> objects.</param> /// <param name="isFinalPart">Whether or not this is the final part of a multi-part message.</param> /// <param name="extension">The message header extension.</param> /// <returns>The sent message on success; <c>null</c> otherwise.</returns> public virtual EtpMessage <GetResourcesResponse> GetResourcesResponse(IMessageHeader correlatedHeader, IList <Resource> resources, bool isFinalPart = true, IMessageHeaderExtension extension = null) { var body = new GetResourcesResponse { Resources = resources ?? new List <Resource>(), }; return(SendResponse(body, correlatedHeader, extension: extension, isMultiPart: true, isFinalPart: isFinalPart)); }