Posts

Xamarin.forms.Maps - Tap to get a position on the map...

Image
Xamarin.Forms.Map component Xamarin.Forms.Maps is a great component. It gives you the possibility to deal with maps and geolocation problematics in a few lines of code. This "Map" component internally use native map controls for iOS, Android and Windows Phone: You can display and locate "Pins" with custom information on the map. I suggest you to read the reference links above. Display pins with custom information The problem But actually, in my mind, the Map control miss a very important feature: --> Tap  on the map to get the relative location (to put a new pin, to get the relative address...) The workaround Use renderers Actually, to solve this problem, we need to implement custom renderers for iOS and Android. Maybe this feature will be implemented later by Xamarin... So here is my solution (3 code files below): - ExtMap.cs : overloaded map control that will contain our "Tapped" event to get the tapped location

Microservices architecture

Building a monolithic app, even subdivided in different layers is not the only path... Recently, I discovered the Microservices architecture. This allow to separate the whole application itself in autonomous part of sub application. It has pros & cons. You can see this website for an advanced comparison. Martin fowler speaks about it: http://martinfowler.com/articles/microservices.html . Paul Mooney has also started an interesting series on this kind of architecture. Here are the first two parts: http://insidethecpu.com/2015/07/17/microservices-in-c-part-1-building-and-testing/ . http://insidethecpu.com/2015/07/31/microservices-in-c-part-2-consistent-message-delivery/ .

AOP through Unity interceptors - Conclusion

We have seen how pleasant could be the programmation with Unity and interceptors. Of course, you can use another IoC framework to achieve what we have done in this series. A good advice would be to use Autofac . This framework has more capabilities than Unity. An other point of attention is performance. Enabling interception is not cost free. You should take care of it: I would advice to measure the impact of enabling/disabling interception.

VS2013 Xamarin's incompatible plugin when installing VS2015...

Image
As a good .NET developer, yesterday I installed the new Visual Studio 2015 IDE to discover all its new features... VS2015 installed ! I was previously developping mobile apps with Xamarin on VS2013. So as I am impatient I installed VS2015 without thinking of all the modifications it can bring to my environment... And bingo ! When I started back VS2013 to edit my Xamarin's projects, I had a bad surprise: iOS & Android projects no more compatible... But, fortunately, I find a really quick solution to restore Xamarin compatibility with VS2013. In fact in the windows programs / functionnalities menu, I  changed the Xamarin app components configuration like above: Xamarin, change installation Xamarin for Visual Studio 2013 is disabled ! Re-enable it and it s all good :) And go you can continue to develop Xamarin projects with VS2013 !

AOP through Unity interceptors - Cryptography

Today, in our AOP serie, we will use Unity to encrypt/decrypt our data. Let's imagine that you have a repo that stores personal information about users. You may want some of this data to be encrypted, in case your database is stolen, or accessed illegaly. Once again, AOP helps us in this situation. Let's build our sample. We will need an interface & an implementation representing the user repository. public interface IUserRepo     {         bool IsUserAuthenticated(string login, [Encrypt] string password);          [Decrypt]         string GetPasswordForUser(string login);     } public class UserRepoImpl : IUserRepo     {         public bool IsUserAuthenticated(string login, string password)         {             if (password == "1234")                 return false;             return true;         }         public string GetPasswordForUser(string login)         {             return "wOSHX/n2NyWWn53YXVvJIg==";         }     } Using t

AOP through Unity interceptors - Compression

Today we are going to compress our data. We will still use AOP through Unity. The scenario is the following: we have a class generating a huge set of data (in our example, data structure is string). we don't want it to be kept in memory, because we will use it later, or not often. So one solution could be to compress this data & uncompress it once we will really need it. public interface IBigDataRepo     {         string GetData();     }  public class BigDataRepo : IBigDataRepo     {         public string GetData()         {             return new string('X', 100000);         }     } We are going to use is this way: static void Main(string[] args)         {             using (var container = new UnityContainer())             {                 container.AddNewExtension<Interception>();                 // Register                 container.RegisterType<IBigDataRepo, BigDataRepo>(                     new Interceptor<InterfaceInterceptor>(),       

AOP through Unity interceptors - Performance monitoring

Today we continue the serie on AOP with Performance monitoring. The principle is very simple: we want to monitor the time a method took to execute. Here is the code of the class. public class PerformanceMonitoringInterceptionBehavior : IInterceptionBehavior     {         public IEnumerable<Type> GetRequiredInterfaces()         {             return Type.EmptyTypes;         }         public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)         {             Stopwatch sw = Stopwatch.StartNew();             var result = getNext()(input, getNext);             sw.Stop();              WriteLog(String.Format("Method {0} took {1} ms", input.MethodBase, sw.ElapsedMilliseconds));             return result;         }         public bool WillExecute         {             get { return true; }         }         private void WriteLog(string message, string args = null)         {             var utcNow = DateTime.UtcNow;            

AOP through Unity interceptors - Caching

Image
Let's continue our serie on AOP with another popular usage of interception: caching. Let's use the previously created project and add this class: public class CachingInterceptionBehavior : IInterceptionBehavior     {         private static IDictionary<string, MemoryCache> Cache = new Dictionary<string, MemoryCache>();         private static IList<string> SyncLock = new List<string>();         private static object SyncRoot = new object();         public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)         {             if (input.MethodBase.GetCustomAttribute<IgnoreCacheAttribute>() != null)             {                 return getNext()(input, getNext);             }             var arguments = JsonConvert.SerializeObject(input.Arguments);             string key = string.Concat(input.MethodBase.DeclaringType.FullName, "|", input.MethodBase.ToString(), "|", arguments); if (IsInCa