juin

24

Posted by : admin | On : 24 juin 2014

http://www.kanazawa-net.ne.jp/~pmansato/parallel/parallel_taskfactory.htm

http://codereview.stackexchange.com/questions/44547/writing-highly-asynchronous-code

https://www.dropbox.com/s/f053j1pgw2qo9fz/AsynchronousProgramming.rar

http://chsakell.com/2014/01/11/asynchronous-programming-using-tasks/

http://slynetblog.blogspot.fr/2013/04/downloading-multiple-files-on-windows.html

Connection SQL Serveur

https://www.connectionstrings.com/sql-server-2008/

 

 

WCF Asynchronous

http://robbincremers.me/2011/12/31/wcf-asynchronous-client-proxy-and-asynchronous-service-operations/

http://stackoverflow.com/questions/8040002/how-to-make-a-wcf-rest-method-entirely-asynchronous-with-the-task-parallel-libra

 

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AsynchronousProgramming
{
    class Program
    {
        //const string connectionString = "Data source = localhost; Initial catalog = Chinook; Integrated security = SSPI;";
        const string connectionString = "Data Source=ARTAUDHOME\\SQLEXPRESS;Initial Catalog=Chinook;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False";
        static void Main(string[] args)
        {
            Thread.CurrentThread.Name = "MainThread";

            #region This will block the thread...
            DataSet dsArtists = GetArtistsAsync().Result;
            foreach (DataRow row in dsArtists.Tables["Artists"].Rows)
            {
               foreach (DataColumn col in dsArtists.Tables[0].Columns)
                {
                    Console.Write(row[col] + "\t");
                }
               Console.WriteLine();
            }
            #endregion

            #region This won't block the main thread
            //GetArtistsAsync().ContinueWith(task =>
            //{
            //    DataSet dsArtists = task.Result;
            //    foreach (DataRow row in dsArtists.Tables["Artists"].Rows)
            //    {
            //        foreach (DataColumn col in dsArtists.Tables[0].Columns)
            //        {
            //            Console.Write(row[col] + "\t");
            //        }
            //        Console.WriteLine();
            //    }
            //});
            #endregion

            #region This won't block the thread and catches exceptions
            //GetArtistsAsync().ContinueWith(task =>
            //{
            //    DataSet dsArtists = task.Result;
            //    foreach (DataRow row in dsArtists.Tables["Artists"].Rows)
            //    {
            //        foreach (DataColumn col in dsArtists.Tables[0].Columns)
            //        {
            //            Console.Write(row[col] + "\t");
            //        }
            //        Console.WriteLine();
            //    }
            //}, TaskContinuationOptions.NotOnFaulted);

            //GetArtistsAsync().ContinueWith(task =>
            //{
            //    Console.WriteLine(task.Exception.InnerException.Message);
            //}, TaskContinuationOptions.OnlyOnFaulted);

            #endregion

            #region Task Composition - Multithreading
            //var watch = Stopwatch.StartNew();

            //Task<DataSet> artistsTask = GetArtistsAsync();
            //Task<DataSet> albumsTask = GetAlbumsAsync();

            //Task.Factory.ContinueWhenAll(new[] { artistsTask, albumsTask }, (tasks) =>
            //{
            //    foreach (var task in tasks)
            //    {
            //        if (task.Status == TaskStatus.RanToCompletion)
            //        {
            //            DataSet ds = task.Result;
            //            if (ds.Tables[0].TableName == "Artists")
            //            {
            //                foreach (DataRow row in ds.Tables["Artists"].Rows)
            //                {
            //                    foreach (DataColumn col in ds.Tables[0].Columns)
            //                    {
            //                        Console.Write(row[col] + "\t");
            //                    }
            //                    Console.WriteLine();
            //                }
            //            }
            //            else if (ds.Tables[0].TableName == "Albums")
            //            {
            //                foreach (DataRow row in ds.Tables["Albums"].Rows)
            //                {
            //                    foreach (DataColumn col in ds.Tables[0].Columns)
            //                    {
            //                        Console.Write(row[col] + "\t");
            //                    }
            //                    Console.WriteLine();
            //                }
            //            }
            //        }
            //        else
            //        {
            //            Console.WriteLine("An error has occurred..");
            //            Console.WriteLine(task.Exception.InnerException.Message);
            //        }
            //        Console.WriteLine();
            //        Console.WriteLine("------------------------------------------------");
            //        Console.WriteLine();
            //    }

            //    watch.Stop();
            //    Console.WriteLine("Time elapsed: " + watch.ElapsedMilliseconds + " milliseconds");
            //});
            #endregion

            #region Asynchronous - No multithreading
            //GetCustomersAsync().ContinueWith((task) =>
            //{
            //    DataSet dsCustomers = task.Result;
            //    foreach (DataRow row in dsCustomers.Tables["Customers"].Rows)
            //    {
            //        foreach (DataColumn col in dsCustomers.Tables[0].Columns)
            //        {
            //            Console.Write(row[col] + "\t");
            //        }az
            //        Console.WriteLine();
            //    }
            //});

            #endregion

            Console.WriteLine();
            Console.WriteLine("Thread: " + Thread.CurrentThread.Name);
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }

        static Task<DataSet> GetArtistsAsync()
        {
            DataSet ds = new DataSet();
            return Task<DataSet>.Factory.StartNew(() =>
            {
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    string sqlSelect = @"WAITFOR DELAY '000:00:05'
                                        SELECT TOP 10 * FROM Artist";
                    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, con);
                    da.Fill(ds);
                    ds.Tables[0].TableName = "Artists";
                }
                Console.WriteLine("Thread: " + Thread.CurrentThread.Name);
                return ds;
            });
        }

        static Task<DataSet> GetAlbumsAsync()
        {
            DataSet ds = new DataSet();
            return Task<DataSet>.Factory.StartNew(() =>
            {
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    string sqlSelect = @"WAITFOR DELAY '000:00:05'
                                        SELECT TOP 10 * FROM Album";
                    SqlDataAdapter da = new SqlDataAdapter(sqlSelect, con);
                    da.Fill(ds);
                    ds.Tables[0].TableName = "Albums";
                }
                Console.WriteLine("Thread: " + Thread.CurrentThread.Name);
                return ds;
            });
        }

        static Task<DataSet> GetCustomersAsync()
        {
            var tcs = new TaskCompletionSource<DataSet>();

            DataSet ds = new DataSet();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                string sqlSelect = @"WAITFOR DELAY '000:00:05'
                                        SELECT TOP 10 * FROM Customer";
                SqlDataAdapter da = new SqlDataAdapter(sqlSelect, con);
                da.Fill(ds);
                ds.Tables[0].TableName = "Customers";
            }
            Console.WriteLine("Thread in GetCustomersAsync: " + Thread.CurrentThread.Name);
            tcs.SetResult(ds);
            return tcs.Task;
        }
    }
}

