Raise Azure VM from marketplace image via C# - c#

Failing to raise an azure VM from a marketplace image programatically.
The code:
var linuxVM = await _azure.VirtualMachines.Define(linuxVmName)
.WithRegion(Region)
.WithExistingResourceGroup(rgName)
.WithNewPrimaryNetwork("10.0.0.0/28")
.WithPrimaryPrivateIPAddressDynamic()
.WithoutPrimaryPublicIPAddress()
.WithSpecificLinuxImageVersion(new ImageReference())
.WithRootUsername(userName)
.WithRootPassword(password)
.WithSize(VirtualMachineSizeTypes.StandardNC6sV3)
.WithPlan(new PurchasePlan("nvidia", "ngc-base-version-20-10-1", "ngc_azure_17_11"))
.CreateAsync();
In Azure I've enabled "Want to deploy programmatically? Get started" for the given image (as explained here).
There are several options as to the method that selects the image, not sure which method should be used and with which parameters. Tried several combinations, but all returned misc error messages.
Did not find code samples more detailed this (which does not explain how to use an image from the marketplace).
Edit:
The code above returns this exception:
Microsoft.Rest.Azure.CloudException: 'This resource was created without a plan. A new plan cannot be associated with an update.'
Another attempt with more populated parameters causes the same exception:
.WithSpecificLinuxImageVersion(new ImageReference(new ImageReferenceInner(
publisher: "nvidia",
offer: "ngc_azure_17_11",
sku: "ngc-base-version-20-10-1"
)))

The missing parameter was the image's version. The code to raise the image looks like so:
var vm = await _azure.VirtualMachines.Define(linuxVmName)
.WithRegion(_region)
.WithExistingResourceGroup(_rgName)
.WithNewPrimaryNetwork("10.0.0.0/28")
.WithPrimaryPrivateIPAddressDynamic()
.WithoutPrimaryPublicIPAddress()
.WithSpecificLinuxImageVersion(new ImageReference(new ImageReferenceInner(
publisher: "nvidia",
offer: "ngc_azure_17_11",
sku: "ngc-base-version-20-10-1",
version: "20.10.1"
)))
.WithRootUsername(userName)
.WithRootPassword(password)
.WithSize(VirtualMachineSizeTypes.StandardNC6sV3)
.WithPlan(new PurchasePlan("nvidia", "ngc-base-version-20-10-1", "ngc_azure_17_11"))
.CreateAsync();
The version can be found in the UI:
It's also possible to get all the image's details via CLI:
Get-AzVMImageOffer -Location "West Europe" -PublisherName nvidia
A fuller guide can be found here

Related

How do I programmatically add a file to a fileupload control from a windows form to a webpage

