detect existense of wp7 sdk and particular components - windows-phone-7.1

Is there a way to programmatically detect the for the existence of the Windows Phone 7 SDK (versions 7.0, 7.1 and/or 7.11) and particular components such as the emulator, emulator version, emulator image version, assemblies, etc.
I'm looking to do this from a simple .NET 4 console app. How can I tell what WP7 SDK version a machine is using? has a little bit of information, but doesn't seem complete enough.
Thanks

This is the class i use for device information
public class DeviceInformation
{
public static Device GetDeviceInfo()
{
Device deviceInfo = new Device();
deviceInfo.Id = getDeviceId();
deviceInfo.Name = getDeviceName();
deviceInfo.Manufacturer = getDeviceManufacturer();
deviceInfo.OSVersion = System.Environment.OSVersion.ToString();
deviceInfo.Language = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
return deviceInfo;
}
private static String getDeviceId()
{
Object uniqueId;
StringBuilder deviceId = new StringBuilder();
if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))
{
for (int i = 0; i < ((byte[])uniqueId).Length; i++)
{
deviceId.Append(((byte[])uniqueId)[i]);
}
}
return deviceId.ToString();
}
private static String getDeviceName()
{
Object deviceName;
DeviceExtendedProperties.TryGetValue("DeviceName", out deviceName);
return deviceName.ToString();
}
private static String getDeviceManufacturer()
{
Object deviceManufacturer;
DeviceExtendedProperties.TryGetValue("DeviceManufacturer", out deviceManufacturer);
return deviceManufacturer.ToString();
}
}
Greets

