March, 2008

  • Wriju's BLOG

    The Developer Highway Code Free E Book

    • 1 Comments

    The Developer Highway Code, written by Paul Maher of DPE, is a concise handbook that captures and summarizes the key security engineering activities that should be an integral part of the software development process. This companion guide should be a must for any Developer, Architect, Tester etc. undertaking software development...The book is presented in easy to read checklist form, covering essential guidance on writing and releasing secure code. And it is available for free!

    “Developers are a most critical component to a more safe computing experience for all computer users in the UK and around the world. Code written for a program or operating system, or process must be able to withstand the most aggressive attempts to ‘break it’.  From games to mission-critical operations, secure code will form the base for success or disaster.  The Developer Highway Code should be a required reading." Edward P Gibson, Chief Security Advisor, Microsoft Ltd

    Where can you get The Developer Highway Code?

    Download full book only as a pdf or Download full book only as an xps

    I got the information from here.

    Namoskar!!!

  • Wriju's BLOG

    LINQ to XML : Adding Namespace quickly

    • 6 Comments

    I have written a post earlier on how to attach Namespaces. After reading my article someone complained about the redundancy of the code. I also realized the pain. I was reading the book C# 3.0 In a Nutshell. There I got a very elegant solution. Let me explain the scenario,

     

    If you create a XML like,

     

    <?xml version="1.0" encoding="utf-8" ?>

    - <numbers xmlns="urn:myns-com">

      <number value="1" square="1" xmlns="" />

      <number value="2" square="4" xmlns="" />

      <number value="3" square="9" xmlns="" />

      <number value="4" square="16" xmlns="" />

      <number value="5" square="25" xmlns="" />

      <number value="6" square="36" xmlns="" />

      <number value="7" square="49" xmlns="" />

      <number value="8" square="64" xmlns="" />

      <number value="9" square="81" xmlns="" />

      <number value="10" square="100" xmlns="" />

    </numbers>

     

    By writing

     

    XNamespace ns = XNamespace.Get("urn:myns-com");

     

    XElement root = new XElement(ns+ "numbers",

        from i in Enumerable.Range(1, 10)

        select new XElement("number",

            new XAttribute("value", i),

            new XAttribute("square", i*i)));

     

    Now since we have not added ns in all the blocks it adds xmlns=”” in all the areas. We can avoid this by writing,

     

    XNamespace ns = XNamespace.Get("urn:myns-com");

     

    XElement root = new XElement(ns+ "numbers",

        from i in Enumerable.Range(1, 10)

        select new XElement(ns + "number",

            new XAttribute("value", i),

            new XAttribute("square", i*i)));

     

    Sometimes this could be painful if the structure is more complicated.

     

    So writers have given us a tip,

    foreach (XElement e in root.DescendantsAndSelf())

    {

        if (e.Name.Namespace == "")

        {

            e.Name = ns + e.Name.LocalName;

        }

    }

     

    This will modify the existing Xml to

     

    <?xml version="1.0" encoding="utf-8" ?>

    - <numbers xmlns="urn:myns-com">

      <number value="1" square="1" />

      <number value="2" square="4" />

      <number value="3" square="9" />

      <number value="4" square="16" />

      <number value="5" square="25" />

      <number value="6" square="36" />

      <number value="7" square="49" />

      <number value="8" square="64" />

      <number value="9" square="81" />

      <number value="10" square="100" />

    </numbers>

     

     

    Namoskar!!!

  • Wriju's BLOG

    LINQ to XML : Join Xml Data

    • 13 Comments

    Let’s say I have created two Xml files using LINQ to XML from Northwind database. I have taken two tables Category and Products and tried to join between two different files.

     

    Category XML

     

    <?xml version="1.0" encoding="utf-8"?>

    <categories>

      <category id="1">

        <CategoryName>Beverages</CategoryName>

      </category>

      <category id="2">

        <CategoryName>Condiments</CategoryName>

      </category>

      <category id="3">

    ……

     

    Products XML

     

    <?xml version="1.0" encoding="utf-8"?>

    <products>

      <product ProductID="1" CategoryID="1">

        <ProductName>Chai</ProductName>

      </product>

      <product ProductID="2" CategoryID="1">

        <ProductName>Chang</ProductName>

      </product>

    ……

     

    LINQ rocks here,

    XElement prods =  XElement.Load(@"..\..\XmlData\Product.xml");

    XElement cats = XElement.Load(@"..\..\XmlData\Category.xml");

     

    var root =

        from p in prods.Descendants("product")

        join c in cats.Descendants("category")

        on

            (string)p.Attribute("CategoryID")

        equals

            (string)c.Attribute("id")

        select new

        {

            ProductId = (string)p.Attribute("ProductID"),

            ProductName = (string)p.Element("ProductName"),

            CategoryName = (string)c.Element("CategoryName")

        };

     

    //Console.WriteLine(root.Count());

     

    foreach (var k in root)

    {

        Console.WriteLine(k);

    }

     

    Output will look like,

    { ProductId = 1, ProductName = Chai, CategoryName = Beverages }

    { ProductId = 2, ProductName = Chang, CategoryName = Beverages }

    { ProductId = 3, ProductName = Aniseed Syrup, CategoryName = Condiments }

     

    If you want to create Xml file

     

    var root = new XElement("ProdList",

        from p in prods.Descendants("product")

        join c in cats.Descendants("category")

        on

            (string)p.Attribute("CategoryID")

        equals

            (string)c.Attribute("id")

        select new XElement("ProductCategory",

    new XAttribute("ProductID", (string)p.Attribute("ProductID")),

    new XElement("ProductName", (string)p.Element("ProductName")),

    new XElement("CategoryName", (string)c.Element("CategoryName"))));

     

    Console.WriteLine(root);

     

     

    Output will look like,

    <CategoryName>Produce</CategoryName>

    </ProductCategory>

    <ProductCategory ProductID="8">

      <ProductName>Northwoods Cranberry Sauce</ProductName>

      <CategoryName>Condiments</CategoryName>

    </ProductCategory>

    <ProductCategory ProductID="9">

      <ProductName>Mishi Kobe Niku</ProductName>

      <CategoryName>Meat/Poultry</CategoryName>

    </ProductCategory>

    …..

     

    Namoskar!!!

  • Wriju's BLOG

    LINQ to XML : Working with Prefixes

    • 5 Comments

    Based on my previous post on LINQ to XML : Working with Namespaces, if you want to add prefixes to your Xml things becomes little crazy. The trick is that you have to use XAttribute() to attach prefixes. So the Xml as below need the following code,  

     

    <pfx:root xmlns:pfx="urn:mynamespace-com">

      <pfx:child />

    </pfx:root>

     

    XNamespace ns = XNamespace.Get("urn:mynamespace-com");

     

    XElement root = new XElement(ns+"root",

        new XAttribute(XNamespace.Xmlns + "pfx", ns),

        new XElement(ns+"child"));

     

    Namoskar!!!

  • Wriju's BLOG

    LINQ to XML : Working with Namespaces

    • 7 Comments

    If you are working with complex real world XML then you have to deal with namespaces to disambiguate. There are several ways to implement namespaces in LINQ to XML. One is you can use pure string to add your namespace with each element declaration, like

     

    <root>

      <child />

    </root>

     

    To create the above Xml you will be writing

    XElement root = new XElement("root",

        new XElement("child"));

     

    To add namespace here, it is very simple

     

    XElement root = new XElement("{urn:mynamespace-com}root",

        new XElement("child"));

     

    Console.WriteLine(root);

     

    The output will look like,

    <root xmlns="urn:mynamespace-com">

      <child xmlns="" />

    </root>

     

    But this does not add namespace to child. So if you have to add namespace to child also,

     

    XElement root = new XElement("{urn:mynamespace-com}root",

        new XElement("{urn:mynamespace-com}child"));

     

    Then the output will look like,

    <root xmlns="urn:munamespace-com">

      <child />

    </root>

     

    But this approach is redundant as you have to type {urn:mynamespace-com} everywhere to make that the part of the same namespace.

     

    So to avoid this you can write some elegant code.

     

    XNamespace ns = XNamespace.Get("urn:mynamespace-com");

     

    XElement root = new XElement(ns+"root",

        new XElement(ns+"child"));

     

    This looks more elegant code.

     

    Another Mike Taulty magic.

     

    Namoskar!!!

  • Wriju's BLOG

    LINQ to SQL Overview Video

    • 0 Comments

    Luca, the Microsoft Lead Program Manager, he is one of my favorite presenters. The way he demonstrate uninteresting thing and make fun of himself is one everyone should learn. Please enjoy the through presentation of LINQ to SQL at http://blogs.msdn.com/lucabol/archive/2008/03/03/linq-to-sql-overview-video.aspx

     

    Namoskar!!!

  • Wriju's BLOG

    Amazing BlueScreen Screen Saver

    • 0 Comments

    I am not a screen saver crazy person. But I do keep on adding screen saver as and when I get good one. My friend Amit found out such one which is the most feared one i.e., BlueScreen. It also simulates the startup screen. This was created by one of Microsoft’s Technical Fellows (the most respected technical position at Microsoft) Dr. Mark Russinovich. I always feel good to share @microsoft.com in my email address with them. Join Microsoft and enjoy the fun.

     

    If you install it you can easily make your colleague fool. Good one for the month of April.

     

    Find more at http://technet.microsoft.com/en-us/sysinternals/bb897558.aspx  

     

    Namoskar!!!

  • Wriju's BLOG

    Parallel Extensions to the .NET Framework

    • 0 Comments

    Daniel Moth posted a nice blog on Parallel Extension. Enjoy http://www.vsj.co.uk/articles/display.asp?id=704

    Namoskar!!!

  • Wriju's BLOG

    MSDN Magazine March 2008 is now online

    • 1 Comments

    March2008

    http://msdn2.microsoft.com/en-us/magazine/cc301916.aspx

    Namoskar!!!

  • Wriju's BLOG

    C# 3.0 Query Expressions by Bruce Eckel and Jamie King

    • 2 Comments

    Bruce, a renowned author of the famous book “Thinking in Java” is now exploring C# 3.0. He wrote many other books on

    Ø       The Hands-On Java Seminar CD ROM (available on the Web site)

    Ø       Thinking in C++ (PH 1995; 2nd edition 2000, Volume 2 with Chuck Allison, 2003)

    Ø       C++ Inside & Out (Osborne/McGraw-Hill 1993

     

    In his preface he wrote, “The dollar amount you pay for any education is the cheapest part. It’s the work, dedication, and sweat you put forth to acquire your education that increases your value as a programmer (and your salary).”

     

    The preview of this book is available for free download,

    http://www.mindviewinc.com/Books/CSharp/Index.php

     

    Respect authors,

    Note: This book is only available from this web site. Please do not mirror or otherwise distribute this book from any other location.

     

    Namoskar!!!

  • Wriju's BLOG

    MIX8 is now online

    • 0 Comments

    http://sessions.visitmix.com/

    Namoskar!!!

Page 1 of 1 (11 items)