Software Development

Remove white spaces using regular expression [\t ]+

The correct expression to remove white spaces using regular expression is

[\t ]+ — Make sure  you select Regular Expression in Search Criteria

I used the following which id not quite work [\t ]*. The problem with this one is it match 0 or more. So it basically matche every single character rather than matches spaces only. Hope this helps somebody.

 

It is also a good practice, instead of complete removing white spaces, replace it by a single space as your code might not work if you remove all spaces. The search critera also remove tab characters.

Some variotions

^[\t ]+ =  Will match white spaces that are in the beginning of each line

[\t ]+$ = will match white spaces that are at the end of each line

 

Copy and Past in Visual Studio and Fix IDs

When you copy a big chunk of ASP.NET code the chances are you are going to run int IDs problem. IDs from the new code is wiped as soon as you past them. Here is a solution to fix it.

Copy the chuck of code into clipboard and past into “Sublime Text 2” for example. Use the following RegPater to call all IDs.

Use the following patter in the replace text

Make sure you have select “Regular Expression” (there is a short cut button for it).
Replace everything it finds. And the copy and past the new code. This should fix the problem.

If your code has control validator, use the following regex as a second run to fix that issues

Please note, do not leave – character in ID as Visual Studio will automatically wipe that out.

set up new website in iis7

Setting up new site in IIS can be tricky. Actually the process is easy most of the time it may not work for you mainly because of Application pool setting or for other unknown reason. I had similar issue setting up site in IIS7 today so I will write all the steps, What you should be doing and what you should not be doing.

This tutorial is for IIS7 on Windows7 System.

Steps to Setup Site in IIS7

  • Start IIS by typing IIS in Start-> Search Box. If it is not installed you have to install by going to Add/Remove Windows Components
  • Inside IIS, got to Sites, right click , Add new site. Name It local.yahoo.com.IIS7 Add new site
  • Select “Local.Yahoo.Com” then select Basic Binding. The following dialog will pop up.Screenshot 2014-09-22 19.27.41
  • Select the directory from where you want to server the site. But importantly click on the Connect as button select the user who has full permission to the directory. This is important as authentication will fail later if you do not complete this step. If you are logged in with username which does not have password. Go to System Users and create a new user, name it something like “FOR IIS” and set user name and password. After you enter those credentials here, click on “Test Settings” button and make sure both the permission have green icons.
  • Next click “Binding” from the right side, just above “Basic Binding”. The following dialog will pop up.Screenshot 2014-09-22 19.31.05
  • In the above dialog, highlight the entry, edit will become active. Then click edit. In the host name, click “local.Yahoo.com”. Leave port 80 as it is as you want to direct all traffic through this port. IP Address can be to local IP or leave it as a steric. Both options are available from drop down.
  • Edit Windows host file which is located in c:\Windows\System32\drivers\etc\hosts. You will not Administrator permission. Open Notepad first by right clicking on it and select “run as administrator”. Then File open, give location.
  • Enter the following entry in a new line “127.0.0.1 Local.yahoo.com”
  • Go to the binding property again, click edit on local.yahoo.com and select the browse button. It should display contents in your site if there is any index.html or default.aspx page.

Setting up Multiple Sites

You can setup multiple sites in IIS by proving hostname in the “Binding Dialog” and corresponding enter that host name in the Windows host file as well.

When you provide hostname in binding dialog (as we did Local.Yahoo.com), IIS recognizes that hostname and will server the appropriate site when request from a recognized host is received.

Issue with IIS Sites

There is a fair chances the site will not work in first chance. In my case, I had to play with Application pool. Changed it from V2 to V4 and Playing changing setting from Integrated to Classic. Somehow that resolved it for me, not sure why. The other sites that I created worked in Integrated mode V2 which the first site did not work. So I am not really sure why it works one time and why it doesn’t the other. Probably it is some type of bug in II7. The solution is trying changing Application pool setting, recycle it and restart the site, it *might* work.

Note that you do not need to Add Application to your website. It should work without adding any application.

If this tutorial was useful, please comment below so I can continue my other writing.

In case of Proxy Server

If you use proxy to access internet or use resources over network, you will have to add exception or use not proxy for your local site.

In FireFox, go to top menu, select Tools > Options > Advanced> Network tab > Connection Setting. Type your local domains in “No Proxy for” area. This step is required if Proxy is configured on your machine.

Summary of Errors I was getting

Explanation: The IP address for the website you requested could not be found.

The above error resolved by itself on first machine when I was playing with Application Pool Settings.


The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.


HTTP Error 500.21 – Internal Server Error
Handler “PageHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list

directory is already under version control SmartSVN

Directory already under version control - smartSVN error

Directory already under version control – smartSVN error

I was getting this error while adding my project in SmartSVN and I had no clue whatsoever

*directory* is already under version control SmartSVN

The reason I was getting this error was because I had select the root folder and the sub folder and choose to add the files recursively . That basically added the sub-folder two time, one time as part of recursion and a second time because it was explicated added.

Simple solution is, select only the root folders and click add *recursively* or select all folder and choose to “Only Add Directory”.  The first solution worked better for me btw. Hope this helps someone.

SmartSVN Add files recursively

SmartSVN Add files recursively

regex-greedy

Greedy means it will go towards the end of line and will NOT stop at first match if there are other matches available.

'.*'  = Greedy
'.*?' = Lazy

Lazy has extra character (?) in the regex syntax. Similarly you can use ‘+’ operator instead of ‘*’

'.+'  = Greedy
'.+?' = Non Greedy (also called Lazy, Reluctant)

‘+’ mean one or more characters
‘*’ mean zero or more characters

List all worker processess in IIS

run as adminIf you hit ctrl+alt+del, you will notice one ore many w3wp process. Each of these correspond to a different site (or Application Pool). In Windows Task Manager, you cannot judge which process is associated with which site. You can issue the following command to find that out. Copy and past the following in command Window. Make sure you start cmd in Administrator mode otherwise you will get an error

c:\Windows\System32\inetsrv\appcmd list wp

Or you can changed directory first and issue the same command

cd \Windows\System32\inetsrv.
appcmd list wp

If you did not start cmd prompt in administrator mode, you will end up getting this error

message:The WAS service is not available – try starting the service first

Contact Hammad

Hammad Khan is an experienced software engineer with 10+ years of experience in desktop application, web application, databases and websites. You may contact him for technical expertise or hire him for your project on contract or perm basis.

Your Email:
Your Message:

Quartz.net Working Example

I could not find a working example for Quarts.net. The examples at Quart.net site, does not compile. Found out they are build against Quartz.net version 1.0. The following is a working Quartz.net example that is built against Quartz.net 2.0 (Latest). What this job does is write a text message, “Hello Job is executed” in the console every 5 sec.

Tutorial

Start a Visual Studio 2012 project. Select Windows Console Application. Name it Quartz1 or what ever you like.

Requirements

Download Quartz.NET assembly using NUGET. Right click on project, select “Manage Nuget Packages”. Then search for Quart.NET. Once found select and install. Note that you have to have online connection for this.

Copy and past the following Code

How to delete Quartz.net job

Debug C# Application without running code

You can debug/test your code without running the application itself. There is a neat feature in Visual Studio (I am using VS 2012) where you can go to Debug menu -> Windows -> Immediate. In this window, you can type in the name of the function you want to execute and it will execute and return result. Pretty nice feature!

More on this link from Microsoft