I believe, you want to get information about installed developer tools on developer machine.
For that reason, one way could be to check the installed folders and for that following code can be used:
public static List<double> GetSdkVersion()
{
var versions = new List<double>();
var data = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86);
var sdkPath = Path.Combine(data, #"Microsoft SDKs\Windows Phone\v7.0");
var version = Directory.Exists(sdkPath);
versions.Add(7.0);
sdkPath = Path.Combine(data, #"Microsoft SDKs\Windows Phone\v7.1");
return versions;
}
public static List<double> GetEmulatorVersios()
{
var versions = new List<double>();
var data = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86);
var sdkPath = Path.Combine(data, #"Microsoft XDE\1.0");
var version = Directory.Exists(sdkPath);
versions.Add(1.0);
return versions;
}
Indeed, there can be better to write this code, but this is what I can come with.
Hope, it helps.

Related

Forcing specific MAUI view to Landscape Orientation using MultiTargeting Feature working for Android but not iOS

I need a specific MAUI page to be in Landscape only orientation.
I found this tutorial about forcing device orientation and I am using the multi-targeting feature of MAUI to implement the device specific code needed to force this orientation. The tutorial says that they didn't test the iOS version.
I have the tutorial working for Android (allows programmatic forcing of Landscape orientation for a single page through a singleton service) but not for iOS.
using System;
namespace ScoreKeepersBoard.DeviceServices;
public partial class DeviceOrientationService : IDeviceOrientationService
{
public partial void SetDeviceOrientation(DisplayOrientation displayOrientation);
}
Here is where I inject my device orientation service into my view model and set the orientation to landscape:
public partial class NewGameViewModel : ObservableObject
{
IGameTypeDataAccess gameTypeDataAccess;
ITeamDataAccess teamDataAccess;
IDeviceOrientationService deviceOrientationService;
[ObservableProperty]
IList<GameType> gameTypes = new List<GameType>();
[ObservableProperty]
private GameType selectedGameType;
[ObservableProperty]
private string gameTypeSelectionError;
[ObservableProperty]
private ObservableCollection<Team> teamOneTeams = new ObservableCollection<Team>();
[ObservableProperty]
private Team teamOneSelection;
[ObservableProperty]
private string teamOneSelectionError;
[ObservableProperty]
private ObservableCollection<Team> teamTwoTeams = new ObservableCollection<Team>();
[ObservableProperty]
private Team teamTwoSelection;
[ObservableProperty]
private string teamTwoSelectionError;
private ObservableCollection<Team> allTeams = new ObservableCollection<Team>();
private bool react = true;
public NewGameViewModel(IGameTypeDataAccess iGameTypeDataAccess, ITeamDataAccess iTeamDataAccess, IDeviceOrientationService iDeviceOrientationService)
{
gameTypeDataAccess = iGameTypeDataAccess;
teamDataAccess = iTeamDataAccess;
deviceOrientationService = iDeviceOrientationService;
deviceOrientationService.SetDeviceOrientation(DisplayOrientation.Landscape);
}
}
And here is my multi targeted code in the /Platforms/Android folder:
using System;
using Android.Content.PM;
namespace ScoreKeepersBoard.DeviceServices;
public partial class DeviceOrientationService
{
private static readonly IReadOnlyDictionary<DisplayOrientation, ScreenOrientation> _androidDisplayOrientationMap =
new Dictionary<DisplayOrientation, ScreenOrientation>
{
[DisplayOrientation.Landscape] = ScreenOrientation.Landscape,
[DisplayOrientation.Portrait] = ScreenOrientation.Portrait,
};
public partial void SetDeviceOrientation(DisplayOrientation displayOrientation)
{
var currentActivity = ActivityStateManager.Default.GetCurrentActivity();
if(currentActivity is not null)
{
if(_androidDisplayOrientationMap.TryGetValue(displayOrientation, out ScreenOrientation screenOrientation))
{
currentActivity.RequestedOrientation = screenOrientation;
}
}
}
}
I have similar setup for multi-targeted to iOS in /Platforms/iOS.
UPDATE: I Edited my code according to the answer from Dongzhi Wang-MSFT
using System;
using Foundation;
using UIKit;
namespace ScoreKeepersBoard.DeviceServices;
public partial class DeviceOrientationService
{
private static readonly IReadOnlyDictionary<DisplayOrientation, UIInterfaceOrientation> _iosDisplayOrientationMap =
new Dictionary<DisplayOrientation, UIInterfaceOrientation>
{
[DisplayOrientation.Landscape] = UIInterfaceOrientation.LandscapeLeft,
[DisplayOrientation.Portrait] = UIInterfaceOrientation.Portrait,
};
public partial void SetDeviceOrientation(DisplayOrientation displayOrientation)
{
if (UIDevice.CurrentDevice.CheckSystemVersion(16, 0))
{
var scene = (UIApplication.SharedApplication.ConnectedScenes.ToArray()[0] as UIWindowScene);
if (scene != null)
{
var uiAppplication = UIApplication.SharedApplication;
var test = UIApplication.SharedApplication.KeyWindow?.RootViewController;
if (test != null)
{
test.SetNeedsUpdateOfSupportedInterfaceOrientations();
scene.RequestGeometryUpdate(
new UIWindowSceneGeometryPreferencesIOS(UIInterfaceOrientationMask.Portrait), error => { });
}
}
}
else
{
UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.Portrait), new NSString("orientation"));
}
}
}
This forces the orientation to Portrait but when I switch from Portrait to Landscape the layout first switches to Landscape and then gets forced into Portrait as shown in the GIF image below.
How can I KEEP it in Portrait as the user changes the orientation?
UPDATE:
I updated my .NET MAUI and the update required me to use XCODE 14.2 and now my virtual emulators are all running iOS 16.2 and now the iOS version of the code doesn't work at all and doesn't lock the screen into any orientation.
I get this warning now in the iOS platform specific code:
It looks like for iOS version 16.2 this solution doesn't work anymore!
In Maui, you can use Invoke platform code to call the iOS native API to achieve. For details, please refer to the official documentation: Invoke platform code | Microsoft.
For iOS part of the code:
if (UIDevice.CurrentDevice.CheckSystemVersion(16, 0))
{
var scene = (UIApplication.SharedApplication.ConnectedScenes.ToArray()[0] as UIWindowScene);
if(scene != null)
{
var test = UIApplication.SharedApplication.KeyWindow?.RootViewController;
if (test != null)
{
test.SetNeedsUpdateOfSupportedInterfaceOrientations();
scene.RequestGeometryUpdate(
new UIWindowSceneGeometryPreferencesIOS(UIInterfaceOrientationMask.Landscape), error => { });
}
}
}
else
{
UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.LandscapeLeft), new NSString("orientation"));
}

Xamarin Android TypefaceSpan with custom font in Assets folder

