The mysteries of software development and networking... RSS 2.0



 Friday, March 10, 2006

Beth Massi has an interesting post about the performance of DataSets when using Binary Serialization.

Read more: http://bethmassi.blogspot.com/2006/01/binary-serialization-of-datasets-in.html

Friday, March 10, 2006 2:30:57 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
C#

I'm working on a WinForm 2.0 window on which I have a DataGridView.

The DataGridView is connected to an ObjectDataSource and the datasource of this ObjectDataSource is pointing to an array of items.

This works nicely, however, the user can use a popup to add an entry to the array. The DataGridView will not automatically detect that the underlying array has changed.

Solution: Call BindingSource.ResetBindings(..) after updating the array. This will raise an event which makes the DataGridView redraw itself.

Friday, March 10, 2006 10:01:38 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
C# | General
 Wednesday, March 08, 2006

Microsoft Live Search is the new search engine from Microsoft. Will it be able to nibble at google's marketshare?

We'll see. Go to: http://search.live.com

 

:-)

 

Wednesday, March 08, 2006 5:25:06 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General | Vista
 Monday, March 06, 2006

With WPF we are far more flexible in creating UI solutions since now almost every control can contain other controls.

The classic example being ofcourse the button.
A button cannot just have a text on the surface of the button, it can just as easily have an image.

Example of button with text.

<Button Name="button1">Just text</Button>

Example of button with image.

<Button Name="button1">
 <Image Source="C:\Documents and Settings\Mark\Desktop\banner.jpg" Name="image1" Width="100"/>
</Button>

Now a lot of buttons will have an image and also some text.
With our HTML background we'll probably attempt:

<Button Name="button1">
 Just text<br/>
 <Image Source="C:\Documents and Settings\Mark\Desktop\banner.jpg" Name="image1" Width="100"/>
</Button>

Wrong! A button can contain controls, but has no 'knowledge' of how to produce a layout for multiple controls.
WPF has special controls that provide layout implementation. These are panels. There are four kinds of panels:
- DockPanel
- StackPanel
- Grid
- Canvas

The same is actually true of the Window control. A Window has no 'default' knowledge of layout. VS2005 will by
default add a 'Grid' control as the root panel.

A StackPanel is easiest to use. It will stack items either horizontally or vertically.
In our button example we would want to use the StackPanel as the child of our Button.

<Button Name="button1">
  <StackPanel Orientation="Vertical">
    <TextBlock>Just text</TextBlock>
    <Image Source="C:\Documents and Settings\Mark\Desktop\banner.jpg" Name="image1" Width="100"/>
  </StackPanel>
</Button>

Notice that we don't need the <BR> tag anymore.
The linefeed is really layout information and our StackPanel is in charge of layouting the content.
If however we have a lot of text, then we could put a newline within the TextBlock.

<Button Name="button1">
  <StackPanel Orientation="Vertical">
    <TextBlock>
      Just text
      <LineBreak/>
      The next line
    </TextBlock>
    <Image Source="C:\Documents and Settings\Mark\Desktop\banner.jpg" Name="image1" Width="100"/>
  </StackPanel>
</Button>

A Grid offers more options and acts much more like a table with rows and columns. I'll show a quick example:

<Grid ShowGridLines="True">
  <Grid.ColumnDefinitions>
    <ColumnDefinition/>
    <ColumnDefinition/>
    <ColumnDefinition/>
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
    <RowDefinition/>
    <RowDefinition/>
    <RowDefinition/>
  </Grid.RowDefinitions>
  <TextBlock Grid.Column="0" Grid.Row="0">Top left</TextBlock>
  <TextBlock Grid.Column="1" Grid.Row="1">Middle</TextBlock>
  <TextBlock Grid.Column="2" Grid.Row="2">Bottom right</TextBlock>
  <Image Source="C:\Documents and Settings\Mark\Desktop\banner.jpg" Name="image1"
      Width="50" Grid.Column="1" Grid.Row="0"/>
</Grid>

As you can see the content of an actual cell is not placed in the cell, but instead the content is listed below the column and row definitions. I must say that I'm still getting used to this notation.

