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();
}
}
}
Related
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."
I want to open an existing PDF document and add different annotations to it. Namely bookmarks and some text
I am using the Telerik Document Processing Library (dpl) v2019.3.1021.40
I am new to dpl , but I believe the RadFlowDocument is the way to go.
I am having troubles creating the RadFlowDocument
FlowProvider.PdfFormatProvider provider = new FlowProvider.PdfFormatProvider();
using (Stream stream = File.OpenRead(sourceFile))
{
--> RadFlowDocument flowDoc = provider.Import(stream);
}
The line indicated w/ the arrow give the error "Import Not Supported"
There is a telerik blog post here
https://www.telerik.com/forums/radflowdocument-to-pdf-error
It seems relevant, but not 100% sure.
It cautions to be sure the providers are mated correctly, I believe they are in my example....
Again, ultimate goal is to open a PDF and add some stuff to it. I think the RadFlowDocument is the right direction. If there is a better solution, Im happy to hear that too.
I figured it out. The DPL is pretty good, but doc is still growing, hope this helps someone out...
This draws from a myriad of articles, I cant begin to cite them all.
There are 2 notions for working w/ PDFs in the DPL.
FixedDocument takes pages. I think this is meant for sewing docs together.
FlowDocument I believe lays things out like an HTML renderer would.
I am using Fixed, mainly b/c I can get that to work.
using System;
using System.IO;
using System.Windows; //nec for Size struct
using System.Diagnostics; //nec for launching the pdf at the end
using Telerik.Windows.Documents.Fixed.Model;
//if you have fixed and flow provider, you have to specify, so I make a shortcut
using FixedProvider = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
using Telerik.Windows.Documents.Fixed.Model.Editing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace DocAggregator
{
[TestClass]
public class UnitTest2
{
[TestMethod]
public void EditNewFIle_SrcAsFixed_TrgAsFixed()
{
String dt = #"C:\USERS\greg\DESKTOP\DPL\";
String sourceFile = dt + "output.pdf";
//Open the sourceDoc so you can add stuff to it
RadFixedDocument sourceDoc;
//a provider parses the actual file into the model.
FixedProvider.PdfFormatProvider fixedProv = new FixedProvider.PdfFormatProvider();
using (Stream stream = File.OpenRead(sourceFile))
{
//'populate' the doc object from the file
//using the FLOW classes, I get "Import Not Supported".
sourceDoc = fixedProv.Import(stream);
}
int pages = sourceDoc.Pages.Count;
int pageCounter = 1;
int xoffset = 150;
int yoffset = 50;
//editor is the thing that lets you add elements into the source doc
//Like the provider, the Editor needs to match the document class (Fixed or Flow)
RadFixedDocumentEditor editor = new RadFixedDocumentEditor(sourceDoc);
foreach (RadFixedPage page in sourceDoc.Pages)
{
FixedContentEditor pEd = new FixedContentEditor(page);
Size ps = page.Size;
pEd.Position.Translate(ps.Width - xoffset, ps.Height - yoffset);
Block block = new Block();
block.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
block.TextProperties.FontSize = 22;
block.InsertText(string.Format("Page {0} of {1} ", pageCounter, pages));
pEd.DrawBlock(block);
pageCounter++;
}
string exportFileName = "addedPageNums.pdf";
if (File.Exists(exportFileName))
{
File.Delete(exportFileName);
}
File.WriteAllBytes(exportFileName, fixedProv.Export(sourceDoc));
//launch the app
Process.Start(exportFileName);
}
}
}
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.
I installed a TFS2012 as a test system and doing some tests before we go productive.
This includes to define many BuildDefinitions which was a lot of work.
After the tests are successful, an new server will be installed with TFS2012 on it.
For this new server - which operates then as the productive system - i would like to restore the BuildDefinitions from the test system. But only the BuildDefinitions, not the whole TeamCollections. Because i ran test checkins and i don`t want these on my productive server.
Now, is it possible to backup and restore BuildDefinitions only?
Maybe it is possible directly throught the Sql database?, but i`am a little affraid of references there, pointing on some other tables.
Best Regards, Peter Bucher
Build definitions are not source controlled. The only option is relying on the TFS database backup where can restore or view the tbl_BuildDefinition* tables in the Tfs_DefaultCollection database.
There is a user voice for this feature and also you can use TFS API to do it.
Add a vote on uservoice:
provide a way to version-control build definitions
Using TFS API
How can I copy a TFS 2010 Build Definition?
Finally i decided not to touch the database, because there are references to a lot of other tables.
I used the TFS API v11 (TFS2012) and a bit C# Code, which i fitted to my needs from this base: How can I copy a TFS 2010 Build Definition?
It copies all Build Definitions from one TFS2012 Server to another. For both servers there is the need to specifiy a TeamCollection and a TeamProject.
So, the copy-task has to be done per TeamProject.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace TFSBuildDefinitionCreator
{
internal class Program
{
private static void Main(string[] args)
{
// Copies build definitions from one server to another.
// Uses the TeamFoundation API V11 (TFS2012).
// Code was used to copy b uild definitions from a test server to a productive.
string sourceServer = "http://testTfs:8080/tfs/MyTeamCollection";
string sourceTeamProject = "MyTeamProject";
string targetServer = "https://productiveTfs:8080/tfs/MyTeamCollection";
string targetTeamProject = "MyTeamProject";
// DropLocation for defininitions: Share on which the build should be dropped.
string defaultDropLocation = "\\\\MyBuildserver\\Builds$";
// Change the DefaultProcessTemplate in the following method below: GetDefaultProcessTemplateByServerPathFromBuildServer.
CopyBuildDefinitions(sourceServer, sourceTeamProject, targetServer, targetTeamProject, defaultDropLocation);
Console.Read();
}
private static IBuildServer GetBuildServerFromServerUrl(string serverUrl)
{
var tfs = TeamFoundationServerFactory.GetServer(serverUrl);
return (IBuildServer)tfs.GetService(typeof(IBuildServer));
}
private static IBuildController GetDefaultBuildControllerFromBuildServer(IBuildServer buildServer)
{
return buildServer.QueryBuildControllers()[0];
}
private static IProcessTemplate GetDefaultProcessTemplateByServerPathFromBuildServer(IBuildServer buildServer, string teamProject)
{
var processTemplates = buildServer.QueryProcessTemplates(teamProject);
var result = processTemplates.First(t => t.ServerPath.Contains("/BuildProcessTemplates/MyDefaultTemplate.xaml"));
return result;
}
private static void CopyBuildDefinitions(string sourceServer, string sourceTeamProject, string targetServer,
string targetTeamProject, string defaultDropLocation)
{
var sourceBuildServer = GetBuildServerFromServerUrl(sourceServer);
var sourceBuildDetails = sourceBuildServer.QueryBuildDefinitions(sourceTeamProject);
foreach (var sourceBuildDetail in sourceBuildDetails)
{
CopyBuildDefinition(sourceBuildDetail, targetServer, targetTeamProject, defaultDropLocation);
}
}
private static void CopyBuildDefinition(IBuildDefinition buildDefinition, string targetServer, string targetTeamProject, string defaultDropLocation)
{
var targetBuildServer = GetBuildServerFromServerUrl(targetServer);
var buildDefinitionClone = targetBuildServer.CreateBuildDefinition(targetTeamProject);
buildDefinitionClone.BuildController = GetDefaultBuildControllerFromBuildServer(targetBuildServer);
buildDefinitionClone.ContinuousIntegrationType = buildDefinition.ContinuousIntegrationType;
buildDefinitionClone.ContinuousIntegrationQuietPeriod = buildDefinition.ContinuousIntegrationQuietPeriod;
// Noch ändern.
//buildDefinitionClone.DefaultDropLocation = buildDefinition.DefaultDropLocation;
buildDefinitionClone.DefaultDropLocation = defaultDropLocation;
buildDefinitionClone.Description = buildDefinition.Description;
buildDefinitionClone.Enabled = buildDefinition.Enabled;
//buildDefinitionClone.Name = String.Format("Copy of {0}", buildDefinition.Name);
buildDefinitionClone.Name = buildDefinition.Name;
//buildDefinitionClone.Process = buildDefinition.Process;
buildDefinitionClone.Process = GetDefaultProcessTemplateByServerPathFromBuildServer(targetBuildServer, targetTeamProject);
buildDefinitionClone.ProcessParameters = buildDefinition.ProcessParameters;
foreach (var schedule in buildDefinition.Schedules)
{
var newSchedule = buildDefinitionClone.AddSchedule();
newSchedule.DaysToBuild = schedule.DaysToBuild;
newSchedule.StartTime = schedule.StartTime;
newSchedule.TimeZone = schedule.TimeZone;
}
foreach (var mapping in buildDefinition.Workspace.Mappings)
{
buildDefinitionClone.Workspace.AddMapping(
mapping.ServerItem, mapping.LocalItem, mapping.MappingType, mapping.Depth);
}
buildDefinitionClone.RetentionPolicyList.Clear();
foreach (var policy in buildDefinition.RetentionPolicyList)
{
buildDefinitionClone.AddRetentionPolicy(
policy.BuildReason, policy.BuildStatus, policy.NumberToKeep, policy.DeleteOptions);
}
buildDefinitionClone.Save();
}
}
}
Hope that helps others.
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.