C# – MVVMLight Toolkit Messages

MVVM pattern is the most popular pattern to developers in WPF environment and there are already many platforms/frameworks supporting this pattern out there in internet. For example, I use Caliburn Micro Framework at work and use MVVM Light Toolkit at home for my private studying. Each framework has its own advantages and disadvantages so just choose one which you like or it satisfies you at most. Today I would like to make a small post to describe how the Messenger of MVVM Light Toolkit (MLT) works so that we can make the communication within application without violating the MVVM pattern.

Continue reading C# – MVVMLight Toolkit Messages

C# – Microsoft Sync Framework for file and database

Data synchronization is always a top feature for any product in IT zone, especially if your product is a database-based product. It provides the customers more flexibilities and “freedom” when using the products. For example, the customer is on construction area, enter data through a concise mini mobile client, then sync them with the server and when they are back to the office, they have all data in the main software and finish the rest of work. That means at any time and anywhere they can access their updated data. However, it’s not easy at all to implement this dreaming feature in any application because of the complexity. However, if you’re using Microsoft products, you can easily build this feature in your apps thanks to Microsoft Sync Framework (MSF) http://msdn.microsoft.com/en-us/sync/bb736753. Maybe you’ll say that there is already the replication feature in MS SQL Server, why do you need to use MSF? Yes, it’s correct that MS SQL has already this feature but obviously, we can only sync between MS SQL Servers. How about if we want to sync with MS SQL Express? The answer can be MSF.

Continue reading C# – Microsoft Sync Framework for file and database

How to activate Guitar Pro 6?

I have bought a new guitar to play in my free time. I am just amateur not so professional. I haven’t played guitar 6 years since I left my country to make my master degree in Germany. I forget all of music theories and cannot read any note in music sheet. It’s hard for me now to read note as fluently as 6 years before but I’ll try my best. There is a lot of guitar tutorial inclusive music sheet in internet but they are all saved under format of Guitar Pro (*.gpx or *.gp5). I heard about this program and would like to try it. So I start to search through in internet but most of results were infected with virus. There is only one version which I think it may be clean until now. You can follow the steps below to activate your Guitar Pro.

1. Download file from this link http://www.megaupload.com/?d=5FZ7JQNV
2. Turn off your internet connection
3. Run vcredist_x86.exe file to install Microsoft Visual C++ 2010 Redistributable Package. If you have installed it before, the setup will turn off itself.
4. Run Guitar_Pro_66.0.7_b2_r8924_Repack_Setup.exe file to install Guitar Pro 6.
5. Run crack_x86.exe or crack_x64.exe depending on your operating system.
6. If you’re using Windows Vista/ Windows 7, copy the hosts file under C:\Windows\System32\drivers\etc to your desktop, open it in Notepad and add this row at the of file	 activation.guitar-pro.com

If you don’t file hosts file, you can read this article and find it yourself http://en.wikipedia.org/wiki/Hosts_%28file%29
7. Double click on disable-updates.reg to disable update function of Guitar Pro 6. Finish.

When I read on Internet, I think that the license routine of Guitar Pro basing on the MAC address of network card. As my opinion it’s pretty bad when a license bases on this one because the software of my company based on MAC of network card too. Until a day a customer has many network cards on his computer and he usually enables/disables these network cards because his work requires accessing to many types of network (LAN, WLAN, GPRS…). And our license model doesn’t work anymore because we don’t know anymore which card is used for license. Just some chat about license model.
And now we reach the end of this blog post. Nothing special just only on suggestion from me: Guitar Pro costs only 60$. If you are working professionally with it, I recommend buying a licensed version to support the provider. And remember, crack can contain virus, use it on your risk. I always say that a crack is seen as clean until an antivirus finds it as malicious.

C#, Tools – PC Time to track on/off time of computer

One boring task at my company is that each employee should report how he allocates time for each project he was following. Of course it is a must-do-work for project managers or supporters because they have to monitor how much time they have worked for each project so that the accounting department can send billings to customers later. But it doesn’t mean to me because I am a programmer and I have only 2 or 3 projects to take care of. I am just swinging between 2 phases: developing and bug fixing. The Test-phase will be made by Testers. Sometimes I write some Unit-Tests too but it’s not my fulltime field. As you see, my tasks are pretty “simple” however I must make myself an hour booking report at the end of each month too.
So I try to keep this task as simple as it is. Each day I make a notice on my calendar about with which project I am on. For a small, short-time project, I notice its name and its duration. It works great. But for a long-time project then I really don’t know how long I was on because it takes weeks, months to accomplish. The problem is that I always forget to book hours after working day. Then I have an idea to approximate my PC on time as project time (Of course I have to subtract lunch pause and some minutes for short break) It won’t be exact as project time but I believe it will be nearly exact. With this solution I don’t need to remember to book hour after each day anymore.
To monitor PC on/off time there is also half-free software on Internet, you can easily find him with search engine. In free version, I can only see 3 weeks before today. If I want to see more, I must buy a PRO-version. I am a poor man so I don’t have money to buy one therefore I must write myself to help me making my hour booking report.
The tool is not very complicated because any action of computer was logged by operating system. The On/Off events are not exceptions. I just have to read them out from log files and show them in easy-read way. Every time when I turn the computer on/off, the actions will be logged in Windows Logs –> System which can be viewed through Event Viewer

