Thursday, October 08, 2015

Why this new Microsoft is impressive

The last Microsoft event on October 6 showed a few surprises, let me explain you why this is impressive and why I think the new Nadella direction at MS is different. Iris Scanner, Liquid Cooling, Continuum...

A new Surface 4 tablet with Liquid Cooling
The new Surface 4 was a really good upgrade, and a real big one. More resolution in the same size, up to 16GB of RAM and 1TB of HDD and Liquid Cooling. All that packaged in a device as think as this, only 8.5mm of depth.

Check how the cooling works.

New phones with Continuum and Liquid Cooling

I know Windows only have 3% of the market on phones, and that's a bummer because we don't get to have all the apps. But now the new phones have continuum, a feature that allows using a phone as a full size computer. They also manage to get liquid cooling into a handheld device. That's a good direction. Let's just hope this new direction combined with universal apps will get more developers into the boat.

A new Surface Book.

Think got even crazier when MS announced this product, I think is safe to say that nobody saw it coming. A new powerful laptop hybrid (although expensive) and a crazy beautiful product. Looks like Microsoft is finally putting good design in combination with good specs in an effort to gain the consumer market.

That's impressive, right?

A new line of products, beautiful and powerful. New technologies like continuum, iris scanner and liquid cooling in devices so thin and small. New redesigned products like the new Band or the new Pen for Surface. This is a new MS, way different than the one that created the Zune. 

PS: if you reading this from CodeProject then the CP crawler is still buggy and pulling posts without the CodeProject tag.

Friday, October 02, 2015

Fixing Visual Studio 2015 Android Designer with Xamarin

While using Visual Studio 2015 to edit and android layout file (axml) I got this error:

 The installed Android SDK is too old. Version 24.3.4 or newer is required

The number version might be different in your case. Here are a few possible causes for the error:

1) You actually need to upgrade your Android SDK.
2) You have the wrong path for the Android SDK installation on Visual Studio. (change it on Tools->Options->Xamarin)
3) Mixed Xamarin extensions (this was my case)

After reinstalling the Android SDK and checking the everything was fine on that part I went to check on Visual Studio extensions (Tools->Extensions and Updates). It turns out that  I caused a mix up of versions, since I already had Xamarin and Visual Studio 2013 side by side. and now 2015 had another one, my Visual Studio 2015 ended up with 2 extensions for Xamarin. Disabling one of them solved the problem and the designer was working again.

The one that I disabled was titled "Get Xamarin" and I kept the one that shows in the image. Unfortunately I uninstalled the bad extension before taking a screenshot.

Now you might not experience this problem if you have VS2015 in a clean install, but my computer does not have a clean install since 2011. Good luck!

Monday, February 23, 2015

Was the Lenovo/Superfish thing so unique?

It is a big deal, and by no means I would defend them; I don't think anyone can. They did a cheap and horrible thing by installing a piece of adware junk, that not only was used to monetize on the buyers, it is also a major security breach. Many people are still upset at lenovo and blaming everything on the "chinese government" and talking about all sorts of conspiracies.

But I don't want to talk about who did it or why, as I was reading about all this, I just could not stop wondering:  are they the only ones? Of course not.

The Gemalto hack

But did you know about the Gemalto SIM card hack? A massive sim card hack that allegedly allows US and UK spies access to billions of phones. The Gemalto hack quoted here from PC World:

"Gemalto, based in the Netherlands, produces about 2 billion SIM cards a year. About 450 mobile carriers, including AT&T, T-Mobile, Verizon Wireless and Sprint, use the company’s SIM cards.
With the compromised encryption keys, the surveillance agencies would be able to monitor mobile communications without the approval of the carriers or foreign governments, The Intercept story said. The encryption keys would allow the agencies to intercept mobile traffic without court-ordered warrants or wiretaps, the story said."

The supercookies

Also Verizon and AT&T got involved into some pretty high level user tracking, using something called  "supercookies". Basically they would be able to track all internet usage by users, no matter if they were using private navigation or incognito modes. 

