Apr 30, 2012

Initial for Word List study Open Source Project using MVC3

Last year I was listening to podcast from Scott Hanselman  about being Be A Better Developer In Six Months.  One thing they suggest was to read code, contribute in open source communities and test other frameworks. Even from the suggestion of the authors of The-Pragmatic-Programmer-Journeyman-Master programmatic programmers book was to learn new language every year. Though It seems clumsy to study and master a language every year, they advocated it to study the style of the language and bring the style to your current language.  The blogger James Justin also also asserted  in his 10 tips to go from a beginner to an intermediate developer to study other type of framework and bring the notion or culture of the framework to your current and this will improve the design of your code.

At first I didn’t give much attention but when I started to follow it really worked for me. I just started to read unintentionally from an eBook about ASP.NET MVC. However the book grabs me and I can't leave it out. I just read the first version in last year.  According to the suggestion I climbed to develop an open source project to test my skill. At first I stared an open source project called http://petshelter.codeplex.com/ with  other developers around the world.  Although by profession I was not web developer this has clearly paved me to enter the web world.  Later when I got good test about the razor engine and EF in the MVC3 I inclined to develop my own an open source project hosted at codeplex. The intent of the project is for two purposes. First when I was starting the application I was in need for collaborative word study application.  Second the application also seems good to improve and test my MVC3 skill.

At the moment I have uploaded the initial version of the project at the Word List Study . Being an open source project I welcome for other contribution also.
The idea behind the application is simple. It is a collaborative engine for word study [currently an English].  A user study a word from the list and also adds new word if it is not in the list. Besides top student according the number of words is rated. The word studied among the students is also open so that other can easily study it and compute.
In conclusion, being a windows desktop application developer I was not much interested to develop the web application. But I have a habit of reading any kind of good book I get; my journey in the ASP.NET MVC has really boasted my programming skills.  I got very handy skill from the MVC world which still I am using in my daily desktop application profession.  The notion of clean testing, DI, separation of concern and thin view has become my daily arsenal in my workspace.

Feb 27, 2012

A tiny Tool to unhide hidden files on USB drive

At the time many computer viruses reset the attribute of files in USB drive.  Some of them create a shortcut using the name of the files to link to the virus’s name, while others simply hide your file.  In this article I will note a small source code to an application for this operation. Though, my main intention is not explain about the action of the scripts, it is vital to know what the scripts do.
In most cases the operation by the viruses to reset or add hidden, system and read-only attributes to the files and directory. As a computer professional I have seen also many novice users to face problem to reset the attribute of these files. It is also a handy to return files to its normal view using single command in command prompt. Unlikely, many end users feels aghast by the black screen and typing dos command in the shell. They feel arduous to remember the single command i.e. attribute –s  -r –h /s /d.
I took commence approach to make the command easier using simple C# codes. To make it short, the program is simple UI which iterates over the removable device. Once the user select the USB drive and click the reset button the whole files in the USB reset to normal (archive only) attribute.
Although, the application can be done using different ways such as
-          calling batch command from the program
-          using system.IO namespace
I choose to develop it using the System.IO namespace with Microsoft Input/ output namespace as it is flexible enough to play around.
The fun things I do in this program are mainly in the two functions.
-          The recursive function to process the whole files and directory on the USB drive
-          The Reset Attribute function which reset a file or directory to normal attributes (archive) type.
1.     The Recursive Scan Function


        /// Drive or Directory path
        private void ScanFiles(string currDir)
            if(!Directory .Exists (currDir ))
            //set the prograss bar max value
            pbar.Maximum += Directory.GetFileSystemEntries(currDir).Count();
            //iterate over the files
            foreach (string ff in Directory.GetFiles(currDir))
            {   //super cast to the parent class FileSystemInfo
                ResetAttribute((new FileInfo(ff)) as FileSystemInfo );
            foreach (string dr in Directory.GetDirectories(currDir))
                if (!Directory.Exists(dr))
                //reset the directory attribute
               ResetAttribute((new DirectoryInfo(dr)) as FileSystemInfo);
                      ScanFiles(dr); //scan the directory

Here when to reset the file and directory attribute an associate object is created then this is super casted to the parent abstract class of DirectoryInfo and FileInfo which is FileSystemInfo
1.   i.e. ResetAttribute((new DirectoryInfo(dr)) as FileSystemInfo);

Similarly for the file also.
2.  ResetAttribute((new FileInfo(ff)) as FileSystemInfo );

2.ResetAttribute Function

The second core part is the method ResetAttribute; which function for resetting the attributes of the file


        /// Remove file attribe of s,h and r

        /// fileSysteminfo type object
       private void ResetAttribute(FileSystemInfo fsi)
            { //bitwise operator on the file attribute
                fsi.Attributes &= ~FileAttributes.Hidden;
                fsi.Attributes &= ~FileAttributes.System;
                fsi.Attributes &= ~FileAttributes.ReadOnly;
            pbar.Value += 1;
            catch (Exception ex)
This function removes the attribute of a file when any of attribute type system, hidden and read-only are set on the file. Since both DirectoryInfo and FileInfo are subclass of FilesystemInfo, I chose this method over overload methods to accept a FileInfo type and DirectoryInfo type.

The resetting operation is done using bitwise operation where an AND operation is done with complement of the attribute type. Since AND operation true only if both operand are true, we complement the attribute to yield one false operand. i.e.  ~FileAttributes.Hidden. So what ever the previous attribute of the file it is, the attribute is reset (false).

Inconclusion , I developed this small application to be a handy and easy to use for the lame computer users. I hope this will alleviate some of the common inquiry from users to sysadmin.

Source Code 
There was an error in this gadget