I am using WebView2 in a C# windows application and I want to be able to upload screen captures.
I capture the screen and save it to a file (jpg) on the local hard drive. I want to attach this file (upload) it to the FILEUPLOAD control on a web page being displayed on a windows form using WebView2.
I was using CEFSHARP browser and was using DOM to upload the file before we switched to WebView2.
CEFSHAPRP had the DOM objects wrapped in the browser control so it was very
easy to use this code :
if (client == null)
{
client = browser.GetDevToolsClient();
dom = client.DOM.GetDocumentAsync();
}
await Task.Run(async () =>
{
QuerySelectorResponse querySelectorResponse = await client.DOM.QuerySelectorAsync(dom.Result.Root.NodeId, "#fileupload");
_ = client.DOM.SetFileInputFilesAsync(new string[] { filename }, querySelectorResponse.NodeId);
});
I do not see anything like this built into the WebView2 control. I did see that WebView has another nuget called WebView2.DOM but it requires me to convert my entire project from .NET framework 4.7.2 to .netCore.
Any help would be greatly appreciated. I am very new to WebView2 and cannot see how I can access the DOM to make this happen. I am using .net framework 4.7.2
******* June 17 Update *****
I installed the Microsoft.Web.WebView2.DevToolsProtocolExtension and tried to use the existing framework I already had working with CEFSHARP.
DevToolsProtocolHelper helper = webView21.CoreWebView2.GetDevToolsProtocolHelper();
Task<DOM.Node> t = helper.DOM.GetDocumentAsync(-1,false);
await Task.Run(async () =>
{
var querySelectorResponse = await helper.DOM.QuerySelectorAsync(t.Result.NodeId, "#fileupload");
_ = helper.DOM.SetFileInputFilesAsync(new string[] { filename }, querySelectorResponse);
});
It gives me the following error when I try to execute the line :
var querySelectorResponse = await helper.DOM.QuerySelectorAsync(t.Result.NodeId, "#fileupload");
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Web.WebView2.Core.Raw.ICoreWebView2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{76ECEACB-0462-4D94-AC83-423A6793775E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Any ideas. Thank you for all the advice and help I have received already.
I believe there would be three ways to do this;
Get the screen co-ordinates of the button, and then using send keys send an enter key to open the dialog. Then (currently webview2 cannot intercept this dialog like CefSharp) you would need to use the WinAPI to manipulate the file dialog window.
I have used 1 before. It is a little unreliable with the send keys and in waiting for the dialog to appear and then getting the timing right with the dialog.
Using javascript you should be able to add to the filelist files and then add them to the element. I have not tried this with Webview2.
Finally, and the one you already know can be used. In your question here you use DOM.SetFileInputFilesAsync which as amaitland pointed out comes from the chrome devtools protocol.. WebView2 also supports the Chrome Devtools protocols so you can effectively use the same code you already know.

Unity Android: NoClassDefFoundError: Can't create Notifications

Edit
I found out, that the requirements for showing a notification consist of setting a content-title, a context-text and a small icon. The last of which I do not do. Unfortunately, I don't know, how to provide a small icon especially in unity.
Original Question
I'm currently trying to show a notification from a unity-instance via android. I want to show the notification, when the user enters a specific gps-area. Thus, the script should run, when the app is paused. That's why I want to use the android-functionality.
With this code, I currently try to show the notification manually:
public void createNotification(){
NotificationManagerCompat nManager = NotificationManagerCompat.from(curContext);
NotificationCompat.Builder builder = new NotificationCompat.Builder(curContext, CHANNEL_ID)
.setContentTitle("Stuff")
.setContentText("MoreStuff")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
nManager.notify(1551, builder.build());
}
The context is stored in a static variable and is set, when calling the method.
The function is called in C# with:
PluginInstance.Call("createNotification");
The PluginInstance works, the function can be called, but I get the error:
AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/NotificationManagerCompat
I found the solution for my problem: I used the Unity Android Jar-Resolver in which I provided the *Dependencies.xml (Where the * presents the Name of my project). In the *Dependenices.xml I specified: <androidPackage spec="androidx.appcompat:appcompat:1.1.0"> and run through the steps, provided in the Tutorial of the Resolver.
Afterwards, multiple dependencies appeared in my /Assets/Plugin/Android-Folder, which were successfully transferred to the app, when building it.

How to enable LightningProviders for GPIO?

I am trying to access the GPIO on my custom SBC using Windows 10 IoT Core. I have discovered that I must use LightningProviders to accomplish this . So I tried to follow this guide to use lightning providers properly.
I used very simple code:
if (LightningProvider.IsLightningEnabled)
{
LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
}
GpioStatus = "Initializing...";
var gpio = GpioController.GetDefault();
if (gpio == null)
{
GpioStatus = "There is no GPIO controller on this device.";
}
else
{
gpio.OpenPin(1).Write(GpioPinValue.High);
GpioStatus = gpio.OpenPin(1).Read().ToString();
}
Where GpioStatus is output text on a UI.
I discovered that if I run the LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider(); line outside of the enabled check, it picks up the GPIO controller and lets me detect how many pins I have and read them (All low). However I can't change the DriveMode or write to the pins without error. The error I get just says to Make sure the LightningProviders are enabled.
This brings me back to the guide I linked at the start. It suggests to enable DMAP drivers using the Device Portal for W10IoT or DMAPUtil.exe. I have tried both. In the Device Portal the area where it should be is just blank. And in the command line trying to use the DMAPUtil.exe only returns that dmaputil.exe is not available on this system.
Therefore I am asking if there is any other way to enable the LightningProviders or if there a way to know if they are incompatible with my board?
Thanks!
UPDATE
Also tried using the devcon.exe commands in the W10IoT Command line.
I am able to locate the Direct memory access controller but when i do devcon.exe enable *PNP0200 it says it is enabled but remains disabled when checked with devcon.exe status *PNP0200
Please confirm if you have added the IOT_DMAP_DRIVER feature in your OEMInput.xml, this feature will add the DMAP driver in the image. If IOT_DMAP_DRIVER is removed from the OEMInput.xml, the Default Driver Controller will be blank in device protal, and dmaputil will be not available on Windows IoT Core. Please see the IoT Core feature list.
Update:
You can download the source of Lighting Provider, and then deploy and debug in your custom image.

Retrieving AVPlayerItem from Gallery Asset

I'm trying to play a video using the AVPlayer and an AVPlayerItem.
Im using following code:
asset = AVAsset.FromUrl(new NSUrl(GalleryURL));
playerItem = new AVPlayerItem(asset);
playerItem.AddObserver(this, (NSString)"status", NSKeyValueObservingOptions.OldNew, IntPtr.Zero);
player = new AVPlayer(playerItem);
the property GalleryURL is one of the following:
1.) When saving a video to the gallery, i get this url from the ALAssetsLibrary instance call: WriteVideoToSavedPhotosAlbum(url, (galleryPath, error) => { ... });
where "galleryPath" is something like this:
file:///var/mobile/Containers/Data/Application/0D510365-4A63-425B-840C-A4E18BD870A8/Documents/...
this works fine, I can create the AVAsset and retrieve the AVPlayerItemStatus, especially the status "ReadyToPlay", via the added Observer.
2.) However when I retrieve a Video from the gallery, the url looks different:
assets-library://asset/asset.MOV?id=EB9FC214...
and in this case I'm not able to retrieve a working AVAsset
How can I get part 2 to create a working AVAsset, which I can use for video playback? I believe this works in iOS versions prior to iOS 11.
Landu Lu - MSFT helped me to find the answer:
He told me that there are 2 paths that I receive from the UIImagePickerController:
The asset-library path could not be used, maybe I have to remove the "assets-library:" part? but the path beginning with "file://" could be used. The problem of the plugin was, that the start of the url was cut off, there was no "file://" at the beginning. I manually added this string and it works! Thanks alot!

C# WindowsStore inapp purchase

I'm trying to duplicate the functionality in this sample app from here : http://code.msdn.microsoft.com/windowsapps/Licensing-API-Sample-19712f1a
into an app I'm writing. I've started with working on implementing the ability to buy a consumable item.
What I've done so far:
1.) Copy the function body into the event handler for my "buy" button.
2.) Copy the WindowsStoreProxy.xml from the working sample to replace the one in my project.
3.) Double and triple checked that trial mode is false.
Note:
CurrentAppSimulator.RequestProductPurchaseAsync("product2");
Does not bring up the gui to select a return code in my project code (it did in the sample). Changing "product2" to "2" fixed that problem. However, when the awaited RequestProductPurchaseAsync returns, the following expression:
licenseInformation.ProductLicenses["2"].IsActive
is still false when in the sample says it should be true, so my code never succeeds.
Are you reading the WindowsStoreProxy.xml into the Simulator?
StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data");
StorageFile proxyFile = await proxyDataFolder.GetFileAsync("WindowsStoreProxy.xml");
await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);

Categories