src/K4W.KinectVOD.Client.WinStore/App.xaml.cs
/// <summary>
/// Register for push notifications or update the expiration when required
/// </summary>
/// <param name="hubName">Name of the sending hub</param>
/// <param name="connectionString">Connection string to the Service Bus namespace</param>
/// <param name="templateName">Name of the template</param>
/// <param name="metadata">Notification property holding the metadata</param>
/// <param name="header">Header text of the toast</param>
/// <param name="footer">Footer text of the toast</param>
/// <param name="image">Url to the image</param>
Register for push notifications or update the expiration when required
Register for push notifications or update the expiration when required
public async Task RegisterPushNotifications(string hubName, string connectionString, string templateName, string metadata, string header, string footer, string image)
        {
            bool registerTemplate = false;
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
            object registerExpiration = localSettings.Values[templateName.Replace(" ", "-")];
            if (registerExpiration != null)
            {
                DateTime expirationDateTime;
                DateTime.TryParse(registerExpiration.ToString(), out expirationDateTime);
                if (expirationDateTime <= DateTime.Now)
                    registerTemplate = true;
            }
            else
                registerTemplate = true;
            if (registerTemplate == true)
            {
                TemplateRegistration tempRegistration = await PushNotificationsHelper.RegisterTemplateNotificationAsync(hubName, connectionString, templateName, metadata, header, footer, image);
                localSettings.Values[templateName.Replace(" ", "-")] = tempRegistration.ExpiresAt.ToString();
            }
        }
public async Task RegisterPushNotifications ( string hubName , string connectionString , string templateName , string metadata , string header , string footer , string image ) { bool registerTemplate = false ; ApplicationDataContainer localSettings = ApplicationData . Current . LocalSettings ; object registerExpiration = localSettings . Values [ templateName . Replace ( " " , " " ) ] ; if ( registerExpiration != null ) { DateTime expirationDateTime ; DateTime . TryParse ( registerExpiration . ToString ( ) , out expirationDateTime ) ; if ( expirationDateTime <= DateTime . Now ) registerTemplate = true ; } else registerTemplate = true ; if ( registerTemplate == true ) { TemplateRegistration tempRegistration = await PushNotificationsHelper . RegisterTemplateNotificationAsync ( hubName , connectionString , templateName , metadata , header , footer , image ) ; localSettings . Values [ templateName . Replace ( " " , " " ) ] = tempRegistration . ExpiresAt . ToString ( ) ; } }
Register for push notifications or update the expiration when required
Register for push notifications or update the expiration when required
// Retrieve local settings // Retrieve saved expiration date for this template // Flag as to-register when no value found // Try parse to datetime // Register when expired // Create a new registration when required // Save new expiration date
hubName
string
Name of the sending hub
Name of the sending hub
connectionString
string
Connection string to the Service Bus namespace
Connection string to the Service Bus namespace
templateName
string
Name of the template
Name of the template
metadata
string
Notification property holding the metadata
Notification property holding the metadata
header
string
Header text of the toast
Header text of the toast
footer
string
Footer text of the toast
Footer text of the toast
image
string
Url to the image
Url to the image