connect to windows phone 8 using console application - automation

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.

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."

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

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.

How to trigger Cortana Programmatically?

Is there a way to use VoiceCommand methods used to programaticlly trigger Cortana as if the Cortana has registered "Hey Cortana" to begin listening?
I had this same question, but for Windows 10. Found a solution: on Windows 10, you can trigger Cortana with Win + C key stroke combination. To get this working programmatically, you would need interop with the Win32 SendInput method. Fortunately there is a NuGet package Windows Input Simulator, that does just this:
Install-Package InputSimulator
With that installed I was able to trigger Cortana from a WPF app using:
var sim = new InputSimulator();
sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.VK_C);
It is not possible the closest you can get is using something like this:
async static void LaunchCortana(bool untrusted, string searchText)
{
// The URI to launch
string uriToLaunch = #"http://www.bing.com/";
searchText = "search?q=" + searchText.Replace(" ", "+");
var uri = new Uri(uriToLaunch + searchText);
// Set the option to show a warning
var options = new Windows.System.LauncherOptions();
options.TreatAsUntrusted = untrusted;
// Launch the URI with a warning prompt
var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
if (success)
{
// URI launched
}
else
{
// URI launch failed
}
}
or
await Launcher.LaunchUriAsync(new Uri("bing://home"));
It works in Windows Phone 8.x only and utilizes the fact that Cortana disables Bing.com , but you can't use it to launch Cortana commands. It will just starts a Web search.

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();
}
}
}