Monday, December 20, 2010

wpf: Setting folder permissions on NetApp server.


Recently I was working on a project to set folder permissions on one of our file servers. We are migrating to a new corporate domain structure with new user names.
Neither the old and new domains are in a single forest nor do have a two way trust. Once we are migrated to the new domain, we want the users to have access to their files with their new user credentials. This file server is a NetApp server and folders are secured using NTFS file system permissions. Even though this server can be managed using windows explorer, it doesn't support WMI or RPC to get/set permissions. Luckily I was able to use ICACLS to enumerate and set permissions on these folders.

[If you want to set permissions on a windows based file server, you can use ICACLS or the native DirectorySecurity namespace or WMI.]

Highlights:
- If the log on user is a department owner, he can specify the folder to start
- Use background thread to do the job. This will free up the mail UI thread and better program responsiveness
- Log results to a database for reporting
- Email the user once the process is finished
- Display % completed, total directories, completed directories and currently executing commands
- Display vista style progressbar on non vista platforms.

download code

-paul

Sunday, December 12, 2010

c#: Outlook plug-in


Many people prefers to work directly from their email program. Even though you may have a cool website, the convenience of working directly from your email program in response to an email is one of the best way to boost the productivity of people. This is an outlook plug-in designed to full fill the needs of an offline system with ease and convenience of working directly from Outlook.

If you have a web service and a mailbox processor, writing an Outlook plug-in is very easy and rewarding. You can easily add offline capability for many tasks without needing any special software on users computer. If you are connected to a back-end system, this plug-in forwards all calls to the back end system. If you are offline, this plug-in formats the message in a specific way and then emails to a mailbox which will process and update the back end system.

Based on the currently selected item in outlook, this plug-in enables or disables appropriate buttons. For eg, if you select an existing ticket email, then CreateTicket button is disabled.

It may be necessary to add toolbars to the Outlook menu bar and/or to the Message Item window. By adding to the menu bar, you can respond to many emails at once without opening one at a time.


Programming Logic:
- Create new buttons and attach event handlers to each for them.
- OnButtonClick event, check the sender and take appropriate actions
- When the selected email changes, check and enable/disable buttons
- If online, use the back-end system directly.
- If offline, compose new email with commands and send to a monitored mailbox
- Create Windows Forms for Configuration and additional data

download code

-paul

Friday, November 5, 2010

c#: POP3 mail processing Windows Service

Often times we need to process mails in a mailbox and based on the subject or message body, take actions in back-end systems. This was a project to process POP3 mailbox using c# implemented as a Windows Service. You can use TCP/IP to connect and process mails on a POP3 server. If your server requires SSL, use SSLStream on top the existing TCP stream to establish communication with the server. Sending commands to POP3 server is quite simple as writing the command (eg "DELE\r\n") to the TCP/IP socket and check the response.
Unlike IMAP, pop3 server doesn't keep track for message status (read/unread) so you cannot just fetch all unready message from the server. Once you are done with processing, delete the mail or keep track of the message guids to exclude in the next batch.

In this program, I am fetching all messages into an array and then sort them based on sent date. All attachments are saved to the file system and a handler is saved in the database.


The windows service that hosts this library has a timer which calls the StartMailBoxProcessor code on a user defined time intervals. This service is deployed to two servers with fail over capability.

download code

-paul

Thursday, September 9, 2010

wcf: MS Exchange Agent


An Ajax enabled web application that communicates with a wcf service for getting appointment items from Exchange Server. This service defines interfaces for create/update/delete/get appointments from Exchange server.
Users can click on any date in the calender control and Outlook appointments will be presented in an Ajax enabled web portlet.

In the past I have used .Net remoting to communicate with the server to get results from a service to the web page. It was slow and was kind of ugly to write code to interpret the integer command argument (only way to communicate with a service) for processing.


Proxy files are generated using svcutil.exe. We chose to host the service in Windows Services rather than IIS. This enables us to take advantage of Corporate Service Monitoring application to monitor the service. This service is installed on two servers with a fail-over capability.

download code

-paul

Tuesday, August 3, 2010

wood working: Rails



I saw this style of railing in a movie long back and it looked pretty cool. This is a common style used in most temples in South India and recently a lot of new houses are built with this style of rails. I decided to build a railing for my patio and here is the end result. I made a template in mdf and then replicated on pine. First I rough cut the wood using a band saw and then routed the final piece using the template.
The most tedious job was drilling the through hole for the bar. I couldn't find a drill bit that matches the rod diameter, so I have to enlarge the hole by sanding using a hand held drum sander.
I thought drilling the hole in the stone/concrete floor would be tougher job. But it turned out to be the most easy one. I was able to attach the post to the concrete in less than 10 minutes.
After sanding, 3 coats of exterior paint and 2 coats of polyurethane, this is how it looks.


