CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

November 2004 - Posts

  • Comment spam, Outlook 2003 and .text

    When your blog gets spammed you receive an email notification. And can take action. Outlook has a spam filter; it will dump (some of) these spam comments in the Junk mail folder. And you'll miss it. There is only one solution: again and again I'm begging for an update of the .text engine. Not to mention the problem on getting anything posted before it gets spammed, like Stefano has described.

    Peter

  • Dotned went North

    Yesterday, november 25th, Dutch user group dotned had a meeting hosted by DTS in Meppel. Which is in the Northern part of the country. Nice for me but for the most of my fellow Dutch .net-ers it was an occasion for a favorite hobby over here : complaining about the traffic. In the Netherlands travelling more than 2 hours is considered to much. Most people arrived late; Hasan, up till yesterday, the most faitfull visitor didn't even show up...

    We had a preview of the upcoming Enterprise Library. This will wrap up most of the MS application blocks and adds a very nice configuration tool. Avanade has built a library on top of that. Dennis Mulder tried to give an overview of how to use the library and how to fiddle with the source code of the lib. Perhaps that was a little to much for the time available. But I got a good starting point for Enterprise Libs. Most of my customers don't belong to the fortune-100 Denis's company is targeting but Enterprise Library is interesting to any .net application.

    The hosting company DTS is a Delphi and a Java shop. In their introduction they spoke of Delphi being a product nearing the end of it's lide cycle and DTS setting up a new C# branch. To be followed by the presentation on...... : Delphi 2005. Which targets multiple languages: Object Pascal and C#; as well as multiple platforms: Win 32 and .net. To me it is becoming vaguer and vaguer what the moniker Delphi stands for: the language or the IDE. According to the latest insights it's the IDE again ? Which looks like a Visual Studio clone, works better than Borlands first C#builder attempts and has (in the Architect version) ECO, a very nice UML integration.

    I had a pleasant drive home.

    Peter

  • (Changing) the length of a database text field and asp.net apps

    The title suggest this should be a trivial matter. To get my user's satisfied I found some points to watch:

    • The amount of text the user can enter in a textbox on a webform is unlimited. The amount of space to store the text in the database is. To prevent the user typing in to much you set the MaxLength property of the textbox. By default this is 0, signifying no max.
    • When the columns type in the DB is set to char the content is padded with trailing spaces in the database. When the user tries to insert characters in a textbox where MaxLength has been set the trailing spaces will bump against the max and the input is stuck. The user first has to trim off the trailing spaces. VarChar columns don't suffer from this behavior.
    • When you change the length of of a text column you have to check all update and insertcommands of dataadapters working on the table. The column is in the parameter-lists and parameters have a length. You have to update those as well.

    Peter

  • Article on tablet PC development

    The site of the SDN, the Dutch user group for .NET, Delphi, Fox and VO and Clipper developers with a very rich history, has put my tablet PC article on line. The story is a fast rush though the tablet and the SDK. With many, many hooks for sequels. Who knows...

    Peter

     

  • A tool to check IIS permissions

    This is a nice diagnostics tool to check (amongst others) permissions in IIS. As experienced by many others one of the major reasons for “The Web server reported the following error when attempting to create or open the Web project located at the following“ is a lack of permissions for the asp.net acccount. This tool will help you to get an overview

    Peter

    Posted Nov 15 2004, 12:09 PM by pvanooijen with no comments
    Filed under:
  • Debugging Tablet PC applications

    A tablet PC is fun, writing apps for a tablet is even more fun. But it took me some time to find out the easiest way to do that. You can write tablet apps on every PC which has the SDK installed but tablet specific features such as text recognition only work on a tablet. A tablet PC is powerfull enough to run Visual Studio but a pen is not the ideal device to enter code. The keyboard and screen real estate of my desktop are a nicer coding environment.

    Instead of strapping in my tablet with cables for an external monitor and keyboard I now use two machines in sync to build the app. Both work on the same project, the desktop shares the directory of the tablet-project on the local network, the tablet opens the project from this network directory. Visual Studio will keep the two instances in sync. Every time you change a file on one of the machines it pops up a dialog.

    Click yes to continue.

    There is a security issue when opening the project over the network. VS will warn you for that.

    As the tablet assemblies wrap up unmanaged code security will hit harder when you share that over the network. Make sure the Microsoft.Ink assembly is installed on both machines and that the project references it using a relative local directory. Then you will have a very good debugging "experience". Your desktop to hammer in code and your tablet to strikeout the bugs.

    Peter  

  • Working hours

    Game maker EA is getting quite a lot of attention these days. Their new Sims2 is received quite well by my social neighbourhood, finally we have a piece of software to talk about. The way EA operates its own sims is received with less enthousiams. In his blogpost Frans refers to the case as “White Collar Slavery”, on EA emplyees working 90 hours a week on a structural base. In the comments on the post is a quite interesting discussion on the culture of labor law and practices.

    Dutch legislation on the matter is quite complex. In a recent project I worked on an automated script to check hours worked. To mention (an over-simplified version of) some of the tests:

    • You are entitled to 11 hours free of work, in one stretch, per day
    • Having worked in a night shift this is 14 hours
    • A nigth shift should be no longer than 9 hours
    • Once every 9 days you are entitled to 32 hours of  leave
    • Once every 9 days you are entitled to 60 hours of leave. Your employer can neglect this rule once every 5 weeks

    The letter of the law and the actual tests are somewhat more complicated, how to exactly measure the timespans is even more tricky. But we made it to automate the testing. The amount of hours worked by the EA emplyees would have been interesting test material, it will probably lead to overflows ;/

    Peter

  • Is a Tablet PC cool (to program) ? Oh yes !

    In yesterday's post I listed some practical experiences, looking back on using a tablet PC. Today I want to spend some time looking ahead, there is more to be done. The tablet has really won my heart. The “experience” of using a tablet is addicting. You walk around freed from your desk with a fully functional PC disguised as a pen and paper book. It's Windows coming to a device near you. My tablet is a convertible notebook with a swiveling screen. Sometimes I wish I had bought a slate model, in most cases the pen works good enough. The text recognition engine still has me baffled, writing an English text demonstrates how good it is. Or how bad, trying to write in a language not supported (yet), like Dutch, just does not work.

    Developer resources for the tablet are rare but good. MS is really trying to push the tablet to the developer. Remember the “Does your code think in ink?” campaign on the last PDC ? It got snowed under by Longhorn/Whidbey but right at this moment it is there. There is a good SDK and a good platform (Windows XP tablet PC edition 2005) to target. So what are we waiting for ? On DevExpress there is a very nice article by Lary O'Brien with a good overview of tablet resources avalaible. And of course there is the MSDN tablet site.

    Peter

  • Using a tablet PC

    For a couple of months I've been using a tablet PC as a part of my everyday activities, time tor a little update.

    Some observations.

    • The machine is quite powerful as a PC. It runs Outlook, Feeddemon and a Virtual. Small Business Server at the same time.
    • The machine is really mobile and connective, it has 3 ways to connect to the network: a TP plug, WiFi and bluetooth.  Windows switches  automatically to fastest available. When I'm on the road the Siemens Data Suite connects me seamlessly to the net using my Cell phone.
    • The screen is quite useless out of doors, it's just not bright enough. Indoors, it is a pleasure to use.
    • lt is difficult to allign the pen with the cursor. Sometimes you have to tap outside of the screen to hit the right spot. This sounds worse than it is, you get the feel for the right place to hit by using. According to the tablet hardware specs a deviation of 2 mm between actual hit and visual feedback is allowed. l think my tablet is within limits.
    • The tablet SDK is great. But they don't know who to target. It's a mixture old style COM and managed. NET Code. You can do almost everything in managed .NET code and I can't imagine why you would run a tablet on anything else than XP tablet edition 2005 which includes the framework.
    • Literature on developing apps is rare. There is one good MS book and that's just about all. Going to dive deeper into tablet development and will keep you informed.

    Peter

     

  • Apress teaches .NET

    Apress publishers are rolling out a good series of books on .NET development. These books build on each other to teach .net from the first steps to a variety of advanced topics. In his Apress blog Ewan Buckingham gives a very nice overview of the roadmap to the .NET.

    Peter

     

  • How to freeze a dynamic aspx page into a static html page (on the server).

    Take this scenario: On a website a visitor fills in a form after which the form is to be filed as a static html page. You might have several reasons for wanting to do that, one of them are search engines. Getting it done in asp.net took me more effort than I had originally expected. Let me share what I have found to be working.

    The easy way to catch the html rendered by asp.net is to save a page in the client browser. To catch it on the server you have to hook into the (html) rendering process. There is no Page.OnRender event but the Page class does have a Render method. The method has a protected visibility, you cannot  invoke it form your code. The Render method is invoked when asp.net renders the page to the output, to hook in you override the method. The Render method has a parameter of type HtnlTextWriter, the default implementation of the overriden Render method is invoking Base.Render passing it the HtmlTextWriter object.

    protected override void Render(HtmlTextWriter writer)
    {
       // Default behavior
      
    base.Render(writer);
    }

    This gives a place to hook in an own textwriter where asp,net can render the html into. The constructor of the HTMLtextwriter class has a protected visibility. Passing an own htmltextwriter requires specializing the frameworks's HTMLtextwriter class. The constructor of the base class requires a stringwriter. A wrapper class to house both custom HTMLtextwriter and stringwriter:

    internal class MyHtmlFileCreator
    {
       private StringWriter html;
       private MyHtmlTextWriter htmlWriter;

       // override the HtmlTextWriter to reach the constructor
       // the constructor in the base class is protected 
       class MyHtmlTextWriter : HtmlTextWriter
       {
          internal MyHtmlTextWriter(TextWriter tw): base(tw){}
       }

       // publish the HTMLwriter
       internal HtmlTextWriter RenderHere
       {
          get {return htmlWriter;}
       }

       // constructor initializes stringwriter and htmlwriter based on that
       // initialize Url 
       internal MyHtmlFileCreator()
       {
          html = new StringWriter();
          htmlWriter = new MyHtmlTextWriter(html);
          newUrl = Context.Request.Url.AbsolutePath.ToString();
          newUrl = newUrl.Replace(".aspx",".htm");
       }

       internal void WriteHTMLFile(string virtualFileName)
       {
          // Stringreader reads output rendered by asp.net
          // Stringwriter writes html output file
          StringReader sr = new StringReader(html.ToString());
          StringWriter sw = new StringWriter();

          // Read from input
          string htmlLine = sr.ReadLine();
          while (htmlLine != null)
          {
          // Filter out ASp.net specific tags
          if (! ((htmlLine.IndexOf("<form") > 0) ||
                (htmlLine.IndexOf("__VIEWSTATE") > 0) ||
                (htmlLine.IndexOf("</form>") > 0) ))
             {sw.WriteLine(htmlLine);}

          htmlLine = sr.ReadLine();
          }

          // Write contents stringwriter to html file
         
    StreamWriter fs = new StreamWriter(virtualFileName);
          fs.Write(sw.ToString());
           fs.Close();
       }

    }

    A MyHtmlFileCreator object has a place asp.net can render to and it has a method to write the contents of the stringwriter (inside the htmlwriter) to file. I use the MyHtmlFileCreator in a page base class. The page hooks in the render event. When the freeze flag is set the html is rendered to a file and the application is redirected to the html file just created.

    public class FreezablePage : System.Web.UI.Page
    {
       internal class MyHtmlFileCreator{}

       // When Asp.Net renders the page the Page.Render method is invoked
       // Override the method to hook in

       protected override void Render(HtmlTextWriter writer)
       {
          if (freeze)
          {
             MyHtmlFileCreator htmlFile = new MyHtmlFileCreator();
             // Let Asp.net render the output, catch it in the file creator
             base.Render(htmlFile.RenderHere);
             // Write new html file
             htmlFile.WriteHTMLFile(Server.MapPath(NewUrl));
             // Redirect
             Response.Redirect(NewUrl, true);
          }
       else
       {
          // Default behavior
          base.Render(writer);
       }

       }

       // Flag render event
       protected void Freeze()
      {
          freeze = true;
       }

       protected void Freeze(string toUrl)
       {
          freeze = true;
          NewUrl = toUrl;
       }

       private bool freeze = false;

       private string newUrl;

       internal string NewUrl
       {
          get
          {
             return newUrl;
          }
          set
          {
              newUrl = value;
          }

       }

       }

    }

    Use this on your page like this :

    public class _Default : Gekko.Web.UI.FreezablePage
    {
        private void Button1_Click(object sender, System.EventArgs e)
       {
          Freeze(string.Format(@"Statisch/{0}.htm", TextBox1.Text));
       }
    }

    You will see that the resulting page has lost its form knocking out al buttons. There are no more postback possible. And the viewstate is also cut away. To process any file asp.net might produce will require more filtering. You can do quite flexible things treating the input as xml. Which requires some cutting and pasting, an html document is not always well-formed.

    BTW Firefox was a lovely sidekick. The way it  displays the html source of a page..mmm:>

    Peter

  • Christian Weyer on &quot;Contract first&quot; for dotned

    Thursday october 28th Christian Weyer did a very good presentation to celebrate the 2nd aniversary of the Dutch user group dotned. Christian is a team member of thinktecture, just like Ingo Rammer who did a dotned presentation last july.

    Christain's subject was "Contract first". In the new hype of web services and SOA we are told that it is all about the contract. First define the contract, after that you can implement it, for instance in a webservice. The problem is that all tools focus on implementation. Create a new webservice in Visual Studio and you are thrown right into the implementation code. Eeven in VS 2005 team system there is no tool for defining a contract.

    Contract designers are nothing new, take stuff like IDL the interface description language for COM. Mmyself I have spent days and days in the Delphi type library editor which is a visual tool to edit an IDL out of which a typelibrary and an implementation skeleton is generated. Christain demonstrated an add on for VS he is building himself. It works with xsd schemas, not just for the data types your service is working with but also for the operations your service supports. It was a clear story full of revelations. The full story and the tool can be found here on the thinktecture website. Absolutely recomended !

    Peter

More Posts

Our Sponsors

Free Tech Publications

This Blog

Syndication

News