The update contains several improvements to the HttpClientimplementation, which should improve performance of the library a lot:
all handlers now use one static HttpClientinstance. HttpClientis built to use it that way, and there is also no problem with multiple request handled by that instance. So everyone should use it in that way
the library is now actively enforcing gzip/deflate compression to make responses faster, especially when requesting bigger lists of items (if you want do deactivate it on the managed implementation, pass in falsewith the new useCompressionparameter with your call to the SetupClientmethod
deserialization by default now happens directly from the HttpResponsestream instead of first converting it to a string
added an API to pass in your own HttpClientinstance instead of the managed one (you could even use one static instance for your whole app this way to improve performance even further). To do so, just use the newly added method SetCustomClient(HttpClient client)on your handler instances.
I made this changes working without breaking existing implementations. Just by updating the library, you will get a better performance.
I also updated the source code on GitHub. If you just want to update the library, the update is already available on NuGet.
Happy coding, everyone!
If you want to see the library in a live app, you can download my official blog reader app (which is written around it as a Xamarin.Formsapp) here:
I am happy to announce my new WordPressReader (Standard) library that is available on NuGet now. It is written in .netStandard 1.4 which enables you to use it in a lot of of places. As the name suggests, it focuses on reading tasks against the WordPress API.
get, search and filter posts
get and filter categories
get, search and filter tags
post anonymous comments (needs additional work on the WordPress site)
get basic user info
The library uses a generic WordPressEntity model implementation, which makes it easy to implement and extend. You can always get the raw json-value as well. The additional Error property on every model makes it easy to handle API errors properly. You can read the full documentation in the GitHub Wiki.
If you have problems with the library or want to contribute, you can do so on the GitHub repo.
Happy coding, everyone!
If you want to see the library in a live app, you can download my official blog reader app (which is written around it) here:
Some of you might have noticed that UniShare has its own folder in your devices picture library. Also some other apps like WhatsApp or Tweetium have it. The advantages of your app’s own folder are clear:
easier to get images into your app
user can always reflect which pictures come from your app
another presence of your app within the OS
higher remember rate for your app at the user site (which leads to more frequent usage of your app)
This post will show you how easy it is to generate a folder into the Pictures Library as well as save and read files into/from this folder.
First, you need to add this using statements to your app:
Next, add the Picture Library capabilities to your app’s Package.appmanifest.
If you have a 8.1 Silverlight app, you need to add it to both the Package.appmanifest as well as the WMAppManifest.xml:
Then we are already able to generate our folder with this single line of code (counts for both Silverlight and Runtime apps):
You should always use the CreateFolderAsync method together with the CollisionOption ‘OpenIfExists’. This way, your app will open it every time you are going to save a file, but creates the folder if it does not exist yet. If you now go to your pictures library, you will not see your folder yet, although it is there (use a File Manager app to check it if you want). Folders do only get populated when they have content. This is what the next step is about.
Save an image file
Saving an image is also pretty straight forward. First we are generating a StorageFile within our folder:
This generates a File Container that we can write our image to. To save the image we are going to asynchronously write the Stream of our image into it:
//asuming we have an Image control, replace this with your local code
var img = myImage.Source as WriteableBitmap;
//get fresh drawn image
using (Stream stream = await myfile.OpenStreamForWriteAsync())
img.SaveJpeg(stream, img.PixelWidth, img.PixelHeight, 0, 100);
This code works for both a Windows Phone 8.1 Silverlight and Runtime apps. If you now go to your Pictures library, you will see your app’s folder as well as your saved image. Pretty easy, right?
Read images from our app’s folder
Reading an image file is pretty easy as well. Here is the code:
//open the picture library
StorageFolder libfolder = KnownFolders.PicturesLibrary;
//get all folders first
IReadOnlyList<StorageFolder> folderList = await libfolder.GetFoldersAsync();
//select our app's folder
var appfolder = folderList.FirstOrDefault(f => f.Name.Contains("myCustomAppFolder"));
//get the desired file (assuming you know the file name)
StorageFile picfile = await appPicturesFolder.GetFileAsync("myfile.jpg");
//generate a stream from the StorageFile
var stream = await picfile.OpenAsync(FileAccessMode.Read);
//generate a new image and set the source to our stream
BitmapImage img = new BitmapImage();
//todo: work with the image
To get our generated folder, we need to fetch a list of folders in the library using the StorageFolder.GetFoldersAsync() method. We then query this list for our app’s folder. If you want to get a list of all pictures in your folder, you can use the StorageFile.GetFilesAsync() method. What I have done above is to load our saved single file. Finally, I opened a stream from this file and assigned it to a new BitmapImage, which can be used in our app.
There are also a lot of other options one can do with these folders and files, this is a very common scenario.
As always, I hope this post is helpful for some of you.
As I have already developed a news reader app for my blog, I got asked quite a few times if I want to share my code to help others creating their apps. As I need to redesign my blog reader to match the latest OS features of Windows and Windows Phone, I decided to create my WordPressUniversal library.
Automattic, the company behind WordPress, integrated a powerful JSON API into their JetPack plugin. My library is based on this API. Please make sure the JSON API is active on the blog you are developing your app for.
The library currently provides the following features:
getting a list posts or pages
getting a list of all categories
getting a list of comments for the site and single posts
supports Windows Phone 8 & 8.1 Silverlight, Windows Phone 8.1 RT, Windows 8, Xamarin.iOS and Xamarin.Android
The library deserializes all data into C# objects you can immediately work with.
It is still a work in progress, but as it provides already a bunch of options to get you started, I am making this public already.
I am constantly working on the library, so be sure to follow the project along.
Note: JetPack’s JSON API does not support guest commenting at the moment. I already reached out to Automattic to (hopefully) find a solution for this. If you cannot wait, Disqus has a portable solution for Windows Phone apps.