The DockPanel allows you to dock content to a border of the window.
The Canvas panel performs no layout functionality, you're in charge of all layout matters. Much the way 'regular' WinForms let you do all the layouting.

 

Monday, March 06, 2006 8:51:07 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
WPF
 Sunday, March 05, 2006

WPF introduces EventBubbling. People who have done scripting in Internet Explorer will find this very familiar. The concept is that an eventhandler may not be implemented on a GUI-control, but can also be implemented on the parent of that GUI-control. When an event is fired it will traverse the tree from child to parent to parent to parent until it reaches the top control, usually the window.

Let's look at a demo.

Below is the XAML file for Window1.

<Window x:Class="Demo3.EventHandling.Window1"
    xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
    xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
    Title="Demo3.EventHandling"
    >
    <Grid>
    <Button VerticalAlignment="Stretch" Click="button1_Click"
            HorizontalAlignment="Stretch" Grid.Column="0" Grid.ColumnSpan="1"
            Grid.Row="0" Grid.RowSpan="1" Margin="80,85,77,121"
            Width="NaN" Height="NaN" Name="button1">
      <StackPanel Orientation="Vertical">
        <Image Source="C:\Documents and Settings\Mark\Desktop\banner.jpg" Name="image1"/>
        <TextBox Name="textbox1" Text="Type your name here!" Height="20" Width="333" />
        <Button Name="innerButton" Click="innerButton_Click">Press me!</Button>
      </StackPanel>
    </Button>
  </Grid>
</Window>

Here is the code.

void button1_Click(object sender, RoutedEventArgs e)
{
    MessageBox.Show("Hello " + this.textbox1.Text);
    Button source = e.OriginalSource as Button;
    if (source != null)
    {
        MessageBox.Show("The original source is: " + source.Name);
    }
}

void innerButton_Click(object sender, RoutedEventArgs e)
{
    MessageBox.Show("Hello SDN!");
}

This will look like:


Just click on the various controls. Notice that controls that do not have a 'Click' event do not participate in the routing, but may still pass the event on.

In WPF this concept is called event routing. You can halt the routing of an event by setting

e.Halted = true;

 

 

Sunday, March 05, 2006 4:37:49 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
WPF

In the System.Windows namespace there is an 'Application' object. Your application should make use of this class since it allows for lifetime tracking through events like StartUp and SessionEnding and methods like Run.

We can expand our hello world to:

using System;
using System.Windows;


namespace HelloWorld
{
    public class MyApp : Application
    {
        [STAThread]
        static void Main(string[] args)
        {
            MyApp app = new MyApp();
            app.Startup += app.OnApplicationStart;
            app.Run(args);
        }


        void OnApplicationStart(object sender, StartupEventArgs e)
        {
            Window w = new Window();
            w.Title = "Mark says: Hello World!";
            w.Show();
        }
    }
}

With a little bit of digging around you can find the code that Visual Studio uses for initializing the application:


public partial class MyApp : System.Windows.Application
{
    /// <summary>
    /// InitializeComponent
    /// </summary>
    public void InitializeComponent()
    {
        this.StartupUri = new System.Uri("Window1.xaml", System.UriKind.Relative);
        System.Uri resourceLocater = new System.Uri("myapp.baml", System.UriKind.RelativeOrAbsolute);
        System.Windows.Application.LoadComponent(this, resourceLocater);
    }



    /// <summary>
    /// Application Entry Point.
    /// </summary>
    [System.STAThreadAttribute()]
    public static int Main(string[] args)
    {
        System.Threading.Thread.CurrentThread.SetApartmentState(System.Threading.ApartmentState.STA);
        MyApp app = new MyApp();
        app.InitializeComponent();
        return app.Run(args);
    }
}

As you can see some resources are initialized in the InitializeComponent. By default the VS2005 WinFx project sets up some resources, you find them under the 'Properties' folder. Also an URI is set to track the initial window. This URI is the window that will be started when app.Run(..) is executed.

 

