Dennis Bottjer | ASP.NET + SharePoint Architect, Trainer & Speaker

"An Ounce of Prevention is Worth a Pound of Cure" - Ben Franklin
posts - 168, comments - 59, trackbacks - 41

My Links

News

Add to Technorati Favorites The views expressed in this blog are mine and mine alone, not that of my employer, Microsoft, or anyone else’s. No warrantee is given for the quality of any material on this site.

Tag Cloud

Archives

Post Categories

Systems Integration: No Assumptions

There are many sayings about assumptions and I’ll let you fill in your favorite.  Regarding Systems Integration, the hard lesson I’ve learned is not to assume the other system will properly filter or handle a specific constraint.  For example, Windows systems use a carriage-return-line-feed to mark the end-of-a-line.  However, UNIX systems simply use a line-feed to mark the end-of-a-line.  This is not to say that UNIX systems can’t handle files containing CRLF’s.  It just means that most UNIX Systems just use an LF to mark the end-of-a-line.

 

When writing code to integrate a Windows based system and a UNIX based system that transfers data through a file based feed, noting and handling this simple end-of-line difference can save much time and yes stress.  Having a simple tool like NotePad2 in your arsenal is a great way to inspect your feed at various stages to ensure compatibility between the systems.

 

NotePad2 (http://www.flos-freeware.ch/notepad2.html) is a small, powerful replacement editor for “NotePad” which comes with Microsoft Windows.  This tool is worth a look especially for its ability to show hidden characters such as those marking the end-of-line.

 

To handle the case described above I would recommend implementing a simple scrubber that removes carriage returns (CR's) from the end of each line before sending the file to the UNIX System.  Here is an example scrubber:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System.IO;
using System.Text.RegularExpressions;

public class UnixStripperActivity
{
public static void SripCarriageReturn(string filePath)
{
string output;
FileStream fs = File.OpenRead(filePath);
StreamReader reader = new StreamReader(fs);
string input = reader.ReadToEnd();
reader.Close();
fs.Close();
output = Regex.Replace(input, @"\r", "", RegexOptions.Multiline);
FileStream fsw = File.OpenWrite(filePath);
StreamWriter sw = new StreamWriter(fsw);
sw.Write(output);
sw.Close();
fsw.Close();
}
}

 

Print | posted on Tuesday, October 31, 2006 2:51 AM | Filed Under [ Architecture System Integration ]

Feedback

Gravatar

# re: Systems Integration: No Assumptions

public static void nocr(string f)
{
string t;
using (StreamReader r = new StreamReader(f))
t = Regex.Replace(r.ReadToEnd(), "\r", "");
using (StreamWriter w = new StreamWriter(f))
w.Write(t);
}
10/31/2006 12:05 PM | royashbrook
Gravatar

# Systems Integration: No Assumptions

10/31/2006 3:52 AM | www.dotnetkicks.com
Gravatar

# replacing carriage return

10/31/2006 10:44 PM | drowningintechnicaldebt.com
Comments have been closed on this topic.

Powered by: