Friday, February 15, 2013

Schedule job to check process running

In my day job I had to have a scheduled job to check whether an application was running. If it wasn't then it needs to be restarted.

As any developer would do I got into the rabbit hole fast, worrying about the threads/schedules etc. Alas Quartz.Net came to my rescue. You can find it at Quartz.Net.

Quartz.Net is a job scheduler for .Net based on Quartz (Java). It is a very flexible and comprehensive library. Download it and just add the Quartz.dll to your project from the release directory of the zip file.

Below are some sample code that might help you get started

Program.CS


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz.Impl;
using Quartz;
using Quartz.Core;
using Quartz.Job;
using Quartz.Simpl;
using Quartz.Util;

using System.Configuration;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create scheduler factory
            ISchedulerFactory sf = new StdSchedulerFactory();
            IScheduler sched = sf.GetScheduler();

            //Get interval you want to check
            String interval = ConfigurationManager.AppSettings["CheckInterval"];
            int checkInterval;

            //No AppSetting set it to a default value
            if (!int.TryParse(interval, out checkInterval))
                checkInterval = 60;
         
            // define the job and tie it to our Class1 class
            IJobDetail job = JobBuilder.Create().WithIdentity("Checker", "Group1").Build();
         
            // Trigger the job to run on the next round minute
            ITrigger trigger = TriggerBuilder.Create().WithIdentity("Trigger", "Group1").StartNow()
                                                      .WithDailyTimeIntervalSchedule(x => x.WithIntervalInSeconds(checkInterval))
                                                      .Build();

            // Tell quartz to schedule the job using our trigger
            sched.ScheduleJob(job, trigger);

            // Start up the scheduler (nothing can actually run until the
            // scheduler has been started)
            sched.Start();

            String quit = Console.ReadLine();
        }
    }
}

Class1.CS


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz.Impl;
using Quartz;
using System.Configuration;
using System.Diagnostics;

namespace ConsoleApplication1
{
    [PersistJobDataAfterExecution]
    class Class1:IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            //Example to check whether a application is running, use WebClient to check whether website is up.
            //it's up to you.
            String ProcessName = ConfigurationManager.AppSettings["ProcessName"];
            if (!String.IsNullOrEmpty(ProcessName))
            {
                var running = Process.GetProcesses().Where(prc => prc.ProcessName.ToLower().Contains(ProcessName)).FirstOrDefault();
                if (running == null)
                {
                    //Process is not running!! Call Mama!!
                    //Send a email
                    //Try running the process again
                    //Twilio integration for SMS!!
                    Console.Out.WriteLine(ProcessName + " is NOT Running!");
                }
            }
        }
    }
}

App.config

Your app.config should have two keys with "CheckInterval" and "ProcessName".


     
       
   
 
   
   
 



     
       
   
 
   
   
 


     
       
   
 
   
   
 




Thursday, February 14, 2013

My Favourite book on creativity

I'm very interested in the studies on Creativity and throughout the years I've read as much as I could on this topic. Throughout my years of reading, there were a lot of books that I've wasted money on. Most of these books have a tendency of talking too much about case studies that you and I can easily find on the web or writings that doesn't include a concrete way for you to embark on your quest for becoming a creative person.

A look into my Kindle library these include:

1. Imagine: How Creativity Works by John Lehrer
2. Cracking Creativity by Michael Michalko
3. Lateral Thinking by Edward De Bono
4. Your Creative Brain by Shelley Carson
5. Creativity by Mihaly Csikszentmihalyi
6. Disciplined Dreaming by Josh Linkner

Out of the 6 books, the only book that I would recommend is Disciplined Dreaming: A Proven System to Drive Breakthrough Creativity (Amazon affiliate link) His book helps you to be creative by giving you processes that improves you or your team's creativity. All of these processes was used by the author in his company ePrize to help him innovate keep his company on it's toes. These process includes:

1. Asking the three magic questions
2. Developing the five skills of master innovators
3. Looking through different lens
4. Putting patterns to use

There are more in the book but I'll just list these 4 as examples.

For a brief description, the "Looking through a different lens" process allows you to find new perspectives for a problem.This can be achieved by looking at a problem with different roles. i.e. Student, Musician, Architect or a Villain. There's more in the chapter so go have a look at the book.

I really highly recommend this book to whoever wants a step 1 - 10 guide on improving your creativity. If you have any other book to recommend please feel free to let me know in the comments.

Friday, January 4, 2013

Using command line to compress files using 7zip

In my day work I had to compress the database backup file to an external storage using 7zip. I did this by creating a batch file E.g. Compress.bat and inside it using the 7zip executable to compress the backup file

"C:\Program Files\7-Zip\7z.exe" a -t7Z -m0=LZMA2 -mx9 -mmt10 "E:\backup.7z" "C:\Database\productionbackup.bak"

This assumes that your 7z.exe is installed in C:\Program Files directory. The -t7Z means that you want the destination file to be in 7zip format. The -m0=LZMA2 means that the compression algorithm to be used is LZMA2. The mx9 switch specifies that you want Ultra compression ratio.

The mmt10 switch specifies that you want to use 10 processor core for the compression. PLEASE BE AWARE that you should specify -mmt5 if you want to use 5 out of the 10 cores available to avoid overloading the processor for the batch job.

The next parameter is the destination file name, after that would be the source file name.

With the batch file then you can schedule a scheduled task in Windows server for compression of the backup file automatically. Poor man's implementation but it's been so far so good for me.

Hope this helps.

Tuesday, February 10, 2009

Same problem as us?

nice article on how UK's emphasis on financial wizardry might hurt them in the road to recover.

http://www.guardian.co.uk/commentisfree/2009/feb/08/james-dyson-engineering-britain-railways

Are we on the same track?

Monday, February 9, 2009

Here is what makes me goes on...

As my last post suggests the earnings are actually going down very rapidly. Therefore had been busy coming up with other apps, when I've decided to take a breather and check out reviews for my current application here is what I saw and it really gives me the motivation to try and come out with other 'innovative' (shameless me) way of doing mobile software.

I am really really happy that my new way of creating flowchart with focus of fast and simple works for the reviewers (UK appstore). It feels great when your creation is being appreciated by the users. Hope I've achieve the aim of showing my friends that we are better than what we/others think. (I still remember my friend's remark on doing a flowchart is too difficult)

Oh how can I forget, if you are interested you can purchase it here

Sunday, January 25, 2009

Sales figures so far

Hi all,

As promised more posts. Here is the sales figure for 5 days so far.

Total downloads: 100
Commision paid to me: USD $1.4 per sales
Estimated profits: USD $140

Majority of the sales comes from USA. Second most downloaded region is Japan (pretty surprised considering I did no localization). Third coming in is Great Britain.

So no, you can't survive on iPhone apps alone.

iPhone flowchart application

Best regards.

Tuesday, January 20, 2009

My first iphone flowchart app up

Yes after all the wait and frustrations finally my first iPhone app is up! Of course there are some gotchas again. Most importantly for your W-8BEN submission the ITIN number is not really required, key in 000000000 also for item 9 select first and second checkbox, leave 10 empty as singapore have no tax treaty with the states. This got me for a while...trying to apply for ITIN from IRS...

you can have a look at my app here. anyway more post to come...oh I'm available for iPhone application consulting jobs in the meantime..(finding inspiration for next app still)