MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.18k stars 21.32k forks source link

Improved code sample for exporting registrered devices using C# #120251

Open frode opened 6 months ago

frode commented 6 months ago

Hi,

I wanted to contribute with a better export of device registrations sample code in C#:

using Microsoft.Azure.NotificationHubs;

namespace Base_12
{
    class Program
    {
        private static async Task Main(string[] args)
        {
            NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("endpointURI", "NotificationHubName");

            NotificationHubJob job = new()
            {
                JobType = NotificationHubJobType.ExportRegistrations,
                OutputContainerUri = new Uri("containerConnectionURI")
            };

            job = await hub.SubmitNotificationHubJobAsync(job);

            Console.WriteLine("Export job submitted. Waiting for completion...");

            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            while (true)
            {
                Thread.Sleep(1000);
                job = await hub.GetNotificationHubJobAsync(job.JobId);

                if (stopwatch.Elapsed.Seconds % 10 == 0)
                {
                    Console.WriteLine($"Job is still running. Elapsed time: {stopwatch.Elapsed.Minutes} minutes and {stopwatch.Elapsed.Seconds % 60} seconds...");
                }

                if (job.Status == NotificationHubJobStatus.Completed)
                {
                    Console.WriteLine("Export job completed successfully.");
                    break;
                }
                else if (job.Status == NotificationHubJobStatus.Failed)
                {
                    Console.WriteLine("Export job failed.");
                    break;
                }
            }

            Console.WriteLine("Export Job Completed");
        }
    }
}

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

RamanathanChinnappan-MSFT commented 6 months ago

@frode Thanks for your feedback! We will investigate and update as appropriate.

BryanTrach-MSFT commented 6 months ago

@frode Thank you for sharing your inputs to help improve the docs.

I'm not sure I feel comfortable changing a large part of the doc as this likely would require a code review. As a result, I'm going to assign your issue directly to the doc author to have them review this further.