Perfil de PaulioIT BytesBlogListasScraps Ferramentas Ajuda

Blog


28 de agosto

iE6 + default Silverlight + https = unsecure prompt

IE6 (ah bless) is oddly paranoid when rendering https sites. This can be seen when it attempts to use a page that contains a Silverlight application. The problem stems from the default template Visual Studio generates for hosting the application. It contains a invisible iFrame element, apparently to support Safari. However, if you attempt follow the links to explain why Safari needs such a hack you hit a dead-end. Assuming that was because Safari 4 has since been released I tested the previous problem, that you can't correctly browser-back to a page with SL content. It seems to work fine. However, Ken Tucker pointed out that Silverlight Navigation now requires the use of this iFrame. So the simplest solutions is to add a src="#' attribute to the iFrame - this doesn't seem to cause any problems to "modern" browsers and IE6 now understands that the src is secure.

27 de agosto

Upgrading from 5.3.1 to 5.3.4

For some strange reason when my existing projects referenced Type Mock and Type Mock Isolator it would mark Type Mock as copy local true and Isolator as false. However, after upgrading to 5.3.4 when I add a reference the opposite occurs. This causes a problem when upgrading a project and the project continues to use Type Mock as the local copy (5.3.1) and Isolator and the new version (5.3.4). This leads to some strange behaviour. So double check your references after upgrading.
 
22 de agosto

Using Blend to set the colour of the text in a button

Silverlight & Blend try and encourage you to separate styles and structure in much the same way as you should with HTML and CSS. However, Blend can be confusing as it will offer up some properties to be changed but “hide” others. One example of this is the seemingly simple task of changing the colour of the text in a button. You’d be forgiven for thinking you can select the button and directly edit the foreground colour since the background is available. You must ignore this temptation, if you don’t attempt to make style changes directly to the structure (control) then you’ll avoid a lot of confusion. I’ve created a little tutorial to show one way of solving this;

  1. Create a new project in Blend and accept the defaults.
    image
  2. Add a button
    image
  3. Select the button, hint using the control tree is often more reliable, right-click and choose Edit Templatate->Edit a Copy. To promote separation I recommend saving the style to the Application. You should give the style a good name, but I’ll be naughty and leave it at ButtonStyle1
    image
  4. You’ll now find yourself in the Template for the button. Ignore this and return the MainPage.xaml (there is a quicker way but lets keep things simple). Now you want to change the colour of the button, so you need to edit the buttons style. Select the Resources tab and click the button to edit ButtonStyle1
    image
  5. Now switch back to the Properties tab and you can change the Foreground (remember to drag the little colour select from the bottom left of the selector).
    image
  6. All done.

So the “take home” from this is don’t make style changes directly to your controls always look at changing the separate style xaml, not only will you have better separation but you’ll avoid a lot of frustration when trying to find the property you want to change.


17 de agosto

Update Service Reference not working?

The integration provided by Visual Studio between Silverlight and and WCF Service is good but can be frustrating. Here are a couple of simple things to try when things don't appear to be working;
1. I've created/changed my service but when I update the reference or attempt to discover the new sevice it can't be found - make sure the service has built by rebuilding the service
2. I've changed the service and ran 'update the service reference' but my Silverlight code cannot see the changes, in fact it seems to have lost all references to the proxy code - rebuild (not compile) the Silverlight project.
 

15 de agosto

Windows 7 64bit, sharing Canon printer with 32bit clients

My trusty Canon MP800 printer was shared to my home network via it's Vista 32-bit host, however I've now installed Windows 7 64-bit. The problem is that although you can share the printer easily enough you have to allow the "server" to have the 32bit drivers available to the clients. The problem is that when you tick the 32bit architecture and try and search for the drivers it won't detect them, I'm guessing the downloaded 32bit driver package hides the actual drivers until you do a normal install. You can't do a normal 32bit on a 64bit OS. Luckily I discovered this post that I've duplicated (in case it gets losts);
 
 
To share printers across a network between Vista x64 and any other operating
> system do the following.
>
> Vista
> ------
> Click Start >>
Control Panel >> Hardware and Sound >> Printers
> Click on Add a printer
> Select Add a local printer
> Create a new port >> Local Port >> Click on Next
> Enter the port name for the network printer (i.e. \\
Computer Name\Printer
> Name)
> Select the printer from the list
> Continue until the printer is installed.
>
> Other operating systems
> ----------------------------
> Find the Add printer wizard and do exactly the same method as for Vista.
>
> With any luck your printer will already have printer
drivers included with
> Vista and obtaining drivers for other operating systems if they are missing
> should not be a problem.
>

13 de agosto

Windows 7, where has my DVD Drive gone?

