Using Android Emulator from Windows in WMWare Fusion on a Mac – Xamarin

download.jpgYou can’t run Android in a VM so if you are running Windows on a Mac using VMWare Fusion, you’ll need to connect to the Android running on the Mac. More detail

Once you have installed Visual Studio for Mac, open it and run the emulator for Android.

On the Mac

Open a Terminal on your Mac and enter this to add the Android platform tools into the path:

echo ‘export PATH=$PATH:~/Library/Developer/Xamarin/android-sdk-macosx/platform-tools/’ >> ~/.bash_profile
source ~/.bash_profile
adb devices

If you get a permission error on the bash_profile, run this:

sudo chown YOURACCOUNTNAME ~/.bash_profile

You should see a nice list of the emulators running. That will show you that you have completed the first step. You do not need to ever run this again.

Screen Shot 2018-07-05 at 9.03.31 AM.png

Open TextEdit and add this as a text file:

#!/bin/bash
echo ‘Starting android pipe listener’
cd /tmp
mkfifo backpipe
nc -kl 5555 0<backpipe | nc 127.0.0.1 5555 > backpipe

In TextEdit go to the Format menu and choose Make Plain Text

In TexEdit save the file to your desktop but without the .txt extension. Note that we unchecked the .txt extension

Screen Shot 2018-07-05 at 9.20.27 AM.png

We now need to tell OSX that the file is an executable. Open Terminal and use the following command and path (yours will be a bit different than mine)

chmod 700 /Users/<your account>/Desktop/adb

Now we can run it by double clicking the adb file. This should will run in the background always. so many sure it’s run when you want to connect to Android from the Windows VM

Screen Shot 2018-07-05 at 10.41.07 AM.png

Screen Shot 2018-07-05 at 9.25.24 AM.png

On the PC

Now that you are running the bash script on the Mac, it’s ready to be connected to.

Add a Windows Batch file on your desktop there with the following. Run it one to have the connection set up. It will appear then disappear. If you loose connection, then run it again.

cd C:\Program Files (x86)\Android\android-sdk\platform-tools
adb.exe connect <IP address of the Mac, get it from the Mac Settings app-> network>

You’ll see the Android device in your Visual Studio:

Screen Shot 2018-07-05 at 11.05.24 AM.png

Enjoy!

Problems?

If when you use the adb devices command on the PC, you get an “unauthorized” go check the running android and ensure it isn’t asking for permission. If it is, grant it then run both script on the Mac and PC to re-establish connection.

Advertisements

Kendo Controls in an AngularJS ng-repeat

Mark_verticalKendo has long been an awesome JavaScript framework for UI controls. I had to build a user management system and needed to dynamically show a number of Kendo controls, all created via an AngularJS ng-repeat.

Kendo is smart enough to know that the item in the repeat, a user in this case, is the bound object and will keep a reference to it.

<div  ng-repeat="user in model.users">
        <input kendo-numeric-text-box
               k-min="0" k-max="10000000"
               k-ng-model="user.wealth" />
</div>

 

AngularJS: ng-repeat with Groups

1_iOmwue1uxW2O6sbDUEItPw.jpgHere’s a quick tip on how to display grouped data in AngularJS on your ASP.Net Core page (or any other).

Let’s say your have a list of cities, with their associated country already sorted by country then by city:

Canada Toronto
Canada Ottawa
Canada Vancouver

USA Boston
USA New York

To display the Country once, then all the cities, you can use this:

<div ng-repeat="(key, value) in data.cities| groupBy: 'country'">
    <h1>{{key}}</h1>
    <div ng-repeat="row in value">
        {{row.city}}
    </div>
</div>

 

ASP.Net Core 2: Quick and Dirty Windows Authentication

410329-636167162756711825-16x9.jpgHere’s the bare minimum you need to add to your ASP.Net Core 2 application to restrict it to certain Windows Active Directory groups.

 

 

 

Step 1: Enable Windows Authentication in the Project Properties:

2018-06-06_14-32-08.png

Step 2: add this to your Web.Config <aspNetCore> node:

 <aspNetCore forwardWindowsAuthToken="true"

Step 3: Enable Windows Authentication in IIS

2018-06-06_14-33-18.png

Step 4: Add Authentication to the ConfigureServices call in your Startup.cs

        public void ConfigureServices(IServiceCollection services)
        {
            // IISDefaults requires the following import:
            // using Microsoft.AspNetCore.Server.IISIntegration;
            services.AddAuthentication(IISDefaults.AuthenticationScheme);
 
            services.Configure<IISOptions>(options => {
                options.AutomaticAuthentication = true;
                options.ForwardClientCertificate = true;
            });

Step 5: Add this to your Configuration call in Startup.cs

app.UseAuthentication();

Step 6: Add [AllowAnonymous] to Controllers which need anonymous access

Step 7: Add [Authorize(Roles…)] to controllers that need to be restricted

namespace App.Web.Areas.Kxg.Controllers
{
 
    [Authorize(Roles = "MyAD\\Developer,MyAD\\IT_Support_Desk_Staff ")]
    [Area("MyArea")]
    public class CustomerSearch : Controller

Bonus!

To get a list of the Groups used in [Authorize], in PowerShell type:

whoami /groups

ps.png

ASP.Net Core 2: Shared Localization

main-qimg-82f43ebb6d5b671466ae8fbce0195735.pngIn this post we’ll cover the absolute simplest way to localize using a shared resource instead of one resx per controller. Here’s a good deep dive as there is much more to know, but this will get you going.

Step 1: Set up the Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<RequestLocalizationOptions>(
        opts =>
        {
            var supportedCultures = new List<CultureInfo>
            {
                new CultureInfo("en"),
                new CultureInfo("fr"),
            };
 
            opts.DefaultRequestCulture = new RequestCulture("en");
            // Formatting numbers, dates, etc.
            opts.SupportedCultures = supportedCultures;
            // UI strings that we have localized.
            opts.SupportedUICultures = supportedCultures;
        });

Step 2: Then update Configure()

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    var options = app.ApplicationServices
               .GetService<IOptions<RequestLocalizationOptions>>();
    app.UseRequestLocalization(options.Value);

Step 3: Add a folder called “Resources” to the web project. NOT in an external project. Add these three resx files.

2018-05-27 09_35_12-Window.png

Step 4: Reference the shared resource in your controller

public class PickersController : Controller
{
    private readonly IStringLocalizer<Startup_localizaer;
    public PickersController(IStringLocalizer<Startup> localizaer)
    {
        _localizaer = localizaer;
       var someString =  _localizaer["Your Key from Resx"];
    }