Stack Overflow

by Juan 22. August 2008 20:21

No, this is not a post about that old problem with the same name, this is about a new Website

I've been beta testing for a few days Jeff Atwood's new venture, and I must say, it's promising. It is a site made and maintained by programmers, for programmers... kind of like a wikipedia meets experts-exchange, but free.

The beta is supposed to end at the end of the month, so that means that it will open to the general public (at least that's the current rumor) next month.

In the meantime, here are some screenshots

image

 

image

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

General | Programming

Dynamic SiteMap for ASP.NET Websites

by Juan 20. August 2008 10:56

I wanted some easy way to add modules to a website of mine, and have it automatically generate the menu, so I thought I'd compile some existing ideas and code I found into something useful for that end.

In short, what I wanted to do is have a Sitemap generated based on the folders in the application.

First, armed with what I learned about HttpHandlers, I created one to do just that: search folders and .aspx files and create the sitemap as needed by the XmlSiteMapProvider. It hooks to sitemap.axd and outputs the xml.
You can download that code at the end of this article, just drop it in the App_Code folder.

The target format is this

<siteMap>
  <siteMapNode title="RootNode" description="This is the root node of the site map. There can be only one root node." url="Page1.aspx" >
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page2.aspx">
      <siteMapNode title="ChildOfChildNode" description="SiteMapNode objects can be nested to any level." url="Page3.aspx"/>
    </siteMapNode>
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page4.aspx"/>
  </siteMapNode>
</siteMap>

The first problem I run into was that the .NET provider didn't like two things, the extension (.axd) and the fact that the file doesn't really exists, as can be seen quickly using Reflector.

image
(...)
image

After thinking for a bit, I decided to implement my own SiteMapProvider, luckily one already existed.

I used Stefan Sedich's code, removed the dynamic node part, and modified the way it looks for the file (which was to map the physical path, but as I said earlier, the file doesn't exist) like this:

   siteMapXML = XDocument.Load(GetUrlPath(HttpContext.Current.Request.Url.AbsoluteUri) + "/~/" +this.siteMapFile);

This way, the HttpHandler takes the request, and outputs the sitemap xml.

The result is that for this sample web site:

image

This xml is generated:

image

There's also configuration entry in the web.config file to exclude specific folders in the search, nothing too fancy:

   <add key="SiteMap_ExcludeFolders" value="App_Code;App_Themes;Bin;MasterPages"/>

So with this, whenever I add a subfolder in my application, it will automatically appear in the Menu, SiteMapPath, or whatever control that uses the sitemap.

I hope this is useful to someone

