本文整理汇总了C#中RequestData.ToHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# RequestData.ToHeaders方法的具体用法?C# RequestData.ToHeaders怎么用?C# RequestData.ToHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestData
的用法示例。
在下文中一共展示了RequestData.ToHeaders方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Notify
/// <summary>
/// Sends a notification to Growl that specifies callback information and allows for additional request data.
/// </summary>
/// <param name="notification">The <see cref="Notification"/> to send.</param>
/// <param name="callbackContext">The <see cref="CallbackContext"/> containing the callback information.</param>
/// <param name="requestData">The <see cref="RequestData"/> containing the additional information.</param>
/// <param name="state">An optional state object that will be passed into the response events associated with this request</param>
public virtual void Notify(Notification notification, CallbackContext callbackContext, RequestData requestData, object state)
{
bool waitForCallback = false;
HeaderCollection notificationHeaders = notification.ToHeaders();
MessageBuilder mb = new MessageBuilder(RequestType.NOTIFY, this.GetKey());
foreach (Header header in notificationHeaders)
{
mb.AddHeader(header);
}
if (callbackContext != null)
{
string url = callbackContext.CallbackUrl;
if (!String.IsNullOrEmpty(url))
{
mb.AddHeader(new Header(Header.NOTIFICATION_CALLBACK_TARGET, url));
}
else
{
mb.AddHeader(new Header(Header.NOTIFICATION_CALLBACK_CONTEXT, callbackContext.Data));
mb.AddHeader(new Header(Header.NOTIFICATION_CALLBACK_CONTEXT_TYPE, callbackContext.Type.ToString()));
waitForCallback = true;
}
}
// handle any additional request data
if (requestData != null)
{
HeaderCollection requestDataHeaders = requestData.ToHeaders();
foreach (Header header in requestDataHeaders)
{
mb.AddHeader(header);
}
}
Send(mb, OnResponseReceived, waitForCallback, state);
}
示例2: Register
/// <summary>
/// Registers the specified application and notification types and allows for additional request data.
/// </summary>
/// <param name="application">The <see cref="Application"/> to register.</param>
/// <param name="notificationTypes">The <see cref="NotificationType"/>s to register.</param>
/// <param name="requestData">The <see cref="RequestData"/> containing the additional information.</param>
/// <param name="state">An optional state object that will be passed into the response events associated with this request</param>
public virtual void Register(Application application, NotificationType[] notificationTypes, RequestData requestData, object state)
{
HeaderCollection appHeaders = application.ToHeaders();
List<HeaderCollection> notifications = new List<HeaderCollection>();
foreach (NotificationType notificationType in notificationTypes)
{
HeaderCollection notificationHeaders = notificationType.ToHeaders();
notifications.Add(notificationHeaders);
}
MessageBuilder mb = new MessageBuilder(RequestType.REGISTER, this.GetKey());
foreach(Header header in appHeaders)
{
mb.AddHeader(header);
}
mb.AddHeader(new Header(Header.NOTIFICATIONS_COUNT, notificationTypes.Length.ToString()));
// handle any additional request data
if (requestData != null)
{
HeaderCollection requestDataHeaders = requestData.ToHeaders();
foreach (Header header in requestDataHeaders)
{
mb.AddHeader(header);
}
}
foreach(HeaderCollection headers in notifications)
{
MessageSection ms = new MessageSection();
foreach(Header header in headers)
{
ms.AddHeader(header);
}
mb.AddMessageSection(ms);
}
Send(mb, OnResponseReceived, false, state);
}
示例3: AddRequestData
/// <summary>
/// Adds any application-specific headers to the message
/// </summary>
/// <param name="mb">The <see cref="MessageBuilder"/> used to construct the message</param>
/// <param name="requestData">The <see cref="RequestData"/> that contains the application-specific data</param>
private void AddRequestData(MessageBuilder mb, RequestData requestData)
{
if (requestData != null)
{
HeaderCollection headers = requestData.ToHeaders();
foreach (Header header in headers)
{
mb.AddHeader(header);
}
}
}