Big data « Jump-start-lets » on azure

2 septembre 2014 Laisser un commentaire

Hi,
I’m starting a series of posts related to big data in azure platform.
The purpose of this series is to « scriptify » tasks, jobs, instructions, programs, etc. in order to automate operations using Powershell.

Before writing any instruction, the user should establish a secure connection between the local machine and you reserved azure platform. For that, you need to download on your local drive a certificate in order to include it in you PowerShell development environment. Here i explain how to proceed :

Step 0: install and configure PowerShell using this link
Step 1 : open ise PowerShell with administrator right

Lancement ISE

Step 2/ Please enter this command

Get-AzurePublishSettingsFile

A new web browser window would be prompted inviting you to log to you azure account
Step 3/ Please enter your login and password account and press « connect »

If you do not have a credential, you can ask for free trial one in this adress

Step 4/ Please save the file (having the file extension « .publishsettings ») containing credentials to allow your local computer to access to your azure plateform ressources

for example « c:\MyPath\BizSpark-8-20-2014-credentials.publishsettings »

Step 5/Please enter this command to load your certificate to you ISE environment

Import-AzurePublishSettingsFile C:\MyPath\BizSpark-8-20-2014-credentials.publishsettings

Now  your are ready to execute your azure PowerShell cmdlets

for example you can enter this command, doc link

Get-AzureLocation

N.B. if you want to remove your subscription from your computer, enter the following command

Remove-AzureSubscription -SubscriptionName Name

Notice that the value « Name » in the command above, is the name of your Azure Subscription, you can get this value using this cmdlet

Get-AzureSubscription
Catégories :.NET, Azure

Ria vs Data Services

This post targets to gather some links related to show some Data Access Layer (DAL) technics around .Net framework.
This page would be updated with new related links.

Comparison:
link1
link2

Data services tutos:
link1

MSDN resources :
Data Services link1
Ria Services link2

Catégories :.NET, Data Access

A pattern to handle periodic tasks

27 décembre 2012 Laisser un commentaire

I used to create simple periodic tasks. Generally it looks like this

    public class PeriodicTask
    {
        private Timer timer;
        private int dueTime;
        private int periodTime;

        public PeriodicTask()
        {
            timer = new Timer(Task, null, Timeout.Infinite, Timeout.Infinite);
            dueTime = 100;
            periodTime = 200;
        }

        public void Start()
        {
            timer.Change(dueTime, periodTime);
        }

        public void Stop()
        {
            timer.Change(Timeout.Infinite, Timeout.Infinite);
        }

        private void Task(object parameter)
        {
            Console.WriteLine("do job");
        }
    }

and with the following code, i instantiate the time to execute de task

    public class Program
    {
        static void Main(string[] args)
        {
            PeriodicTask task = new PeriodicTask();
            task.Start();  
            Console.ReadKey();
        }
    }

Well, in case that you have many periodic task to implement, this way of doing can be heavy …

So i suggest to create a container that consumes only method delegate and information concerning the due and period time of the task

First we need a TimerWrapper that will host a System.Threading.Timer in order to execute periodically a task. This class contains necessary information required for System.Threading.Timer. Optionally, you can add an object parameter to the constructor if you want to execute parametrized actions

    public class TimerWrapper : IDisposable
    {
        private bool isDisposed;
        private Timer Timer { get; set; }
        
        public int Period { get; set; }
        public int DueTime { get; set; }
        public string Id { get; set; }

        public TimerWrapper(string id, Action action, int period, int dueTime)
        {
            Id = id;
            TimerCallback timerCallback = (a) => action();
            Timer = new Timer(timerCallback, null, Timeout.Infinite, Timeout.Infinite);
            Period = period;
            Period = dueTime;
        }

        public void Start() { Timer.Change(Period, Period); }

        public void Stop() { Timer.Change(-1, -1); }

        public void Dispose() {
            if (!isDisposed)
                Timer.Dispose();
        }
    }

