Flores
terug naar het overzicht

One of the programming      guys

I’m passionate about technology in general and particularly about software development. Specializing in Microsoft .NET, I can handle the entire process, from installing a Team Foundation Server to the smallest programming detail. Always innovating and on the cutting edge.

CanReorderItems="true"

door Flores 10-2-2012

Disclaimer: this is written for the Windows 8 Developer Preview

That’s a new property on the ListViewBase in Metro Style Windows 8 apps. ListView and GridView inherit from this base.

I think it’s a GREAT feature.. it allows the user to drag around items in the gridview or listview and animates this nicely:

image

But, there are some things you need to know to get it to work. First of all the AllowDrop property also needs to be set to true.

And the grid or list needs to be binded to a ObservableVector (no ObservableCollection is not good enough). But in the developer preview only an interface exists for this collection, so you have to make your own implementation or borrow one.. like this one.

One caveat remains.. the ObservableVector needs to be initialized with object as T, strong types will not work in the developer preview of windows 8. Like so:

image

Hope this helps.

Tags:

Inherit the asp.net menu control

door Flores 13-12-2011

I want to make a very specific menu, so I decided on creating a custom menu control like this:

public class MyMenu : System.Web.UI.WebControls.Menu

I want to override the existing menu control to be able to use the databinding capabilities, I want to use this menu with a sitemapprovider.

To be able to create my own menu HTML output I need to override the Render method:

protected override void Render(System.Web.UI.HtmlTextWriter writer)

Once you do that and don’t want to call the base.Render method, you are going to run into this runtime error:

image

Microsoft JScript runtime error: Unable to get value of the property 'tagName': object is null or undefined.

This is because the scripts from the asp.net menu control expect certain elements. The fix for this is to override the OnPreRender method and do NOT call the base:

protected override void OnPreRender(EventArgs e)
{
     //prevent scripts from loading
     //base.OnPreRender(e);
}

Now the control works, but when you set the DataSourceID the Items collection stays empty. I took me a while to find out this one: the solution is to call the PerformDataBinding method in the Render method. After this call you can use the Items collection to build your menu:

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
    this.PerformDataBinding();

    writer.Write("<div id='menu'>");

    foreach (MenuItem item in Items)
    {
        ..your code here..
    }

    writer.Write("</div>");
}

Hope this helps.

Tags:

CallContext

door Flores 16-11-2011

I’m working on a web application that handles pages that are executed within the context of a chosen department. Some pages require a selected department, some don’t. The application is split into tiers, so I have a UI layer,business layer and data layer.

One of the customer requirements is that every change in the database is logged, this logging will occur in a separate database table. One of the fields in the logging is the selected department.

Because of the large amount of methods I wanted to implement a generic principle for transporting the current department, other than adding it to every method in every layer as a parameter. Something like

 
Thread.CurrentPrincipal.Identity.Name

It’s always there, and that rather helpful. It can be used in the data layer without passing it as a parameter.

A session variable won’t do, once it is set I will stay set. If I use a page that has no department context after a page that does, it will look like the page without a department context gets used in de department context. Unless I set and reset the session variable on every page… but that’s not a nice solution.

I would like to push the department on the callstack in the UI layer en pull it out again in the data layer. Took me some time to find it, but it can be done! CallContext is your friend, this is what it will do:

public void Method1() 
{ 
    CallContext.SetData("Key", 1); 
    Method2(); 
} 
 
public void Method2() 
{ 
    int value = (int)CallContext.GetData("Key"); 
} 

Perfect for my problem, because this also works between different layers. According to MSDN this is the description:

Provides a set of properties that are carried with the execution code path.

So it can be used by all the methods in the callstack.

The rest is easy, create a BasePage class that inherits from Page for the pages with department context, and call the CallContext.SetData in the masterpage for the pages of the BasePage class.

Tags:

Catching WCF exceptions

door Flores 12-6-2011

