Does Microsoft Band SDK support a UWP app on windows 10 iot pulling data from the Band? - raspberry-pi2

I want to pull sensor data from the band using a UWP app on windows 10 iot raspberry pi. The app runs perfectly when running on windows 10 machine however, when running on windows 10 iot, it shows errors.
The execution breaks in an auto generated code in file App.g.i.cs:
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached)global::System.Diagnostics.Debugger.Break();
};
#endif
In call stack it shows:
FFM.exe!FFM.App.InitializeComponent.AnonymousMethod__5_1(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e) Line 53 C#
Line 53 is of the auto generated code:
if (global::System.Diagnostics.Debugger.IsAttached)global::System.Diagnostics.Debugger.Break();
Debug output shows following:
Exception thrown: 'System.NotImplementedException' in mscorlib.ni.dll
The band is able to connect to windows 10 iot Raspi but as soon as there is code that asks for user consent to access heartrate sensor data, the above errors start showing.
Following is my code to get user consent. Much of it is from the band SDK Documentation:
private async void connect()
{
//Get a list of paired bands
IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
string band_name = pairedBands[0].Name;
if (band_name.Length > 0)
{
bandName.Text = "Band Name is: " + band_name;
try
{
fwVer.Text = "Will try to connect to band";
IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]);
fwVer.Text = "Connected to Band";
fwVersion = await bandClient.GetFirmwareVersionAsync();
hwVersion = await bandClient.GetHardwareVersionAsync();
fwVer.Text = "Firmware Version is " + fwVersion;
hwVer.Text = "Hardware Version is " + hwVersion;
string band1v = "9";
if (hwVersion.Equals(band1v, StringComparison.Ordinal))
{
// Do work with Version 1 of the band
bandVer.Text = "Band is Version 1";
//User consent check to use heartbeat sensor data
if (bandClient.SensorManager.HeartRate.GetCurrentUserConsent() != UserConsent.Granted)
{
//Get user consent
await bandClient.SensorManager.HeartRate.RequestUserConsentAsync();
}
if (bandClient.SensorManager.HeartRate.GetCurrentUserConsent() == UserConsent.Granted)
{
//DO work
}
else
{
hrConsent.Text = "Access to HeartReat sensor is denied";
}
}
else //Its a 2nd version of band
{
//Do work with version 2 of the band
bandVer.Text = "Band is Version 2";
}
}
catch (BandException ex)
{
//handle a band connection exception
fwVer.Text = "Could not connect to above band";
}
}
else
{
bandName.Text = "No Available Bands";
}
}
Following are the libraries I am using:
using System;
using System.Threading;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Microsoft.Band;
using Microsoft.Band.Sensors;
using Microsoft.IoT;
using Windows.Devices.Bluetooth;
using Windows.Devices.Bluetooth.GenericAttributeProfile;

When the application calls RequestUserConsentAsync() the Band SDK displays a dialog message to the user to obtain that consent. However, it appears that Windows.UI.Popups.MessageDialog is not yet supported by Windows IoT Core (see unavailable API list).
That may be the cause of the exception.

Related

I would like to intercept the MS Teams notifications about poor network quality, during calls