juin

16

Posted by : admin | On : 16 juin 2014

sample code

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Collections.Concurrent;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Action<Action> mesure = (body) =>
                {
                    var startTime = DateTime.Now;
                    body();
                    Console.WriteLine("{0} {1}", DateTime.Now - startTime, Thread.CurrentThread.ManagedThreadId);
                };

            Action calJob = () => { for (int i = 0; i < 350000000; i++); };
            Action ioJob = () => { Thread.Sleep(1000); };

            // TPL on top of thread
            /* mesure(() =>
                 {
                  var tasks = Enumerable.Range(1,10)
                              .Select(_ => Task.Factory.StartNew(() => mesure(ioJob)))
                              .ToArray();
                  Task.WaitAll(tasks); // Start 2 task in background
                 });*/

            //Parallel.For(1, 10, _ => { mesure(ioJob); });

            //PLINQ on top TPL
            //use of multiple core

            //Enumerable.Range(1,10).ToList().ForEach(_=>mesure(ioJob)); //no sort order
            //Enumerable.Range(1, 10).AsParallel().WithDegreeOfParallelism(10).ForAll(_ => mesure(ioJob));
            //ThreadPool.SetMinThreads(5, 5);
            // ParallelEnumerable.Range(1, 10).WithDegreeOfParallelism(10).ForAll(_ => mesure(calJob)); 

            //producer Xml reader => queue => consumer
            //var queue = new Queue<int>();

            var queue = new BlockingCollection<int>(100);// concurrent Queue
            var producers = Enumerable.Range(1, 10).Select(_ => Task.Factory.StartNew(() =>
            {
                Enumerable.Range(1, 100)
                    .ToList()
                    .ForEach(i =>
                {
                    queue.Add(i);
                    Thread.Sleep(100);
                });
            })).ToArray();

            var consumers = Enumerable.Range(1, 2).Select(_ => Task.Factory.StartNew(() =>
            {
                foreach(var item in queue.GetConsumingEnumerable()) //get next element and remove from the queue 
                {
                   Console.WriteLine(item);
                };
            })).ToArray();

            Task.WaitAll(producers); // run all producers 
            queue.CompleteAdding(); // when all producers have finished so that it will notify to the consumers when the queue is dequeue 

            Task.WaitAll(consumers);
            Console.ReadKey();
        }
    }
}

juin

09

Posted by : admin | On : 9 juin 2014

 

http://www.symbolsource.org/Public/Metadata/NuGet/Project/SignalR.Client/0.3.3/Release/.NETFramework,Version%3Dv4.0/SignalR.Client/SignalR.Client/SignalR/TaskAsyncHelper.cs?ImageName=SignalR.Client