Now, we need only a container that host all the TimerWrapper

    public class PeriodicTaskContainer : IDisposable
    {
        private bool isDisposed;
        private readonly Dictionary<string, TimerWrapper> timerWrappers = new Dictionary<string, TimerWrapper>();

        public TimerWrapper AddPeriodicTask(Action action, int dueTime, int periodTime)
        {
            return AddPeriodicTask(Guid.NewGuid().ToString(), action, dueTime, periodTime);
        }

        ~PeriodicTaskContainer()
        {
            Dispose();
        }

        public void Dispose()
        {
            if (!isDisposed)
            {
                foreach (var timerWrapper in timerWrappers.Values)
                    timerWrapper.Dispose();
                isDisposed = true;
            }
        }

        #region Helpers

        private TimerWrapper AddPeriodicTask(string id, Action action, int dueTime, int periodTime)
        {
            var timerWrapper = new TimerWrapper(id, action, dueTime, periodTime);
            timerWrappers.Add(timerWrapper.Id, timerWrapper);
            return timerWrapper;
        }
        #endregion

Finally, you can write the following code to add periodic action.

    public class Program
    {
        static void Main(string[] args)
        {
            PeriodicTaskContainer periodicTaskContainer = new PeriodicTaskContainer();
            periodicTaskContainer.AddPeriodicTask(() => Console.WriteLine("do job"), 100, 200).Start();
            periodicTaskContainer.AddPeriodicTask(() => Console.WriteLine("do an other job"), 100, 200).Start();
            Console.ReadKey();
        }
    }

this code could be interesting for at least two periodic tasks

Catégories :.NET, design pattern

project .net + maven

Just a little complementary information to this very interesting post of Choudhury

For a quick set up, you only need to have .net sdk and Gallio, the other tools are not required

You just need to add the above pom file in the same directory of your sln file.

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>MyProject</groupId>
  <artifactId>MyProject-parent</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>MyProject</name>
  <packaging>netpack</packaging>
  <profiles>
    <profile>
      <id>sonar-dotnet</id>
      <activation>
        <!-- Optional activation by default -->
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <gallio.directory>C:/Program Files/Gallio</gallio.directory>
        <sourcemonitor.directory>C:/Program Files/SourceMonitor</sourcemonitor.directory>
        <partcover.directory>C:/Program Files/PartCover/PartCover .NET 4.0</partcover.directory>
        <fxcop.directory>C:/Program Files/Microsoft Fxcop 10.0</fxcop.directory>
        <stylecop.directory>C:\Program Files\StyleCop 4.7</stylecop.directory>
        <dotnet.2.0.sdk.directory>C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727</dotnet.2.0.sdk.directory>
        <dotnet.3.5.sdk.directory>C:/WINDOWS/Microsoft.NET/Framework/v3.5</dotnet.3.5.sdk.directory>
        <dotnet.4.0.sdk.directory>C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319</dotnet.4.0.sdk.directory>
        <sonar.host.url>http://localhost:9000/</sonar.host.url>
      </properties>
    </profile>
  </profiles>
  <properties>
    <visual.studio.solution>MySolution.sln</visual.studio.solution>
   <visual.test.project.pattern>*.Tests</visual.test.project.pattern>
   <dotnet.tool.version>4.0</dotnet.tool.version>
   <msbuild.configurations>Debug,Release</msbuild.configurations>
   <maven.compiler.debug>false</maven.compiler.debug>

   <!-- Package construction patterns -->
    <dotnet.pack.files>
      files=./MyMainProject/bin/Release/*.*        to-dir=bin
    </dotnet.pack.files>
  </properties>
  <build>
    <plugins>
        <plugin>
		   <groupId>org.codehaus.sonar-plugins.dotnet</groupId>
		   <artifactId>maven-dotnet-plugin</artifactId>
		   <extensions>true</extensions>
		   <version>1.1</version>
		   <configuration>
			 <language>cs</language>
		   </configuration>        
        </plugin>
    </plugins>
  </build>
</project>

Notice that i added the profile in the pom file, which is not a best practice. This information should be set in the xml setting file in Maven directory, because the profile is related to the machine rather than the project.

Other additional information in the link

Catégories :.NET, Maven, Sonar

A small tip for Unity and « StartableService » pattern

Personally, i use to use the « StartableService » pattern to implement my services in .Net.

public interface IStartableService
{
    void Start();
    void Stop();
    bool IsStarted{ get; }
}

When defining a service that needs a starting strategy (external to the constructor), it would be suitable to use this interface.

While starting the app (web or RDA) I need to start all the service, and using Unity , it would be like this

Container.Resolve<Type1>().Start(); // Type1 : IStartableService
Container.Resolve<Type2>().Start(); // Type2 : IStartableService
Container.Resolve<Type3>().Start(); // Type3 : IStartableService
...

I the case that the start service order is not important, instead of doing like the above code,

it is nicer to do it in this way:

var startableServices = Container.ResolveAllExtending<IStartableService>();
startableServices.ToList().ForEach(e => e.Start());

and here is the implementation of the extension methode

public static IEnumerable<T> ResolveAllExtending<T>(this IUnityContainer container) where T : class
{
     Type type = typeof(T);
     foreach (var registration in container.Registrations)
     {
          var mappedToType = registration.MappedToType;
          if (mappedToType == type ||
              (mappedToType.BaseType != null && mappedToType.BaseType.FullName.Equals(type.FullName))||
              mappedToType.GetInterface(type.Name) != null)
                   yield return container.Resolve(mappedToType) as T;
     }
}
Catégories :.NET, design pattern, IoC, Unity

TIOBE: Java Vs .Net popularity

4 avril 2012 2 commentaires

In 2002 Java’s popularity, over the rest of the other programming languages, was 26.5%. Since, it popularity was decreasing till 17% this year. About 9.5% less!

However, C#’s popularity has been rising during the same period: From 0.5% (in 2002) to 8.5% (in 2012). About 8% up! This is very close to the bearish Java Gap.





But, how would end this battle. Would Java’s popularity continue decreasing? It might be so!
There are a couple of reasons that makes me believe that. First of all, looking back in time, since 1996 (first java release) every (approximately) 2 years a new java release (Java 6) was published till 2006. After that, in July 2011 we just had Java 7, 5 years later! This is not a positive sign … However, C# since 2002 every 2 years (approximately) a new release is published. This means than Microsoft teams are trying to maintain a regular release frequency.

The Second main reason is that, many technologies and concepts introduced in Java ecosystem were adapted to the .net framework and enhanced: Hibernate, IoC, etc. While Microsoft is having a regular release strategy for it products, this makes him to provide highly integrated and efficient technologies and a better product’s quality. Even more, .Net since 2005 is providing more effort to simplify the usage of the programming languages (lambda expression, extension methods, etc.) and provides some technologies (F#, MVVM, LINQ, Reactive extensions, WCF abstraction, etc.)
Today the way of user interaction and way of data consumption has changed in the last years: we are more and more connected and want to consume more and more data and streams. Since apple releases the IPhone and after that the IPad, this lead many developers to turn on Objective-C (see the chart below).

Then the third reason, I think is Google: since java ecosystem is well known, Google is supporting this ecosystem, for instance through the Android marketplace which products are based on java technology. Well, Oracle has « bought » java, which leads some interest conflicts between Google and Oracle (link1 and link2). Notice that, in 2009 Google has created his own programming language GoLang and recently in March 29th, 2012 the 1.0 version has been released … Is Google thinking on a new strategy based on GoLang? $1.16 billion in damages that Oracle is pretending to get in his trial against Google could be a good reason.

What next? Now Java (JEE, JSE) and .net frameworks are both proprietary and equivalent technologies. There are no main differences between them: many .net framework enhancements were announced to be integrated in the next Java releases (Link1 link2). Java or Oracle is in conflict with his best partner until now for the mobile devices (Android). I’m guessing that the gap of popularity between C# (and more globally .net) and Java Will be reduced, or even null, for the next 10 years.

Rendez-vous in 10 years !

Catégories :.NET, Java

MVVM, MVP and MVC software patterns againts 3-Layered architecture

28 mars 2012 4 commentaires

While writing some programming recommendations, I was interested to know how software designer communities map the MVVM, MVP and MVC software patterns to the 3-Layered architecture.

I found many comment, ideas, explanations and sometimes impressions concerning these patterns.

I confess that I did not understand “exactly” theses explanations, for the simple reason that it wasn’t formal explanations, which is not a simple task. For this reason I decided to propose the simplest and formal way to emphases the main differences between those patterns.

Some useful references to understand those patterns:

MVC link1 link2
MVP Link1
MVVM Link1

I made the above simple layer diagram, where we can see the decomposition the software patterns in sub layers and their projection in the 3-layered architecture. For instance, the projection of the sub layers View and Controller of MVC in the 3-Layered architecture is the UI layer.

At the first glance, we have two observations:
1/ All theses software patterns are structurally equivalent: we find many layers and sub layers reused in the three patterns like View, Services, Tasks and repositories. They all have the same responsibilities.
2/ There are three different sub layers Controller, Presenter and View, which have different responsibilities and interaction protocol (with other layers).

Indeed, looking at this link1, and link2 we realize that the way of interaction between these layers are very different, even with the user. The following diagram shows how each patterns interacts through it components.

First, we can point out the very similar communication protocol between sub layers in MVVM and MVP pattern. However the only difference that exists between them is the ways of communication between the View and the Model. While MVP pattern uses a direct invoke to push or update for data synchronization, the MVVM pattern uses a notification system to synchronize data (i.e. data binding and command).

Second, the View in both MVP and MVVM patterns do not communicate with the Model. However, the MVC pattern has to access to the Model layer to get updated data.

Third, the way of interaction between the user and the application changes depending on the implemented pattern. In the above figure, we can see that the user access to the Controller layer in order to get the target View. Nevertheless, the user interacts exclusively with the View in case of an application implemented against the MVP or MVVM patterns.

Catégories :MVC, MVP, MVVM, patterns Étiquettes :