So this is not a new thing, big companies and governments placing adware and/or tracking us while compromising our security? It is not new. 

What can you do?

You can use a Tor browser for better privacy online, VPNs are also a good option. And the next the time you buy a new PC at the Home Depot, do a clean install and put everything yourself.

Friday, November 14, 2014

My bipolar approach when recommending a mobile device (phones)

Recommending a new device to somebody else requires a lot of analysis, first of all, they will think you are trying to push your own preferences. And that could be true, at least up to a certain point. For me, however, recommending a device becomes a more complex thing. As a developer I work with and own a lot of them: iPhone, iPad, Android phones and tablets, Windows tablets, both "RT" and regular x86. And while my own device is a Windows Phone (Lumia 925) the right device for you depends on a lot of factors.

First, the Phones

Let's compare the three platforms, but only phones for now, we'll be talking about tablets later. So we have iOS (iPhone), Android and Windows Phone. At some point the discussion must be about a specific brand, but at the end we will have to sort results by platform.


Most likely the app you need is available for both iOS and Android. There is a huge app gap, as well as a huge number of low quality apps in some stores, so my recommendation is for you to check if the apps that you need are available and if they worth it. For example I don't have Candy Crush on my Windows Phone (yes: I can live without it) but the Instagram app on WP is way better than those on other platforms, and it will let you have multiple profiles, more editing features, regram, etc. You will in fact need several apps to accomplish the same result on iOS. In any case, considering the number of apps available alone:
  1. Android:1.3M (source
  2. iOS: 725K  (1.2M total with 475K iPad-specific source)
  3. Windows Phone: 350K (source)

Second only to phone calling, texting and LOL-ing, FB-ing, etc, there are the maps...And while we can  all have Google Maps on all devices and iOS even having their own, my recommendation goes to the HERE Suite. This suite of products was named after Nokia some time ago; but it actually works on any Windows Phone and is going to be released for iOS and Android. The suite contains HERE  Maps, HERE Drive+ with voice and turn by turn navigation, offline maps, and the HERE Transit app . So when it comes to maps:
  1. Windows Phone
  2. Android
  3. iOS
Do you like to take pictures with your phone? Do you take a lot of them? Do you try to take pictures in a club at night? Suffering from those blurry photos? Do you have to use flash all the time? Ok, here we can't compare OSes, We need to talk about the actual devices.  So we can check iPhone 6 vs Galaxy S5.  or Nokia Lumia 1520 vs iPhone 6+, or we can bring into the fight devices like the Lumia 830, 925, 930, or the 41 MP Lumia 1020. So if we try to sort platforms by selecting  the best cameras to represent  them, would be like this:
  1. Windows Phone (because of the Lumias with PureView technology)
  2. Android (some Samsung and Sony models )
  3. iOS (iPhone 6+ is the only one with OIS and only 8MP)
Here again it's very hard to decide unless we talk about specific models. Since some Samsungs are IP67 certified, they look like the clear winners. Lumias (and Nokias in general) are known to be tough devices (remember the 3310?)  The Lumia series of polycarbonate and gorilla glass turn out to be extremely resistant devices. You can actually smash other phones with a Lumia without  having a scratch, and even without an IPxx certification, I have put some of them in water and they are still working. So my ranking would be this one:
  1. Android  
  2. Windows Phone (a close second)
  3. iOS (iPhone is one of the most fragile devices ever created, especially the iPhone 6+ )

The winner here is the iPhone. You can find almost any compatible toy, tool, sensor, reader, drone, home automation system and fashion cover out there for it. Android is a second option here, with Windows Phone being a distant third, so:
  1. iOS
  2. Android
  3. Windows Phone
Have you heard about the recent celebrity leaks? Well, security is something important on modern devices, not only because some private photos might be exposed, but also because we keep a lot of information on them, we perform online purchases, access our bank accounts, and reserve plane tickets. When it comes to security, Windows Phone has the edge, and they are the most secure smartphones out there. Android, in the other hand, is the most insecure one due to lot of fake apps in third party app stores, spyware and many security issues. It is in fact the only one where you actually need an antivirus. 
  1. Windows Phone
  2. iOS
  3. Android
Here is the full Kaspersky report. See below how 98.5% of the mobile malware targets Android.

Also check this 2014 Pwn2Own.

Design (Hardware)
I could not sort devices in general by this aspect, since judging a  device by its design it's a subjective task and each person has its own preferences. I would say iPhone 5S has a good design, then the HTC One M8 and Lumia 830, 930 and 925.

Design (UI)
Well, are you tired of icons? I am. Decades of icons it's enough. But don't take my word for it. Let's just show an image I took in the skytrain at DFW airport. Notice they used an iPhone-ish style for the hardware but the inside design is "modern UI" like Windows Phone and Windows 8 (formerly "metro"). Sadly the app itself is not available for Windows Phone (talking about app gap, right?)

The ad shows a modern UI design inside an iPhone case; however the app is not available for Windows Phone.
Clearly, a preference over design is most likely subjective and not possible to measure, however we can notice that even iOS and Android are flattening their UIs to make it more "modern". What do we get from that?

So, what should I get?
It's up to you... What is the most important thing for you? At the end we are talking about phones, and all of them can make phone calls and messaging. So that extra thing that you want will make the difference.

Here's my order of priorities:  Security,  Camera, Maps and Durability, and that's how I ended up with a Lumia 925 and probably will get a 1020 successor when it comes out.

So now tell me: what's in your pocket?

Tuesday, August 12, 2014

From AsyncCompleted to async await

Since we got the magic of async/await on C# things got much easier on the developer front. Working with Tasks is the key to it, but we also have two older approaches in .NET framework that we need to deal with.
  1.  APM (Asynchronous Programming Model) The pair of Being/End methods.
  2.  EAP (Event-based Asynchronous Programming) The MethodAsync/MethodCompleted pair.
Converting from APM to Tasks is achieved by means of the  System.Threading.Tasks.TaskFactory  class and its generic counterpart.

Now converting from EAP to Tasks  requires us to use the TaskCompletionSource<T> class and notify of the state of the task as it goes. See the example of a "handshake" operation in a WCF service. I am also using the approach from my older post regarding events and anonymous methods. The return type of the WCF operation is WrappedResultOfString, and that will be the actual generic parameter of the Task<T> that the HandshakeAsync method will produce.

 public Task<WrappedResultofString> HandshakeAsync(Credentials credentials)
            var tcs = new TaskCompletionSource<WrappedResultofString>();
            var client = _serviceFactory.Invoke(); //get a WCF client instance
            EventHandler<HandshakeCompletedEventArgs> callback = null;
            callback = (s, e) =>
                client.HandshakeCompleted -= callback;
                 if (e.Error != null)
                    tcs.TrySetResult(new WrappedResultOfstring
                        Value = null,
                        IsFailed = true,
                        Error =  e.Error
                 else if (e.Cancelled)
                    tcs.TrySetResult(new WrappedResultOfstring
                        Value = null,
                        IsFailed = true,
                        Error = "Operation Cancelled"

            client.HandshakeCompleted += callback;
            client.HandshakeAsync(credentials.UserName, credentials.Password);
            return tcs.Task;

//then this is ready to be used with async/await

public async void LoginMethod()
   var credentials = //build your credentials;
  //now we can use 'await'
   var handshake = await this.HandshakeAsync(credentials);

This is particularly useful when dealing with WCF proxies in silverlight or windows phone apps where we only get EAP-based operations.

Thursday, June 05, 2014

The uncatchable exceptions in WCF clients

Did you ever have a problem with a WCF client throwing exceptions you can't catch?

If you have used WCF clients from Windows Phone, Silverlight or Xamarin.iOS, you might have noticed that it is not possible to create Synchronous or Task-Based operations; the functionality is reduced to the Event-based Asynchronous Pattern (EAP). That means that the way to call a WCF method and get the response is usually as follows:

var client = new MyWCFClient();
client.DownloadDataCompleted += (sender, e) =>
     //accessing e.Result here might raise an exception in another
     //thread, that will not be captured by the 'catch' below.
 catch(Exception ex)

Our results are wrapped in an auto-generated class that inherits from AsyncCompletedEventArgs, this class has a property Error of type Exception, that will carry information about the error and a property Result with our expected return value.

Accessing the property Result after a failed operation call, might cause cause an exception like this one: "An exception of type 'System.ServiceModel.CommunicationException' occurred in but was not handled in user code", you will also realize there is no place in your code that you could place a try-catch to capture it, and your application crashes...

The cause of the problem

The behavior is partially "by design". A quick look at the client  generated  code and you will find the root of the problem. The implementation of DownloadDataCompletedEventArgs contains this code:

 public MyTest.WrappedResultOfstring Result {
            get {
                return ((MyTest.WrappedResultOfstring)(this.results[0]));
So they actually planned to throw an exception if there is something wrong with the operation, which is a good approach actually. However the exception is raised  in another thread.

The solution 

You must first check if the operation failed, and if it did, don't read the property Result, if you do it, then the exception will rise in another thread and it won't be possible to catch it, causing your application to fail. And in the case of Windows Phone and the other mobile apps, that means getting your app rejected from the store. Here is how you should always handle responses from WCF clients.

client.DownloadDataCompleted += (sender, e) =>
    if (e.Error != null)
                //handle the error
                //but never even read from e.Result
                // do something with e.Result

Why the exception is raised in another thread is beyond me, however the solution to prevent it just implies a bit of good programming practices and nothing more.

Thursday, May 01, 2014

Get-ChildItem vs Dir in PowerShell

Batch as usual

Recently I was in the need of modifying a huge amount of files across a network share. After installing Serviio media streaming service I noticed that it will crash "randomly". After checking the logs it was clear that ffmpeg was crashing when trying to open subtitle files that were not in the encoding indicated by the Serviio console. I needed a quick way to update all subtitle files to a common encoding, so I decided to convert all files to UTF8.

Since I use a windows environment I went directly to PowerShell and wrote this.

 Get-ChildItem -path .\ -filter *.srt -file  | ForEach-Object { (get-content $_.FullName) | Out-File $_.FullName -encoding utf8 }

This worked almost right except for files with "[" or "]" (among other symbols) on the name or path. To solve it, just added the "-LiteralPath" switch to tell powershell not to consider any wildcards on the path name and just use it exactly as it is.

 Get-ChildItem -path .\ -filter *.srt -file  | ForEach-Object { (get-content -LiteralPath $_.FullName) | Out-File -LiteralPath $_.FullName -encoding utf8 }

And done! All subtitles files in my media server are now in UTF-8 and Serviio will work without crashing. 

Too slow?

Performance however was a concern, I noticed this was a bit slower that it should, considering a fast network, small size of the subtitle files (avg<100kb) and how simple the process is. This single-line script has only 2 parts:

(get the files)  then for each file (convert it)

I started to dig a little bit into Get-ChildItem I found that there have been complains about its performance for some time, but it is much better now than in previous versions. Anyway I tried a different way to do that same first part of getting the files and compared it against Get-ChildItem.

Using "cmd /c" executed "dir /s /b <pattern>" and did some tests, local and over the network. See the image below for an example measuring the search for .exe files in another drive.

Both over the network and locally, the "dir" version worked faster, of course it grabs less information than Get-ChildItem, which actually creates an object around the file returned.

For a final test I then changed the original script to: 

cmd /c dir /s /b *.srt  | foreach { (Get-Content -LiteralPath $_) | Out-File -LiteralPath $_ -Encoding UTF8 }

It works 100% like the original script and a bit faster. Although since the big chunk of  execution time belongs to the conversion of the files encoding, the jump in speed is not that big in this particular case. However, when I need to do search and filtering of files in the terms of thousands I no longer use Get-ChildItem.

Hope this is useful for you all.