carolynvs / nutritionix

This is a .NET client for the Nutritionix API
MIT License
8 stars 11 forks source link

Make library Portable (a PCL) #1

Open cmshawns opened 10 years ago

cmshawns commented 10 years ago

I have started this effort at cmshawns/nutritionix:portableLibrary. Specifically, I am looking to get this working on mobile devices with the Xamarin platform so I can use it for my FoodStats project.

cmshawns commented 10 years ago

Unfortunately, I only have access to Visual Studio 2010 at the moment and the ASP.NET WebApi Client library doesn't appear to be compatible with the portable library targets it supports. If anyone has a recommendation for a PCL REST library (especially if it closely resembles Microsoft.AspNet.WebApi.Client) please let me know.

As a first pass, I'm investigating the following REST libraries:

cmshawns commented 10 years ago

The RestSharp.Portable (which says it's not related to RestSharp) package manages to install all its dependencies, then balks at itself but isn't able to roll back:

Adding 'FubarCoder.RestSharp.Portable 1.6.1' to Nutritionix.Portable.
Install failed. Rolling back...
Unable to uninstall 'Microsoft.Bcl.Build 1.0.14' because 'Microsoft.Bcl 1.1.3' depends on it.

I'm assuming this is because the package says it only supports Silverlight 5 and Windows Phone 8; normally I get an error to that effect, but this time I'm getting the rollback error instead.

Portable Tools for vs2010 only provides a profile for Windows 7.5, and vs2010 drops to Silverlight 4 when I include the Xamarin profiles.

I'm thinking next steps may need to be one of the following:

carolynvs commented 10 years ago

I haven't worked much with PCLs but I do have VS 2013 and would be happy to help. I found this article which looks promising.

Just so I understand the problem, why is VS 2013 required? Is the issue that only .NET 4.5 is compatible with the PCL for ASP.NET WebApiClient?

cmshawns commented 10 years ago

Okay, even without RestSharp.Portable the dependencies have gotten me a good way there - just need to look into refactoring the remaining code that relies on classes not present in the PCL.

Some useful references during this process:

cmshawns commented 10 years ago

@carolynvs Thanks, that's one of the articles I started with.

This is my first attempt at a PCL as well, but I'm finding the profiles - and how VS is implmenting them - to be a bit more restrictive than I expected. The upshot though, is that the vs2013 requirement appears to come from the Windows Phone 8 - see the note at the bottom of this screenshot from the article:

There are a few other issues caused by VS automatically selecting other compatible profiles (even though you didn't select them yourself) when you click Ok, but that's the crux.

I'm also going to install 2013 Express and see how much I can do with that.

cmshawns commented 10 years ago

Also, to clarify the current code incompatibilies with PCL, the following namespaces are not present/available in PCL:

What I'm seeing so far is that the prevailing suggestions are to refactor code that uses those namespaces. (E.g. I haven't yet found any replacement libraries that are PCL-compatible.)

cmshawns commented 10 years ago

First draft of the PCL port is complete:

cmshawns/nutritionix@093d13012a04010b7883d34861c5ad6b6d4648b5

Where classes were not part of the PCL framework, I created them - which will need robust testing.