Beispiel #1
0
        /// <summary>
        /// Register a particular channelUri with a template
        /// </summary>
        /// <param name="channelUri">The channelUri to register</param>
        /// <param name="xmlTemplate">The XmlDocument defining the template</param>
        /// <param name="templateName">The template name</param>
        /// <param name="tags">The tags to register to receive notifications from</param>
        /// <returns>Task that completes when registration is complete</returns>
        public Task RegisterTemplateAsync(string channelUri, string xmlTemplate, string templateName, IEnumerable <string> tags)
        {
            if (string.IsNullOrWhiteSpace(channelUri))
            {
                throw new ArgumentNullException("channelUri");
            }

            if (string.IsNullOrWhiteSpace(xmlTemplate))
            {
                throw new ArgumentNullException("xmlTemplate");
            }

            if (string.IsNullOrWhiteSpace(templateName))
            {
                throw new ArgumentNullException("templateName");
            }

            var registration = new MpnsTemplateRegistration(channelUri, xmlTemplate, templateName, tags, null);

            return(this.RegistrationManager.RegisterAsync(registration));
        }
        private static ZumoTest CreateRegisterChannelTest(bool registerTemplate = false, string templateType = null)
        {
            return new ZumoTest("Register push channel", async delegate(ZumoTest test)
            {
                string channelName = "MyPushChannel";
                var pushChannel = HttpNotificationChannel.Find(channelName);
                if (pushChannel == null)
                {
                    pushChannel = new HttpNotificationChannel(channelName);
                    test.AddLog("Created new channel");
                }
                else
                {
                    test.AddLog("Reusing existing channel");
                }

                ZumoWP8PushTests.pushChannel = pushChannel;

                if (pushChannel.ConnectionStatus == ChannelConnectionStatus.Disconnected || pushChannel.ChannelUri == null)
                {
                    pushChannel.Open();
                    test.AddLog("Opened the push channel");
                }
                else
                {
                    test.AddLog("Channel already opened");
                }

                if (pushChannel.IsShellToastBound)
                {
                    test.AddLog("Channel is already bound to shell toast");
                }
                else
                {
                    var uris = new System.Collections.ObjectModel.Collection<Uri>();
                    uris.Add(new Uri(ImageUrlDomain));
                    pushChannel.BindToShellTile(uris);
                    pushChannel.BindToShellToast();
                    test.AddLog("Bound the push channel to shell toast / tile");
                }

                TimeSpan maxWait = TimeSpan.FromSeconds(30);
                await WaitForChannelUriAssignment(test, pushChannel, maxWait);


                if (ZumoTestGlobals.Instance.IsNHPushEnabled)
                {
                    var zumoPush = ZumoTestGlobals.Instance.Client.GetPush();
                    MpnsTemplateRegistration reg = null;
                    if (registerTemplate)
                    {
                        switch (templateType)
                        {
                            case "toast":
                                reg = new MpnsTemplateRegistration(pushChannel.ChannelUri.ToString(), ZumoPushTestGlobals.NHWp8ToastTemplate, "wp8" + ZumoPushTestGlobals.NHToastTemplateName, "World English".Split());
                                break;
                            case "tile":
                                reg = new MpnsTemplateRegistration(pushChannel.ChannelUri.ToString(), ZumoPushTestGlobals.NHWp8TileTemplate, "wp8" + ZumoPushTestGlobals.NHTileTemplateName, "World Mandarin".Split());
                                break;
                            case "raw":
                                IDictionary<string, string> wp8Headers = new Dictionary<string, string>();
                                wp8Headers.Add("X-NotificationClass", "3");
                                reg = new MpnsTemplateRegistration(pushChannel.ChannelUri.ToString(), ZumoPushTestGlobals.NHWp8RawTemplate, "wp8" + ZumoPushTestGlobals.NHRawTemplateName, "World French".Split(), wp8Headers);
                                break;
                        }

                        await zumoPush.RegisterAsync(reg);
                        pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
                        {
                            await zumoPush.RegisterAsync(reg);
                        });

                        test.AddLog("Registered to Notification hub");
                    }
                    else
                    {
                        await zumoPush.RegisterNativeAsync(pushChannel.ChannelUri.ToString(), "tag1 tag2".Split());
                        pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
                        {
                            await zumoPush.RegisterNativeAsync(args.ChannelUri.ToString(), "tag1 tag2".Split());
                        });
                        test.AddLog("Registered with NH");
                    }
                }
                pushChannel.HttpNotificationReceived += pushChannel_HttpNotificationReceived;
                pushChannel.ShellToastNotificationReceived += pushChannel_ShellToastNotificationReceived;
                test.AddLog("Registered to raw / shell toast events");

                if (pushChannel.ConnectionStatus != ChannelConnectionStatus.Connected || pushChannel.ChannelUri == null)
                {
                    test.AddLog("Error, push channel isn't connected or channel URI is null");
                    return false;
                }
                else
                {
                    return true;
                }
            }, registerTemplate ? ZumoTestGlobals.RuntimeFeatureNames.NH_PUSH_ENABLED : null);
        }
        /// <summary>
        /// Register a particular channelUri with a template
        /// </summary>
        /// <param name="channelUri">The channelUri to register</param>
        /// <param name="xmlTemplate">The XmlDocument defining the template</param>
        /// <param name="templateName">The template name</param>
        /// <param name="tags">The tags to register to receive notifications from</param>
        /// <returns>Task that completes when registration is complete</returns>        
        public Task RegisterTemplateAsync(string channelUri, string xmlTemplate, string templateName, IEnumerable<string> tags)
        {
            if (string.IsNullOrWhiteSpace(channelUri))
            {
                throw new ArgumentNullException("channelUri");
            }

            if (string.IsNullOrWhiteSpace(xmlTemplate))
            {
                throw new ArgumentNullException("xmlTemplate");
            }

            if (string.IsNullOrWhiteSpace(templateName))
            {
                throw new ArgumentNullException("templateName");
            }

            var registration = new MpnsTemplateRegistration(channelUri, xmlTemplate, templateName, tags, null);
            return this.RegistrationManager.RegisterAsync(registration);
        }