Sunday, March 05, 2006 3:40:50 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
WPF

Time to continue with WPF.

You don't need to use XAML to program WPF. Quite the contrary. Everything you can do with XAML you can do with C#. It's just a matter of using the right tool for the right job. It doesn't make much sense to do all the layout code in C#, XAML will hopefully do a better job there. Anyway, just to prove the point I have to start where every new technology starts: Hello World!

I've installed all the necessary tools. I've started VS2005 and created a new WinFx application.
The application by default holds references to all relevant assemblies, these being:
- PresentationCode
- PresentationFramework
- ReachFramework
- UIAutomationProvider
- UIAutomationTypes
- WindowsBase

The names of these assemblies don't look very RTM-like, so I have to assume they'll change in one of the upcoming CTP's or RTM.

I like to start as clean as possible, so I throw out all the stuff under the properties folder and also the default created MyApp.xaml and Class1.xaml.

Now add a new class called HelloWorld:


using System;
using System.Windows;  //This is the WPF namespace

namespace HelloWorld
{
    public class HelloWorld
    {
        [STAThread]
        public static void Main()
        {
            // This is the System.Windows.MessageBox
            MessageBox.Show("Hello SDN!");           
        }

    }
}

Startup the application and go!

Sunday, March 05, 2006 3:16:26 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
WPF
 Saturday, March 04, 2006

An interesting thread is going on at Ted's blog: http://blogs.tedneward.com/Trackback.aspx?guid=5f213ccd-5acb-4c81-9ec3-23b20db68447. I've put my 2 cents in, so read the comments.

Saturday, March 04, 2006 9:07:46 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General
 Thursday, March 02, 2006

Mike Henderlight blogs that the "Crossbow"-technology will actually be part of WPF.

"We have spent the last several months working very hard on developing and executing on a plan where we could deliver the Crossbow runtime as an integral part of WPF.  As of the Beta2 release of WPF, the Crossbow runtime will be part of the WPF redist and reside in the GAC just like all of the other WPF components.  And from that point forward we will be on the WPF ship schedule which means that we will RTM with WPF."

This is great! The Crossbow-technology has been created by a seperate team within Microsoft, but I'm sure when WPF hits the streets most developers will assume this to be a very "oh yeah, there is interop with WinForms, what's new" kind of feature. You know? One that everyone expects to be there, but is really very very cool.

Thursday, March 02, 2006 1:45:24 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
WPF
 Wednesday, March 01, 2006
Wednesday, March 01, 2006 8:43:08 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Vista
Just installed Messenger Live Beta.
 
Looks okay, not too much new stuff here, except the 'Call' button next to a contact. Will MSN Messenger move into the VOIP space? A quick Google action results in:
 
"The phone function (result of a partnership between Microsoft and communications firm MCI) will be known as MCI web Calling for Windows Live Call and will allows subscribe to make pc to telephone calls at competitive rates."
 
It'll be interesting to see if Messenger can catch up with Skype. I had a video-phone call from the States to the Netherlands yesterday and the quality of Skype for voice and video are both higher than MSN Messenger.
I'll have to try Messenger Live to see if it has improved.
 
Contacts Live is also coming. This appears to be a similar service to Plaxo (www.plaxo.com). I don't have a MSN or Hotmail account so sadly I can't test it with my current passport.
 
 
 
Wednesday, March 01, 2006 8:31:19 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General
 Tuesday, February 28, 2006

There will be a session about Windows Workflow Foundation (WWF) by Marcel de Vries on the upcoming Software Developer Event. Just to get a headstart have a look at this article by Dino Espito: http://msdn.microsoft.com/windowsvista/building/workflow/default.aspx?pull=/library/en-us/dnlong/html/wfgetstart.asp

Tuesday, February 28, 2006 7:32:29 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
WF
 Monday, February 27, 2006

Last december I did a presentation on using Visual Studio Tools for Office 2005 to develop Outlook add-ins. I just received an email from my friend Lucas with a bunch of more recent links on this topic.

Here it is:

Extending Enterprise Applications with Microsoft Outlook: Architectural Design Guide

