DCSIMG

 Subscribe in a reader

March 2008 - Posts - Guy kolbis

March 2008 - Posts

Hi,

Here is a little sample on how to merge two lists into a single list using Linq To Objects.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        class Person
        {
            public int Id { get; set; }
            public string Name { get; set; }
        }

        static void Main(string[] args)
        {
            List<Person> list = new List<Person>();
            
            for (int i = 0; i < 10000; i++)
            {
                list.Add(new Person { Id = i, Name = "guy" + i.ToString() });
            }

            List<Person> list2 = new List<Person>();

            for (int i = 5000; i < 10000; i++)
            {
                list2.Add(new Person { Id = i, Name = "guy" + i.ToString() });
            }

            var q = from first in list
                    join second in list2
                    on first.Id equals second.Id
                    select first;

            Console.WriteLine("Total: ", q.Count());

            foreach (var item in q)
            {
                Console.WriteLine("Id: {0} ; Name: {1}.", item.Id, item.Name);
            }
        }
    }
}

I have updated the meeting information for the up coming Tech Ed.

image 

If you want to talk about:

  1. Performance.
  2. Design & Architecture.
  3. Configuration Management.
  4. Team System.

Than harry up and set a meeting.

Here is an example of how to create a message inspector that will inspect every message that the client sends and modify the message body:

public class ClientOutputMessageInspector : IClientMessageInspector
{
    #region IClientMessageInspector Members

    public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
    {
        return;
    }

    public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
    {
        string action = request.Headers.GetHeader<string>("Action", request.Headers[0].Namespace);

        if (action.Contains("SendMessage"))
        {
            XmlDocument doc = new XmlDocument();
            MemoryStream ms = new MemoryStream();
            XmlWriter writer = XmlWriter.Create(ms);
            request.WriteMessage(writer);
            writer.Flush();
            ms.Position = 0;

            doc.Load(ms);
            ChangeMessage(doc);
            ms.SetLength(0);
            writer = XmlWriter.Create(ms);
            doc.WriteTo(writer);
            writer.Flush();
            ms.Position = 0;

            XmlReader reader = XmlReader.Create(ms);
            request = Message.CreateMessage(reader, int.MaxValue, request.Version);
        }
        return null;
    }

    void ChangeMessage(XmlDocument doc)
    {
        XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);
        nsManager.AddNamespace("s", "http://schemas.xmlsoap.org/soap/envelope/");
        nsManager.AddNamespace("tempuri", "http://tempuri.org/");
        XmlNode node = doc.SelectSingleNode("//s:Body/tempuriendMessage/tempuri:text", nsManager);

        if (node != null)
        {
            XmlText text = node.FirstChild as XmlText;

            if (text != null)
            {
                text.Value = "Modified: " + text.Value;
            }
        }
    }

    #endregion
}

kolbis כתב בתאריך Tuesday, March 18, 2008 10:36 PM
תגים:

I have created a Data-Driven Unit Test using Visual Studio Team System 2008 and bounded it to an SQL data source. When I executed the unit test for each row in the data source I got this strange result:

bug

In the data source I got only three records.