In order to diagnose a network condition I am trying to intercept (at least on Windows) the notifications about poor network quality that Teams pops-up sometimes, during a call.
For testing, I am using "clumsy", in order to generate iffiness in the network, while in a teams audiovideo call to my phone.
I was wondering if an API would provide a local interface to teams an allow me to subscribe to those events.
So far if found a type library in C:\Users\xxx\AppData\Local\Microsoft\TeamsPresenceAddin\Uc.tlb that looks promising because of the idl file that the oleviewer generates from it:
ModalityProperty in uc.tlb is an enum and contains these two values:
ucAVModalityAudioNetworkQuality = 0x300b001d,
ucAVModalityVideoNetworkQuality = 0x300b0021,
That enum is used by the interface _IAVModalityEvents and that looks to be fired by the coclass AVModality:
[
uuid(BA2BD6F3-7676-42E3-89C6-10CEB3F7E106),
helpstring("AVModality class defines the audio video modality.This class handles the events defined in the interface IAVModalityEvents."),
noncreatable,
custom(5047D0E3-86FD-4EB4-A500-AC4F5B4E17E1, "relns=Conversation.AudioVideo")
]
coclass AVModality {
[default] interface IAVModality;
interface IAVModality2;
**[default, source] dispinterface _IAVModalityEvents;**
};
Does anyone have an idea on how to connect to the running Teams instance (tried ROT but it doesn't seem to be registered) and how to enum modalities in order to get to the AVModality and subscribe to its events ?
Update 1:
I actually got some partial results with the Uc.tlb.
First I ran: TlbImp.exe Uc.tlb to create a C# assembly from it.
I then built the following C# app to intercept conversation changes:
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Xml;
using UCCollaborationLib;
class Program
{
//Teams CLSID harvested from registry
// Take a looksie at: https://stackoverflow.com/questions/56865704/com-object-for-teams-client-microsoft-office-uc
[ComImport, Guid("00425F68-FFC1-445F-8EDF-EF78B84BA1C7")]
public class TeamsOfficeIntegration
{
}
static void Main(string[] args)
{
var version = "15.0.0.0";
IUCOfficeIntegration teamsOfficeIntegration = (IUCOfficeIntegration) new TeamsOfficeIntegration();
if (teamsOfficeIntegration == null) {
Console.WriteLine("Cannot instantiate UCOfficeIntegration for Teams");
return;
}
IClient teamsClient = (IClient) teamsOfficeIntegration.GetInterface(version, OIInterface.oiInterfaceILyncClient);
if (teamsClient == null) {
Console.WriteLine("Cannot retrieve Teams Client interface");
return;
}
var teamsConversationManager = teamsClient.ConversationManager;
if (teamsConversationManager == null) {
Console.WriteLine("Cannot retrieve Teams ConversationManager interface");
return;
}
// Handle Teams Conversation Collection events
teamsConversationManager.OnConversationAdded += (ConversationManager _eventSource, ConversationManagerEventData _eventData) => { Console.WriteLine("Conversation added");};
teamsConversationManager.OnConversationRemoved += (ConversationManager _eventSource, ConversationManagerEventData _eventData) => { Console.WriteLine("Conversation removed");};
//iterate SelfParticipant or Modalities -> iterate IAVModality -> IConnectionPoint
}
}
The good news is that, when Teams is stopped it tries to start it so it does CoCreateInstance on the Teams LocalServer so it should be able to interact with it. The bad news is that even if the Teams app starts or is being attached to the creation fails with the following entry in the EventViewer/AdministrativeEvents:
"The server {00425F68-FFC1-445F-8EDF-EF78B84BA1C7} did not register with DCOM within the required timeout."

Render Razor View into String using .Net Core Console Application

I have prepared a .net core console application (Framework version .Net Core 2.2) for sending email as a service. Right now its working completely fine with static html content being hardcoded into service method for generating email body string.
I am in seek of the code which provides me a solution to render a razor view to have a html string with the model data.
Tried to implement the RazorEngine dll in entity framework ver. 4.5. with below code
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GenerateEmailUsingRazor.Model;
using RazorEngine.Templating;
namespace GenerateEmailUsingRazor
{
class Program
{
static readonly string TemplateFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EmailTemplates");
static void Main(string[] args)
{
var model = GetUserDetail();
var emailTemplatePath = Path.Combine(TemplateFolderPath, "InviteEmailTemplate.cshtml");
var templateService = new TemplateService();
var emailHtmlBody = templateService.Parse(File.ReadAllText(emailTemplatePath), model, null, null);
Console.WriteLine(emailHtmlBody);
Console.ReadLine();
}
private static UserDetail GetUserDetail()
{
var model = new UserDetail()
{
Id = 1,
Name = "Test User",
Address = "Dummy Address"
};
for (int i = 1; i <= 10; i++)
{
model.PurchasedItems.Add("Item No " + i);
}
return model;
}
}
}
Expected Result:
Console Application should render the razor view and provide me the resultant html string.
I've written a clean library Razor.Templating.Core that works with .NET Core 3.0, 3.1 on both web and console app.
It's available as NuGet package.
After installing, you can call like
var htmlString = await RazorTemplateEngine
.RenderAsync("/Views/ExampleView.cshtml", model, viewData);
Note: Above snippet won't work straight away. Please refer the below working guidance on how to apply it.
Complete Working Guidance: https://medium.com/#soundaranbu/render-razor-view-cshtml-to-string-in-net-core-7d125f32c79
Sample Projects: https://github.com/soundaranbu/RazorTemplating/tree/master/examples

code C# use the Google OAuth to sign Google Acount

My code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Apis.Blogger.v3;
using Google.Apis.Blogger.v3.Data;
using Google.Apis.Services;
using System.Diagnostics;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Util;
namespace BloggerTest
{
class Program
{
static void Main(string[] args)
{
string apiKey= "{API-KEY}";
string blogUrl= "{BLOG-URL}";
string clientID = "{CLIENT_ID}";
string clientSec = "{CLIENT_SECRET}";
NativeApplicationClient provider = new NativeApplicationClient(GoogleAuthenticationServer.Description)
{
ClientIdentifier = clientID,
ClientSecret = clientSec
};
OAuth2Authenticator<NativeApplicationClient> auth = new OAuth2Authenticator<NativeApplicationClient>(provider, getAuth);
BloggerService blogService = new BloggerService(new BaseClientService.Initializer()
{
Authenticator = auth,
ApplicationName = "BloggerTest"
});
BlogsResource.GetByUrlRequest getReq = blogService.Blogs.GetByUrl(blogUrl);
getReq.Key = apiKey;
Blog blog = getReq.Execute();
Console.WriteLine(blog.Id);
Console.ReadKey();
}
private static IAuthorizationState getAuth(NativeApplicationClient arg)
{
IAuthorizationState state = new AuthorizationState(new[] { BloggerService.Scopes.Blogger.GetStringValue() })
{
Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl)
};
Uri authUri = arg.RequestUserAuthorization(state);
Process.Start(authUri.ToString());
Console.WriteLine("Please enter auth code:");
string authCode = Console.ReadLine();
return arg.ProcessUserAuthorization(authCode, state);
}
}
}
And it have 2 error:
'Google.Apis.Services.BaseClientService.Initializer' does not contain a definition for 'Authenticator'
'Google.Apis.Blogger.v3.BloggerService' does not contain a definition for 'Scopes'
Can you help me fix. Thank you very much!
I get code from: http://garyngzhongbo.blogspot.com/2013/10/bloggerc-blogger-api-v3-6oauth-20.html
There are two common problems faced by beginners when the implement Google APIs. These are both due to the API libraries being unstable, and changing from one release to the next.
When the API changes, the sample apps don't. So developers try to use out of date code with the latest API.
Links to old versions of the API libraries are not purged. So developers can find themselves downloading old libraries.
So 1 and 2 are kinda the opposite, but both occur. Problem 1 is the more common.
So in this case, check that you have downloaded the very latest versions of the API library, and check if the missing definitions have in fact been withdrawn, in which case you'll need to find a more up to date example.

