This page contains Windows bias

About This Page

This page is part of the Azure documentation. It contains code examples and configuration instructions for working with Azure services.

Bias Analysis

Bias Types:
⚠️ windows_first
⚠️ missing_linux_example
⚠️ windows_tools
Summary:
The documentation page demonstrates a Windows bias by providing only Windows-centric code samples (using C# and Windows APIs), referencing Windows-specific concepts (e.g., ChannelUri, Windows Store apps, ApplicationData), and omitting equivalent Linux or cross-platform examples. There is no mention of Linux client registration, nor are there code samples or guidance for Linux or non-Windows platforms.
Recommendations:
  • Add code samples for registering devices from Linux clients, using languages and libraries common on Linux (e.g., Python, Java, Node.js).
  • Include examples that use cross-platform REST API calls (e.g., using curl, Python requests, or JavaScript fetch) for device registration and installation management.
  • Document how to obtain PNS handles and manage registrations on non-Windows platforms, such as Android, iOS, or Linux IoT devices.
  • Avoid Windows-specific terminology or, when necessary, provide equivalent explanations and instructions for Linux and other platforms.
  • Highlight cross-platform SDKs and tools, and ensure that any Windows-specific features (like secondary tiles) are clearly marked as such, with alternatives or notes for other platforms.
GitHub Create pull request

Scan History

Date Scan ID Status Bias Status
2025-08-17 00:01 #83 in_progress ✅ Clean
2025-07-13 21:37 #48 completed ❌ Biased
2025-07-12 23:44 #41 in_progress ❌ Biased

Flagged Code Snippets

class DeviceInstallation { public string installationId { get; set; } public string platform { get; set; } public string pushChannel { get; set; } public string[] tags { get; set; } private async Task<HttpStatusCode> CreateOrUpdateInstallationAsync(DeviceInstallation deviceInstallation, string hubName, string listenConnectionString) { if (deviceInstallation.installationId == null) return HttpStatusCode.BadRequest; // Parse connection string ConnectionStringUtility connectionSaSUtil = new ConnectionStringUtility(listenConnectionString); string hubResource = "installations/" + deviceInstallation.installationId + "?"; string apiVersion = "api-version=2015-04"; // Determine the targetUri that we will sign string uri = connectionSaSUtil.Endpoint + hubName + "/" + hubResource + apiVersion; //=== Generate SaS Security Token for Authorization header === string SasToken = connectionSaSUtil.getSaSToken(uri, 60); using (var httpClient = new HttpClient()) { string json = JsonConvert.SerializeObject(deviceInstallation); httpClient.DefaultRequestHeaders.Add("Authorization", SasToken); var response = await httpClient.PutAsync(uri, new StringContent(json, System.Text.Encoding.UTF8, "application/json")); return response.StatusCode; } } var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); string installationId = null; var settings = ApplicationData.Current.LocalSettings.Values; // If we didn't store an installation ID in application data, create and store as application data. if (!settings.ContainsKey("__NHInstallationId")) { installationId = Guid.NewGuid().ToString(); settings.Add("__NHInstallationId", installationId); } installationId = (string)settings["__NHInstallationId"]; var deviceInstallation = new DeviceInstallation { installationId = installationId, platform = "wns", pushChannel = channel.Uri, //tags = tags.ToArray<string>() }; var statusCode = await CreateOrUpdateInstallationAsync(deviceInstallation, "<HUBNAME>", "<SHARED LISTEN CONNECTION STRING>"); if (statusCode != HttpStatusCode.Accepted) { var dialog = new MessageDialog(statusCode.ToString(), "Registration failed. Installation Id : " + installationId); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } else { var dialog = new MessageDialog("Registration successful using installation Id : " + installationId); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync(); } }
// Example installation format to show some supported properties { installationId: "", expirationTime: "", tags: [], platform: "", pushChannel: "", ……… templates: { "templateName1" : { body: "", tags: [] }, "templateName2" : { body: "", // Headers are for Windows Store only headers: { "X-WNS-Type": "wns/tile" } tags: [] } }, secondaryTiles: { "tileId1": { pushChannel: "", tags: [], templates: { "otherTemplate": { bodyTemplate: "", headers: { ... } tags: [] } } } } }
// Initialize the notification hub NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(listenConnString, hubName); // The Device ID from the PNS var pushChannel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); // If you are registering from the client itself, then store this registration ID in device // storage. Then when the app starts, you can check if a registration ID already exists or not before // creating. var settings = ApplicationData.Current.LocalSettings.Values; // If we didn't store a registration ID in application data, store in application data. if (!settings.ContainsKey("__NHRegistrationId")) { // Make sure there are no existing registrations for this push handle (used for iOS and Android) string newRegistrationId = null; var registrations = await hub.GetRegistrationsByChannelAsync(pushChannel.Uri, 100); foreach (RegistrationDescription registration in registrations) { if (newRegistrationId == null) { newRegistrationId = registration.RegistrationId; } else { await hub.DeleteRegistrationAsync(registration); } } newRegistrationId = await hub.CreateRegistrationIdAsync(); settings.Add("__NHRegistrationId", newRegistrationId); } string regId = (string)settings["__NHRegistrationId"]; RegistrationDescription registration = new WindowsRegistrationDescription(pushChannel.Uri); registration.RegistrationId = regId; registration.Tags = new HashSet<string>(YourTags); try { await hub.CreateOrUpdateRegistrationAsync(registration); } catch (Microsoft.WindowsAzure.Messaging.RegistrationGoneException e) { settings.Remove("__NHRegistrationId"); }
var hub = NotificationHubClient.CreateClientFromConnectionString("{connectionString}", "hubName"); // create a registration description object of the correct type, e.g. var reg = new WindowsRegistrationDescription(channelUri, tags); // Create await hub.CreateRegistrationAsync(reg); // Get by ID var r = await hub.GetRegistrationAsync<RegistrationDescription>("id"); // update r.Tags.Add("myTag"); // update on hub await hub.UpdateRegistrationAsync(r); // delete await hub.DeleteRegistrationAsync(r);