So, on one hand, as we can see in the lower square,  it displays a message that all four tests passed (4??? wasn't 3?). On the upper square it displays a message the all three tests passed (this is correct).

This is great!

if you will be at Tech Ed, you can set a meeting and talk face to face with any lecture you wish (as long as there is time).

You can meet with me as well. All you need to do is sign in and select "Guy Kolbis" at the Participants list.

Here is a link to the face2face meeting scheduler:

http://www.face2facemeeting.com/teched/

See you there!

This is an error message I got when I extended WCF with a client inspector.

The lifetime of a message only lasts for one use. Once you've looked at the contents of a message, or copied the contents somewhere, you can't read the message again.

This is a common problem encountered when people are trying to write a message inspector. Since you're expected to pass the message along after you're done inspecting it, it's quite likely that you'll need to make a new copy of the message. If you don't make a copy of the message, then the next person will have nothing to read.

This means that your message inspector code should look something like this:

public void BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel)
{
MessageBuffer buffer = request.CreateBufferedCopy(int.MaxValue);

// Do something with the copied message reply = buffer.CreateMessage(); buffer.Close(); }

Hi all,

As I mentioned before, I will give a session in the upcoming Tech Ed.

sign_come2 

The name for my lecture is "Performance Driven Development".

By 2010 Performance-Driven Development will be widespread and half the organizations that today do little more than load testing will have adopted performance-driven development practices.

In this session I will give you the tools you need to improve your design, your code and your tests by adopting the Performance-Driven Development practices.

I will give a cool Demo! We will build an application using WCF (Extensibility) and Team System Tools for Developers and Testers.

I hope to see you there!

DocProject is an open source help authoring tool (HAT) that consists of Visual Studio Project Templates, an Add-In and an API that provide an extensible platform for authoring, managing and building compiled help in various formats.


The latest version of Microsoft Sandcastle is used to generate HTML help topics for conceptual documentation and auto-generated reference documentation for managed assemblies in various presentation styles, such as one that looks like the documentation for Visual Studio and the Microsoft .NET Framework. DocProject also automates HTML Help compilers to produce Help 1.x (.chm) and Help 2.x (.HxS) output in a single build.

Using DocProject, help authors and developers can build documentation easily, both inside and outside of Visual Studio 2005, 2008, Visual C# Express, Visual Basic.NET Express, on the command-line using MSBuild, on a build server such as Team Build, or in the DocProject External UI program.

DocProjectInVS2005

For more information and download see this link.

When presenting we must set both our laptop and Visual Studio environment.

Daniel Moth wrote two really nice posts describing how to do just that:

Setting your laptop:

http://www.danielmoth.com/Blog/2008/02/10-tips-on-how-to-setup-your-laptop.html

Setting your Visual Studio environment:

http://www.danielmoth.com/Blog/2008/03/abcdefghi-of-setting-up-visual-studio.html

A really cool tool that was released by Microsoft enables you to take a WCF trace file and a WCF client proxy, or a WCF interface contract, and generates a unit test that replays the same sequence of calls found in the trace file. The code generated is easily modifiable so that data variation can be introduced for the purpose of doing performance testing.
The tool generates code for both Visual Studio 2005 and Visual Studio 2008.

Microsoft_logo 

You can download the tool or the source code from here.

kolbis כתב בתאריך Saturday, March 08, 2008 2:42 PM
תגים:,

How do you load test you WCF service?

Basically, in order to load test any API capable functionality in Visual Studio Team System, you will need to use a Unit Test template.

This is a bit confusing. A Unit Test is by definition: "Testing a Unit".

In fact there are many other strategies for functional testing, and most “unit tests” written today are not true Unit tests (with a capital U) that isolate and only test a single class, but test from the API down.

When we use a unit test to load test the WCF service, we kind of getting out of scope. A Unit Test that tests a WCF service, or a client API that hits a server, are really functional tests.

Never the less, we need to create a Unit Test in order to Load Test out service and add the service reference. For more info on how to Load Test services see this link.

kolbis כתב בתאריך Saturday, March 08, 2008 2:38 PM
תגים:,

 

Capacity testing is basically trying to break our application.

So, how do we break it?

Take the load formula and multiply it by a factor. For example if the load includes invoking 100 requests/sec, try interactively to multiply it by a constant (1,2,3…) factor starting with 2 and continue while you did not reach your capacity.

Run the test and wait for failed requests.

§ TIP: Set the test for run duration of at least 30 minutes.

If a request fails, check what the critical resource that caused it is.

§ TIP: A capacity can be caused by system resources or application related reasons. Usually it is caused by a certain system resource, such as Memory, Disk, CPU or Network. By indicating the resources that caused the capacity, we can recommend how to increase the capacity.

§ Generally speaking a failed request is a request that returns with an error code higher than 400.

§ TIP: In case you want to create a capacity for the current IIS configuration any request failure will result a capacity.

§ TIP: In case you want to create a capacity and ignore the current IIS configurations, insure that the failures are not resulted by those configurations such as connection limit or maximum queue length. The type of failure returns with the error code. So a 503 error code means that the server is unavailable. This could be because the server crushed or because the IIS is configure for small amount of connections.

If no requests fail, increase the stress factor and do so until reaching capacity.

kick it on DotNetKicks.com

I have encountered a strange bug while using Visual Studio Team System 2008 Load Test.

I configured a load test and executed it. Here is the test run result:

for_guy

As you can see, I have selected to monitor the Bytes Total/Sec performance counter during the load test execution. The strange thing about it is the following result:

44 

As you can see,the Min value is 1,826,176 bytes total/sec and the max value is 3,506,534 bytes total/sec, however the average is 81,056. This must be wrong!!!

Teched is right around the corner and everywhere I go, I hear people talk about it. This year Teched will be Bigger, Better and luckily I will be there!!!

There are a lot of great tracks this year for you guys to choose from. I will be lecturing on the "Application Life Cycle Management" track.

This is a continues from the session I gave at the Developer Academy 2. In that session I talked about the tools and gave some tips and tricks for improving your application performance. I went over the Profiler, Unit Testing framework, web testing and load testing.

The session I will give at Teched will be about methodology and bringing it to practice. Its title is: "Performance Driven Development (PDD)".

I am trying to build something really nice for you guys. Beside talking about the methodology behind the concept of PDD, I will build a complete WCF application with some nice features in it based on PDD.

I hope to see you all!