Summary: Provides an architectural design and sample code that demonstrates an approach for integrating enterprise CRM and other LOB application data into the Microsoft Outlook user interface. (20 printed pages)

http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnbda/html/OtlkLOBCRM.asp

Synchronizing a Local Data Store with Microsoft OutlookSynchronizing a Local Data Store with Microsoft Outlook

Summary: Utilize a SQL Express database as a local data cache and the programmability of Microsoft Outlook to integrate enterprise CRM data within the Outlook user interface. (25 printed pages)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/OtlkLDSSynch.asp

Outlook Customization for Integrating with Enterprise Applications

Summary: Improve the availability of CRM data for information workers by creating a sample Outlook add-in and associated set of utility classes using Visual Studio Tools for Office that displays enterprise CRM data naturally within the Outlook user interface. (30 printed pages)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/OtlkCustInEntApp.asp

Sample

Microsoft has developed a sample Outlook add-in solution that demonstrates how the Outlook UI can be extended and customized to create a front-end for a CRM system. For more information about the "CRM Integration Add-in Sample for Microsoft Outlook" see http://download.microsoft.com/download/9/9/C/99CD8598-2A46-48A8-9A5B-7A30D46C0856/CRM Integration Sample for Outlook Source Setup.msi.

 

Monday, February 27, 2006 1:14:14 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General
 Sunday, February 26, 2006
Sunday, February 26, 2006 7:14:02 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General
 Friday, February 24, 2006

I was coding a little tool to send our SDN newsletters and discovered the new SmtpMail stuff in .NET2.0. Now you don't need to code any stuff for setting your mailserver or credential. Just configure it!

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="mail.myserver.net"
          port="25" 
          userName="Mark"
          password="secret"/>
      </smtp>
    </mailSettings>
  </system.net>
</configuration>

Now just send the message using the new classes in System.Net.Mail:

System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Send( message );
Friday, February 24, 2006 2:30:45 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
C#
 Thursday, February 23, 2006

The February CTP build of the WinFX SDK and also the Orcas February CTP will both feature Crossbow.

Crossbow will allow you to use WPF functionality on existing Windows Forms.

Read more on: http://blogs.msdn.com/mhendersblog/archive/2006/02/01/522723.aspx

Update:

There is also an MSDN show on MSDNtv: http://msdn.microsoft.com/msdntv/episode.aspx?xml=episodes/en/20060216CrossbowMH/manifest.xml

Thursday, February 23, 2006 4:07:26 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
WPF

The February CTP is now available for download, also the WinFX release candidate is available on the same page:

http://msdn.microsoft.com/windowsvista/getthebeta/default.aspx

A list of breaking changes between this and the January CTP has been posted here:

http://windowscommunication.net/collateral/pages/BreakingChangesJanCTPToFebCTP.htm

Thursday, February 23, 2006 4:45:56 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General | Vista | WPF
 Tuesday, February 21, 2006

Today I had a discussion about coding guidelines and in particular about the size of a class, the number of methods in a class and the number of lines of code per class. What is right?

Ofcourse a little search on Google revealed millions of hits. Some of the more useful ones were:

Most standards don't say much about the size of a class, the number of methods in a class and the number of lines of code per class. The few that do say something come fairly close.

Here's the sum of guidelines that I think I'll stick by:

  1. A source file should only contain one class
  2. A method should be no more than 30 lines of code, excluding blank lines and comments
  3. A source file should contain no more than 1000 lines, including blanks and comments
  4. An interface should have no more than 10 methods, excluding overloads, ie. the combination of overloads counts as one methods
  5. C# 2.0 allows partial classes:
    • a source file should only contain one partial class
    • don't split the implementation of an interface across multiple files
    • for large classes split the implementation of interfaces and implement one interface per file
      • Filename:  <classname>.<interfacename>.cs
    • if you have a class which implements one interace, but has a lot of private methods, then create a partial class with just the private methods:
      • Filename: <classname>.private.cs

Ad 2.
This is the average I found and seems to make sense, since this means that with one look at the screen your brain can absorb the whole method.