Windows Logs System

As you can see in image above (in case that you can read German ^_^), Event-ID 12 is ID of ON-Event which was sent by Kernel when I turn the computer on. The OFF-Event has ID 13. So basing on this log, I can trace back when I switch my computer on/off, calculate the ON time, make some magical calculations and then I have my project time at last. I will show you how to read on/off time from this log with C#.

Dictionary<DateTime, List<TimeBlock>> PCOnOffTime = new Dictionary<DateTime, List<TimeBlock>>();
private void IntializeData()
	EventLog log = new EventLog();
	log.Log = "System";
	log.MachineName = ".";

	var entries = log.Entries.Cast<EventLogEntry>();
	var itemMin = from e in entries
				  group e by e.TimeGenerated.Date into g
				  select new CustomEntry { EntryDate = g.Key, TimeGenerated = g.Min(e => e.TimeGenerated), ActionType = "On" };
	var itemMax = from e in entries
				  group e by e.TimeGenerated.Date into g
				  select new CustomEntry { EntryDate = g.Key, TimeGenerated = g.Max(e => e.TimeGenerated), ActionType = "Off" };
	var itemOn = from e in entries
				 where e.InstanceId == 12 && e.Source.Contains("Kernel-General") && e.EntryType == EventLogEntryType.Information
				 select new CustomEntry { EntryDate = e.TimeGenerated.Date, TimeGenerated = e.TimeGenerated, ActionType = "On" };
	var itemOff = from e in entries
				  where e.InstanceId == 13 && e.Source.Contains("Kernel-General") && e.EntryType == EventLogEntryType.Information
				  select new CustomEntry { EntryDate = e.TimeGenerated.Date, TimeGenerated = e.TimeGenerated, ActionType = "Off" };

	List<CustomEntry> temp = new List<CustomEntry>();
	itemMin.ToList().ForEach(x => temp.Add(x));
	itemMax.ToList().ForEach(x =>
		if (temp.FirstOrDefault(y => y.TimeGenerated == x.TimeGenerated) == null)
	itemOn.ToList().ForEach(x =>
		if (temp.FirstOrDefault(y => y.TimeGenerated == x.TimeGenerated) == null)
	itemOff.ToList().ForEach(x =>
		if (temp.FirstOrDefault(y => y.TimeGenerated == x.TimeGenerated) == null)

	List<CustomEntry> result = new List<CustomEntry>();
	string actionType = "";
	CustomEntry itemBefore = null;
	foreach (CustomEntry item in temp.Distinct().OrderBy(x => x.TimeGenerated))
		if (actionType == item.ActionType)
		actionType = item.ActionType;
		itemBefore = item;

	for (int index = 0; index < result.Count; index++)
		if (!PCOnOffTime.ContainsKey(result[index].EntryDate))
			List<TimeBlock> listTimeBlocks = new List<TimeBlock>();
			PCOnOffTime.Add(result[index].EntryDate, listTimeBlocks);

		PCOnOffTime[result[index].EntryDate].Add(new TimeBlock() { EntryStartTime = result[index].TimeGenerated, EntryEndTime = result[++index].TimeGenerated });

The code is pretty simple. I just instantiate a variable whose type is EventLog, indicate it to work with the System-Log at my local machine (MachineName = “.”). Then I read the first entry of each day and set it as ON action and last entry of each day and set it as OFF action. Now I have a likely ON duration but it will be wrong if I turn on the computer in the morning at 8:00, turn it off at 8:15, go out, come back to company at 17:00, turn computer on again and turn it off at 17:15. Then the first entry is 8:00 and the last is 17:15 but the truth is I am not in company during this time. So I have to catch the ON/OFF events within day as in variables itemOn/itemOff.
After having all ON/OFF events, I just add them together, order ascending according to time, remove duplicated ones and then construct them in a Dictionary whose Key is date and Value is a list of time block marked with On and Off time. That means in one date, computer can be turned on/off many times. These on/off time will be parsed as EntryStartTime/EntryOffTime and saved in list.

class CustomEntry
	public DateTime EntryDate { get; set; }
	public DateTime TimeGenerated { get; set; }
	public string ActionType { get; set; }
class TimeBlock
	public DateTime EntryStartTime { get; set; }
	public DateTime EntryEndTime { get; set; }

At the end is the GUI. With some mock-up from WPF, I have beautiful PC Time software to show me when I turned on/off my computer.

PC Time On Loading

PC Time Load Finished

Maybe you’ll tell me that you can let the computer on and go out. My tool cannot detect that. Yes, it’s true but this tool is to help you to control yourself, not to cheat someone else. 😀
Binary: http://hintdesk.com/Web/Tool/PC%20Time.zip
Source code: https://bitbucket.org/hintdesk/dotnet-tools-pc-time-to-track-onoff-time-of-computer