Feeds:
Posts
Comments

Welcome

Hi and welcome. This blog is the technical side of of a combined blog I used to keep called Life in the Trenches. I decided to go ahead and split out the content since they focus was lacking. Sure combining software development and MMORPGs is not unnatural; I know a lot of coders that are gamers, or is that a lot of gamers that are coders?

At any rate I’ll be transferring the ‘good’ posts from my old archive to get he ball rolling.

I ran into a video tutorial for learning JQuery over at ThemeForest.net
I’m one of the people they talked about; I know its out there, I know it uses css selectors, and I know that it does a lot to hide some of the javascript pain. So I’m finally checking it out in more detail. Even though my preferred area is web services and other business layer on down I do still have to do some gui work from time to time.

Alright; so I was working on a new project and I wanted to create a Windows Service that would host a WCF Service. The basic idea is that the Windows Service will use the WCF Service to do it’s heavy lifting on a schedule. The WCF Service will also be called from a management web site later on. In the past I’ve always wanted to reduce the amount of coding and configuration required to call one of these services.

So.. what did i come up with? The following lines create the service host in my Windows Service:

_wcfAsnService = new ServiceHost(typeof(Edi.Wcf.AsnService));
_wcfAsnService.AddServiceEndpoint(typeof(IAsnService), new NetTcpBinding(), Settings.Default.WcfAsnServer);
_wcfAsnService.Open();

The setting for that last parameter is defined as: net.tcp://localhost:8000

And I created this class to use for managing the life cycle of the client proxy:
using System;
using System.ServiceModel;
namespace EDI.AsnService

{
public class ServiceProxy : IDisposable
{

private readonly T _endPoint;
private readonly ICommunicationObject _proxy;

public ServiceProxy(string endPointAddress)

{
// Create a service client proxy
_endPoint = ChannelFactory.CreateChannel(new NetTcpBinding(), new EndpointAddress(endPointAddress));

// Create a CommunicationObject for state and end point closure
_proxy = _endPoint as ICommunicationObject;

}

public void Dispose()

{
// Close down the communication channel
if (_proxy != null)
_proxy.Close();
}

///
/// Returns the state object from the communication end point
///
public CommunicationState State
{
get { return _proxy.State; }
}

///

/// Returns the Endpoint where methods can be called

///

public T Client { get { return _endPoint; } }

}

}

Pretty simple. All you have to do is pass in the contract as the type and the proxy is created on the fly. Inside my method that executes the service client I have the following code to invoke the service:

using (ServiceProxy service = new ServiceProxy(Settings.Default.WcfAsnServer))
{

eventLog.WriteEntry(“Processing Start”);

eventLog.WriteEntry(service.Client.ExtractFromVisual().Message);

eventLog.WriteEntry(service.Client.UpdateGentran().Message);

eventLog.WriteEntry(“Processing Completed”);

}

The end result is that I don’t have to worry about configuring bindings in the config file. In fact the only thing I have in the config file in the endpoint address and port. I think this is much lighter weight and reduces some of the problems I’ve run into in the past with updating service references and duplication of the bindings in the config file.

If you are like me you tend to download a lot of software from the net. Open Source, Demos, Free/Share ware and the list goes on. I happened onto a little gem that is starting to make my life easier.
Here is the problem:
I write software for a living.. period. One of the hardest things is trying to come up with a solid user interface with your clients. Sure I’ve used things like Visio and PowerPoint in the past with decent results. There is a tendency with some clients to not make the logical leap that it takes time to actually implement the screen design. What they see is rapid layout and assume thats as hard as it gets.
Enter Balsamiq Mockups. How is this application any different? Well first off the mockups look like they are hand drawn; something you might come up with if you sat down with your client and grabbed a stack paper and a pen.

SilverLight Debugging

I was working through a tutorial for SilverLight over the weekend and things were going just fine until the debugger just didn’t seem to want to hit my break points. Oddly they were working fine but I did see on the net that some people had problems a while back with this. In those cases there is a check box added to the project properties where you select ASP.NET debugging that was getting turned off. For those the solution had been moved.. this is not the case for me of course so maybe there is another issue there someplace.
Has anyone run into this situation? I guess I can try the old standby of making a new project to see if it still fails to hit the break points or try not hosting in a web page.
Update: I found out that using a browser other then IE will cause this to happen. Sure enough.. after I reset IE as the default browser then the debugger hit my break points once again. The odd thing is it was working just fine for a while.. go figure.

Reading Excel Files

I’ve run into the problem a few times of needing to convert rows in an Excel file into an object for some kind of processing. I found an example that was pretty trim in what it was doing so I ended up using it as a model for a new template class.
 
The basic idea is that you create a new class and provide the overrides for converting a row into an object and after the main method returns you end up with a Collection where T is the type of Data Transfer Object (DTO) that your application can use.
 
