in

mscommunity.net

Interactive mscommunity.net online activities

DamirDobric

studeni 2009 - Posts

  • How to prevent Caching of Images in Silverlight?

    When working with images in Silverlight it might be sometimes required to prevent caching. As long you just present some photos  the caching feature is definitely a great one. However if you bind to frequently changing images like charts, you will need to download images on each request or binding refresh. In such cases you could experience few problems:

    1. What ever you do Silverlight will never download the image again after it is cached once.
    2. If you append dynamic arguments,SIlverlight will sometimes download images, but sometime just show them from cache.

    Problem Description

    To illustrate the problem let’s use image with following binding:

     <Image Stretch="Uniform"  Grid.Column="1"  Visibility="Visible"  Source="{Binding ImageUri}"/>

    Once the image is downloaded (after first binding) image is persisted in the browser cache. That means image will never be downloaded again. SOme people believe, that image is downloaded again on every browser start, but this is not true. This explains issue [1].

    To workaround this problem I tried using of different simple techniques like appending of arguments to image name:

    myBIndingEntity.ImageUri += DateTime.Now.Ticks;

    Unfortinatelly browser cache has very interesting algorithm to check if one file is in cache. For example the file name abc.jpeg?blablabla
    will be stored in the cache as abc[1].jpeg. So, by trying different combinations of parameters image will be cached as abc[1].jpeg, abc[2].jpeg etc.
    Depending on how you have created the dynamic name of the new URI it can happen that the new URI cause browser to treat it as abcNo.jpeg, which never has been cached. This cause the browser to download the image once and persist it under name abc.jpeg.
    On the next dynamic name every transformation to abc[k] ( 1 < k < N) will prebent the Silverlight application to download image.

    In this case you will have a feeling that images are sometimes downloaded and sometimes just shown from the cache. This explains the issue [2].

    Following picture shows what the browser cache looks like in the case of image SingleSlide_256_t4trust-aLifePass-Flyer.jpg :

    image

    One more thing. If the source in binding of the image is relative one, Silverlight will start donwloading of the image with URI without of any additional parameters which you have added.

    For example the image ImageName.jpg?MyParam=abcefg will be sent over network as (notice no arguments are appended):

    GET /Daenet.SLPresentationManagerGui.Web/ClientBin/ImageName.jpg HTTP/1.1

    Solution

    To solve the problem Microsoft provided property BitmapCreateOptions.IgnoreImageCache. Unfortunately this does not work for some reason.
    I figured out that Silverlight always do caching if the image is bind as relative one. To make it working I implemented the convertEr which binds the image as absolute one:

     

    Here is the binding via converter:

     <Image Stretch="Uniform"  Grid.Column="1"  Visibility="Visible" 
                              
    Source="{Binding ImageUri, Converter={StaticResource ImageSourceConverter}}"/>

    … and here is the converter itself:

    public object Convert( object value, Type targetType,
                           object parameter, 
                           System.Globalization.CultureInfo culture )      
    {

        if (value == null)
          
    return null;

       

        Image img = new Image();

        Uri uri = new Uri(“http://host/virtfolder/”, UriKind.Absolute);
       
    BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage(uri);

        //bi.CreateOptions = BitmapCreateOptions.IgnoreImageCache; (This does not work anyhow!)

        img.Source = bi;
        
       
    return img.Source;
    }      

    Notice that property CreateOptions is commented out, because it does not work. After this is done, take a look in Fiddler.You will notice, that the image is downloaded on every single binding. Using of dynamic arguments is important in this example. They cause Silverlight to use other way when working with the cache:

    GET /Daenet.SLPresentationManagerGui.Web/ClientBin/PresentationThumbnails/80bede99-75bb-4225-95ff-d15b3170c426/ImageName.jpg?633951716001752447 HTTP/1.1

     

    Hope this helps… :)

     

     

     

     

     

  • Get the Office 2010 and SharePoint 2010 Betas

     

    Download the Microsoft Office Professional Plus 2010 Beta

    Get the new Microsoft Office Professional Plus 2010 beta release. Also check out the new Microsoft Visio 2010 beta.

     

    Evaluate the SharePoint Server Enterprise 2010 Beta

    Download the new SharePoint Server Enterprise 2010 beta release. You can also download the new Microsoft FAST Search Server 2010 for SharePoint beta.

  • Windows Server AppFabric or “Bye bye Dublin”

    Application Server Dublin and Velocity are two technologies which from now have one name “AppFabric”. Windows Server AppFabric is a set of integrated technologies (Dublin, Velocity and Service Bus) that make it easier to build, scale and manage web and composite applications that run on IIS.


    The publicly available Beta 1 will be provided at this Windows Server Development Center soon.

  • Windows Azure SLA-s

    Just want to point out that few minutes ago, Microsoft has published two SLA documents for Windows Azure platform AppFabric Access Control and Windows Azure platform AppFabric Service Bus.

    More information can be found here.

  • Implementing Custom Map in Silverlight Map Control

    Few months ago I described shortly how to about how to integrate the custom map instead of the standard one provided by Silverlight Map control (released few days ago).

    The code compatible with Map Control 1.0 is shown below:

    // This removes standard Virtual Earth map.
    // If you do not have this line of code, your custom map will be tailed over the
    // standard one.


    m_WorldMap.Mode = MercatorMode;

    // Create a Tile Layer that will display our custom Map Imagery Tiles
    var customTileLayer = new MapTileLayer();

    // Create a LocationRectTileSource
    LocationRectTileSource customTileSource = new LocationRectTileSource();

    // Set the Uri for the custom Map Imagery Tiles c
    customTileSource.UriFormat = uriFormat;

    // Set the Min and Max Zoom Levels that the imagery is to be visible within
    customTileSource.ZoomRange = 3;

    // The bounding rectangle area that the tile overaly is valid in.
    customTileSource.BoundingRectangle = boundingRect;

    // Add the Tile Source to the Tile Layer
    customTileLayer.TileSources.Add(customTileSource);

    // Set the Tile Layer Opacity to a desired value
    customTileLayer.Opacity = 1;

    customTileLayer.BorderBrush = new SolidColorBrush(Colors.Blue);

    In the code above I marked the variable uriFormat which is crucial one in this case. If you already have created custom map by using of CTP version of Map Control the uri fromat looks like:

    http://www.daenet.eu/share/Maps/Cockpit/Layer_NewLayer/{0}.png

    Unfortunately after installing of the release version of control you will notice that the map will just not appear. The reason is that the uri Format has been slightly changed now. After digging in reflector I figured out that following uri format will work now:

    {UriScheme}://www.daenet.eu/share/Maps/Cockpit/Layer_NewLayer/{quadkey}.png

     

     

     


  • Attach Debugger Security Warning

    While debugging you WCF-Service or ASP.NET application within UnitTest you may get following warning when stepping into the service code.

    “Attaching to this process can potentially harm your computer…”

    For example, this can happen when you have the UnitTest which invokes the Service via generate Proxy instance. When you start the UnitTest method in debugger the Visual Studio will attach VsTest.exe process. However, if you want to step into the service code (by pressing “F11”) the Visual Studio will first have to attach to the process which hosts the service. This might be Cassini or IIS. At this moment you may get following warning:

    image

    If you have been doing this for a while you might be surprised that this message sometimes appears and sometimes not. If you have this feeling you are right.
    This message will appear if the attaching process which hosts the service is hosted by user which has no debugging permissions. Mostly this just mean it is not the local admin. More precisely, if the host is a process started by IIS (w3wp.exe) the host identity is defined by identity of the pool of the web application which hosts the service.

     

    So, if the pool’s identity has no permission for debugging the message shown above will be popped up. Please be also aware that when working in team you will sometimes be forced to create (next picture) the local directory. In this case IIS will automatically setup the application to default pool, which by default (NETWORK_SERVICE) has no debugging permission.

    image

  • Working with certificates in Internet Explorer

    When you visit a website that uses a secure (SSL) connection, the color of the Security Status bar tells you whether the certificate is valid or not. These colors inform you about some kind of security level of the connection (certificate).

    The following describes what that colors mean.

    Red

    The certificate is out of date, invalid, or has an error. For more information see About Certificate Errors.

    Yellow

    The authenticity of the certificate or certification authority that issued it cannot be verified. This might indicate a problem with the certification authority's website.

    White

    The certificate has normal validation. This means that communication between your browser and the website is encrypted. The certification authority makes no assertion about the business practices of the website.

    Green

    The certificate uses extended validation. This means that communication between your browser and website is encrypted and that the certification authority has confirmed the website is owned or operated by a business that is legally organized under the jurisdiction shown in the certificate and on the Security Status bar. The certification authority makes no assertion about the business practices of the website.

    More about this here.

  • Bing Maps Silverlight Control

    UNPRECEDENTED INNOVATION - Bing Maps now includes a Silverlight Control, so that the rich, multimedia benefits native to Silverlight, like embedded video, can now be integrated into Bing Maps.

    Please note that the CTP control will cease to function at midnight, December 31, 2009. to ensure continued functionality, please make plans to upgrade your applications to the version 1 code before that time. For a description of the version 1 changes from the CTP build, please visit the changelist reference in the SDK here.

    The Connect site will remain available until December 15th for reference purposes only. Future technical questions/discussion should be directed to the Bing Map Control Development forum on MSDN (paid, evaluation, and free account types) or to the Bing Maps Enterprise Support Team (paid accounts).

    PLATFORM PERFORMANCE - Our commitment to fast and accurate performance for users across the world continues with this latest release, including our growing network of global data centers that bring both services and content closer to our customers and their end users, as well as improved search and geocoding capabilities in Germany, the U.K., and the U.S.

    EASY TO USE - New lightweight "keys" make the authentication process faster and easier, and provide access to the rich features of the Bing Maps APIs.

  • Managed Extensibility Framework in MSDN Flash

    Editorial

    For all German speaking visitors, I would like to point out my MSDN article, which introduce Managed Extensibility Framework.

    If you would like to see how to build Composed Applications with .NET 4.0 I would highly recommend to take a look on MEF.

    . Klassisch: http://msdn.microsoft.com/de-de/library/ee332203(classic).aspx
    . Kompakt (neu): http://msdn.microsoft.com/de-de/library/ee332203(lightweight).aspx
    . Ohne Skripts (neu): http://msdn.microsoft.com/de-de/library/ee332203(loband).aspx

    Damir

Powered by Community Server (Commercial Edition), by Telligent Systems