What is the purpose of WINRT_NOT_PRESENT? - c#

In a few Windows 8 App code samples I've seen code blocks encapsulated by these preprocessor instructions
#if !WINRT_NOT_PRESENT
#endif
Is WinRT not always present in Windows 8 Store apps?

This is used by Microsoft's NotificationsExtensions library. You need to specify this build symbol if you want to use ASP.NET to send push notifications to Windows Push Notification Services (WNS).
From Quickstart: Using the NotificationsExtensions library in your code (Windows):
You can also use NotificationsExtensions in your app server code if you are using ASP.NET to send push notifications to Windows Push Notification Services (WNS). The only caveat is that you must add the WINRT_NOT_PRESENT compilation build symbol in the NotificationsExtensions project properties.

Related

Send commands remotely to mobile app in Xamarin C#

I am developing a mobile (Xamarin.IOS) and a desktop app (C# Winforms) for our small start-up for internal use. I want to be able to send commands (not remote notifications) to the client (mobile app) through our main desktop app.
For example; I want all our employees using our mobile app to perform certain task, let's say, show a popup window with specific text when they open up the app. Any ideas about how to implement such kind of thing? Is is technically possible to tell a device to remotely execute certain management commands?
Thanks in advance.
There are multiple ways of doing this.
A Microsoft MVP, Mark Arteaga, suggests using Azure Functions-HTTP Triggers to do this. He presented this in multiple Microsoft events and also has a Github repo where he implements it in a sample mobile app.
So whenever you need to, you would send commands through Azure Functions to the client using similar, and if you want to go one step further, you can even look into implementing it with Backgrounding using Shiny

Push Notification Service for WPF based desktop app?

I need help to choose a Push Notification Service for my WPF desktop based app. I was checking on Google's Firebase, Windows Push Notification Services (WNS) etc but they all speak in context of App based environment i.e. iOS, Android or WP. Further more they have documented references for Web Apps using JavaScript.
Now i am stuck to find one which is compatible for my desktop based WPF + C# App.
Can anyone help me please?
It wouldn't work unless you convert your app (No matter if it's WPF/MFC/other desktop tech) to UWP/Store app.
Fine details are listed here:
https://msdn.microsoft.com/en-us/library/windows/desktop/mt695951(v=vs.85).aspx
Reason: WNS Push notification API doesn't support DualApiPartition attribute:
https://learn.microsoft.com/en-us/uwp/api/windows.networking.pushnotifications.pushnotificationchannelmanager
As mentioned in the comments by Wolfgang you can use Azure Notification Hubs. If you install the NuGet package Microsoft.Azure.NotificationHubs you can then use that to subscribe to notifications. It requires a minimum of .Net 4.5, so long as your WPF application is targeting that or higher you should be fine.

How to create a background application using UWP without UI?

I need to run a BLE Discovery in background and need to show toast when a device found.This is done using UWP with UI. But I need only background application. Is there any way?
Firstly I think that it is good to clarify that even if you want to create UWP app that works in background you have to create normal Universal Windows Application from template in Visual Studio:
Each UWP application can register Background Task to perform some background operations.
You can find the whole implementation guide under below link:
https://msdn.microsoft.com/en-us/windows/uwp/launch-resume/create-and-register-a-background-task
Background task has to be registered by the app so there is no way to create only Background task without the app.
Please also remember that application without UI will not pass Windows Store certification.
Lukmanul Hakim,
I have been facing a similar problem and found the best way is through a windows service. In particular:
BluetoothLEAdvertisementWatcher works in Windows services, unit test projects, and UWP packages (with the right manifest capabilities).
The advertisment watcher executes but does not deliver data/events in WPF desktop apps and .net command line programs.
As you note, UWP seems to require annoying UI and can only communicate in a limited way via app services.
Once you have the data in a windows service, you can do work there or communicate with any desktop app using regular IPC mechanisms like named pipes.
You will need to install the Windows 10 SDK and reference the windows runtime typically at: C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
For reference here is the basic code to get advertisments:
var watcher = new BluetoothLEAdvertisementWatcher();
watcher.Received += OnAdvertismentReceived;
watcher.Start();

Add/Start/Stop IoT Core application from another application

I would like to add/start/stop/remove an application (IoT Core) just like the web interface or the Power Shell commands: "IotStartup" but from within a C# application running on the IoT Core itself.
Is there a c# API for this or do I have to implement the Power Shell commands inside my application?
Using the Device Portal API could work for you.
Here are the docs.
https://learn.microsoft.com/en-us/windows/uwp/debug-test-perf/device-portal-api-core
Device Portal APIs are intended for remote management, and may not work from within a UWP against localhost due to loopback restrictions in Windows (to prevent an app from attacking the device it's running on).
That said, the Windows.Management.Deployment.PackageManager class provides installation and removal APIs for apps. To launch an app, you can use Windows.System.Launcher. Note that PackageManager is a restricted capability, so the app won't be able to go into the Store without special permissions from Microsoft. It will work in sideloaded scenarios though.
There is no way to close an app from another app with existing APIs. However, Launching the app using the above, then connecting with an AppServiceConnection to manage it, you can send a "Close" message over the AppServiceConnection that causes the app to close itself.

How do I real time communicate a Universal Windows App with a older .Net 4.5 app in the same solution. IPC?

I have been struggling with this for over a month, but am slowly learning. Here is what I have:
C# Solution With 3 Projects
-Universal Windows Platform App (Cortana Voice Support)
::Above just shows a floating PNG image and is Cortana enabled
-Universal Windows Service (Cortana Background Service)
::Needed for the Cortana Support
-.Net 4.5 C# App with HTML DOM Automation
::Automates locating elements and clicking of a website
I can't re-code my .Net app's functionality in my Universal app because some of the libraries it uses won't install. (GhostDriver, PhantomJS, and a HotKey Library provided via NuGet. Installing on the Universal Platform fails on all 3 libraries).
What is needed:
-Master Universal Windows App or Service sends signal to .Net App
-.Net App receives signal and calls method/function providing my functionality.
I've never tried calling methods in other apps within the same solution and was wondering if there was a few-code workaround. What I need I think is a method of inter process communication or events, but can't find any examples of a UWP. Most are .Net communicating with other older non universal apps.
Thank you so much!
If I understand correctly, you were developing a app which will can automate the DOM operation through Cortana.
Do you need to submit this app to App Store?
If no, as Scott said, you can use WCF to communicate between UWP process and .NET 4.5 desktop app process.
If yes, as Andrew pointed out, you need an intermediate remote server hosting the service.

Categories