How to trigger Cortana Programmatically? - windows-phone

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.

Related

Genesys Platform : Get Call Details From Sip Server

I want to get Call Details from Genesys Platform SIP Server.
And Genesys Platform has Platform SDK for .NET .
Anybod has a SIMPLE sample code which shows how to get call details using Platform SDK for .NET [ C# ] from SIP Server?
Extra Notes:
Call Details : especially i wanted to get AgentId for a given call
and
From Sip Server : I am not sure if Sip Server is the best candiate to
take call details. So open to other suggestions/ alternatives
You can build a class that monitor DN actions. Also you watch specific DN or all DN depending what you had to done. If its all about the call, this is the best way to this.
Firstly, you must define a TServerProtocol, then you must connect via host,port and client info.
var endpoint = new Endpoint(host, port, config);
//Endpoint backupEndpoint = new Endpoint("", 0, config);
protocol = new TServerProtocol(endpoint)
{
ClientName = clientName
};
//Sync. way;
protocol.Open();
//Async way;
protocol.BeginOpen();
I always use async way to do this. I got my reason thou :) You can detect when connection open with event that provided by SDK.
protocol.Opened += new EventHandler(OnProtocolOpened);
protocol.Closed += new EventHandler(OnProtocolClosed);
protocol.Received += new EventHandler(OnMessageReceived);
protocol.Error += new EventHandler(OnProtocolError);
Here there is OnMessageReceived event. This event where the magic happens. You can track all of your call events and DN actions. If you go genesys support site. You'll gonna find a SDK reference manual. On that manual quiet easy to understand there lot of information about references and usage.
So in your case, you want agentid for a call. So you need EventEstablished to do this. You can use this in your recieve event;
var message = ((MessageEventArgs)e).Message;
// your event-handling code goes here
switch (message.Id)
{
case EventEstablished.MessageId:
var eventEstablished = message as EventEstablished;
var AgentID = eventEstablished.AgentID;
break;
}
You can lot of this with this usage. Like dialing, holding on a call inbound or outbound even you can detect internal calls and reporting that genesys platform don't.
I hope this is clear enough.
If you have access to routing strategy and you can edit it. You can add some code to strategy to send the details you need to some web server (for example) or to DB. We do such kind of stuff in our strategy. After successful routing block as a post routing strategy sends values of RTargetPlaceSelected and RTargetAgentSelected.
Try this:
>
Genesyslab.Platform.Contacts.Protocols.ContactServer.Requests.JirayuGetInteractionContent
JirayuGetInteractionContent =
Genesyslab.Platform.Contacts.Protocols.ContactServer.Requests.JirayuGetInteractionContent.Create();
JirayuGetInteractionContent.InteractionId = "004N4aEB63TK000P";
Genesyslab.Platform.Commons.Protocols.IMessage respondingEventY =
contactserverProtocol.Request(JirayuGetInteractionContent);
Genesyslab.Platform.Commons.Collections.KeyValueCollection keyValueCollection =
((Genesyslab.Platform.Contacts.Protocols.ContactServer.Events.EventGetInteractionContent)respondingEventY).InteractionAttributes.AllAttributes;
We are getting AgentID and Place as follows,
Step-1:
Create a Custome Command Class and Add Chain of command In ExtensionSampleModule class as follows,
class LogOnCommand : IElementOfCommand
{
readonly IObjectContainer container;
ILogger log;
ICommandManager commandManager;
public bool Execute(IDictionary<string, object> parameters, IProgressUpdater progress)
{
if (Application.Current.Dispatcher != null && !Application.Current.Dispatcher.CheckAccess())
{
object result = Application.Current.Dispatcher.Invoke(DispatcherPriority.Send, new ExecuteDelegate(Execute), parameters, progress);
return (bool)result;
}
else
{
// Get the parameter
IAgent agent = parameters["EnterpriseAgent"] as IAgent;
IIdentity workMode = parameters["WorkMode"] as IIdentity;
IAgent agentManager = container.Resolve<IAgent>();
Genesyslab.Desktop.Modules.Core.Model.Agents.IPlace place = agentManager.Place;
if (place != null)
{
string Place = place.PlaceName;
}
else
log.Debug("Place object is null");
CfgPerson person = agentManager.ConfPerson;
if (person != null)
{
string AgentID = person.UserName;
log.DebugFormat("Place: {0} ", AgentID);
}
else
log.Debug("AgentID object is null");
}
}
}
// In ExtensionSampleModule
readonly ICommandManager commandManager;
commandManager.InsertCommandToChainOfCommandAfter("MediaVoiceLogOn", "LogOn", new
List<CommandActivator>() { new CommandActivator()
{ CommandType = typeof(LogOnCommand), Name = "OnEventLogOn" } });
enter code here
IInteractionVoice interaction = (IInteractionVoice)e.Value;
switch (interaction.EntrepriseLastInteractionEvent.Id)
{
case EventEstablished.MessageId:
var eventEstablished = interaction.EntrepriseLastInteractionEvent as EventEstablished;
var genesysCallUuid = eventEstablished.CallUuid;
var genesysAgentid = eventEstablished.AgentID;
.
.
.
.
break;
}

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.

Can the Windows 8 Live SDK use another Microsoft Account other than the current user?

