• Using Silverlight initParams with ASP.NET MVC

    I looked around and couldn't really find a clean way to add init params to the view of my mvc silverlight host aspx file. Here's what i ended up doing... just wanted to blog it so that i didn't forget it :)


    <asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <script src="../../Silverlight.js" type="text/javascript"></script>
        <object height="100%" width="100%" data="data:application/x-silverlight-2," type="application/x-silverlight-2" >
     <param name="source" value="../ClientBin/PalladiumEngine.xap"/>
     <param name="onError" value="onSilverlightError" />
     <param name="background" value="white" />
     <param name="EnableGPUAcceleration" value="true" />
     <%=ViewData["InitParams"] %>
     <param name="minRuntimeVersion" value="3.0.40624.0" />
     <param name="autoUpgrade" value="true" />
     <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
       <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
     </a>
       </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>
    </asp:Content>


    then my Controller action code looked like this:

      public ActionResult Index()
            {
                string port = WebConfigurationManager.AppSettings["PORT"];
                if(string.IsNullOrEmpty(port))
                    throw new ApplicationException("Put a PORT value into the web.config please!");
                ViewData["InitParams"] = string.Format("<param name=\"initParams\" value=\"Port={0}\" />",port);
                ActionResult retval = View();
                return View();
            }

    then my silverlight code using it looked like this:
         private void Application_Startup(object sender, StartupEventArgs e)
            {
                int port = int.Parse(e.InitParams["Port"]);
                Client = new MessageClient<SocketMessage>(port, Serializer);
                Client.ConnectCompleted += OnConnected;
                Client.MessageRecieved += new EventHandler<MessageRecievedEventArgs<SocketMessage>>(client_MessageRecieved);
                Client.ConnectAsync();

                RootVisual = MainPage;
                MainPage.LayoutRoot.Children.Clear();
                MainPage.LayoutRoot.Children.Add(LoginPage);
            }


    I was using it to pass the port into silverlight from my web.config. For security reasons be sure you don't do this with user specified content!

    Full story

    Comments (1)

  • Sockets Light rules for silverlight sockets

    http://socketslight.codeplex.com/

    If you're trying to do server push to silverlight clients this is the scalable and flexible way to go. The polling http sucks compared to this.

     

    I need not say more.

    Full story

    Comments (0)

  • Beginning C# through Test Driven Development

    So this is how this idea began...

    twitter

     

    I figured that, in the interest of bettering those who surround me and those who follow this blog, I would begin at the very start. Just like we all learned c#, let’s learn c# from scratch as if it’s brand new but using Test Driven Development.

     

    So this is my first in potentially a series… “Beginning C# through Test Driven Development”.

     

    So what is an Object?

     

    Objects are a collection of information and functionality. In other words, they are state and behavior, respectively. Every object has some type of data that we wish to manipulate and get some other type of data back out of it. Every object is a black box to which we put something in it, tell it to do something, and then usually get something back out.

    Let's start with the basics of why we use objects.

    What is inheritance?

     Inheritance is taking an Object that someone has already defined and adding more functionality to it. The idea is that you already have something doing most of what you want to do, but you just need to add a little bit more to it. You take what already exists and inherit it, then apply new things to it so you do not have to copy and paste that functionality.

     

    What are Combination, Aggregation, and Containment?

     

    When you have an object that uses or ‘contains’ other objects inside of it, this is thought of as Aggregation or Containment.

     

    Inheritance is often known as the “IS A” relationship. A dog is a mammal. A mammal is an animal.

     

    Combination is often known as the “HAS A” relationship. A dog has a leg. A leg has a foot. A foot has a toe.

     

    Lesson 1: Hello world in TDD

     

    First, we will need to create a C# Class Library project.

    twitter

     

    In .net a dll or exe is called an Assembly. A class library project creates a dll assembly. We are choosing to use a dll assembly because our unit test framework will require a dll and cannot execute tests from an exe file.

     

    Now that you have a dll, we will have to add references to a unit testing library. I have chosen MbUnit as the unit testing framework/library. 

     

    You will need to go download MbUnit and install it. Or you can download Nunit and install that.

     

    Ok now that you have a unit test framework, go back to visual studio and expand your class library project in the solution explorer.

    twitter

     

    Right click on “References” and choose “Add reference…”

    twitter

    Choose the MbUnit.Framework (Or NUnit.Framework) and hit ‘Ok”.

    twitter

     

    You have just added MbUnit.Framework.dll as an assembly reference. This allows your dll to use functionality from that dll.

     

    Now you have code that looks like this:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text

    namespace HelloWorld

    {

        public class Class1

        {

        }

    }

     

    Frankly, the class name is not appropriate and we do not need those using statements (that visual studio automatically adds for you).

     

    We will first rename the class by right clicking “Class1.cs”in the solution explorer and choosing rename:

    twitter

     

    I renamed it to “HelloWorld.cs” and allowed visual studio to change the name of the class as well. Then I removed the using statements. My code looks like this:

    namespace HelloWorld

    {

        public class HelloWorld

        {

        }

    }

     

    Now we are going to add what is called an attribute to our class. An attribute basically just adds description to your class. For now just follow along but you can research more on attributes separately if you desire.

     

    Your code should now appear like this: (or use NUnit.Framework)

     

    using MbUnit.Framework;

     namespace HelloWorld

    {

        [TestFixture]

        public class HelloWorld

        {

        }

    }

     

    A test fixture is a class that represents a set of tests around a particular area of functionality. I believe the term fixture comes from electrical engineering where they would place circuits and a test on a fixture.

     

    So let’s put our test in this fixture. We’ll add a method and give it a “Test” attribute. Methods are behavior or functionality. They can be called from other places in the program to execute a task or some behavior. Ours will start out with nothing in it.

     

    Here’s how it should look:

    using MbUnit.Framework;

     

    namespace HelloWorld

    {

        [TestFixture]

        public class HelloWorld

        {

            [Test]

            public void HelloWorldTest()

            {

     

            }

        }

    }

     

    Go ahead and Build the project by going to the build menu:(or shift + F6) (or F6 to build the whole solution, which happens to be our 1project right now)

    twitter

     

     

    So now we can run the MbUnit application to fire off this test.

     

    By default this is C:\Program Files\MbUnit\bin\MbUnit.GUI.exe

     

    Choose assemblies -> add assembly

    twitter

     

    Browse to your dll…on vista it should be in C:\Users\<userid>\Documents\VisualStudio 2008\Projects\HelloWorld\HelloWorld\bin\Debug

     

    If you click run, it will pass:

    twitter

     

    So we have a basic framed out test and test fixture but wearen’t doing anything yet!

     

    What is TDD?

     

    TDD stands for test driven development. (in some circles it’s test driven design, but in our case we’re talking about the development).

     

    Generally the mantra for TDD is “Red, Green,Refactor”

    1.      make just enough test to fail (RED)

    2.      write just enough code to pass (GREEN)

    3.      REFACTOR to remove any duplication (DRY or do not repeat yourself)

     

    Let’s go ahead and make just enough test to fail using astring object.

    using MbUnit.Framework;

     

    namespace HelloWorld

    {

        [TestFixture]

        public class HelloWorld

        {

            [Test]

            public void HelloWorldTest()

            {

                string helloWorld = null;

                Assert.AreEqual("Hello World!", helloWorld);

            }

        }

    }

    NOTE: There are 3 basic parts to any test. 

    1. Set up some state. Here we've defined a string.
    2. Do some behavior. Right now we don't really have any behavior, but normally there would be a method called .
    3. Assert the state is what you expect

    Build this then run the test again. See what happens.

    twitter

     

    We failed the test. This is GOOD.

     

    Now let’s make the test pass by changing the null to “Hello World!”

     

    using MbUnit.Framework;

     

    namespace HelloWorld

    {

        [TestFixture]

        public class HelloWorld

        {

            [Test]

            public void HelloWorldTest()

            {

                string helloWorld = "Hello World!";

                Assert.AreEqual("Hello World!", helloWorld);

            }

        }

    }

     

    When we build and run the test it now passes.

     

    Red, Green…

     

    Now we should refactor out any duplication.

     

    Do we have any?

     

    Well we have this “Hello World!” string in there twice. Would it be much of a test if we removed that?

     

    I’d say for testing practices sake, we should probably leave each string defined separately! More reasoning for that will be apparent as you learn more about TDD, but for now let’s recap what we’ve learned in this post.

     

     We’ve introduced the class and string keywords. We saw how to create a dll, add references to it, and how to write a basic unit test using MbUnit.  Lastly, we saw how to do the basics of TDD by making it red, making it green, and then checking for duplication.

     

    Full story

    Comments (2)

  • Attempts to migrate to SQL Azure

    I thought i would check out how difficult it is to migrate a database to SQL Azure from my godaddy.com sql hosting. I was really disappointed how difficult it is.

    The first roadblock I ran into was that I couldn't just upload a .bak file from my webhost to the SQL Azure website somehow and restore it.

    That's normally how i restore/migrate a database. So i went googling to find out how microsoft thinks you should migrate a database for SQL Azure.

    Well, first problem in trying to script my database was that Godaddy does not allow you to generate scripts against their SQL server. Weee!

    So i needed to get SQL server installed on my local machine.

    So i installed SQL 2005 express and management studio 2005 express.

    management studio 2005 couldn't connect to SQL azure so i uninstalled that and installed SQL Management Studio Express 2008.

    Much to my surprise, 2008 express could not connect to SQL Azure either! (good thing i tested this right away)

    So I searched around again to find out how microsoft expects you to connect to SQL Azure

    So then I downloaded SQL 2008 R2 Enterprise edition CTP and installed just the management studio so that i could connect to SQL Azure.

    Much to my surprise I hadn't installed Visual Studio 2008 SP1. (strange that it's required for a SQL management studio install, but whatever)

    So now back to figuring out how to script the database. I did a backup to the disk, FTP'd it off godaddy.com and then restored it into my local machine (Sql2005 express)

    Then i scripted it and followed the directions on migrating to SQL Azure again for a few minutes before i got bored and decided to give up.

    I was just getting a TON of errors with the scripts.

    I realize this is a CTP but I think it's more of an Alpha if they haven't even figured out how people can migrate from their existing SQL server to SQL Azure.


    Full story

    Comments (0)

  • Scrum and Multitasking

    Multi tasking isn't bad... all of the impediments that force you to multi task are bad.

    Think about the last time you had the actual opportunity or reason to multi task. You were doing something, then you ran out of things you could do to move forward so you switched over to something else.

    i see it all of the time with software development. You know you need to write a user interface, so you start putting things on the web page, you start adding stuff, and it suddenly occurs to you that you don't know an answer to a question. "I wonder if they want blue or red for this?"

    "I guess I better call the business analyst/customer etc"

    so you pick up the phone and you get their voicemail. "Damn!", you think.

    You leave a voicemail message and you move on to something else.

    Now you've spent a good 10min getting ramped up into the task at hand and you're bopping along. Your phone rings. "Damn, i was on a roll!", you think.

    So now you know they want Red, and you now either go back to making that widget Red or you continue doing your second task.

    Is there no way around this dilemma?

    Well, you could make an assumption and go with red. Unfortunately, if you forget to ask them then you're going to get a defect though if they wanted blue. I guess you could risk it. Lots of us do this... subconsciously. 

    If you do that then you're wasting both your time and the testers time. These wastes are task switching and rework.


    Full story

    Comments (0)

  • Why User Stories? They help us plan and estimate.

    We use basic requirements at our work. They're of the normal "The system shall" style but not nearly so stringent. They don't read like a spec. They are pretty much "right sized" so they have that going for them. They also are fairly detailed as far as the "What".

    When i say they have the "What" part, i mean they say things like "users must be able to click on a heading to sort the field"

     

    So the "What" is this: "Must be able to sort"

    and who needs to sort?

    and why do they need to sort?

     

    What's really missing from these type of requirements is the Who and the Why. These are very important and it's something built right into the "Card" part of the user story.

    Remember, User stories are three things. They are

    1. Card
    2. Conversation
    3. Confirmation

    So the Who, What, and Why are the most basic and first part of the Card. (test objectives and size are also part of the card)

     

    as a [Role] i want [feature] so that [business value]

    or

    as a [Who] i want [what] so that [why]

    For example...

    As a job hunting i want sorting on jobs so that i can find jobs by where they are located.

    This represents the requirement.

    IMPORTANT

    This is NOT the requirement. It represents the requirement.

    It's often confusing to people so i'm going to say it a third time for emphasis...

    A user story is NOT the requirement. It simply represents the requirement for the purpose of estimating and planning.

    So why is the Who and Why relevant to estimating and planning? Because again we're only concerned with a representation of the requirement for the purpose of planning (ok i said it 4 times, shoot me).

    The who is important for planning and estimating because you're going to have to have a little bit of conversation with that person to figure out enough of the requirement to estimate it in size. Now i'm not saying you have to find out all of the details up front!

    One of the agile mantras is "Delay decisions until the last responsible moment". This is so that we can give our customer the opportunity to change the requirements and turn on a dime! Now, this "responsible moment" is very subjective! For example, i might need to know if this sorting needs to be client side or can it be server side. If it's client side, that is architecturally significant and may impact the estimate.

    The why is important because it gives us a chance to think creatively about the problem. The customer wants sorting so they can find jobs by region. Well, what about a search functionality? What about a filter? Are there alternatives to achieving their goal that may be easier? Better? More usable?

    So why user stories?

    They allow us to defer the details, to estimate, to provide options to our customer to achieve their goals and they give a concise description that represents a requirement for the purpose of planning and estimating.

    Full story

    Comments (0)

  • What employees do the scrum roles?

    Who does what role in scrum?

     

    aka

    This Organizational Chart is a Figment of your imagination.

     

     

    Life is full of epiphanies, but some are more amazingly simple than others.

     

    Scrum roles… it’s very simple.

     

    There is one product owner. This is the customer. They wantsomething.

     

    There is one scrum master. This is the coach, facilitator,and a shepherd.

     

    There is a team. These are the people who can make the thing the customer wants. Not just the builders, but everyone who can make what thecustomer wants.

     

    It’s that simple… however org charts are rarely that simple in larger organizations.

     

    Forget them. Seriously. Pretend it doesn’t exist.

    Just strike this completely out of your head.

     

    Let me explain briefly why:

     

    QA manager… are they a product owner? Nope. I won’t get intothe how and why but unless they are programming, analyzing requirements or testing, they aren’t a part of the scrum team.

     

    Development manager… are they a product owner? Nope. Same asabove.

     

    Product manager… are they a product owner? This one is a lot more tricky… well they give us the requirements. They often tell us what weneed to make. They probably even would come to a scrum planning meeting and act like a product owner… saying where to go, what to do, what the priority ofthings are. However, if you listen closely… very closely… they don’t have all of the requirements. They’re merely parroting what they’ve heard someone else say. They’re merely giving you an echo of someone elses desires. Granted, they could be making up some requirements of their own and getting them in… is that what the real customer wants?

     

    So product manager… no

     

    Relationship manager… this is unique to my work I think but maybe other companies have this. Supposedly this relationship manager is the person who brings in all the stakeholders and their goals and is the 1 single wringable neck for how things get prioritized and worked on. Sure sounds like aproduct owner doesn’t it?

     

    Nope. I say no.

     

    You are probably thinking “WTF?”

     

    Here’s a news flash. This relationship manager… they aren’tgoing to come to your scrum meeting. They aren’t going to know the actual requirements for the one epic that they prioritized as number 1 this release. They aren’t going to have the foggiest clue what to do when you say the farkle won’t feebozzle in schneezle so do you have an alternative to feebozzling it? They'll say, hmm let me get back to you on that... or i need to talk to "Fred" (ding, Fred should maybe be your PO?)

     

    So who is the product owner for your scrum team?

     

    GOOD QUESTION.

     

    You are probably sitting there with a vision statement…requirements document… business case… some sort of piece of paper with an ‘DRAFT’ stamped across the front page and a “Confidential” background on every page.

     

    You are staring at the the translation of the real productowner’s words!

     

    OK, So who are they?

     

    Go to the product manager and say “hey, this document… whowrote this?”

     

    Go to the writer of the document and say “Hey, who told you this stuff?”

     

    And keep doing all this and that until you find the real person who wants this product change… and then you simply say to them.

     

    Hey, can I borrow you for 3-4 hours to do sprint planning on such and such day? Can you be available for the next 30 days to answer questions about this thing you want? We hear it’s really important to you and we’re finally working on it!

     

    Let me know what they say.

     

    If you like how this works… go thank Mike Vizdos for this amazing epiphany he gave me.

    http://www.michaelvizdos.com/telephone/index.html

     

    Full story

    Comments (0)

  • Changing the Path on the ASP.NET Session Cookie

    Function Session_Start(Object sender, EventArgs e)

    Dim mycookie As HttpCookie

    mycookie =NewHttpCookie(Response.Cookies("ASP.NET_SessionId").Name,Response.Cookies("ASP.NET_SessionId").Value)

    Response.Cookies.Remove("ASP.NET_SessionId")

    mycookie.Path = "/MyApp"

    Response.Cookies.Add(mycookie)

    End Function


    '''Great work Mike Collier at Commerce Bank for figuring this one out! If any of this VB isn't good, i plea that i'm a c# guy.

    'this goes in the global.asax.vb file


    Full story

    Comments (0)

  • Polymorphing different Types


    So my friend (though not good enough friend to be my ‘boatfriend’) ran into a programming issue the other day at work. He had two objectswith similar data and no behavior (vb6 style data/procedural programming). Unfortunately,these two objects did NOT inherit from the same base object and they were beingused similarly in an asp.net code behind page but there was no clearabstraction.

     

    If(foo.GetType() == typeof(recurringTransaction))

    {

    Foo1();

    }

    Else

    {

    Foo2();

    }

     

    So basically “foo” could be one of two different types… arecurring transfer or a single transfer. Depending on the type, we’d get adifferent UI behavior.

     

    This is clearly an opportunity for polymorphism, but we didNOT have control of these objects! They were vendor code.

     

    So what do you do in this situation?

     

    Well directly to the point, you would create a new baseclass called “Transfer” and then use composition to encapsulate the dataobjects. Making something like this:

     

    What’s that look like in code?

         class OldSingleTransfer

        {

            //Some data

        }

        class OldRecurringTransfer

        {

            //Some similiar data

        }

        abstract class Transfer

        {

            public abstract void MyUIBehavior();

        }

        class SingleTransfer : Transfer

        {

            OldSingleTransfer instance;

            public override void MyUIBehavior()

            {

                //Specific single transfer code

            }

        }

        class RecurringTransfer : Transfer

        {

            OldRecurringTransfer instance;

            public override void MyUIBehavior()

            {

                //specific recurring transfer code

            }

        }

     Now you can just do foo.MyUIBehavior(); and be done with it.

     I know what you're thinking... GOD that's a LOT of code just to do this one thing. That's not how i would do this.

    Well, yes you're right this is more code initially... however in reality what we had was 40-100 lines of 'type specific' code that was mostly all repeated for both types. We've eliminated all of that duplication and left ourselves with an easier set of operations to maintain and reduced the complexity by removing the conditional logic.

    There were bugs lurking in this code... for example what would happen if you made a third type of transfer? it would have hit the "else" condition... meaning "single transfer". What if it was a scheduled transfer?

    Full story

    Comments (7)

  • Init Params in Silverlight 3

    I converted my silverlight app over to silverlight 3 today and ran into an issue with InitParams because the silverlight hosting control is no longer valid for silverlight 3 nor provided in the vs2008 tools.

     

    The quick and dirty: I had to take all of the object tag string and move it to the code behind by inserting into the inner Html of the div tag that hosts it.

     

    Explanation:

     

    When you create a new Silverlight 3 application it asks you if you want to add it to an existing asp.net application. If you do that it generates a test aspx page that has something like this:

     

        <div id="silverlightControlHost">

            <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%"height="100%">

                <param name="source"value="ClientBin/JPeckham.xap"/>

                <param name="onError"value="onSilverlightError"/>

                <param name="background"value="white"/>

                <param name="minRuntimeVersion"value="3.0.40624.0"/>

                <param name="autoUpgrade"value="true"/>

                <href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0"style="text-decoration:none">

                        <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get MicrosoftSilverlight" style="border-style:none"/>

                </a>

              </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

    What you need to do is change the div to be runat=”server” and do a CUT of the object tag contents. You’ll have this then:

    <div id="silverlightControlHost"runat="server">

    </div>

     

    Now inside of your code behind for the page, past that string and parse it using a string builder, like this:

    silverlightControlHost.InnerHtml =

    silverlightControlHost.InnerHtml =

                new StringBuilder(

                @"<object id=""SilverlightApp"" data=""data:application/x-silverlight-2,""

    type=""application/x-silverlight-2"" width=""100%"" height=""100%"" >

                  <param name=""source"" value=""../../ClientBin/JPeckham.xap""/>

                  <param name=""onError"" value=""onSilverlightError"" />

                  <param name=""background"" value=""white""/>

                  <param name=""minRuntimeVersion"" value=""3.0.40624.0"" />

                  <param name=""autoUpgrade"" value=""true""/>

              <param name=""InitParams"" value=")

     

                                                .Append(BuildSilverlightInitParametersFromQueryString())

               

                                                .Append( @"""/>

                  <a href=""http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0""style=""text-decoration:none"">

                        <img src=""http://go.microsoft.com/fwlink/?LinkId=108181"" alt=""Get Microsoft Silverlight"" style=""border-style:none""/>

                  </a>

              </object><iframe id=""_sl_historyFrame"" style=""visibility:hidden;height:0px;width:0px;border:0px""></iframe>").ToString();

     

    NOTE: Basically BuildSilverlightInitParametersFromQueryString()is the method that constructs your InitParams value string. So write thathowever you feel like. Make sure toHtmlEncode it! J

    Full story

    Comments (3)

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. Next page