Archive of entries posted on October 2008

Atlanta’s .NET Users Group

We now have a new site for Atlanta area .NET users’ group.  The group’s focus is more broad than just .NET.  It actually focuses on all Microsoft development technologies.   Here is new address: http://www.atldotnet.org/default.aspx.  There is also an RSS feed on the new site so that you can stay current with what is going on at the users group.

Collaboration

I have been working with Anthony Handley on a WPF project for the last couple of weeks part time.  We are actually one of the first people I know that are trying to follow Microsoft idea on designer/developer collaboration for developing WPF applications.  The application itself looks great!  We are working through some growing pains as a team.  The most time consuming issue that I have seen so far is rebuilding a screen by removing controls that were used to convey the design to the user.  These controls contained fake data to make it mode clear to the user how the screen shows data.  I had to remove those controls and replaced them with controls that were actually supposed to be used.  This of course broke animations that were tied to old controls.  So far, I think the following is the best approach I came up with.  Here are a few key points.  Designer and developers should work in parallel.  Giving designers a head start does not seem like a good idea.  What is needed is probably a head start for developers instead to be able to create classes that can be populated with data.  That way we should be able to avoid faking the data, and use real classes instead.  This way a designer could create a first draft of a screen.  Then developer can put in data and appropriate controls.  Then a designer could put on finishing touches.  I will keep blogging as I learn my lessons of collaboration.  It has been a fun project nonetheless.

CoDe magazine article

I have been working on CSLA for Silverlight project with Rocky Lhotka, Justin Chase, Nermin Dibek, and Mark Steinberg for about three months.  I really enjoyed this challenging and interesting work.  It has been a great opportunity for me to work with the latest technologies and great, smart and super knowledgeable people.  About a month ago Rocky invited Justin and I to help write an article for CoDe magazine on CSLA for Silverlight.  As you can imagine,  both of us jumped at this opportunity.  As Justin just informed me, the article has been published!  I am super (and I mean SUPER) excited.  Read "Using CSLA .NET for Silverlight to Build Line-of-Business Applications" article online here.

Yeay, I am a published author!

Silverlight Error Code 4001 AG_E_NETWORK_ERROR

I encountered this error today, working on a custom Silverlight application.  According to Silverlight.Net this is not a bug.  However, I think it is an issue with Silverlight 2.0 RTW release.  Based on other posts the following situation causes this issue.  You have two images one next to another in your XAML that have the same image file name as source.  Image is actually displayed properly even with the error.  This is exactly what I have in my page.  Here is a workaround that I found.  I had to add the following code to the ASPX page that hosts Silverlight control.

<script type="text/javascript">
    function tellerror(msg, url, linenumber) {
        if (msg.toString().indexOf("Image") >= 0 && msg.toString().indexOf("4001") >= 0) {
            return true;
        }
        else {
            alert('Error message= ' + msg + '\nURL= ' + url + '\nLine Number= ' + linenumber)
            return true;
        }
    }

    window.onerror = tellerror;
</script>

How to draw bitmaps in code

So, I had a task to create a graph in code

Not an easy task at you can see.  It took me about 12 hours to get it done from scratch.  My class takes the following parameters: 4 values – one for each color and bitmap size (width and height).

Here are some code samples:

Create a bitmap

Bitmap returnValue = new Bitmap(width, height);

Draw axes:

private static void DrawAxes(Bitmap result)
    {
      Pen axesPen = new Pen(Color.Black, 1);
      Graphics worker = Graphics.FromImage(result);
      worker.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
      // draw diagonal axis lines
      worker.DrawLine(axesPen, GetTopLeftCorner(result), GetBottomRightCorner(result));

To draw red color polygon:

PointF[] coordinates = new PointF[] {
          GetRedCorner(result, red),
          redYellowIntersect,
          middle,
          greenRedIntersect};
worker.DrawLine(graphPen, redYellowIntersect, GetRedCorner(result, red));
worker.DrawLine(graphPen, greenRedIntersect, GetRedCorner(result, red));
worker.FillPolygon(redBrush, coordinates);

One fun part was to write a code to determine where two lines intersect.  Here is entire function:

/// <summary>
    /// Find a point at which two lines intersect
    /// </summary>
    /// <param name="line1">First line</param>
    /// <param name="line2">Second line</param>
    /// <param name="middle">Coordinates of the middle of the bitmap</param>
    /// <param name="intersectionType">Does this intersect cross x or y axis</param>
    /// <returns></returns>
    private static PointF LinesIntersect(Line line1, Line line2, PointF middle, IntersectType intersectionType)
    {
      PointF returnValue = new PointF();
      float a1, a2, b1, b2;
      if (line1.End.X == line1.Start.X)
        b1 = (line1.End.Y – line1.Start.Y);
      else
        b1 = (line1.End.Y – line1.Start.Y) / (line1.End.X – line1.Start.X);

      if (line2.End.X == line2.Start.X)
        b2 = (line2.End.Y – line2.Start.Y);
      else
        b2 = (line2.End.Y – line2.Start.Y) / (line2.End.X – line2.Start.X);

      a1 = line1.Start.Y – b1 * line1.Start.X;
      a2 = line2.Start.Y – b2 * line2.Start.X;
      returnValue.X = -(a1 – a2) / (b1 – b2);
      returnValue.Y = a1 + b1 * returnValue.X;

      switch (intersectionType)
      {
        case IntersectType.Horizontal:
          returnValue.Y = middle.Y;
          break;
        case IntersectType.Vertical:
          returnValue.X = middle.X;
          break;
        default:
          throw new Exception("Invalid type");

      }
      return returnValue;
    }

Here are internal classes used in it:

/// <summary>
    /// Definition for a line - start and end points
    /// </summary>
    private struct Line
    {
      public PointF Start;
      public PointF End;

      public Line(PointF start, PointF end)
      {
        Start = start;
        End = end;
      }
    }

    /// <summary>
    /// Type of intersection - does cross y or x axis
    /// </summary>
    private enum IntersectType
    {
      Horizontal,
      Vertical
    }

How to debug WCF service server side errors

So, here is the issue I encountered today.  I have a solution that is using WCF service to communicate.  My WCF service is hosted in a web site (web application project).  I was getting error from my client, stating that connection was forcibly closed by the server.  I could not figure out why even though I configured behavior to "includeExceptionDetailInFaults".  So, here is the solution that I found.

I added the following to web.config file to web site that hosts WCF service.

<system.diagnostics>
        <sources>
            <source name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
                <listeners>
                    <add name="traceListener"
                        type="System.Diagnostics.XmlWriterTraceListener"
                        initializeData= "c:\Traces.svclog" />
                </listeners>
            </source>
        </sources>
    </system.diagnostics>

Voila.  I ran the process again, double-clicked on trace log that opened in a viewer.  I was informed that I forgot to add Serializable attribute to my class I was sending across the wire.

What an easy solution!  What a greate WCF feature as well – you can debug service even in production without changing code – just change configuration file.  The same trick works in Windows hosted WCF services – just add the same stuff to app.config.