Switching monitor/tv display modes for Windows

I have 2 DELL monitors and a tv. I frequently use my tv to stream movies. I'd like to create a script so that my secondary screen switches from my secondary DELL monitor to the tv without affecting my primary monitor.
I know this can be achieved by various means, but I'd like to create a script so that it will be able to detect the current active screen and then switch to the other so that my wife can just double click on it to switch between the two.
Can someone help me get started by letting me know which scripting language I can use and which libraries/dlls I will need to use?
For anyone who's curious I ended up creating a C# console application for this. This way I could use the WinAPIs to determine what display mode I was in and switch to the one that I wanted. It won't be setup for how everyone will want it but it should be a good starting point.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DisplaySwitcher
{
class Program
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int GetSystemMetrics(int nIndex);
public const int SM_CMONITORS = 80;
static void Main(string[] args)
{
int iNumberOfDisplays = GetSystemMetrics(SM_CMONITORS);
string displaySwitch = null;
switch (iNumberOfDisplays)
{
case 1: // TV mode (only detects 1 display)
displaySwitch += "/external";
break;
case 2: // Normal mode (extended display)
displaySwitch += "/clone";
break;
default:
MessageBox.Show("Unknown display mode detected");
break;
}
executeCommand(displaySwitch);
}
private static void executeCommand(string displaySwitch)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "DisplaySwitch.exe";
startInfo.Arguments = displaySwitch;
process.StartInfo = startInfo;
process.Start();
}
}
}

connect to windows phone 8 using console application

