本文整理汇总了C#中Response.SetOption方法的典型用法代码示例。如果您正苦于以下问题:C# Response.SetOption方法的具体用法?C# Response.SetOption怎么用?C# Response.SetOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response.SetOption方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendResponse
/// <inheritdoc/>
public override void SendResponse(INextLayer nextLayer, Exchange exchange, Response response)
{
BlockOption block1 = exchange.Block1ToAck;
if (block1 != null)
exchange.Block1ToAck = null;
if (RequiresBlockwise(exchange, response))
{
// This must be a large response to a GET or POST request (PUT?)
if (log.IsDebugEnabled)
log.Debug("Response payload " + response.PayloadSize + "/" + _maxMessageSize + " requires Blockwise");
BlockwiseStatus status = FindResponseBlockStatus(exchange, response);
Response block = GetNextResponseBlock(response, status);
block.Type = response.Type; // This is only true for the first block
if (block1 != null) // in case we still have to ack the last block1
block.SetOption(block1);
if (block.Token == null)
block.Token = exchange.Request.Token;
if (response.HasOption(OptionType.Observe))
{
// the ACK for the first block should acknowledge the whole notification
exchange.CurrentResponse = response;
}
else
{
exchange.CurrentResponse = block;
}
base.SendResponse(nextLayer, exchange, block);
}
else
{
if (block1 != null)
response.SetOption(block1);
exchange.CurrentResponse = response;
base.SendResponse(nextLayer, exchange, response);
}
}
示例2: Respond
/// <summary>
/// Responds Respond with the specified response.
/// </summary>
public void Respond(Response response)
{
if (response == null)
throw new ArgumentNullException("response");
// set the response options configured through the CoapExchange API
if (_locationPath != null)
response.LocationPath = _locationPath;
if (_locationQuery != null)
response.LocationQuery = _locationQuery;
if (_maxAge != 60)
response.MaxAge = _maxAge;
if (_eTag != null)
response.SetOption(Option.Create(OptionType.ETag, _eTag));
_resource.CheckObserveRelation(_exchange, response);
_exchange.SendResponse(response);
}
示例3: CheckObserveRelation
internal void CheckObserveRelation(Exchange exchange, Response response)
{
/*
* If the request for the specified exchange tries to establish an observer
* relation, then the ServerMessageDeliverer must have created such a relation
* and added to the exchange. Otherwise, there is no such relation.
* Remember that different paths might lead to this resource.
*/
ObserveRelation relation = exchange.Relation;
if (relation == null)
return; // because request did not try to establish a relation
if (Code.IsSuccess(response.Code))
{
response.SetOption(Option.Create(OptionType.Observe, _notificationOrderer.Current));
if (!relation.Established)
{
relation.Established = true;
AddObserveRelation(relation);
}
else if (_observeType != MessageType.Unknown)
{
// The resource can control the message type of the notification
response.Type = _observeType;
}
} // ObserveLayer takes care of the else case
}
示例4: SendResponse
/// <inheritdoc/>
public override void SendResponse(INextLayer nextLayer, Exchange exchange, Response response)
{
BlockOption block1 = exchange.Block1ToAck;
if (block1 != null)
exchange.Block1ToAck = null;
if (RequiresBlockwise(exchange, response))
{
if (log.IsDebugEnabled)
log.Debug("Response payload " + response.PayloadSize + "/" + _maxMessageSize + " requires Blockwise");
BlockwiseStatus status = FindResponseBlockStatus(exchange, response);
Response block = GetNextResponseBlock(response, status);
if (block1 != null) // in case we still have to ack the last block1
block.SetOption(block1);
if (block.Token == null)
block.Token = exchange.Request.Token;
if (status.Complete)
{
// clean up blockwise status
if (log.IsDebugEnabled)
log.Debug("Ongoing finished on first block " + status);
exchange.ResponseBlockStatus = null;
ClearBlockCleanup(exchange);
}
else
{
if (log.IsDebugEnabled)
log.Debug("Ongoing started " + status);
}
exchange.CurrentResponse = block;
base.SendResponse(nextLayer, exchange, block);
}
else
{
if (block1 != null)
response.SetOption(block1);
exchange.CurrentResponse = response;
// Block1 transfer completed
ClearBlockCleanup(exchange);
base.SendResponse(nextLayer, exchange, response);
}
}