http://dotnetinside.com/en/type/SignalR.Hosting.AspNet/TaskAsyncHelper/0.5.1.10822

Linq grouping

http://weblogs.asp.net/dixin/understanding-linq-to-objects-3-query-methods

Nice Helper code


using System;

using System.Diagnostics;

using System.Linq;

using System.Threading.Tasks;

namespace SignalR {

 internal static class TaskAsyncHelper {

 private static Task MakeEmpty() {

 return FromResult<object>(null);

 }

 public static Task Empty {

 get {

 // we have to return a new one every time, other wise the task will be disposed

 return MakeEmpty();

 }

 }

 public static Task Catch(this Task task) {

 return task.ContinueWith(t => {

 if (t != null && t.IsFaulted) {

 var ex = t.Exception;

 Trace.TraceError("SignalR exception thrown by Task: {0}", ex);

 }

 return t;

 }).Unwrap();

 }

 public static Task<T> Catch<T>(this Task<T> task) {

 return task.ContinueWith(t => {

 if (t != null && t.IsFaulted) {

 var ex = t.Exception;

 Trace.TraceError("SignalR exception thrown by Task: {0}", ex);

 }

 return t;

 })

 .Unwrap();

 }

 public static Task Success(this Task task, Action<Task> successor) {

 return task.ContinueWith(_ => {

 if (task.IsCanceled || task.IsFaulted) {

 return task;

 }

 return Task.Factory.StartNew(() => successor(task));

 }).Unwrap();

 }

 public static Task Success<TResult>(this Task<TResult> task, Action<Task<TResult>> successor) {

 return task.ContinueWith(_ => {

 if (task.IsCanceled || task.IsFaulted) {

 return task;

 }

 return Task.Factory.StartNew(() => successor(task));

 }).Unwrap();

 }

 public static Task<TResult> Success<TResult>(this Task task, Func<Task, TResult> successor) {

 return task.ContinueWith(_ => {

 if (task.IsFaulted) {

 return FromError<TResult>(task.Exception);

 }

 if (task.IsCanceled) {

 return Cancelled<TResult>();

 }

 return Task.Factory.StartNew(() => successor(task));

 }).Unwrap();

 }

 public static Task<TResult> Success<T, TResult>(this Task<T> task, Func<Task<T>, TResult> successor) {

 return task.ContinueWith(_ => {

 if (task.IsFaulted) {

 return FromError<TResult>(task.Exception);

 }

 if (task.IsCanceled) {

 return Cancelled<TResult>();

 }

 return Task.Factory.StartNew(() => successor(task));

 }).Unwrap();

 }

 public static Task AllSucceeded(this Task[] tasks, Action continuation) {

 return AllSucceeded(tasks, _ => continuation());

 }

 public static Task AllSucceeded(this Task[] tasks, Action<Task[]> continuation) {

 return Task.Factory.ContinueWhenAll(tasks, _ => {

 var cancelledTask = tasks.FirstOrDefault(task => task.IsCanceled);

 if (cancelledTask != null)

 throw new TaskCanceledException();

 var allExceptions =

 tasks.Where(task => task.IsFaulted).SelectMany(task => task.Exception.InnerExceptions).ToList();

 if (allExceptions.Count > 0) {

 throw new AggregateException(allExceptions);

 }

 return Task.Factory.StartNew(() => continuation(tasks));

 }).Unwrap();

 }

 public static Task<T> AllSucceeded<T>(this Task[] tasks, Func<T> continuation) {

 return Task.Factory.ContinueWhenAll(tasks, _ => {

 var cancelledTask = tasks.FirstOrDefault(task => task.IsCanceled);

 if (cancelledTask != null)

 throw new TaskCanceledException();

 var allExceptions =

 tasks.Where(task => task.IsFaulted).SelectMany(task => task.Exception.InnerExceptions).ToList();

 if (allExceptions.Count > 0) {

 throw new AggregateException(allExceptions);

 }

 return Task.Factory.StartNew(continuation);

 }).Unwrap();

 }

 public static Task<T> FromResult<T>(T value) {

 var tcs = new TaskCompletionSource<T>();

 tcs.SetResult(value);

 return tcs.Task;

 }

 private static Task<T> FromError<T>(Exception e) {

 var tcs = new TaskCompletionSource<T>();

 tcs.SetException(e);

 return tcs.Task;

 }

 private static Task<T> Cancelled<T>() {

 var tcs = new TaskCompletionSource<T>();

 tcs.SetCanceled();

 return tcs.Task;

 }

 }

}

 

Resources

http://msdn.microsoft.com/en-us/library/ff963553.aspx

http://www.microsoft.com/en-us/download/confirmation.aspx?id=19222

Article