One more modification that I’m planning on adding is to stream the DTOs to a method instead of returning a collection. Calling a processor will allow for a large number of rows to be processed without storing the DTOs in a collection and thus not incurring the memory overhead.
 
Here is the code so far: [more]
 
1:using System;
2:using System.Collections.ObjectModel;
3:using System.Data.OleDb;
4:using System.IO;
5: 
6:namespace SomeNameSpace
7: {
8:publicclass DigestExcel
9: {
10:///
11:/// True if exceptions should be thrown during processing
12:///
13:publicbool ThrowExceptions { get; set; }
14: 
15:///
16:/// Output StringToWrite to a log
17:///
18:/// A string to be written to a log
19:protectedvirtualvoid WriteLogFileEntry(string StringToWrite)
20: {
21:// This method should be implemented if logging is desired
22: }
23: 
24:///
25:/// Convert a row to a DTO
26:///
27:/// The DataReader to build DTOs from
28:/// A new DTO object
29:protectedvirtual T ParseDataRow(OleDbDataReader DataReader)
30: {
31:// This method should be implemented
32:thrownew NotImplementedException(“You must implement ParseDataRow”);
33: }
34: 
35:///
36:/// Reads each row of an Excel file sheet and returns a collection of DTOs
37:///
38:/// The fully qualified path to the exxcell file
39:/// The sheet/tab name to be processed
40:/// A collection of T objects
41:public Collection ProcessExcelFile(string FileName, string SheetName)
42: {
43: Collection objectList = new Collection();
44: 
45: OleDbConnection conn = new OleDbConnection();
46:try
47: {
48: WriteLogFileEntry(String.Format(“Opening File: {0}”, FileName));
49: 
50:// Make sure the file exists first
51:if( File.Exists( FileName ) == false )
52: {
53:thrownew FileNotFoundException(String.Format(” Unable to locate requested file, aborting: {0}”, FileName));
54: }
55: 
56: conn = new OleDbConnection(“Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + FileName + “;Extended Properties=\”Excel 8.0;\”");
57: conn.Open();
58: 
59: OleDbCommand cmd = new OleDbCommand(String.Format(“SELECT * FROM [{0}$]“, SheetName), conn);
60: 
61: OleDbDataReader dataReader = cmd.ExecuteReader();
62: 
63:int rowCounter = 0;
64:while (dataReader.Read())
65: {
66:// Advance the row number for logging
67: ++rowCounter;
68: 
69: WriteLogFileEntry(String.Format(” Processing data row {0}”, rowCounter));
70: 
71:try
72: {
73:// Add the next row to the collection
74: objectList.Add(ParseDataRow(dataReader));
75: }
76:catch(Exception up)
77: {
78:string exceptionMessage = String.Format(” Exception processing row {0}: {1}”, rowCounter, up.Message);
79: 
80:// If we throw exceptions up then the outer catch will describe the exception so we wont log it here
81:if( ThrowExceptions )
82: {
83:thrownew ApplicationException(exceptionMessage, up);
84: }
85: 
86:// If there is an exception then log it
87: WriteLogFileEntry(exceptionMessage);
88: }
89: }
90: }
91:catch(Exception up)
92: {
93:string exceptionMessage = String.Format(” Exception processing file {0}: {1}”, FileName, up.Message);
94: 
95:// If there is an exception then log it
96: WriteLogFileEntry(exceptionMessage);
97: 
98:if (ThrowExceptions)
99: {
100:thrownew ApplicationException(exceptionMessage, up);
101: }
102: }
103:finally
104: {
105: conn.Close();
106: WriteLogFileEntry(” Processing file completed”);
107: }
108: 
109:return objectList;
110: }
111: }
112: }
In order to use the template you can define a new class and inherit from the DigestExcel class like this:
1:publicclass DigestSample : DigestExcel
2: {
3:protectedoverridevoid WriteLogFileEntry(string StringToWrite)
4: {
5: Console.WriteLine(StringToWrite);
6: }
7: 
8:protectedoverride SampleDTO ParseDataRow(System.Data.OleDb.OleDbDataReader DataReader)
9: {
10: SampleDTO newRow = new SampleDTO();
11: 
12: newRow.Value1 = DataReader[0].ToString().Trim();
13: newRow.Value2 = DataReader[1].ToString().Trim();
14: 
15:return newRow;
16: }
17: }

Hi and welcome. This blog is the technical side of of a combined blog I used to keep called Life in the Trenches. I decided to go ahead and split out the content since they focus was lacking. Sure combining software development and MMORPGs is not unnatural; I know a lot of coders that are gamers, or is that a lot of gamers that are coders?

At any rate I’ll be transferring the ‘good’ posts from my old archive to get he ball rolling.

Follow

Get every new post delivered to your Inbox.