private static async Task CreateRedundantInstallations(RedundantNotificationHubClient nhClient)
        {
            var deviceId     = Guid.NewGuid().ToString();
            var installation = new Installation
            {
                InstallationId     = "test-redundancy-install-id",
                Platform           = NotificationPlatform.Fcm,
                PushChannel        = deviceId,
                PushChannelExpired = false,
                Tags = new[] { "fcm" }
            };
            await nhClient.CreateOrUpdateInstallationAsync(installation);

            // Confirm if the installation is created for primary namepsace.
            await GetInstallationAsync(nhClient, installation.InstallationId);

            var outcomeFcm = await nhClient.SendFcmNativeNotificationAsync(FcmSampleNotificationContent, installation.InstallationId);

            var details = await GetPushDetailsAndPrintOutcome(nhClient, outcomeFcm);

            PrintPushOutcome(details, true);

            // Confirm if the installation is created for backup namepsace.
            nhClient.DefaultNamespace = DefaultNamespace.Backup;
            await GetInstallationAsync(nhClient, installation.InstallationId);

            // Send notifications to installation in backup namespace
            var outcomeFcmFromBackUp = await nhClient.SendFcmNativeNotificationAsync(FcmSampleNotificationContent, installation.InstallationId);

            var backupDetails = await GetPushDetailsAndPrintOutcome(nhClient, outcomeFcmFromBackUp);

            PrintPushOutcome(backupDetails, false);
        }
        static async Task Main(string[] args)
        {
            // Getting connection key from the new resource
            var config   = LoadConfiguration(args);
            var nhClient = new RedundantNotificationHubClient(config.PrimaryConnectionString, config.BackupConnectionString, config.HubName);

            await CreateRedundantInstallations(nhClient);
        }
 private static async Task <Installation> GetInstallationAsync(RedundantNotificationHubClient nhClient, string installationId)
 {
     while (true)
     {
         try
         {
             return(await nhClient.GetInstallationAsync(installationId));
         }
         catch (Exception)
         {
             Console.WriteLine("Waiting for installation to be created");
             Thread.Sleep(1000);
         }
     }
 }
        private static async Task <NotificationDetails> GetPushDetailsAndPrintOutcome(RedundantNotificationHubClient nhClient, NotificationOutcome notificationOutcome)
        {
            if (string.IsNullOrEmpty(notificationOutcome.NotificationId))
            {
                Console.WriteLine($"Fcm has no outcome due to it is only available for Standard SKU pricing tier.");
                return(null);
            }

            var notificationId = notificationOutcome.NotificationId;
            var state          = NotificationOutcomeState.Enqueued;
            var count          = 0;
            NotificationDetails outcomeDetails = null;

            while ((state == NotificationOutcomeState.Enqueued || state == NotificationOutcomeState.Processing) && ++count < 10)
            {
                try
                {
                    Console.WriteLine($"Status: {state}");
                    outcomeDetails = await nhClient.GetNotificationOutcomeDetailsAsync(notificationId);

                    state = outcomeDetails.State;
                }
                catch (MessagingEntityNotFoundException)
                {
                    // It's possible for the notification to not yet be enqueued, so we may have to swallow an exception
                    // until it's ready to give us a new state.
                }
                Thread.Sleep(1000);
            }
            return(outcomeDetails);
        }