Just had a problem burning a file to disc, when I rebooted and checked "my computer" the drive had vanished. After checking the Device Manager el al I couldn't find any problems. Then I realised what was happening, it now only shows the drive if there is something in it to read! Gotcha!
 
12 de agosto

Digitally code signing Office VBA macro

Had some fun today with code signing some macro's in Excel. Applying a code signing certificate is very easy, simply go to the visual basic editor, tools->Signing and you're away. The problem is creating the correct type of certificate in the first place.

My sys admins provided with a p7b certificate. So I installed that, but it didn't show in VBs available certificates. So I thought I'd better try and understand what was going on. In turns out that I need a pfx certificate and a p7b is just part of formula for creating such a beast. You need the private key used to create the original certificate together with the p7b;

pvk2pfx -pvk privateKey.pvk -spc codeSignCert.p7b -pfx actualCodeSign.pfx -po myPassword -f

That will challenge you for the password used to create the original certificate but will produce required pfx file. Now just install that and it should be available for signing

09 de agosto

Windows 7 on Parallels

Vista on Parallels 3 was good, Vista on Parallels 4 was terrible. So I wasn't too bothered in ditching my Vista VM and installing Windows 7, even though it's only marked as 'experimental'. Well so far it's been as good as P3, so I'm very happy with it. Don't know where the blame falls for P4+Vista but P4+Win7 is worth having.

How to install BT Netprotect on Windows 7

After installing Windows 7 I realised I needed to install my antivirus software so off to BT to download Netprotect. However, the download page incorrectly assumes that if the OS isn't XP or Vista then it must be a really old version of Windows - Bzzzt. I first tried to persuade IE to launch in compatibility mode but to no avail. So I donwloaded Firefox, went to the properties, switched compatbiblity mode to run as Vista and downloaded NetProtect - fooled it.
 
 
02 de agosto

Sharing ASP Session state with Silverlight

I’ve been working on a Silverlight project that where the SL application is used within an authenticated ASP.net site. During my testing I found a problem where using Silverlight 3’s Out-Of-Browser feature seem to lose the session token between calls to the site, i.e. I could logon but the next call would fail as if the user had not logged on. After a couple of Twitter conversations it became apparent that it should work. So I decided to take my testing back to basics, so first off can a Silverlight application use ASP session state?

  1. Create a basic Silverlight application – create a Silverlight application with a web project to host it
  2. Create a basic web service – with the web project selected add a new Silverlight WCF service, called SessionTest.svc
    image
  3. Implement some very simple interactions with the Session State

    [ServiceContract(Namespace = "")]

        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

        public class SessionTest

        {

            [OperationContract]

            public void SetState(string value)

            {

                // Add your operation implementation here

                HttpContext.Current.Session["TestState"] = value;

                return;

            }

     

            [OperationContract]

            public string GetState()

            {

                // Add your operation implementation here

                return (string)HttpContext.Current.Session["TestState"];

            }

        }

  4. Add a Service Reference from your Silverlight application to your service, add appropriate using statements to your code-behind.

  5. Create some simple controls in your Silverlight application

    <StackPanel>

        <StackPanel Orientation="Horizontal">

            <Button x:Name="ButtonGetState"  Content="Get State" Click="ButtonGetState_Click" Width="60" ></Button>

            <TextBlock x:Name="TextBlockCurrentState" Width="100"></TextBlock>               

        </StackPanel>

        <StackPanel Orientation="Horizontal">

            <TextBox x:Name="TextBoxNewState" Text="" Width="100"></TextBox>

            <Button x:Name="ButtonSetState" Content="Set State" Click="ButtonSetState_Click" Width="60"></Button>

        </StackPanel>

    </StackPanel>

  6. Add code to the Silverlight application to communicate with the Service

    private void ButtonGetState_Click(object sender, RoutedEventArgs e)

            {

                SessionTestClient client = new SessionTestClient();

                client.GetStateCompleted += (object completedSender, GetStateCompletedEventArgs completedE) =>

                    {

                        if (completedE.Error == null)

                        {

                            TextBlockCurrentState.Text = completedE.Result;

                        }

                    };

                client.GetStateAsync();

            }

     

            private void ButtonSetState_Click(object sender, RoutedEventArgs e)

            {

                SessionTestClient client = new SessionTestClient();

                client.SetStateCompleted += (object completedSender, AsyncCompletedEventArgs completedE) =>

                    {

                        if (completedE.Error == null)

                        {

                            TextBlockCurrentState.Text = "";

                        }

                    };

                client.SetStateAsync(TextBoxNewState.Text);

            }

  7. Run the code, you should see that after you set a value you can retrieve the same value.

So we now know for sure that we can communicate with ASP.net and share the session state with the page. If you make the Silverlight application OOB (select project properties and check the OOB box) you’ll see that it continues to work without any problems. So this is good news, all I have to do now is track down why it isn’t working in my real application.