本文整理汇总了C#中HttpNotificationChannel.Open方法的典型用法代码示例。如果您正苦于以下问题:C# HttpNotificationChannel.Open方法的具体用法?C# HttpNotificationChannel.Open怎么用?C# HttpNotificationChannel.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpNotificationChannel
的用法示例。
在下文中一共展示了HttpNotificationChannel.Open方法的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: Init
public void Init()
{
try
{
//First, try to pick up existing channel
httpChannel = HttpNotificationChannel.Find(channelName);
if (null != httpChannel)
{
SubscribeToChannelEvents();
SubscribeToService();
SubscribeToNotifications();
}
else
{
httpChannel = new HttpNotificationChannel(channelName, "BlandCAPITAL.Shared.FinanceService");
SubscribeToChannelEvents();
httpChannel.Open();
}
}
catch
{
}
}
示例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: RegisterPushNotifications
public void RegisterPushNotifications()
{
if (pushChannel != null) return;
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, "PositiveSSL CA");
// Register for all the events before attempting to open the channel.
pushChannel.ChannelUriUpdated += PushChannel_ChannelUriUpdated;
pushChannel.ErrorOccurred += PushChannel_ErrorOccurred;
pushChannel.HttpNotificationReceived += PushChannel_HttpNotificationReceived;
pushChannel.Open();
pushChannel.BindToShellToast();
pushChannel.BindToShellTile();
} else {
// The channel was already open, so just register for all the events.
pushChannel.ChannelUriUpdated += PushChannel_ChannelUriUpdated;
pushChannel.ErrorOccurred += PushChannel_ErrorOccurred;
pushChannel.HttpNotificationReceived += PushChannel_HttpNotificationReceived;
}
if (UriUpdated != null && pushChannel.ChannelUri != null) {
UriUpdated(pushChannel.ChannelUri.ToString());
}
}
示例5: 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();
}
示例6: 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()));
}
}
示例7: OnInit
public override void OnInit()
{
configHandler.LoadAppPackageConfig();
string channelName = "UAPush";
// 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 toast events.
pushChannel.BindToShellToast();
}
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);
this.RegisterDevice(pushChannel.ChannelUri);
}
}
示例8: 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));
}
}
示例9: SetupNotificationChannel
public void SetupNotificationChannel()
{
if (!InternetIsAvailable()) return;
channel = HttpNotificationChannel.Find(channelName);
if (channel == null)
{
channel = new HttpNotificationChannel(channelName);
HookupHandlers();
channel.Open();
}
else
{
HookupHandlers();
try
{
channelUri = channel.ChannelUri.ToString();
apiMethodRequest.SendRequest(VkApi.Authorization.AccessToken, "account.registerDevice", new Dictionary<string, string>() { { "token", channelUri } });
}
catch (Exception ex)
{
throw ex;
}
}
}
示例10: 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));
}
}
示例11: 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;
}
示例12: OpenChannel
public void OpenChannel(Action<string> channelCallback)
{
try
{
_channel = HttpNotificationChannel.Find(ChannelName);
}
catch { }
if (_channel != null && _channel.ChannelUri != null)
{
channelCallback(_channel.ChannelUri.ToString());
}
else
{
try
{
_channel = new HttpNotificationChannel(ChannelName);
_channel.ChannelUriUpdated += (o, e) => channelCallback(e.ChannelUri.ToString());
_channel.Open();
_channel.BindToShellToast();
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
}
示例13: 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()));
}
}
示例14: 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)
{
//创建或恢复频道时发生异常
}
}
示例15: 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;
}
}
}