Downloads
SiteMap.cs (4.28 kb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

Programming

Live semantic errors

by Juan 15. August 2008 10:11

One of the new features that came with Visual Studio .NET 2008 SP1, is the real-time compiler errors (feature I read VB developers have had for a long time).

So if you type something wrong, you see it without having to compile

image

I've been working with it for two days, and I definitely don't like it, it distracts me to have errors appearing and disappearing all the time, it doesn't even let you finish writing the line, it shows an error when there isn't one (I just need to finish the line please!). I found myself trying to type faster to avoid seeing the "error".

I'm sure they had good intentions.

Luckily, almost anything can be turned off, you just need to find it.

If you go to Tools > Options > Text Editor > C# > Advanced, and uncheck "Show live semantic errors", it works like before, only showing hints

image

I will go back to the old ways with this one...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Programming | Tips

Visual Studio 2008 and .NET 3.5 SP1 Released

by Juan 12. August 2008 11:56

You can download the Visual Studio 2008 SP1 from here (which includes the .NET 3.5 SP1)

Following those links you have the information regarding what fixes and new features they bring

The ASP.NET new features include

  • Enabling high-productivity data scenarios by using ASP.NET Dynamic Data.
  • Supporting the browser navigation in ASP.NET AJAX applications by using ASP.NET AJAX browser history.
  • Increasing the download speed for ASP.NET applications by using ASP.NET AJAX script combining.
  • Enjoy!

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5

    Tags: , , ,

    Programming

    Weak References

    by Juan 30. July 2008 15:01

    The internal framework we are developing here at Iceberg includes a Lock Manager.

    All it does is keep a record of the status of objects (that generally represent records in a table), so you can know if it can be modified (i.e. it's not locked).

    The basic design includes a Lock(obj) method and an UnLock(obj) method. However, the possibility exists for the application to end abruptly, or even for the programmer to forget to call UnLock to free the object's exclusive lock.

    The first approach to solve this was to have the object register itself to a Ping event in the Lock Manager, so it can tell it it's still alive. The problem was that since it's registered in the Lock Manager's event, it was never garbage collected, ergo, it was always alive.

    After a few more ideas that ranged from looking for some reference count (and finding it doesn't exist) to considering manipulating the memory through unsafe code, I found the most beautiful class in the world: WeakReference

    A weak reference allows the garbage collector to collect an object while still allowing an application to access the object. If you need the object, you can still obtain a strong reference to it and prevent it from being collected. For more information about how to use short and long weak references, see Weak References.

    With 2 lines of code you can solve the problem:

    MyClass c = new MyClass();

    WeakReference w = new WeakReference(c);

    // (...)

    bool wasGarbageCollected = w.IsAlive;

    It's magic!

    Currently the Lock Manager creates a Weak Reference in the Lock method and ads it to a list, it has an internal timer where it iterates through the list, and it unlocks every object that was garbage collected.

    You should've seen the test application go... this is by far the best class in the .NET Framework.

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5

    Tags: , ,

    Programming

    Dynamic Master Pages

    by Juan 18. July 2008 15:16

    I wanted to create a template web site with the ability to completely change its layout via the web.config file, and it was also a good excuse to look into HttpModules.

    HttpModules are services that execute when the requests reach the webserver, you can use them to do whatever you want... like compressing the output before sending it to the client, parsing scripts and put them all in a single file, etc, etc, etc

    This time, what I want to do is set the the page's MasterPage according to a value in the web.config file.

    What I do is register for the page's PreInit method, and set the MasterPageFile property in the handler, like this:

    public void Init(HttpApplication context)

    {       

        context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);   

    }   

     

    void context_PreRequestHandlerExecute(object sender, EventArgs e)   

    {       

        Page page = HttpContext.Current.CurrentHandler as Page;       

        if (page != null)       

            page.PreInit += new EventHandler(page_PreInit);       

    }   

     

    void page_PreInit(object sender, EventArgs e)   

    {       

        Page page = sender as Page;       

        if (page != null)

            page.MasterPageFile = "~/MasterPages/" + ConfigurationManager.AppSettings["MasterPageTheme"] + "/site.master";       

    }

    In that example, you have to have a MaterPageTheme setting with the name of the folder that contains site.master.

    image

    Then you just need to register the module, and you are good to go

    <httpModules>

        <add name="MasterPageModule" type="MasterPageModule"/>
    </httpModules>

    You can download the code below, just drop it in the App_Code folder

    MasterPageModule.zip (620.00 bytes)

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5

    Tags: , , ,

    Programming

    Creating template projects with visual studio

    by Juan 16. July 2008 10:48

    As part of the development framework we are creating here in Iceberg I wanted to create a base web site that developers could use as a starting point, with themes, master pages, and some default properties set in the web.config file to use our database and membership engines.

    My initial thought was to create it, and then have them copy/paste it to start a new web site, until I came across the "Export template..." feature in visual studio.

    Basically what it does is package a project or item so it can be reused, exactly what I wanted.

    Let's test it... first I create a project

    image 

    And I added a few items, just to not let it the same as the default project

    image

    Then I go to File, Export template

    image 

    You are presented with this self-explanatory dialog box

    image

    You click next, then finish, and that's it... you can add a new project and select this template as many times as you want (You can set a custom Icon and a Description if you want, play a little with this options if you like)

    image

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5

    Tags: , , , ,

    Programming | Tips

    Google Reader BlogEngine Widget

    by Juan 4. July 2008 12:16

    I modified my Google Reader Pick's box there on the right to be compatible with the new widget framework of BlogEngine.NET, and here's the code if you want to use it in your own blog.

    All you have to do is upload the "Google Reader Picks" folder to the widget folder, and configure it for your account.

    The most important property is your User Id, which you can get from your Google Reader homepage, clicking on "Shared Items", like this

    image

    image

    Then, you can go to the configuration file clicking on the edit link

    image

    • User ID is the user id you have in your Google Reader Homepage.
    • Color Scheme is the color of the list, you can experiment with it, but for the standard blogengine theme I recommend setting it to "none".
    • Items is how many items to show
    • Show item sources adds a link to the original feed
    • Add Xfn Link adds a hidden link with the rel="me" tag for Google's Social Graph API

    And the result looks like this

    image

    You can download it from the following link, any feedback is appreciated, this is my first widget =)

    Google Reader Picks.zip (2.99 kb)

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5

    Tags: , , ,

    Blogging | Programming

    BlogEngine.NET 1.4 Released

    by Juan 2. July 2008 01:21

    As you can see at the bottom of this page, I am now powered by BlogEngine.NET 1.4

    If you are still using some standard blogging provider, I recommend you get you own hosting and install this blogging engine, nothing beats having absolute control over everything... yes world, you are next!

    Some of the new features include (from the official site):

    New database provider
    BlogEngine.NET now works with most commercial and open source databases such as MySQL, SQL Server, VistaDB and many others. This allow you to use practically any database supported by your hosting provider. You can still use XML files if you don't want to use a database.

    Drag 'n drop widgets
    Widgets are the pieces of content most often located at the sidebar. It could be a list of recent posts, latest tweets from Twitter or anything else. You can drag and drop the widgets around in your sidebar and modify the content of them directly on the front-page. The widget works independently of the theme you are using as long as it is implemented in the theme. In BlogEngine.NET it is implemented in the Standard and Indigo themes and many more themes with widgets will be available for download very soon at the BlogEngine.NET website.

    Extension settings
    The new settings model for extensions have been upgraded to give you a much better experience using third-party extensions. For extension developers, it has never been easier to store your settings and let the user change them from the admin section. The same settings model is used by the widgets as well.

    Web 3.0 improvements
    BlogEngine.NET 1.4 makes full use of many semantic formats and technologies such as FOAF, SIOC and APML. It means that the content stored in your BlogEngine.NET installation will be fully portable and auto-discoverable. It is possible to filter the RSS feeds based on the visitor's interest defined in her APML file or do a site search with it as well. Read more the APML filtering in BlogEngine.NET.

    Author profiles
    By utilizing the ASP.NET profile provider it is now possible to let all authors maintain their own profile. This is used in the FOAF document and widget/extension developers can take full advantage of the profiles to provide new exciting visualizations and functionality.

    Other new features
    We've listened to what you - the user - wanted in BlogEngine.NET 1.4 and here is a list of some of those features that made it.

    • Tag selector when adding new posts
    • Subcategories
    • Password encryption
    • Improved live comment preview
    • Hierarchical pages in the control panel
    • Smarter comment spam protection
    • Link collection widget
    • Various performance improvements
    • and much more...

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5

    Tags: , , , ,

    Blogging | Programming

    Friend Assemblies

    by Juan 27. June 2008 17:08

    Today I was designing some unit tests for a project here at work, and needed to access some helper methods (mostly constants) to check the output of a few methods, and was happy to discover this attribute.

    With InternalsVisibleTo you can specify which assembly, if any, other than the current one, can "see" information marked as internal.

    As I said, it's very useful when designing tests, or for example if you want some component to be accessed only by another (the same use you give to internal, but expanding across several assemblies)

    You can use it at assembly level like this

    [assembly: InternalsVisibleTo("JMF.Tests")]

    Where JMF.Tests is the Assembly Friendly Name

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5

    Tags: , , ,

    Programming | Tips

    Powered by BlogEngine.NET 1.4.5.7
    Theme by Mads Kristensen Modified by Juan Manuel Formoso

    About the Author

    Juan Manuel
    Networking
    View my LinkedIn profile View my Technorati profile View my Facebook profile View my bookshelf
    View my Plaxo profile View my digg profile

    Juan Manuel Formoso
    There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something more bizarrely inexplicable.

    There is another theory which states that this has already happened.

    E-mail me Send mail

    Ads

    Most comments

    Cristian Pereyra Cristian Pereyra
    3 comments
    ar Argentina
    Miguel Miguel
    2 comments
    us United States
    Ariel Ariel
    1 comments
    ar Argentina
    Mauro Mauro
    1 comments
    ar Argentina
    Daniel Daniel
    1 comments
    mx Mexico

    Google Reader Picks

    Calendar

    <<  August 2008  >>
    MoTuWeThFrSaSu
    28293031123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    View posts in large calendar

    Recent posts

    Recent comments

    Comment RSS

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in  anyway.

    © Copyright 2008
    XFN Friendly