I’m developing a self hosted (in a console application) WCF service which returns a JSON result. This service has two operation contracts, one that returns only a string and one that returns an object.

After starting the application the service can be checked by opening a browser and pointing it to the correct url. The operation that returns a string works as expected, it returns a string, but the one that returns the object behaves strange. This is the result in the browser:

image

This must have something to do with the serialization of the object.. but what? why is there no exception thrown? Let me check my VS settings:

image

Okay.. that should catch everything.. but clearly it doesn’t.

I took me a while to find the solution, and I won’t bother you with a the details of everything I tried. This is the solution:

Your service should implement the IServiceBehavior:

   1:    [ServiceContract]
   2:      public class TestService : IServiceBehavior
   3:      {
   4:          [OperationContract]
   5:          [WebGet(ResponseFormat = WebMessageFormat.Json)]
   6:          public string SayHello()
   7:          {
   8:    ..

In the implementation of this interface enter this:

 

 
   6:  public void ApplyDispatchBehavior(ServiceDescription 
              serviceDescription, ServiceHostBase serviceHostBase)
   7:  {
   8:     foreach (ChannelDispatcher channel in 
                           serviceHostBase.ChannelDispatchers) 
   9:     { 
  10:          channel.ErrorHandlers.Add(new ErrorHandler()); 
  11:     }
  12:  }

And create this class:

   1:      public class ErrorHandler : IErrorHandler
   2:      {
   3:          bool IErrorHandler.HandleError(Exception error)
   4:          {
   5:              return true;
   6:          }
   7:          void IErrorHandler.ProvideFault(Exception error, 
                          MessageVersion version, ref Message fault)
   8:          {
   9:          }
  10:      }

Now make “return true” a breakpoint and it will show you the exception:

image

{"DateTime values that are greater than DateTime.MaxValue or smaller than DateTime.MinValue when converted to UTC cannot be serialized to JSON."}

Ha..sure.. easy to fix if you know the exception….

Now you know how to get it.

Tags:

SQL Server Error: 100054

door Flores 20-4-2011

Das een makkie.. die ken ik. Unable to create connection..

De scene:

-Microsoft SQL server 2005 op server 2003
- XP clients custom .NET 4 applicatie

De applicatie werkt niet omdat deze geen connectie kan maken met de database. Meestal ligt dit probleem aan de server, binding vergeten te activeren, firewall etc.

Zo niet deze keer.. de server was perfect te benaderen vanaf een andere machine. Dan moet het aan de custom applicatie liggen.. toch? Eens SQL management studio opstarten.. he.. die doet het ook niet.. met dezelfde foutmelding.

Hmmm..ligt het misschien dan toch aan de server.. de management studio doet het eigenlijk altijd.. of moet ik die misschien een keer opnieuw installeren?

Enfin.. 3 troubleshooting guides, network monitors, logfiles en een hoop ergernis verder is het probleem gevonden:

De betreffende machine wordt gebruikt als Visual Studio 2010 Load test agent, en bij de installatie van deze software wordt ook een Microsoft VSTS Network Emulation Driver geinstalleerd, en deze is het probleem.

Blijkbaar blokkeert deze driver specifiek alleen mijn SQL verkeer ofzo want na het uitvinken werkt alles weer goed… raar verhaal.

image

Ik heb hier nergens op het web iets over gevonden, vandaar dat ik het maar even vastleg.. Het komt vast door een vreemde combinatie van omstandigheden.. maar mocht iemand er ook last van hebben dan krijgt hij in google nu in ieder geval 1 result.

Tags:

Service manager 2010 setup

door Flores 13-11-2010

Ik wilde Microsoft System Center Service Manager van dichtbij bekijken, dus gedownload van MSDN gemount in een nieuwe 2008 R2 installatie en setup starten.

image

Huh.. crap..chinees? japans? verkeerde ISO gedownload zeker, even checken..

image

Hmm… das toch echt de goede, en er is er maar 1.. dus ik heb weinig keus.

5 minuten Googlen op alle keywoorden levert niets op..Maar er staat een giveaway tussen het chinees.. .NET 3.5.. misschien moet ik die eerst installeren? Gedaan.. image

..en aha het werkt..

Tags:

Niet alleen cloud is niet zo snel

door Flores 2-11-2010

Ook het support wat er bij hoort gaat allemaal niet zo hard.

De MSDN subscription die ik heb omvat ook SQL Azure, 3 databases als het goed is.
Alleen als ik in het control panel kijk dan zie ik wel een SQL Project, maar daar kan ik niets mee omdat deze disabled is. Ik dus via dat control panel een case ingediend dat mijn SQL Azure service disabled is. Dit was op zondagmiddag, en blijkbaar worden die cases alleen met US office hours bekeken want ik kreeg pas om 16:30 de volgende dag bericht terug.

En dit was het antwoord:

I have taken a look at the screenshot you sent me and searched your subscription within our system. I was able to find the MSDN Premium subscription and was able to verify that the subscription is active, so you should be able to create databases.

I would like to advise you to contact our Frontline Azure Support (FAS) directly through
https://support.microsoft.com/ , as I am unable to assist you in this matter directly.

Juist. Blijkbaar heb ik de verkeerde helpdesk te pakken ofzo.. terwijl ik wel de instructies gevolgd heb.. beetje zonde van de doorlooptijd zo. Goed, dus een nieuw support request aangemaakt, om 17:00 was dat.. en volgens de site zelf zat er een response tijd van 1 uur op het issue... ben benieuwd. 3 uur later bericht dat er een engineer togewezen is aan mijn case, maar verder niets inhoudelijks. Nog maar een uurtje wachten... niets.. dan maar zelf een mailtje sturen. Half uur later een inhoudelijk bericht:

Issue Definition: We understand that that your SQL azure Service is disabled for the newly purchased MSDN subscription and you would like to activate the service.
Scope Agreement: We would enable the SQL azure Service for your subscription at the earliest and shall update you with the status of the issue at the earliest. We would like to inform you that it may take up to 24 hours for us to activate your subscription.

Okay. weer 24 uur wachten dus.

Al met al (zie ook hier) krijg ik niet echt een warm gevoel bij die Azure cloud. En de cloud en ik hebben niet echt een goede start gehad samen op deze manier, maar ik geef nog niet op hoor.. wordt vervolgd

EDIT: Het werkt inmiddels. 8 uur na de initiele melding bij Azure Frontline Support.

Tags:

Cloud

Cloud == Traag ?

door Flores 31-10-2010

Als je in het bezit bent van een MSDN Premium abbonnement dan kan je gratis gebruik maken van de Microsoft Azure Cloud, zie hier.

Gelijk ingeschreven natuurlijk en de SDK voor VS 2010 geïnstalleerd en mijn eerste cloud applicatie gemaakt: ‘Hello cloud’.

Dat is zo simpel als wat, als je het goede template kiest dan ben je eigenlijk al klaar. In Visual Studio zit een optie om deze applicatie gelijk te deployen naar een staging omgeving in de cloud.. gelijk proberen natuurlijk:

11:13:16 PM - Preparing...
11:13:16 PM - Connecting...
11:13:17 PM - Uploading...
11:13:31 PM - Creating...
11:15:29 PM - Starting...
11:16:09 PM - Initializing...
11:16:09 PM - Instance 0 of role WebRole1 is initializing
11:22:54 PM - Instance 0 of role WebRole1 is busy
11:28:30 PM - Instance 0 of role WebRole1 is ready
11:28:31 PM - Complete.

Wat… duurt gewoon 15 minuten. Dat is wel een beetje lang.. als het eenmaal draait is de applicatie wel heel snel, dat wel. Morgen nog maar eens proberen.

Dag later dezelfde applicatie nog een keer gedeployed naar de cloud:

9:32:27 AM - Preparing...
9:32:27 AM - Connecting...
9:32:28 AM - Uploading...
9:32:44 AM - Creating...
9:33:22 AM - Starting...
9:34:01 AM - Initializing...
9:34:01 AM - Instance 0 of role WebRole1 is initializing
10:05:52 AM - Instance 0 of role WebRole1 is busy
10:12:00 AM - Instance 0 of role WebRole1 is ready
10:12:00 AM - Complete.

Ahum.. bijna 45 minuten om mijn ‘Hello cloud’ te stagen in de cloud. Als ik een foutje ontdek dan ben ik dus zomaar 2 uur verder om een goede versie in de cloud te krijgen.

Er zullen onderwater vast hele belangrijke dingen gebeuren maar ik ben wel een beetje teleurgesteld.. behalve dat het lang duurt (ik vind 15 min al lang) blijkt die tijd ook nog eens enorm te varieren… en niet in mijn voordeel.

Tags:

Silverlight vs HTML5

door Flores 30-10-2010

De planning van de PDC sessies bevatte al weinig sessies over silverlight, en het feit dat er geen nieuwe versie werd aangekondigd in combinatie met de aandacht voor IE9 en HTML5 in de keynote doet vermoeden dat Microsoft z’n strategie heeft aangepast.

Er naar gevraagd zegt Bob Muglia van Microsoft:

“Silverlight is our development platform for Windows Phone, Silverlight also has some “sweet spots” in media and line-of-business applications. But when it comes to touting Silverlight as Microsoft’s vehicle for delivering a cross-platform runtime, ‘our strategy has shifted’, Silverlight will continue to be a cross-platform solution, working on a variety of operating system/browser platforms, but HTML is the only true cross platform solution for everything.” bron.

Alleen heeft Microsoft behalve de nieuwe versie van IE helemaal geen tools of iets dergelijks aangekondigd voor HTML5, ik denk dat we daarop moeten wachten tot de MIX in maart 2011.

Maar het begint er sterk op te lijken dat HTML5 de nieuwe standaard wordt.

imagesCAY1MNSA

Tags:

This is an invalid webresource request.

door Flores 30-10-2010

Ik heb net een nieuwe (virtuele) server geïnstalleerd met windows server 2008 R2. Een van de laatste test builds van Provisior geplaatst en alles loopt goed.

Er is een specifieke bug die ik wil testen dus merge alleen die fix naar de branch waarmee ik test. Start een nieuwe build en installeer deze.

HE.. grafisch gaat er van alles mis… het lijkt wel of de stylesheets van de 3rd party controls die we gebruiken niet geladen worden. In de source staat dit:

<link href="/WebResource.axd?d=YNVbZPZmGH01&amp;t=634208710393681275"/>

(ik heb het iets ingekort) En dat is de link naar de stylesheet van dat control. Deze dan maar eens met de hand laden:

        This is an invalid webresource request.

Een error aha.. maar dit kan bijna niet aan mijn code liggen, ik heb namelijk alleen een kleine wijziging gemaakt heel ergens anders. En 10 minuten geleden werkt het nog.. dus het kan ook niet aan de server liggen.. of toch?

Het heeft me even googlen gekost, maar de oplossing is simpel.

Het request naar webresource.axd bevat een timestamp, de t=634208710393681275

En als de datum\tijd van de applicatie assemblies in de toekomst ligt van deze tijd dan krijg je de foutmelding “This is an invalid webresource request.”

Hoe kan het dan dat mijn assemblies een create tijd hebben in de toekomst? Simpel: de server staat toevallig op een andere tijdzone ingesteld.

Dat is ook de reden dat het met de ene build goed gaat en met de andere fout. De eerste test deed ik met een build van een paar uur geleden (zodat deze ondanks de verkeerde zone toch nog ouder was) en de laatste test met een build van een paar minuten geleden.

Tijdzone gelijk zetten, bestanden opnieuw kopieren, en alles werkt weer.

Tags: