Archives

Archives / 2004
  • ASCII Art with variable pixel squares...

    private static string grayscalepalette=" `.~:;I=i+oO08#M";

    public static
     string GetGrayScaleHtml(Bitmap bm,int pixelsquare)
    {
     
    StringBuilder sb = new StringBuilder();
     
    for(int y=0;y<bm.Height-pixelsquare;y+=pixelsquare)
     
    {
       
    for(int x=0;x<bm.Width-pixelsquare;x+=pixelsquare)
       
    {
         
    int luminationtotal=0;
         
    int lumination=0;
         
    for (int i=0;i<pixelsquare;i++)
          
    {
           
    for (int j=0;j<pixelsquare;j++)
           
    {
             
    Color c = bm.GetPixel(x+i,y+j);
             
    lumination = (int)(c.R*0.3 + c.G*0.59+ c.B*0.11);
             
    luminationtotal+=lumination;
           
    }
          
    }
         
    sb.Append(GetGrayScaleChar((int)(luminationtotal/(pixelsquare*pixelsquare))));
        
    }
        
    sb.Append(Environment.NewLine);
     
    }
      
    return sb.ToString();
    }

  • SQL 2005 XML WebServices? Yuck...

    At this years TechEd 2004 in Amsterdam, I went to a session regarding XML Web Services, which are basically now embedded into SQL 2005, provided it runs on Windows Server 2003 with the HTTP.SYS kernel. All I heard was how great all this stuff is for interoperability, Java clients connecting to your HTTP SOAP endpoint blah, blah etc...

    I have some reservations about this. In fact, I won't be exposing HTTP endpoints from within SQL Server 2005 (when I get to use it in 2008 sometime ;-) ) to the Internet. Why? Simply because of the fact that I wouldn't want to expose a database server to the Internet. Sure, you configure a firewall and allow only the minimum ports and protocols required, but any network engineer would rather see a database server sitting in a DMZ, and rightly so.

    So, how would you use these cool XML web services features when your SQL Server 2005 box is sitting in its own DMZ? Well, simple, as the presenter of the session told me afterwards - you use ISA server to route the HTTP requests through. Great. Sounds like an extra product that needs to be purchased and a lot of hassle to maintain all these mappings. I'll code my own web service, thanks very much.

    Bottom line (all IMHO): use SQL 2005 XML web services if you require basic interoperability between apps on your local network, otherwise if you want to expose this to external, global apps, just don't go there.

  • Skype's SkypeOut (PC -> Phone) Service now in public beta!

    The P2P telephony service Skype has now officially launched a public beta version of its SkypeOut - PC to Phone service.

    PC-to-PC telephony will remain free of charge. The international rates for SkypeOut can be found at https://secure.skype.com/store/help.pricelist.html . To use the SkypeOut feature, make sure you have downloaded the latest Skype version. When you login to the Skype store, you can now buy credit for your SkypeOut calls.

    These Skype guys are doing a marvellous job!

  • Win32 API InternetGetConnectedState

    [DllImport("wininet.dll")]
    private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);

    public
    static bool
    IsConnected()
    {
     
    int connectionDescription = 0;
     
    return InternetGetConnectedState(out connectionDescription, 0);
    }

  • ASP.NET Impersonation on Windows 2000 - update

    A while ago, I posted about some problems I ran into when using ASP.NET code impersonation on a Windows 2000 Server (SP4). We even logged a Microsoft Support call for it.

    Anyway, as with most time consuming issues, it turned out there was a very simple solution. As it states in the Knowlegde Base article, the local ASPNET account should be granted the 'Act as part of the operating system' privilege (this does not seem to be required on Windows Server 2003). The KB article 306158 forgets to add that this will require an IIS reset for it to have effect.

    Logical if you think about it maybe...in hindsight.

  • About the VS.NET Express beta products

    Having watched Scott Guthrie's presentation at TechEd in Amsterdam last week about the VS.NET 2005 roadmap, and after having toyed around with some of the Express products, I do have to make some comments - and where better to vent them than a blog?

  • ASP.NET Code Impersonation - problems with W2K

    We have a Windows Server 2000 (SP4) as web server and are trying to upload
    documents to a NAS using code impersonation, following the sample as can be
    found at: http://support.microsoft.com/default.aspx?scid=kb;EN-US;306158 .

    ACL's are correctly set, and the domain account credentials we use are
    correct as well. The ASP.NET app works fine on Windows 2003 (tested on two
    W2K3 boxes). On Windows 2000 however (also tested on two boxes),
    impersonation fails miserably.

    On Windows 2000, it always fails with the following Win32 API error message:
    "The specified procedure could not be found."

    Subsequent calls (after web app startup) result in either one of two Win32
    API error messages:

    "Overlapped I/O operation is in progress."

    Or

    "The system cannot find the file specified."

    The directory to upload to has been added as virtual directory with the path
    to the NAS and the right credentials. ASPNET account has privileges 'Act as
    part of OS'.

    Any idea why this is working fine on Windows 2003, but not on Windows 2000?

    Any comments and suggestions most welcome!

    Thanks!

  • Revisited: Enum values as bit flags - using FlagsAttribute

    In one of my earlier posts about enum bit flags, using the FlagsAttribute, I incorrectly stated that the actual enum values did not have to be specified. Due to the comments on the post, I ran another test, this time a more conclusive one! See the C# code for this test below.

    using
    System;

    public
    class Test
    {
    [Flags]
    public enum DodgyCarOptions
    {
     NoExtras,
     AirCo,
     
    TintedWindows,
     
    Leather,
     
    SunRoof
    }

  • XmlSerializer - some (enum) field not getting serialized...?

    Here's the scenario. I'm serializing a particular object, which contains other objects as properties. I have this particular enum type that won't get included in the serialized XML.

    For illustration - I'll simplify the class (which is a property of the main class being serialized); it looks as follows:

    public class Contact
    {
      public ContactRoleType ContactRole;
      public string ContactID;
      // ....and some more fields...
    }


    The ContactRoleType is a normal enum. All fields are serialized, except the enum field ContactRole. Strange thing is, when I rename the member field ContactRole, it does get serialized.

    I have actually used 
    Chris Sells' excellent tool XmlSerializerPreCompiler , and all the types can be serialized without any problem.

    All comments and ideas are welcomed!

    Thanks!

  • Enum values as bit flags - using FlagsAttribute

    The other day, I was using the RegexOptions enum when creating a Regular Expression, and I thought it would be useful to dedicate a blog entry to using enumeration values as flags.

    The following is a poor example, but it should be illustrative enough.

    Imagine we have a Client class, and one of the Client properties is ClientState. The ClientState enum can be defined as follows:

  • Random records from table

    Hi all,

    Great to be part of this blogging community. I will try to submit several posts each week and will make sure they contain snippets of code here and there.

    Now, what would you do to select a random set of several records from a SQL Server database table?

    A couple of months ago I came across the following simple, but yet very effective solution to do just that. For instance to get 10 random quotes from a Quotes table:

    SELECT TOP 10 * FROM Quotes ORDER BY NEWID()

    Personally I think it's pure gold.