Tuesday, April 14, 2009

IntelliParse

I've started my first SourceForge project named IntelliParse. As the description goes, this is...

A library to parse user-entered form data such as telephone numbers, social security numbers, dates, etc. and intelligently convert them to usable and normalized forms, with country codes, area codes, etc.


I intend for this library to be a cross platform and available on all modern operating systems for the desktop, laptop and smartphone. I'm in the process of deciding on a directory structure, and its taking shape with the answers to this StackOverflow question:


/project //Top level folder

/bin //Binaries ready for deployment
/linux_amd64 //Linux AMD64 platform
/debug //Debug build - duplicated in all platforms
/release //Release build - duplicated in all platforms
/linux_i386 //Linux 32-bit platform
/macosx //Mac OS X
/win32 //Windows 32-bit platform
/cygwin //Windows 32-bit platform compiled with Cygwin
/vs.net //Windows 32-bit platform compiled with Visual Studio .NET
/win64 //Windows 64-bit platform

/build //Make and build files, IDE project files
/linux_amd64 //Linux AMD64 platform
/linux_i386 //Linux 32-bit platform
/macosx //Mac OS X
/win32 //Windows 32-bit platform
/win64 //Windows 64-bit platform

/config //Configuration files that accompany the binaries

/data //Data files that accompany the binaries

/doc //Documentation

/lib //External or third-party libraries
/platforms //Platform-specific code for ...
/linux_amd64 //Linux AMD64 platform
/linux_i386 //Linux 32-bit platform
/macosx //Mac OS X
/win32 //Windows 32-bit platform
/win64 //Windows 64-bit platform
/src //Available library source code in subfolders

/src //Source code tree - this will contain main.cpp
/bindings //Bindings to other languages such as ...
/python
/java
/h //Header files
/modules //Platform-independent modules, components or subprojects
/platforms //Platform-specific code for ...
/linux_amd64 //Linux AMD64 platform-specific code
/linux_i386 //Linux 32-bit platform-specific code
/macosx
/win32 //Windows 32-bit platform-specific code
/win64 //Windows 64-bit platform

/test //Automated test scripts


I am planning on using CMake and Subversion.

Thursday, November 6, 2008

Quick and dirty connection to Oracle using ADO.NET

My C#.NET application needs to read from an Oracle database. There are many elaborate ways to connect to a database in .NET, including the Linq for Entities ORM. However, this was way too much for my purpose. I've found the following code to be much simpler. It's largely copied from a C# Station post. The key difference is that you have to use the OracleClient class.

First: Make sure that your project has a reference to System.Data.OracleClient


string connectionString = @"
SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP
(HOST=OracleHost)(PORT=OraclePort))
(CONNECT_DATA=(SERVICE_NAME=OracleServiceName)))
;uid=UserID;pwd=Password;";

OracleConnection conn = new
OracleConnection(connectionString);

OracleDataReader rdr = null;

try
{
// 2. Open the connection
conn.Open();

// 3. Pass the connection to a command object
OracleCommand cmd = new OracleCommand(
"select * from mytable", conn);

//
// 4. Use the connection
//

// get query results
rdr = cmd.ExecuteReader();

// print each record
while (rdr.Read())
{
for ( int i = 0;
i <rdr.FieldCount; i++)
Console.WriteLine(rdr[i]);
// Print each field
}

}
catch
{
throw;
}
finally
{
// close the reader
if (rdr != null)
{
rdr.Close();
}

// 5. Close the connection
if (conn != null)
{
conn.Close();
}
} // End of try-catch-finally


Thanks are also due to ConnectionStrings.com

Friday, September 19, 2008

Convert < and > to & lt; and & gt;

If you're trying to display HTML or XML tags on a web page, like in my previous post, most web publishing systems will swallow up the tags and the output will not be what you expect.

I came across this nice web converter that converts the < to & lt; and the > to & gt; allowing your content to remain unmangled.

How to encode double quotes and newlines inside a C# string

It turns out that this is not as easy as it seems. The syntax is kludgy. I found the answer on Gus Perez's blog

Imagine that you want this literal string in your C# code:
<GC xmlns:dt="urn:schemas-microsoft-com:datatypes">
<pInLotIDs x:dt="list">
<item dt:dt="string">108P091G-000</item>
</pInLotIDs>
</GC>


Then you have to code this in C# as:


string sInputData = @"
<GC xmlns:dt=""urn:schemas-microsoft-com:datatypes"">
<pInLotIDs CSIM:dt=""list"">
<item dt:dt=""string"">108P091G-000</item>
</pInLotIDs>
</GC>


Ugh!

Tuesday, September 16, 2008

ASP.NET tutorials

I have been learning ASP.NET using Visual Web Developer 2008 Express Edition. Along the way, I came across this structured set of ASP.NET tutorials at DotNetSpider. I want to give them a plug - although the tutorials could be polished some, they are very easy to follow and build up slowly on a good fundamental base. I am halfway through them right now.

I also like Visual Web Developer 2008 Express Edition - it is free to download, use and distribute applications.

My first blog post

I've really created this blog so that I can get an OpenID. This will allow me to log in to a promising new web site for programmers called StackOverflow. Check them out!