Posts

AOP through Unity interceptors - Logging

The first thing we think when talking about interception is logging. Let's see an implementation of a Logger. But before introducing the Logger implementation, let us scaffold a console sample project. public interface IFoo { FooItem GetItem(string name); } public interface IStore { StoreItem Get(int id); IEnumerable<StoreItem> GetAll(); void Save(StoreItem item); void ThrowException(); } public class FooImpl : IFoo { public FooItem GetItem(string name) { return new FooItem { Name = name }; } } public class StoreImpl : IStore { public StoreItem Get(int id) { Thread.Sleep(1000); return new StoreItem { Id = id, Name = "Fake name" }; } public IEnumerables<StoreItem> GetAll() { Thread.Sleep(2000); return new List&ltStoreItem>()

[Xamarin Forms] Button text alignment issue in Android

Image
Recently, I had to deal with custom Buttons in my Android application. So I designed custom renderers to render it. Unfortunately, I encountered a strange behavior with the text alignment of my buttons. This happens when the button changes of state : - Originally the button's text is centered - When you click it, the text moves to the left See images below:   Before / after the button click After investigating, I found a solution to my problem. In my Android custom button renderer, I had to overwrite a specific method:  ChildDrawableStateChanged public class ExtButtonRenderer : ViewRenderer<Extbutton, global::android.widget.button> { ... public override void ChildDrawableStateChanged(Android.Views.View child) { base.ChildDrawableStateChanged(child); if (Control != null) Control.Text = Control.Text; } ... } That's all ! Related links: Custom renderers: http://developer.xamarin.com/guides

[Fast&Furious guide] Get ready to build a Xamarin iOS app

Image
In order to build, test and deploy an iOS application using the Xamarin SDK, you will need to setup your environement first. As you know, it's necessary to have a Mac computer that will be at least your build host... This post is just a quick guide to help you to setup your environment ! So let's go ! Setup your environnement (2 possibilities) The hardware needed: A- First choice: A MAC (MacBook Pro for instance) with a Virtual Machine (VmWare / Parallels) running Windows and Visual Studio with Xamarin. B- Second choice A MAC (will be used only as a build host) A PC (with Windows / Visual Studio / Xamarin SDK) on the same network Requirements: Minimum MAC OS versions : OS X Mountain Lion, iOS Xamarin SDK, XCode IDE Minimum Windows versions : Windows 7, Visual Studio 2010, latest Xamarin tools C-  You will also need an iOS developer account You need to have an iOS developer account in order to: - test / deploy your app on a device - publish your app

AOP through Unity interceptors - Introduction

Image
Hello, Today we will start a serie of blog posts concerning Aspect Oriented Programming (formely AOP ). This technic is used to have a better separation of concerns in the application you write. Let's take a basic example. When you are writing the implementation of a class that is specialized on a task, you could write someting like this: public class Calculator { public decimal Add(decimal num1, decimal num2) { Console.WriteLine("Entering Add Method"); var result = num1 + num2; Console.WriteLine("Exiting Add Method"); return result; } } The issue with this code is that the logging is part of the method. What will happen if you have a huge quantity of code? You will probably duplicate the logging code across te different class & methods you will write. Moreover, the Add method we wrote is not specialized on a single task: it has two different purpose: it effectly performs an adds operation and it lo

[Xamarin Forms] Embed custom fonts in your apps

Image
Recently I had some difficulties to embed custom fonts in my applications. Specially with the iOS application that was crashing with no message (while it was working for the Android version). In fact, it was a font issue. So in this post I will show you some tips to embed quickly custom fonts in both your Android & iOS apps. 1- Select your fonts The first step is to get some cool fonts you want to use. You'll maybe use (free) fonts from various websites like: www.1001freefonts.com www.dafont.com 2- Set font files properties In your solution, include your fonts files: iOS:  Create a subfolder (in the the 'Resources' directory) where to embed the fonts Build Action = BundleResource & "Copy Always" Android : Create a subfolder in the 'Assets' directory where to embed the fonts: Build Action = "AndroidAsset" & "Copy Always" 3- iOS application: edit your plist file With iOS you need to specify the e

C# Clean code book

Remember last week, I presented the website https://leanpub.com/ One interesting & free book recently published is https://leanpub.com/cleancsharp/ . You will find in there a lot of good tips to write clean C# code. Some tips are really useful. If the professional applications I work on would have be written by people who have read this book, my life would be easier! It is only question of "good sense" in my opinion, plus a set of established rules, like proven efficiency stuff. But I have to say that most of them are not applied, even in "top" french companies.

Publishing and/or Reading books

I would like to share with you a platform I found few weeks ago. I've already mentionned SyncFusion ebooks in an earlier post ( http://kampeki-factory.blogspot.fr/2015/03/syncfusion-free-eboks.html) . Notice that they still add free books regulary. The platform I discovered is called Leanpub ( https://leanpub.com/ ). As an author, you can propose your book, writen using your favorite tool. They are doing the publication in different formats (pdf, iPad, kindle...) on their side. An other interesting thing is that you set the price. In fact, you set two prices: the first one the is minimum price, and the second one is a suggested price. As a reader, you are informed of those two prices. You can pay the minimum price (which can be 0$). Or you can follow the author advice and give him the price he thinks his book is really.

Create a startup with DotNet tools?

Here is a pretty good article if you plan to create your startup. Will you choose Microsoft tools? http://rlacovara.blogspot.fr/2012/03/should-you-use-net-for-your-statup.html