As the title states, I need to use a TypefaceSpan object with a custom font present inside the Assets but I can't find the correct way to achieve this.
The file of the font is "HelveticaNeueLTCom-BdCn.ttf"
These are my two attempt which did not work for me:
// first attempt
var textViewTitle = new TextView(Context);
var span = new SpannableString("MyLongTitle");
span.SetSpan(new TypefaceSpan("HelveticaNeueLTCom-BdCn.ttf"), 0, 5, SpanTypes.ExclusiveExclusive);
textViewTitle.TextFormatted = span;
// second attempt
var textViewTitle = new TextView(Context);
var span = new SpannableString("MyLongTitle");
span.SetSpan(new Typeface(Typeface.CreateFromAsset(Context.Assets, "fonts/HelveticaNeueLTCom-BdCn.ttf")), 0, 5, SpanTypes.ExclusiveExclusive);
textViewTitle.TextFormatted = span;
Anyone has some hints or advice?
Almost one year later but I faced the same problem and I found this way of achieving it.
I saw you posted the same question in the Xamarin forum here but the link you wrote in your answer is broken. However, I think that it is this post that helped you as it helped me.
So here the way to go.
First create a custom TypefaceSpan like this
using System;
using Android.OS;
using Android.Runtime;
using Android.Text.Style;
using Android.Graphics;
using Android.Text;
namespace Droid.Spans
{
public class CustomTypefaceSpan : TypefaceSpan
{
private readonly Typeface _typeface;
public CustomTypefaceSpan(Typeface typeface)
: base(string.Empty)
{
_typeface = typeface;
}
public CustomTypefaceSpan(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
public CustomTypefaceSpan(Parcel src)
: base(src)
{
}
public CustomTypefaceSpan(string family)
: base(family)
{
}
public override void UpdateDrawState(TextPaint ds)
{
ApplyTypeface(ds, _typeface);
}
public override void UpdateMeasureState(TextPaint paint)
{
ApplyTypeface(paint, _typeface);
}
private static void ApplyTypeface(Paint paint, Typeface tf)
{
paint.SetTypeface(tf);
}
}
}
Then use this CustomTypefaceSpan to add a span to the SpannableString
var spannableString = new SpannableString("Anything to write with a special font");
spannableString.SetSpan(new CustomTypefaceSpan(Typeface.CreateFromAsset(Assets, "HelveticaNeueLTCom-BdCn.ttf"), 0, 7, SpanTypes.InclusiveInclusive);
textView.TextFormatted = spannableString;

Convert StackLayout as Image in Xamarin

I'm working on Xmarin Forms(PCL) project, I want to convert the StackLayout to Image / buffer and send it to printer for hard print.
Can anyone suggest how to do it in (Xamarin.Android & Xamarin.iOS).
You can't. Xamarin does not have that kind of feature. You should write a Renderer for your UIComponent.
Fortunately there is an Objective-C iOS implementation, and an Android one as well. You can inspire from them.
Taken from this link, which I have personally used, quite a while back though, the following code will take a screenshot of the entire page.
I ended up modifying the code to only take a screenshot of a specific view on the page and also changed a few other things but this example is what I based it off of, so let me know if you would rather see that code and/or if something below is not working for you.
First you create an interface in your Forms project, IScreenshotManager.cs for example:
public interface IScreenshotManager {
Task<byte[]> CaptureAsync();
}
Now we need to implement our interface in Android, ScreenshotManager.cs for example:
public class ScreenshotManager : IScreenshotManager {
public static Activity Activity { get; set; }
public async System.Threading.Tasks.Task<byte[]> CaptureAsync() {
if(Activity == null) {
throw new Exception("You have to set ScreenshotManager.Activity in your Android project");
}
var view = Activity.Window.DecorView;
view.DrawingCacheEnabled = true;
Bitmap bitmap = view.GetDrawingCache(true);
byte[] bitmapData;
using (var stream = new MemoryStream()) {
bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream);
bitmapData = stream.ToArray();
}
return bitmapData;
}
}
Then set ScreenshotManager.Activity in MainActivity:
public class MainActivity : Xamarin.Forms.Platform.Android.FormsApplicationActivity {
protected override async void OnCreate(Android.OS.Bundle bundle) {
...
ScreenshotManager.Activity = this; //There are better ways to do this but this is what the example from the link suggests
...
}
}
Finally we implement this on iOS, ScreenshotManager.cs:
public class ScreenshotManager : IScreenshotManager {
public async System.Threading.Tasks.Task<byte[]> CaptureAsync() {
var view = UIApplication.SharedApplication.KeyWindow.RootViewController.View;
UIGraphics.BeginImageContext(view.Frame.Size);
view.DrawViewHierarchy(view.Frame, true);
var image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
using(var imageData = image.AsPNG()) {
var bytes = new byte[imageData.Length];
System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, bytes, 0, Convert.ToInt32(imageData.Length));
return bytes;
}
}
}

How get current url in Microsoft Edge? [duplicate]