Ad 3.
I'm not convinced this is a very important rule. Having 2000 lines of code in one file or spread across two classes in two files doesn't really make that big a difference to me. See also ad 5.

Ad 4.
This is mainly because of Intellisense. Ten methods will provide optimum use of Intellisense.

Ad 5.
Partial classes are great!

Tuesday, February 21, 2006 6:15:16 AM (Eastern Standard Time, UTC-05:00)  #    Comments [2] -
C# | General
 Monday, February 20, 2006


I'll be speaking at the Software Developer Conference 2006. The biggest software developer usergroup meeting in The Netherlands and probably Europe. Are you going? If not, why not?

Ten reasons for coming to SDC 2006:

- The schedule: 90+ sessions about software development, software development and more software development, and to sum it up: more software development.
- The speakers: the best of best, the cream of the crop from all over the world!
- The sessions: educational, in depth, fun and repeated so you don't have to miss any.
- The evenings: the monday nights at SDC are always great, for now still a suprise but it will be very amusing!
- The Internet Cafe: there will be Wi-Fi at the conference, but for those who don't have a laptop with them there will be the Internet Cafe.
- All-in price: the SDN is a no-nonsense usergroup, so no surprises and a crazy value for money conference. The registrationfee covers everything except for the bartab on Monday night.
- Supplier access: all important industry supplies will be present and available for questions.
- Goodiebag: with notebook, nice bag, extra's and extra's...
- Location: to be at Papendal for two days is a great environment to leave your work behind and submerge in the sessions and the wealth of knowledge which will be shared.
- Price: as a usergroup the SDN does not organize this conference for profit, but for you, the developer!

Want more information? Go to: www.sdc.nl

Ofcourse you're going! See you there!

Monday, February 20, 2006 9:55:37 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
General
 Saturday, February 11, 2006

So you're a developer and you want to get started with Windows Presentation Foundation (a.k.a.) Avalon?
Well here are the steps I took to play around with this new and hip technology:

  1. Create a fresh VirtualPC image with WindowsXP SP2. I read that you can also use Windows Server 2003 if you wish.
  2. Install Visual Studio 2005. I use Professional edition, but the beta's also work with the Visual Studio Express editions.
  3. Download the WinFX software developer kit at: http://msdn.microsoft.com/windowsvista/getthebeta/default.aspx 
    I've downloaded the WinFX RTC plus the VS2005 extensions.
    Note that if you want to install the VS2005 extensions you also need to download the Windows SDK beta.
    If you don't install the SDK the VS2005 extensions will show a message saying that you need to install the Windows SDK and then also make sure that you install the beta SDK, the regular SDK will not suffice!
    Feels like my WindowsXP machine is being turned into a Vista machine already :-)
  4. Install the WinFx RTC download. The installer will want to download another 16MB of data, so make sure your VirtualPC environment has Internet access.
  5. Install the Windows SDK beta.
  6. Install the VS2005 Extensions package.
  7. Install the VS2005 Extensions for Windows Workflow Foundation. These are obviously optional for playing around with the WPF beta, but since we're setting up a play area we might as well get it complete.

Done? Okay, time to test to see if all is well.

Make a little test XAML application, it ofcourse has to be:

a) Use notepad to create a file called 'test.xaml'
b) Copy code below into file.

<Page xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005">
   <TextBlock>Hello World!</TextBlock>
</Page>

c) Save
d) Double click the file.
e) Yeah! A real life XAML application.

I also tried placing this test file on my webserver ( http://www.develop-one.net/presentations/code/wfm/test.xaml ) but opening this URL results in a security exception. I'll look into that some more later. Probably still need to add this URL my Trusted sites.

 


 

Saturday, February 11, 2006 3:11:12 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
WPF
About
This blog is run by Mark Blomsma.
© Copyright 2008
Develop-One
Sign In
Statistics
Total Posts: 337
This Year: 81
This Month: 0
This Week: 1
Comments: 94
All Content © 2008, Develop-One
DasBlog theme 'Business' created by Christoph De Baene (delarou)