Post: 2x2 Redwood.
Rail: 2x10 Pine.

-paul

Friday, June 4, 2010

sqlclr: RegEx search in Sql Server

Even thought T-SQL is very efficient in processing set based data, it is very inefficient in executing many string based operations (eg extract strings from a text column based on search patterns). Unfortunately Sql Server doesn't have any native support for Regular Expressions to do this efficiently. Because of the .Net CLR integration, we can write a sql clr function to achieve this functionality. Here is a generic regular expression search function using RegEx that can be used to extract any pattern matched strings from any text column from Sql Server.
You can use the same logic to extract pattern matched strings from files, network shares etc.
1. define an IEnumerable static method with SqlFunction attribute.
2. define a GetRow method to return a single row for the tvf. Sql CLR will call this method to populate the tvf.
3. use a case-insensitive compare method to remove duplicates. You can either omit this method or use a DISTINCT clause in the select statement in Sql Server query.
[SqlFunction(FillRowMethodName = "GetRow", DataAccess = DataAccessKind.Read, TableDefinition = "found varchar(8000)")]
public static IEnumerable GetRegExSearch([SqlFacet(MaxSize = -1)]SqlString text, SqlString regExSearchFor)
{
List allFound = new List();
MatchCollection matchCollection = Regex.Matches(text.ToString(), regExSearchFor.ToString());
for (int i = 0; i < matchCollection.Count; ++i)
{
String found = matchCollection[i].Value.ToString();
if (FoundInList(found, allFound) == false)
allFound.Add(found);
}
return allFound;
}
public static void GetRow(Object obj, out String found)
{
found = obj.ToString();
}
I am implementing this functionality as a table value function (tvf) so that we can use this to join with other tables or tvfs.

To register this assemby in Sql Server, use the deploy option from Visual Studio or copy the dll to sql server and execute

CREATE ASSEMBLY SqlCLR
FROM 'C:\SqlCLR.dll'
GO
CREATE FUNCTION [dbo].[fxGetRegExSearch](@text [nvarchar](max), @regExSearchFor [nvarchar](4000))
RETURNS TABLE (
[found] [nvarchar](max) NULL
) WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [SqlCLR].[Functions].[fxGetRegExSearch]

download code

-paul

Monday, April 5, 2010

car: Head Light Restoration and Spark Plug Change

My antique gem's headlight is fading faster. One side is completely yellowish. Normal washing and cleaning is doing nothing to bring back the old glory.
I saw a couple of web sites and videos showing how to restore the headlight.
This is my take on cleaning my car's headlight. It took almost 30 minutes to clean both lights. Very simple to use, just apply the chemical to the pad and use a drill to polish. Looks pretty good to me.
Here is the before and after pics:

 

It was time to change the spark plugs. After almost 85k miles, the OEM plugs were still going strong. Changing the spark plug was a quick and easy task. Remove one plug at a time, put some anti-siege component on the new plugs thread and tighten to the correct torque.


Previous >> Throttle Body clean

-paul

Friday, March 5, 2010

c#: Spell checker control using jQuery

Recently I needed to add spell checking functionality to a web page. I wanted to exclude a list of strings from spell checking (like first and last names) and this list of exclusions should be customizable easily. I couldn't find any controls that fits into this need in the aspnet world.
I found this article that uses php and google's spell checking api with jQuery. I thought of porting this as an aspnet control so that I can use it without adding too much scripts on any aspnet pages.


Most of the heavy work is already done by the original author, so all I need to do was call google's api, parse the result and return the result as a JSON object to jQuery. Once the JSON is received, we build a div element with the bad spelled words with a click handler to get the suggestions. When building the div element, use the parent element's width and some images to show the progress or no bad words indicator. Wrap all these scripts and images in a server side control, so to use the spell checker, add the control to the web page and set the TargetControlID to the textbox's ID.




download code

-paul

Friday, February 5, 2010

c#: Exchange Mailbox Processing

This is a windows service that processes mailbox on an Exchange Server. Since the introduction of Outlook Security feature, accessing certain properties (like email) will trigger the Outlook prompt. To circumvent this prompt, we are using Redemption Extended MAPI library to fetch outlook messages.

We can use a profile to login to the mailbox or use profile-less (LogonExchangeMailbox) method to login. As I am processing the mails in a mailbox, I am moving them to a Processed Folder. I am fetching all messages into an array and then sort them on date sent descending order.


All attachments are saved to the file system and a pointer is saved in the database.


The windows service that hosts this library has a timer which calls the StartMailBoxProcessor code on a user defined time intervals. This service is deployed to two servers with fail over capability.

download code

-paul