I'm trying to read out the TITLE & URL from the Microsoft EDGE Browser.
Doing this with System.Windows.Automation most preferably since the code base already uses this for other problems.
Is it possible with System.Windows.Automation?
How to access the URL?
I'm currently this far:
AutomationId "TitleBar"
ClassName "ApplicationFrameWindow"
Name = [string]
=> Reading out this element gives me the TITLE
=> Walking it's children, I find the item "addressEditBox":
AutomationId "addressEditBox"
ClassName "RichEditBox"
Name "Search or enter web address"
=> I always get back the string "Search or enter web address"
=> This is the control where the url is in, though it isn't updated as the user goes to a website, it always returns a fixed string.
In code:
var digger1 = AutomationElement.FromHandle(process.MainWindowHandle).RootElement.FindAll(TreeScope.Children, Condition.TrueCondition);
foreach(AutomationElement d1 in digger1 {
if(d1.Current.ClassName.Equals("ApplicationFrameWindow")) {
var digger2 = d1.FindAll(TreeScope.Children, Condition.TrueCondition);
foreach(AutomationElement d2 in digger2) {
if(d2.Current.ClassName.Equals("Windows.Ui.Core.CoreWindow")) {
var digger3 = d2.FindAll(TreeScope.Children, Condition.TrueCondition);
foreach(AutomationElement d3 in digger3) {
if(d3.Current.AutomationId.Equals("addressEditBox")) {
var url = d3.Current.Name;
return url;
}
}
}
}
}
}
You're almost there. You just need to get the TextPattern from the addressEditBox element. Here is a full sample Console app that dumps out all currently running Edge's windows on the desktop:
class Program
{
static void Main(string[] args)
{
AutomationElement main = AutomationElement.FromHandle(GetDesktopWindow());
foreach(AutomationElement child in main.FindAll(TreeScope.Children, PropertyCondition.TrueCondition))
{
AutomationElement window = GetEdgeCommandsWindow(child);
if (window == null) // not edge
continue;
Console.WriteLine("title:" + GetEdgeTitle(child));
Console.WriteLine("url:" + GetEdgeUrl(window));
Console.WriteLine();
}
}
public static AutomationElement GetEdgeCommandsWindow(AutomationElement edgeWindow)
{
return edgeWindow.FindFirst(TreeScope.Children, new AndCondition(
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window),
new PropertyCondition(AutomationElement.NameProperty, "Microsoft Edge")));
}
public static string GetEdgeUrl(AutomationElement edgeCommandsWindow)
{
var adressEditBox = edgeCommandsWindow.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.AutomationIdProperty, "addressEditBox"));
return ((TextPattern)adressEditBox.GetCurrentPattern(TextPattern.Pattern)).DocumentRange.GetText(int.MaxValue);
}
public static string GetEdgeTitle(AutomationElement edgeWindow)
{
var adressEditBox = edgeWindow.FindFirst(TreeScope.Children,
new PropertyCondition(AutomationElement.AutomationIdProperty, "TitleBar"));
return adressEditBox.Current.Name;
}
[DllImport("user32")]
public static extern IntPtr GetDesktopWindow();
}

Get a specific TestSuite by Id using the TFS API

I am trying to get a specific TestSuite using the TFS API for a TestPlan.
The TestSuite could exist anywhere within a TestSuite hierarchy, so, of course I could write a recursive function. I want something more efficient however.
Is there a method I am missing, or maybe a query that I could write?
If you already know the testSuiteId things are quite straightforward. You only need to know the name of your TeamProject teamProjectName:
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
namespace GetTestSuite
{
class Program
{
static void Main()
{
int testSuiteId = 555;
const string teamProjectName = "myTeamProjectName";
var tpc =
TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
new Uri("http://tfsURI"));
var tstService = (ITestManagementService)tpc.GetService(typeof(ITestManagementService));
var tProject = tstService.GetTeamProject(teamProjectName);
var myTestSuite = tProject.TestSuites.Find(testSuiteId);
}
}
}
If you don't, you probably need to go for a solution similar to the one presented here (it's a S.Raiten post), where recursion does come into picture. Access to a testPlanId is assumed:
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
namespace GetTestSuite
{
class Program
{
static void Main()
{
int testPlanId = 555;
const string teamProjectName = "myTeamProjectName";
var tpc =
TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
new Uri("http://tfsURI"));
var tstService = (ITestManagementService)tpc.GetService(typeof(ITestManagementService));
var tProject = tstService.GetTeamProject(teamProjectName);
var myTestPlan = tProject.TestPlans.Find(testPlanId);
GetPlanSuites(myTestPlan.RootSuite.Entries);
}
public static void GetPlanSuites(ITestSuiteEntryCollection suites)
{
foreach (ITestSuiteEntry suiteEntry in suites)
{
Console.WriteLine(suiteEntry.Id);
var suite = suiteEntry.TestSuite as IStaticTestSuite;
if (suite != null)
{
if (suite.Entries.Count > 0)
GetPlanSuites(suite.Entries);
}
}
}
}
}

Resources