Posts

Showing posts from August 9, 2009

Validate a text file based on LINQ

Image
Introduction This article will introduce how to validate a text file based on LINQ. Background A flat file is being used as the data file to pass around. In order to make the file to be accepted from other systems, the file has to follow some data format that the other systems expect. Not only the data format, some business rules may also need to be pre-evaluated before the file is sent out. In this article, I'll build a validation engine based on LINQ to a text file to challenge if the file meets all the requirements which I defined for a system to process it. Rules need to be validated The valid file should have a HEADER record, a FOOTER record, and some CONTENT records. The first 3 characters will be used to describe the type of record it is. In this case, I am going to use 111 for HEADER record, 999 for FOOTER record, and 222 for CONTENT records. We could use 4-6 characters to describe the sub-record information. However, I am only going to demo the HEADER, FOOT

Glass Effect Extender Library for your Applications

Image
Introduction As is known, the first noticeable thing when moving from Windows XP to Windows Vista or Windows 7 is the enhanced graphical user interface, and if your hardware is good enough to support the Windows Aero Theme , you'll get great looks for the window title bars (see the figure below): But if this theme is not enabled due to lack of good enough hardware, or is manually disabled by the user, the window titles will appear like this: And here, we are going to get some control of this feature (the Glass Effect of the window titles and frames). Window Desktop Manager In the old days of Windows XP and earlier, each window was responsible to draw directly to the screen or the primary display device, but starting from Windows Vista, this is no longer happening, and a new feature has been introduced. This feature, called the Window Desktop Manager, is a service responsible for Desktop Composition that changes the way applications display pixels on the screen, s

File Encryption and Decryption in C#

Introduction This article demonstrates how to use C# to encrypt and decrypt files of any type. Background Recently, I needed to find a simple way to encrypt and decrypt a file of any type (I actually needed to encrypt image and text files) and any size. I found hundreds of examples on the web, many of which just plain didn't work, or threw errors on certain file types. Eventually, I put together the following two methods using the Rijndael encryption algorithm. They simply require that you pass them the full path to the original and target files. They both require the use of the System.Security , System.Security.Cryptography , System.Runtime.InteropServices , and System.Text.RegularExpressions namespaces. Unfortunately, as I looked at so many examples on the web and actually did all this a while ago, I do not remember which bits of code were originally written by who. So, if you recognise some of it, many thanks, leave a comment below so that your work doesn't

How to encrypt and decrypt a file by using Visual C#

This article describes how to use the cryptography classes that are provided by the Microsoft .NET Framework to encrypt a text file to an unreadable state, and then to decrypt that text file back to its original format. Requirements The following list outlines the recommended hardware, software, network infrastructure, and service packs that you must have: Microsoft Windows 2000 Professional, Windows 2000 Server, Windows 2000 Advanced Server, Windows NT 4.0 Server or Microsoft Windows XP Professional Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET Encryption and decryption The System.Security.Cryptographic namespace in the Microsoft .NET Framework provides a variety of tools to help you with encryption and with decryption. The CryptoStream class is one of the many classes that is provided. The CryptoStream class is designed to encrypt or to decrypt content as it is streamed out to a file. Encrypt a file To encrypt a file, follow these steps: Start V

Working with CLR Objects in SQL Server 2005 or Above Part 1

Image
Introduction Sql Server 2005 introduces a new way of writing database object for .NET developers. In addition to Extended stored procedures we may now use CLR stored procedures to fetch or store data, write Triggers , User Defined Functions etc and get the full functionality of powerful .NET framework through SQL server. For example, Suppose you want to create an xml parser which parses data and gives output. Let us think what are the options you will be having if you want to do this in database. You can write a Normal Stored Procedure to handle this complex Logic of creating an XML output. Use OpenXML, to read the xml, open cursor to read only the data within the output table from Open XML. Use Manual String parsing technique. Use XML Data Type introduced in Sql Server 2005. From the above few techniques available the best way is to use XML Data Type. If you have used XML datatype ever, you might have already got the flavour of CLR types. XML is serialisable data t