本文整理汇总了C#中HttpNotificationChannel类的典型用法代码示例。如果您正苦于以下问题:C# HttpNotificationChannel类的具体用法?C# HttpNotificationChannel怎么用?C# HttpNotificationChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpNotificationChannel类属于命名空间,在下文中一共展示了HttpNotificationChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AcquireToken
private async void AcquireToken()
{
var currentChannel = HttpNotificationChannel.Find(ChannelName);
if (currentChannel == null)
{
currentChannel = new HttpNotificationChannel(ChannelName);
currentChannel.Open();
currentChannel.BindToShellToast();
currentChannel.ChannelUriUpdated += (sender, args) =>
{
RegisterToken(currentChannel.ChannelUri.AbsoluteUri);
};
if (currentChannel.ChannelUri == null)
{
await Task.Delay(200);
if(currentChannel.ChannelUri == null)
return;
}
RegisterToken(currentChannel.ChannelUri.AbsoluteUri);
}
else
{
currentChannel.ChannelUriUpdated += (sender, args) =>
{
RegisterToken(currentChannel.ChannelUri.AbsoluteUri);
};
}
currentChannel.ShellToastNotificationReceived += OnNotificationReceived;
}
示例2: open_Click
private void open_Click(object sender, RoutedEventArgs e)
{
var channel = HttpNotificationChannel.Find("TestChannel");
if (channel == null || channel.ChannelUri == null)
{
if(channel != null)
{
channel.Close();
channel.Dispose();
}
channel = new HttpNotificationChannel("TestChannel");
channel.ChannelUriUpdated += channel_ChannelUriUpdated;
channel.ErrorOccurred += channel_ErrorOccurred;
channel.Open();
}
else
{
channel.ErrorOccurred += channel_ErrorOccurred;
Debug.WriteLine(channel.ChannelUri.AbsoluteUri);
}
channel.ShellToastNotificationReceived += channel_ShellToastNotificationReceived;
if(!channel.IsShellToastBound) channel.BindToShellToast();
}
示例3: AcquirePushChannel
private void AcquirePushChannel()
{
CurrentChannel = HttpNotificationChannel.Find("MyPushChannel");
if (CurrentChannel == null)
{
CurrentChannel = new HttpNotificationChannel("MyPushChannel");
CurrentChannel.Open();
CurrentChannel.BindToShellToast();
}
CurrentChannel.ChannelUriUpdated +=
new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
{
MobileServiceClient client = todoItemManager.GetClient;
// Register for notifications using the new channel
const string template =
"<?xml version=\"1.0\" encoding=\"utf-8\"?><wp:Notification " +
"xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1>$(message)</wp:Text1></wp:Toast></wp:Notification>";
await client.GetPush()
.RegisterTemplateAsync(CurrentChannel.ChannelUri.ToString(), template, "mytemplate");
});
}
示例4: EnableNotifications
public static void EnableNotifications(string username)
{
_username = username;
if (_channel != null)
return;
_channel = HttpNotificationChannel.Find(CHANNEL);
if (_channel == null)
{
_channel = new HttpNotificationChannel(CHANNEL);
WireChannel(_channel);
_channel.Open();
}
else
WireChannel(_channel);
if (!_channel.IsShellToastBound)
_channel.BindToShellToast();
if (_channel.ChannelUri != null)
{
var ns = new NotificationServiceClient();
ns.RegisterEndpointAsync(username, _channel.ChannelUri.ToString());
}
}
示例5: RegisterTilePushChannel
public void RegisterTilePushChannel(string channelName = "TilePushChannel")
{
// Holds the push channel that is created or found.
HttpNotificationChannel _tilePushChannel;
// Try to find the push channel.
_tilePushChannel = HttpNotificationChannel.Find(channelName);
// If the channel was not found, then create a new connection to the push service.
if (_tilePushChannel == null)
{
_tilePushChannel = new HttpNotificationChannel(channelName);
// Register for all the events before attempting to open the channel.
_tilePushChannel.ChannelUriUpdated += TileChannelUriUpdated;
_tilePushChannel.ErrorOccurred += TileErrorOccurred;
_tilePushChannel.Open();
// Bind this new channel for toast events.
_tilePushChannel.BindToShellToast();
}
else
{
// The channel was already open, so just register for all the events.
_tilePushChannel.ChannelUriUpdated += TileChannelUriUpdated;
_tilePushChannel.ErrorOccurred += TileErrorOccurred;
// Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
}
}
示例6: CreateNewChannel
private HttpNotificationChannel CreateNewChannel()
{
var channel = HttpNotificationChannel.Find(AppContext.State.AppId);
if (channel == null)
{
channel = new HttpNotificationChannel(AppContext.State.AppId);
SubscribeToEvents(channel);
// Open the channel
channel.Open();
UpdateChannelUri(channel.ChannelUri);
// Register for tile notifications
var whitelistedDomains = AppContext.State.Settings.PushSettings.WhitelistedDomains;
if (whitelistedDomains.Count == 0)
channel.BindToShellTile();
else
channel.BindToShellTile(new Collection<Uri>(whitelistedDomains));
// Register for shell notifications
channel.BindToShellToast();
}
else
{
SubscribeToEvents(channel);
UpdateChannelUri(channel.ChannelUri);
}
return channel;
}
示例7: register
public void register(string options)
{
try
{
var args = JSON.JsonHelper.Deserialize<string[]>(options);
var pushOptions = JSON.JsonHelper.Deserialize<Options>(args[0]);
this.channelName = pushOptions.ChannelName;
this.toastCallback = pushOptions.NotificationCallback;
}
catch (Exception)
{
this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
return;
}
this.pushChannel = HttpNotificationChannel.Find(this.channelName);
if (this.pushChannel == null)
{
this.pushChannel = new HttpNotificationChannel(this.channelName);
this.PushChannel_HookEvents();
this.pushChannel.Open();
this.pushChannel.BindToShellToast();
this.pushChannel.BindToShellTile();
}
else
{
this.PushChannel_HookEvents();
var result = new RegisterResult();
result.ChannelName = this.channelName;
result.Uri = this.pushChannel.ChannelUri.ToString();
this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result));
}
}
示例8: RegisterDevice
public void RegisterDevice(object state)
{
IsRegistering = true;
HttpNotificationChannel pushChannel;
pushChannel = HttpNotificationChannel.Find("RegistrationChannel");
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel("RegistrationChannel");
}
RegistrationRequest req = new RegistrationRequest()
{
ChannelUri = pushChannel.ChannelUri.ToString(),
DeviceType = (short)Common.Data.DeviceType.WindowsPhone7
};
string json = null;
using (MemoryStream ms = new MemoryStream())
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RegistrationRequest));
serializer.WriteObject(ms, req);
json = Encoding.UTF8.GetString(ms.ToArray(), 0, (int)ms.Length);
}
WebClient registrationClient = new WebClient();
registrationClient.Headers["content-type"] = "application/json";
registrationClient.UploadStringCompleted += registrationClient_UploadStringCompleted;
string url = string.Format("http://{0}/Services/RegisterDevice", App.ServiceHostName);
registrationClient.UploadStringAsync(new Uri(url), json);
}
示例9: DoConnect
private void DoConnect()
{
try
{
//首先查看现有的频道
httpChannel = HttpNotificationChannel.Find(channelName);
//如果频道存在
if (httpChannel != null)
{
//注册Microsoft推送通知事件
SubscribeToChannelEvents();
//检测Microsoft通知服务注册状态
SubscribeToService();
//订阅Toast和Title通知
SubscribeToNotifications();
}
else
{
//试图创建一个新的频道
//创建频道
httpChannel = new HttpNotificationChannel(channelName, "PuzzleService");
//推送通知频道创建成功
SubscribeToChannelEvents();
//注册Microsoft推送通知事件
httpChannel.Open();
}
}
catch (Exception ex)
{
//创建或恢复频道时发生异常
}
}
示例10: CreatePushChannel
// LIVE TILE CODE ADDED HERE !!!!!!!!------------------------!!!!!!!!!!!!!!!!
private void CreatePushChannel()
{
// Try to find the push channel.
pushChannel = HttpNotificationChannel.Find(channelName);
// If the channel was not found, then create a new connection to the push service.
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
// Register for all the events before attempting to open the channel.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.Open();
// Bind this new channel for Tile events.
pushChannel.BindToShellTile();
}
else
{
// The channel was already open, so just register for all the events.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
// Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
// hereeee uncommnt // System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
//MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));
}
}
示例11: Connect
public void Connect()
{
try
{
httpChannel = HttpNotificationChannel.Find(channelName);
if (null != httpChannel)
{
SubscribeToChannelEvents();
SubscribeToNotifications();
Deployment.Current.Dispatcher.BeginInvoke(() => this.UpdateStatus("Channel recovered"));
}
else
{
httpChannel = new HttpNotificationChannel(channelName, "GeoScavChannel");
SubscribeToChannelEvents();
httpChannel.Open();
Deployment.Current.Dispatcher.BeginInvoke(() => this.UpdateStatus("Channel open requested"));
}
}
catch (Exception ex)
{
Deployment.Current.Dispatcher.BeginInvoke(() => UpdateStatus("Channel error: " + ex.Message));
}
}
示例12: SetupNotificationChannel
public void SetupNotificationChannel()
{
if (!InternetIsAvailable()) return;
channel = HttpNotificationChannel.Find(channelName);
if (channel == null)
{
channel = new HttpNotificationChannel(channelName);
HookupHandlers();
channel.Open();
}
else
{
HookupHandlers();
try
{
pushClient.RegisterPhoneAsync(WP7App1.Bootstrapper.phoneId, channel.ChannelUri.ToString(), username);
}
catch (Exception ex)
{
throw ex;
}
}
}
示例13: SetupChannel
void SetupChannel()
{
bool newChannel = false;
channel = HttpNotificationChannel.Find(CHANNEL_NAME);
if (channel == null)
{
channel = new HttpNotificationChannel(CHANNEL_NAME);
newChannel = true;
}
channel.ConnectionStatusChanged += channel_ConnectionStatusChanged;
channel.ChannelUriUpdated += channel_ChannelUriUpdated;
channel.ErrorOccurred += channel_ErrorOccurred;
channel.ShellToastNotificationReceived += channel_ShellToastNotificationReceived;
if (newChannel)
{
channel.Open();
channel.BindToShellTile();
channel.BindToShellToast();
}
channelStatus.Text = channel.ConnectionStatus.ToString();
if (channel.ChannelUri != null)
channelUri.Text = channel.ChannelUri.ToString();
}
示例14: MainPage
// Constructor
public MainPage()
{
HttpNotificationChannel pushChannel;
String channelName = "ToastSampleChannel";
InitializeComponent();
pushChannel = HttpNotificationChannel.Find(channelName);
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
pushChannel.Open();
pushChannel.BindToShellToast();
}
else
{
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
MessageBox.Show(String.Format("Channel uri is {0}", pushChannel.ChannelUri.ToString()));
}
}
示例15: DoConnect
private void DoConnect()
{
try
{
httpChannel = HttpNotificationChannel.Find(channelName);
if (null != httpChannel)
{
SubscribeToChannelEvents();
SubscribeToService();
SubscribeToNotifications();
Dispatcher.BeginInvoke(() => UpdateStatus("Channel recovered"));
}
else
{
httpChannel = new HttpNotificationChannel(channelName, "HOLWeatherService");
SubscribeToChannelEvents();
httpChannel.Open();
Dispatcher.BeginInvoke(() => UpdateStatus("Channel open requested"));
}
}
catch (Exception ex)
{
Dispatcher.BeginInvoke(() => UpdateStatus("Channel error: " + ex.Message));
}
}