MSDN Blog Postings

via RSS Feed

Archive for the 'MSDN Blogs' Category

[Tip] Tool Window Dragging with the Keyboard in Visual Studio

Posted by on 5th July 2009

 


With the desired tool window selected, press Alt+Minus to bring up the tool window menu. Press Down Arrow to select the Move command and hit Enter. Now, you can control the tool window with the arrow keys.


To dock, simply use the arrow keys to the desired dock target and hit Enter.


Reposted from Did you know… How to drag a tool window around using the keyboard? - #005 by Sara Ford, author of Microsoft Visual Studio Tips




Microsoft TechDays Canada is a technology training conference for IT professionals and developers. With forty, 200+ level sessions, it brings you the rich learning experience of Microsoft Tech·Ed (without the travel) on both current technologies and new products like Windows 7, Exchange 2010 and much more. Register today by visiting http://www.techdays.ca/.


This post originated from and is provided by the MSDN Blogs RSS feed. The original post of the article can be found here.

Posted in MSDN Blogs | Comments Off

direto do Egito: Brasil mandando super bem na Imagine Cup :)

Posted by on 5th July 2009

olha o Brasil brilhando de novo na Imagine Cup   : )   (aliás… você tem idéia do tamanho da Imagine Cup 2009?  leia isso entao: This is the seventh Imagine Cup and the largest yet.  Over 300,000 students from every corner of the globe registered for this year’s competition (up from 200,000 last year) and through local, regional and online finals, the top 400 students will compete from July 3 rd to July 7 th with the winners being announced at the foot of the Pyramids. o…(read more)
This post originated from and is provided by the MSDN Blogs RSS feed. The original post of the article can be found here.

Posted in MSDN Blogs | Comments Off

Mapové podklady a Silverlight

Posted by on 5th July 2009

Zobrazení map na webových stránkách je dnes tak běžné, že nad jejich existencí vůbec neuvažujeme. Ne vždy však vidíme něco více, než samotné mapy s vyznačenými body zájmu. Pravděpodobně to bude tím, že vytvořit sofistikovanou logiku s dodatečnými vrstvami zobrazujícími specifické informace a ovládací prvky není vždy zcela jednoduché. Nezávisle na poskytovateli map (Microsoft, Google, Yahoo), všechny firmy standardně nabízí mapové API v JavaScriptu, často i s podporou AJAXu. Úvodní informace a příklady lze vidět např. zde: Microsoft, Google a Yahoo. Pokud zůstaneme u Microsoft Virtual Earth, nejjednodušší způsob jak začít s využíváním mapového softwaru je interaktivní generátor zdrojového kódu - Bing Maps Interactive SDK. Zde lze velice jednoduše nasimulovat ovládání mapy, vkládání a zobrazování různých tvarů, vkládání dat do vrstev atd. Pokud bychom např. potřebovali zobrazit mapu ve 2D pohledu s označeným místem pushpinem a orámovanou oblastí, leze si tento scénář na interaktivní mapě naklikat (Custom shapes -> Add custom shapes, v dialogu vybrat Add Polygon).

BingMapsInteractiveSDK

Po přepnutí do záložky Source Code získáme plný zdrojový kód pro vložení do web stránky, případně na další záložce Reference od dokumentaci k použité funkci AddShape().

Silverlight - to, co vás odliší

Osobně se zřídka spokojím s tím, že mé aplikace dělají “jen to co jiné”. A tak hledám jak je udělat jiné a lepší. Při programování s mapami se tedy jasně nabízí Virtual Earth Silverlight Map Control. Vedle všech možností ovládání jako máme u standardního mapového API můžeme využít veškerou funkcionalitu a možnosti, které nám dává Silverlight. V první řadě, z pohledu programátora, je to tvorba aplikační logiky v .NET jazycích. Není to boží se vyhnout JavaScriptu? J Druhou, neméně zajímavou je pak schopnost vložit do vrstev mapy libovolnou grafiku nebo ovládací prvky, které známe zběžných Silverlight aplikací.

I samotný Silverlight Map prvek přináší celou řadu vylepšení. Mezi ty nevýznamnější patří:

  • Plynulé překreslování jednotlivých dlaždic, ze kterých je mapa složena (pannování, zoomování)
  • Lepší systém událostí
  • Přizpůsobitelné chování
  • Integrace s webovými službami

Abychom opět ulehčili a zrychlili vývojářům práci, vedle běžného SDK je k dispozici i Microsoft Virtual Earth Silverlight Map Control Interactive SDK (to fakt není krátký název aplikace). V online aplikaci si lze opět nasimulovat jednoduché situace, např. zobrazení souřadnic centra mapy a jednotlivých jejích okrajů.

BingMapsSLInteractiveSDK

V záložce Source Code pak vidíme zdrojový kód. Ten si dovolím také vypsat, protože jeho jednoduchost a čitelnost je opravdu luxusní. Nejdříve XAML kód aplikace:

<UserControl x:Class="MapControlInteractiveSdk.Tutorials.Tutorial4"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:m="clr-namespace:Microsoft.VirtualEarth.MapControl;           assembly=Microsoft.VirtualEarth.MapControl">
  <Grid x:Name="LayoutRoot" Background="White">
    <m:Map Center="47.640,-122.125" ZoomLevel="11" x:Name="MyMap" />
    <Border Background="Black" VerticalAlignment="Top"             HorizontalAlignment="Right" Opacity="0.8"             BorderBrush="White" BorderThickness="2" CornerRadius="5">
      <TextBlock x:Name="MapInfo" Foreground="#008800" FontSize="12"             Padding="5" />
    </Border>
  </Grid>
</UserControl>

A ještě kód v pozadí, který reaguje na pannování a zoom v okně mapy a překresluje informaci a aktuálním pohledu:

using System;
using System.Windows;
using System.Windows.Controls;
using Microsoft.VirtualEarth.MapControl;

namespace MapControlInteractiveSdk.Tutorials
{
  public partial class Tutorial4 : UserControl
  {
    public Tutorial4()
    {
      InitializeComponent();

      MyMap.ViewChangeOnFrame +=             new EventHandler<MapEventArgs>(MyMap_ViewChangeOnFrame);
    }

    void MyMap_ViewChangeOnFrame(object sender, MapEventArgs e)
    {
      Map map = (Map) sender;

      MapInfo.Text = string.Format("Center: {0:F5} ZoomLevel: {1:F5} rn",                                    map.View.Center, map.View.ZoomLevel);

      LocationRect bounds = map.GetBoundingRectangle();
      MapInfo.Text += string.Format("Northwest: {0:F5}, Southeast: {1:F5}                     (Current)rn", bounds.Northwest, bounds.Southeast);

      LocationRect targetBounds = map.GetBoundingRectangle(map.TargetView);
      MapInfo.Text += string.Format("Northwest: {0:F5}, Southeast: {1:F5}           (Animating to)",targetBounds.Northwest, targetBounds.Southeast);
    }
  }
}

Jak se k Silverlight komponentě dostat

Předvedená komponenta v době psaní článku je v CTP (Community Technology Preview) verzi. Pro přístup ke všem SDK, příkladům a dokumentaci se musíte bezplatně registrovat v programu Connect. Je to velice jednouchý postup:

  • Najeďte na stránku http://connect.microsoft.com
  • Přihlaste se svým Live ID
  • Přepněte se nabídky Connection Directory a kategoriích vyberte Windows Live a v nabídce Virtual Earth Silverlight Map Control CTP.

BingSLMapsSDKConnect


This post originated from and is provided by the MSDN Blogs RSS feed. The original post of the article can be found here.

Posted in MSDN Blogs | Comments Off

今日のワンポイント : [クイック ウォッチ] ウィンドウに他の変数を簡単に表示する方法- #307

Posted by on 5th July 2009

エディターで変数を選択して QuickWatch コマンドを実行したり、[クイック ウォッチ] ウィンドウの [] ボックスに式を入力したりすると、その変数はボックスのドロップダウン リストに保存されます。



QuickWatch Expressions drop down 


 


Technorati タグ : VS2005TipVS2008Tip


投稿 : 2008 9 5 () 3:00 AM saraford


Sara Ford さんの Web ログ - http://blogs.msdn.com/saraford/archive/2008/09/05/did-you-know-you-can-quickly-view-other-variables-in-the-quickwatch-window-307.aspx より。


分類 : Visual Studio 2008 ワンポイント


This post originated from and is provided by the MSDN Blogs RSS feed. The original post of the article can be found here.

Posted in MSDN Blogs | Comments Off

Comparing Two Open XML Documents using the Zip Extension Method

Posted by on 5th July 2009

[BlogMap]


Sometimes we want to compare two word processing documents to see if they contain the same content.  I’m working on a blog post to merge comments from multiple Open XML documents into a single document.  This is based on a feature in Word 2007 that allows you to lock a document and prevent changes to content, yet allows users to add comments to the document.  However, we don’t want to attempt to merge comments if the documents don’t contain the same content.


One Approach to Comparing Two Documents for Equivalency


If two documents contain exactly the same content, they will have the same number of paragraphs, tables, content controls, and custom XML markup, and more, and these elements will occur in the same order, and have the same content.  However, two paragraphs may contain the same content yet their XML representation may be very different if one has a comment and the other does not – the paragraph with the comment may have its runs split differently.  I’ve written a previous post that examines run splitting in detail, and contains a method to report where the run splits are, and a method that splits runs based on a list of split locations.


The following markup shows a very simple paragraph.  We can see the paragraph element, the run element, and the text element.


<w:p>


  <w:r>


    <w:t>abcdefghi</w:t>


  </w:r>


</w:p>


 


If we select “def” in the above text, and add a comment, the markup changes to look like this:


<w:p>


  <w:r>


    <w:t>abc</w:t>


  </w:r>


  <w:commentRangeStart w:id=0/>


  <w:r>


    <w:t>def</w:t>


  </w:r>


  <w:commentRangeEnd w:id=0/>


  <w:r>


    <w:rPr>


      <w:rStyle w:val=CommentReference/>


    </w:rPr>


    <w:commentReference w:id=0/>


  </w:r>


  <w:r>


    <w:t>ghi</w:t>


  </w:r>


</w:p>


 


We can write a query that returns a collection of a very specific subset of the elements in the XML document.  This is the subset of elements that won’t change if the contents of the document don’t change.  This query consists of all elements in the document except:




  • w:commentRangeStart and w:commentRangeEnd – these elements will be added when the user adds comments to a document.


  • w:proofErr – this element is added automatically by Word when there are spelling or grammar errors, and has no effect on content.  Word can (and will) add this element even though the document is locked for editing with the exception of being able to add comments.  Therefore, we want to trim this element from the collection returned by a query that we’re going to use to determine document equivalency.


  • Finally, we want to eliminate all of the descendants of paragraphs from the query, as these elements can change quite a bit even if the contents of the document don’t change.  Instead, we want to write a bit of code to determine whether two paragraphs are equivalent.

Here is the query that returns a collection of the elements that we’re interested in:


XDocument xDoc1 = doc1.MainDocumentPart.GetXDocument();


 


var doc1Elements = xDoc1


    .Descendants()


    .Where(e => e.Name != W.commentRangeStart &&


        e.Name != W.commentRangeEnd &&


        e.Name != W.proofErr &&


        !e.Ancestors(W.p).Any());


 


We can query two word processing documents, and if the elements in the returned collection are not in the exact same order, then the documents are different.  And if corresponding paragraphs contain the same content, per whatever algorithm that we define, then we can say that the documents contain the same content.  In the example that I present in this post, I validate paragraph equivalency by checking actual textual content, disregarding formatting changes for runs within the paragraph.  In my case, this is good enough, as the transformation that I wrote (and will present in an upcoming post) that moves comments from one document to another will work properly if the paragraphs have the same text.


The above query works just fine for documents that contain tables, content controls, and custom XML.  The markup for tables, content controls, and custom XML contains paragraphs, and the paragraphs will be in the same order and have the same content if the documents are equivalent.


We could change this query easily enough to define document equality in just about any way we want.  If we want to disregard bookmarks, it’s easy enough to remove them from the results of the query.


The above query is not the most efficient way to do this – more efficient would be to write an iterator that goes through the Descendants axis and trims appropriately.  But queries show intent in a better way, and in my informal testing, the above query performs well enough as is for many scenarios.


Now that we’ve defined the query that will return the elements that won’t change if the document content doesn’t change, we can define another query that determines if two queries, evaluated on two Open XML documents, contain the same items, and in the same order.  This is a job for the Zip extension method, coming with C# 4.0.


The Zip Extension Method


The Zip extension method processes two sequences, matching up each item in one sequence with a corresponding item in another sequence.  While this method won’t be part of the framework until C# 4.0, a simple implementation that we can use with C# 3.0 is trivial:


public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(


    this IEnumerable<TFirst> first,


    IEnumerable<TSecond> second,


    Func<TFirst, TSecond, TResult> func)


{


    var ie1 = first.GetEnumerator();


    var ie2 = second.GetEnumerator();


 


    while (ie1.MoveNext() && ie2.MoveNext())


        yield return func(ie1.Current, ie2.Current);


}


 


Note:  Bart De Smet has a great explanation of the Zip extension method, as well as this example of the implementation of it.  That post also has a good explanation of how iterators work, using IL to explain them.  It’s also useful to read the section 8.14 in the C# 3.0 specification.


Using the Zip Extension Method


If we have one sequence that contains names, and another sequence that contains ages, and we know that the two sequences contain corresponding elements, we can project a new collection of anonymous objects:


string[] names = new[] { “Jim”, “Bob”, “Susan” };


int[] ages = new[] { 50, 35, 41 };


var q = names.Zip(ages, (name, age) => new


{


    Name = name,


    Age = age


});


foreach (var item in q)


    Console.WriteLine(item);


 


When you run this example, you see:


{ Name = Jim, Age = 50 }


{ Name = Bob, Age = 35 }


{ Name = Susan, Age = 41 }


 


Notice that for the projection, we write a lambda expression that takes two arguments – each pair of corresponding items from the two source collections is passed as arguments to the lambda expression.


The following query uses the Zip extension method to project a collection of Booleans indicating if the element or paragraph is equivalent:


IEnumerable<bool> correspondingElementEquivalency = doc1Elements.Zip(doc2Elements, (e1, e2) =>


{


    if (e1.Name != e2.Name)


        return false;


    // determine if two paragraphs contain the same content


    if (e1.Name == W.p && (GetParagraphText(e1) != GetParagraphText(e2)))


        return false;


    return true;


});


 


GetParagraph text is defined as:


// return the text of a paragraph with revisions accepted


public static string GetParagraphText(XElement p)


{


    return p.Descendants(W.r)


        .Where(e => e.Parent.Name != W.del && e.Parent.Name != W.moveFrom)


        .Descendants(W.t)


        .Select(t => (string)t)


        .StringConcatenate();


}


 


So then, we can use the Any extension method to determine if the documents are equivalent:


return ! correspondingElementEquivalency.Any(e => e != true);


 


This will be pretty efficient, as it uses lazy evaluation, and the Any extension method will terminate processing as soon as the code determines that the documents are different.


One Final Note


This code doesn’t process math markup – if the two documents contain a math formula, and one of the documents is commented, then this query will report that the documents differ.  The structure and approach to take are exactly parallel to the approach that I take with comments in regular paragraphs.  Extending this to math markup is another post.


The Code


Following is an example that compares two documents to determine if they have the same content.  The code is quite short.  Note this uses the Open XML SDK.


using System;


using System.Collections.Generic;


using System.IO;


using System.Linq;


using System.Text;


using System.Xml;


using System.Xml.Linq;


using DocumentFormat.OpenXml.Packaging;


 


public static class Extensions


{


    public static XDocument GetXDocument(this OpenXmlPart part)


    {


        XDocument xdoc = part.Annotation<XDocument>();


        if (xdoc != null)


            return xdoc;


        using (StreamReader streamReader = new StreamReader(part.GetStream()))


            xdoc = XDocument.Load(XmlReader.Create(streamReader));


        part.AddAnnotation(xdoc);


        return xdoc;


    }


 


    public static string StringConcatenate(this IEnumerable<string> source)


    {


        StringBuilder sb = new StringBuilder();


        foreach (string s in source)


            sb.Append(s);


        return sb.ToString();


    }


 


    public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(


        this IEnumerable<TFirst> first,


        IEnumerable<TSecond> second,


        Func<TFirst, TSecond, TResult> func)


    {


        var ie1 = first.GetEnumerator();


        var ie2 = second.GetEnumerator();


 


        while (ie1.MoveNext() && ie2.MoveNext())


            yield return func(ie1.Current, ie2.Current);


    }


}


 


public static class W


{


    public static XNamespace w =


        “http://schemas.openxmlformats.org/wordprocessingml/2006/main”;


 


    public static XName p = w + “p”;


    public static XName r = w + “r”;


    public static XName t = w + “t”;


    public static XName commentRangeStart = w + “commentRangeStart”;


    public static XName commentRangeEnd = w + “commentRangeEnd”;


    public static XName proofErr = w + “proofErr”;


    public static XName del = w + “del”;


    public static XName moveFrom = w + “moveFrom”;


}


 


class Program


{


    // return the text of a paragraph with revisions accepted


    public static string GetParagraphText(XElement p)


    {


        return p.Descendants(W.r)


            .Where(e => e.Parent.Name != W.del && e.Parent.Name != W.moveFrom)


            .Descendants(W.t)


            .Select(t => (string)t)


            .StringConcatenate();


    }


 


    // returns true if the documents contain the same content, otherwise false


    private static bool CompareDocuments(WordprocessingDocument doc1,


        WordprocessingDocument doc2)


    {


        XDocument xDoc1 = doc1.MainDocumentPart.GetXDocument();


        XDocument xDoc2 = doc2.MainDocumentPart.GetXDocument();


 


        var doc1Elements = xDoc1


            .Descendants()


            .Where(e => e.Name != W.commentRangeStart &&


                e.Name != W.commentRangeEnd &&


                e.Name != W.proofErr &&


                !e.Ancestors(W.p).Any());


 


        var doc2Elements = xDoc2


            .Descendants()


            .Where(e => e.Name != W.commentRangeStart &&


                e.Name != W.commentRangeEnd &&


                e.Name != W.proofErr &&


                !e.Ancestors(W.p).Any());


 


        IEnumerable<bool> correspondingElementEquivalency = doc1Elements


            .Zip(doc2Elements, (e1, e2) =>


            {


                if (e1.Name != e2.Name)


                    return false;


                // determine if two paragraphs contain the same content


                if (e1.Name == W.p && (GetParagraphText(e1) != GetParagraphText(e2)))


                    return false;


                return true;


            });


 


        return ! correspondingElementEquivalency.Any(e => e != true);


    }


 


    static void Main(string[] args)


    {


        using (WordprocessingDocument doc1 = WordprocessingDocument.Open(“Test3a.docx”, false))


        using (WordprocessingDocument doc2 = WordprocessingDocument.Open(“Test3b.docx”, false))


        {


            bool same = CompareDocuments(doc1, doc2);


 


            Console.WriteLine(same);


        }


    }


 


}


 


 


This post originated from and is provided by the MSDN Blogs RSS feed. The original post of the article can be found here.

Posted in MSDN Blogs | Comments Off

Les temps durs de la compétition…

Posted by on 5th July 2009


This post originated from and is provided by the MSDN Blogs RSS feed. The original post of the article can be found here.

Posted in MSDN Blogs | Comments Off

The Aussies Rocked

Posted by on 5th July 2009

OK, I’m biased. You don’t need to tell me.

But regardless of what you think, the Australian team for Software Design absolutely did indeed rock their presentation. Every time I’ve seen them they’ve been better than the last, but seriously – they were like a group of professionals who had been doing their job for years. The presentation was smooth, articulate and they fielded the questions thrown at them with aplomb and a self-assurance that was exciting to watch.

Their eGreen solution generated some genuine interest from several of the judges, with one coming up afterwards to congratulate the team on coming up with a solution that could impact people worldwide.

Now the “but”. :(

Unfortunately, there were at least twelve other teams who rocked it even better than the Aussies did. That might sound like a lot, but remember there were close to 70 teams in the Software Design category, so going from 70 to 12 is pretty brutal and there were many students who were impacted by the cut.

The next round occurred immediately after the announcement was made, and later in the evening we learned who the top 6 teams were, including Brazil, Spain and Taiwan. I’ll blog coverage of the final presentations tomorrow.

I want to congratulate Team eGreen for being such amazing ambassadors for Australia and showing the world how skilled Aussie students are. Good on you Donovan, Xharmagne and James (and well done, Dat).


This post originated from and is provided by the MSDN Blogs RSS feed. The original post of the article can be found here.

Posted in MSDN Blogs | Comments Off

If you can dream it and if you can imagine it, you can build it..

Posted by on 5th July 2009

 

 ImagineCup[2]

Ray Ozzie recently posted a blog entry ay the Microsoft On The Issues site as he kicked off the Imagine Cup Finals in Cairo. 

I’ve promised myself one day I’ll make it to the Imagine Cup to see the amazing work students are doing with software.  Ray gives 3 examples himself which all sound terrific

  • The all-female Egyptian team is developing a low-cost solution for addressing air pollution in developing countries;
  • A team from India has developed a solution called Pearl to address that country’s high percentage of child and neonatal deaths among rural populations; and
  • A team from Uganda has created an innovative phone application that could help small farmers get better prices for their harvests in a country where more than 70% of the population earns less than $8 per day.

 

I can’t help but mention the team from Kings College here in London who are working on smart traffic routing. This year for the first time, we are asking people to vote online for their favourite entry in the Software Design category so if you like their project, please give them your vote – they’re TKCL with project Pioneer.


This post originated from and is provided by the MSDN Blogs RSS feed. The original post of the article can be found here.

Posted in MSDN Blogs | Comments Off

My MSDN Magazine Articles

Posted by on 5th July 2009

I wrote some MSDN magazine articles but never really blogged about them:

.NET Framework Internals: How the CLR Creates Runtime Objects: http://msdn.microsoft.com/en-us/magazine/cc163791.aspx 

Build Line-Of-Business Enterprise Apps With Silverlight, Part 1: http://msdn.microsoft.com/en-us/magazine/2009.01.entslpt1.aspx

Code download: http://code.msdn.microsoft.com/mag200901Silverlight

Build Line-Of-Business Enterprise Apps With Silverlight, Part 2: http://msdn.microsoft.com/en-us/magazine/dd434653.aspx

Code download: http://code.msdn.microsoft.com/mag200902Silverlight

 

Regards,

Hanu


This post originated from and is provided by the MSDN Blogs RSS feed. The original post of the article can be found here.

Posted in MSDN Blogs | Comments Off

Spooky

Posted by on 5th July 2009

Weird…I was reading a piece in The Sunday Times this morning about the return of Lance Armstrong to the Tour De France and a new video fro Nike to accompany the return. It reminded me that yesterday I was talking with my brother about Lance’s return and just after that chat we were listening to a great piece of music by Mogwai that was used in Miami Vice….

Spooky then that when I searched for the new ad on YouTube it used that same Mogwai piece. Cool ad too…

the tune is called Auto Rock


This post originated from and is provided by the MSDN Blogs RSS feed. The original post of the article can be found here.

Posted in MSDN Blogs | Comments Off