http://www.albahari.com/nutshell/cs4ch22.aspx

 

http://dotnetcodr.com/2014/03/18/continuation-tasks-in-net-tpl-many-tasks-continued-by-a-single-task/

 

Stackoverflow

http://stackoverflow.com/questions/15938254/task-results-into-a-single-list

mai

30

Posted by : admin | On : 30 mai 2014

 

Know your .NEt version

>cd %systemroot%\Microsoft.NET\Framework

>dir /A:D

Useful plugin for VS 2010

http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef


Nuget Package installer

http://docs.nuget.org/docs/start-here/using-the-package-manager-console

Func

http://stackoverflow.com/questions/13128271/task-run-and-func

mai

01

Posted by : admin | On : 1 mai 2014

 

Tibco GEMS

For download go to https://tibbr.tibcommunity.com/tibbr/#client-stream

Gems is a graphical user interface utility for TIBCO Enterprise Message Service  (EMS). It can be used by JMS developers as a general purpose test debugging tool and by  administrative support staff as a management and monitorig tool.

 

Gems provides the following main features:

  • Server Monitoring. Server state and main statistics are automtically updated,  warning and error limits may be configured. Server generated events are also  captured.
  • Server Management. Including, general server configuration, JMS destinations,  JNDI factories, users/groups, permissions, bridges, routes etc.
  • JMS support. Messages may be sent/received, queues may be browsed and message  contents inspected. Selectors and filters may be specified.
  • JMS Message Monitoring. Messages may be monitored (snooped) as they pass trough  the server. Request and reply messages can be correlated to provide service  response times.
  • JMS Message Management. Eg; purging messages, copy messages from a queue to  another queue on a different server.
  • Charting. Server statistics may be charted in real time, data may be saved to  CSV files for export to other tools such as Excel.
  • Logging. Server statistics may be logged automatically when warning or error  limits are breached.
  • Security. SSL connectivity, view only mode.
  • Customisable display and look and feel.
  • Support for Managing and Monitoring TIBCO SubStation
  • Support for Monitoring TIBCO EMS Appliance.
  • Support for Migrating to TIBCO EMS Appliance.

 

Requires:

  • TIBCO EMS 5.0 or later
  • JRE 1.6 or later

fév

20

Posted by : admin | On : 20 février 2014

Good article

 

http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html

http://www.vogella.com/tutorials/AndroidBackgroundProcessing/article.html#concurrency_asynchtask_parallel

fév

02

Posted by : admin | On : 2 février 2014

 

Download driver

http://www.sybase.com/products/allproductsa-z/softwaredeveloperkit/jconnect

Squirrel on sybase

http://dcx.sybase.com/1101/en/dbprogramming_en11/jconnect-using-jdbxextra.html

jconn2.jar

jconn4.jar

alias connection

jdbc:sybase:Tds:<PKATEFORM>:<PORT NumBER>/<SCHEMA>?charset=iso_1

jan

18

Posted by : admin | On : 18 janvier 2014

 

optimize UI in Android

 

  • Bellow a few good reference I found while developping my apps
  • gobal ui in android

http://android-developers.blogspot.in/2009/03/android-layout-tricks-3-optimize-with.html

  • Improving action bar experience

http://www.androidhive.info/2013/11/android-working-with-action-bar/

nov

24

Posted by : admin | On : 24 novembre 2013

Compare CPU speed

a good website : http://www.diffen.com/difference/Special:Compare/Processors

nov

24

Posted by : admin | On : 24 novembre 2013

Rom name : TIGRA  XXUEMJ5]TigraRom_V4 <<<<Updated 19/11>>>>

It’s an amazing ROM , the only thnig that did’nt work is the wifi , but there is a fix  (follow the second link bellow ).

The air gesture didn’t work also , but air view is working perfetcly:)

Bellow the two article I’ve found the first one is the Rom desciption and some screenshot

the second link is how to apply the fix on Odin .

It’s very simple , the only thing you need to do is to press the button AP and select the correct patch.tar.md5 and apply 2 times .

Then just reboot your phone and everything work on !

Thanks for the developper team for all the workon this ROM .


http://forum.xda-developers.com/showthread.php?t=2479698

http://www.theandroidsoul.com/root-galaxy-note-2-on-android-4-3-firmware-and-removes-knox-too/

video youtube :

http://www.youtube.com/watch?feature=player_embedded&v=3i5Hgp4IYTQ

 

Other ROM

All tested rom :   http://www.android.gs/update/samsung-galaxy-note-2-n7100/

http://www.ibtimes.co.uk/articles/522695/20131116/galaxynote2-n7100-android44-kitkat-paranoid-android-rom.htm

 

http://www.theandroidsoul.com/update-samsung-galaxy-note-2-n7100-android-4-4-kitkat-cm11-aosp-rom/