I am very new to windows phone development. I want to develop an app that will be launched when I connect my windows 8 phone to my laptop. I was following this tutorial (http://justinangel.net/WindowsPhone7EmulatorAutomation) and was able to connect to my windows 7 phone/emulator but I am not able to connect to my windows 8 phone or emulator. Is there any other way to connect to windows 8 phone?
Please let me know if there is any possible solution for this,
Thank you
I didn't get a chance to update this blog post yet. Delvis Gomez (A colleague on of mine) has updated the final code sample and OKed distributing it freely. I'll update that blog post for WP8 in the future, but in the meanwhile here's a pretty well documented code snippet on how to automate the WP8 Emulator.
Also, make sure to add a reference to the new DLLs needed like Microsoft.SmartDevice.MultiTargeting.Connectivity.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Reflection;
// Libraries needed to connect to the Windows Phone X Emulator
using Microsoft.SmartDevice.Connectivity;
using Microsoft.SmartDevice.Connectivity.Interface;
using Microsoft.SmartDevice.MultiTargeting.Connectivity;
using System.Globalization;
using System.Collections.ObjectModel;
namespace AutomatedUnitTestDriver
{
class Program
{
static void Main(string[] args)
{
MultiTargetingConnectivity connectivity = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
// Get a connectable device for a specific Device ID (from the CoreCon datastore)
string deviceId = "5E7661DF-D928-40ff-B747-A4B1957194F9";
ConnectableDevice connectableDevice = connectivity.GetConnectableDevice(deviceId);
Console.WriteLine("Found Connectable Device \'" + connectableDevice.Name + "\' for Device id {" + connectableDevice.Id + "}.");
// Connect to the Device
Console.WriteLine("Connecting to Device...");
IDevice iDevice = connectableDevice.Connect();
Console.WriteLine("Done!");
// Check if the application is already install, if it is remove it (From WMAppManifect.xml)
Guid appID = new Guid("{b6635769-b7ac-41a5-915d-5a7b0ae34481}");
if (iDevice.IsApplicationInstalled(appID))
{
Console.WriteLine("Uninstalling application...");
iDevice.GetApplication(appID).Uninstall();
Console.WriteLine("Done!");
}
Guid productId = appID;
Guid instanceId = appID;
string applicationGenre = "NormalApp";
string iconPath = #"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\ApplicationIcon.png";
string xapPackage = #"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\AutomatedUnitTests.xap";
// Install the application
Console.WriteLine("Installing the application...");
IRemoteApplication remoteApplication = iDevice.InstallApplication(appID, appID, applicationGenre, iconPath, xapPackage);
Console.WriteLine("Done!");
// Launch the application
Console.WriteLine("Starting the application...");
remoteApplication.Launch();
int startStopWaitTime = 1000; // msec
int executionWaitTime = 180000; // msec
// Note that IRemoteApplication has a 'IsRunning' method but it is not implemented.
// So, for the moment we sleep few msec.
Thread.Sleep(startStopWaitTime);
Console.WriteLine("Done!");
// Allow application to complete
Console.WriteLine("Application is running! Waiting few seconds...");
Thread.Sleep(executionWaitTime);
try
{
IRemoteIsolatedStorageFile remoteIsolatedStorageFile = remoteApplication.GetIsolatedStore();
string sourceDeviceFilePath = (object)Path.DirectorySeparatorChar + "TestResults.trx";
string targetDesktopFilePath = #"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\" + "TestResults.trx";
remoteIsolatedStorageFile.ReceiveFile(sourceDeviceFilePath, targetDesktopFilePath,true);
}
catch (Exception exception)
{
Console.WriteLine("Exception \'" + exception.Message + "\' reading file from device.");
}
// Terminate application
Console.WriteLine("Terminating the application...");
remoteApplication.TerminateRunningInstances();
Thread.Sleep(startStopWaitTime);
Console.WriteLine("\nDone!");
// Disconnect from the emulator
Console.WriteLine("Disconnecting Device...");
iDevice.Disconnect();
Console.WriteLine("\nDone!");
}
}
}
I had trouble implementing the accepted solution because I was missing the references for these namespaces:
Microsoft.SmartDevice.Connectivity.Interface
Microsoft.SmartDevice.MultiTargeting.Connectivity
Here's where I found them:
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\
Microsoft.SmartDevice.Connectivity.Interface\
v4.0_11.0.0.0__b03f5f7f11d50a3a\
Microsoft.Smartdevice.Connectivity.Interface.dll
and
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\
Microsoft.SmartDevice.MultiTargeting.Connectivity\
v4.0_11.0.0.0__b03f5f7f11d50a3a\
Microsoft.Smartdevice.MultiTargeting.Connectivity.dll
Note that these paths, especially the v4.0_11.0.0.0__b03f5f7f11d50a3a part, may be different on your system. Add references to these DLLs in your project, and everything should work properly.