Using the Windows 8 Live SDK you can have a user give you permission to their Microsoft Account. With this you can get their name and photo and more. But using the Live SDK appears to require the user of the app to use the same Microsoft Account as whoever is signed into the current session of Windows 8.
In some scenarios, using a different account is very legitimate.
I have simple sign-in working like a charm! This uses the same account.
I can't find a way to do use another. Is it possible?
You can call Logout after Init and before LoginUser.
Here's the code for javascript:
function LiveLogin(){
WL.init("<<Your clientID goes here>>");
if (WL.canLogout()) {
WL.logout(function () {Callback(callback);});
}
else{
Callback(callback);
}
}
function Callback(){
WL.login({ scope: ["wl.signin", "wl.basic", "wl.emails"] }, function () {
var session = WL.getSession();
// do stuff with your session
});
}
And this is for C#:
LiveAuthClient liveAuthClient = new LiveAuthClient();
List<string> scopes = new List<string>();
scopes.Add("wl.signin");
scopes.Add("wl.basic");
scopes.Add("wl.emails");
LiveLoginResult loginResult = await liveAuthClient.InitializeAsync();
if (liveAuthClient.CanLogout)
{
liveAuthClient.Logout();
}
loginResult = await liveAuthClient.LoginAsync(scopes);
It worked for me.
I hope this is what you are looking for.

Trouble Attaching File Programmatically to Email in Windows Metro App C#/XAML using Share Charm

I'm simply trying to attach a file named Document.pdf in the DocumentsLibrary to an email using the Share Charm. My code below works perfectly on the Local Machine:
private async void OnDataRequestedFiles(DataTransferManager sender, DataRequestedEventArgs e)
{
List<IStorageItem> shares = new List<IStorageItem>();
StorageFile filetoShare = await Windows.Storage.KnownFolders.DocumentsLibrary.GetFileAsync("Document.pdf");
if (filetoShare != null)
{
shares.Add(filetoShare);
filetoShare = null;
}
if (shares != null)
{
DataPackage requestData = e.Request.Data;
requestData.Properties.Title = "Title";
requestData.Properties.Description = "Description"; // The description is optional.
requestData.SetStorageItems(shares);
shares = null;
}
else
{
e.Request.FailWithDisplayText("File not Found.");
}
}
But when I run the exact same code on a Windows Surface Tablet, I get the dreaded "There's nothing to share right now." on the right in the Charms flyout area.
Here's a little more background to help:
I'm not looking to use a File Picker...I know the exact file I'm looking for
I've enabled the Documents Library Capability in the manifest
I've added a File Type Association for pdf in the manifest
and yes, the file does exist and is in the Documents Library
an email account is properly setup in the Mail App on the surface
I can successfully send text emails from the Tablet...just not emails with attachments
Like I said, this works on my Win 8 Development Machine as expected...just not on the Surface. I'm wondering if the Surface has different file or folder permissions?
Thanks for the help...this is driving me CRAZY
I finally figured it out - the problem was that my Event Handler was async (so that I could use await to set the StorageFile variable).
I solved it by setting the StorageFile variable earlier in my code so that it was already available when the Event Handler was called.
I still have no idea why it worked on my development machine, but no on the WinRT surface...
The handler can be an async method. In this case, it is critical to use DataTransferManager. Please refer to the MSDN page specifically for this scenario. For your convenience, the code from the page is copied to here:
private void RegisterForShare()
{
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager,
DataRequestedEventArgs>(this.ShareStorageItemsHandler);
}
private async void ShareStorageItemsHandler(DataTransferManager sender,
DataRequestedEventArgs e)
{
DataRequest request = e.Request;
request.Data.Properties.Title = "Share StorageItems Example";
request.Data.Properties.Description = "Demonstrates how to share files.";
// Because we are making async calls in the DataRequested event handler,
// we need to get the deferral first.
DataRequestDeferral deferral = request.GetDeferral();
// Make sure we always call Complete on the deferral.
try
{
StorageFile logoFile =
await Package.Current.InstalledLocation.GetFileAsync("Assets\\Logo.png");
List<IStorageItem> storageItems = new List<IStorageItem>();
storageItems.Add(logoFile);
request.Data.SetStorageItems(storageItems);
}
finally
{
deferral.Complete();
}
}
It is critical to place the following statement before any async method is called:
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
You only have half a second to get the whole job done (getting the file, attaching...etc.). If the half-second deadline occurs you'll get this "driving crazy" message. Consider implementing some resumable logic and replace the message with "the attachment is being prepared please try again in a few seconds" (or else).
Your WinRT device might be just slower than your development machine. The latter just does the job before the deadline...

windows 8 modern ui apps - access to data

Where can i find folder with installed modern ui apps? Im developing some app which uses .txt files to store information (win8 doesnot support datebase on arm - facepalm) but they seem to not work properly - thats why i want to access them.
Thanks!
That is not the correct way of doing things in Metro. I assume you mean db files, or txt files. Simply access the local text file from the project folder.
Here is a great tutorial on how you would go about doing so: http://www.codeproject.com/Articles/432876/Windows-8-The-Right-Way-to-Read-Write-Files-in-Win
An example:
private async void ProjectFile()
{
// settings
var _Path = #"Metro.Helpers.Tests\MyFolder\MyFolder.txt";
var _Folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
// acquire file
var _File = await _Folder.GetFileAsync(_Path);
Assert.IsNotNull(_File, "Acquire file");
// read content
var _ReadThis = await Windows.Storage.FileIO.ReadTextAsync(_File);
Assert.AreEqual("Hello world!", _ReadThis, "Contents correct");
}