Journey into C#
Being a moderatly to quite skilled programmer since 15 years, the past four years PHP exclusive, I have for various reasons decided to take up C#. This blog is for sharing my ups and downs with fellow C# coders, beginners and pros alike.
tisdag, november 30, 2004
 
A case of mistaken identity
I've been fooling around with this small application that I need to develop for my job. It's an on-line NDA form of sorts that we're going to show to the user everytime she logs in until she agrees to it. We then update the Active Directory with the date she signed it.

We are going to use a web server to present the form which means that I need to get my IIS up and running as a development server (which I though I had but there's some funk with the connection to the AD). It also means that I need to grab the users credentials from the client operating system.

After looking around the web, mostly MSDN, I found the WindowsIdentity class. After some more fiddling around I got it to grab the name of the currently logged in user:

Console.WriteLine("Username: " + WindowsIdentity.GetCurrent().Name);

Now, what I get here is the actual username, in our case something rather cryptic, so I need to query the AD for the display name, just for looks though when we display the form to the user.

From my C# book I got an example that displays all the properties of an AD object, including users, but I can't modify it to my needs. The original code looks like this:

foreach (string name in properties.PropertyNames)
{
    foreach (object o in properties[name])
    {
        Console.WriteLine(name + ": " + o);
    }
}


and I want to use something like this:

Console.WriteLine("\n\nDisplayName: " + properties["displayName"]);

It doesn't work though and at the moment I'm too tired to keep at it. I'll get back to it tomorrow or Thursday.

Oh, and I found a new C# site; C# Help. Well, new to me atleast.

onsdag, november 24, 2004
 
I've got an IDE
I finally got around to reinstalling the VS. NET 2003 IDE after I rebuilt and reinstalled my computer a month ago or so.

I've been dabbling in some C# ASP .NET development using a standard text editor but it's just too cumbersome to be worth it. The thing I'm pondering is how well I can adapt the VS .NET IDE to my PHP development.

Anyhow... With the IDE properly installed I should be able to get started on some more serious development, even though the small application I'm currently designing might not need too much serious development.

tisdag, november 16, 2004
 
Long time no see...
(Yeah, I could have gone with Long time no C#... but that seemed a bit too nerdy, even for me.)

So, why haven't I posted for months? The simple reason is that I've been fatigued due to an excessive amount of work. Things have been crazy at the office for quite a while now. Combine that with me working out 3-4 days a week and I'm spent once I get back home.

Things aren't all bad though as I've managed to squeeze out a couple of hours here and there on my spare time to do something useful. I have, for instance, discovered the glory of OOP. No, it's not in C#, unfortunately, it's in PHP, and version 4 to boot, but it's a big step in the right direction.

I have also managed to create a much better development environment here at home with a domain controller (for working on those AD-enabled applications), an IIS 6 webserver and an SQL 2000 server. As a bonus I even managed to get the IIS to run PHP 5 in ISAPI mode although that was a bitch to get up and running.

The reason I'm reviving this blog is twofold. First off, the workload has started to decrease a bit which means I'm not all worn out when I get home making it possible for me to get creative with the code. Secondly, we need to put together a small ASP .NET page that displays an end user agreement to all our users. When they agree, the AD needs to be updated with the information that they agreed and when.

Hopefully I'll be keeping a more steadfast updating schedule this time around, eh?

söndag, september 05, 2004
 
A lot on my plate
As of now there's a lot off stuff going on. Some projects are C# related, others are purely PHP/MySQL coding for existing sites that needs to be revamped. I don't know enough to be writing these in ASP .NET yet either so I'll have to stick with what I know.

So there's not going to be a lot of updates in the following months. But I'm guessing that you weren't expecting that either. 8) Just grab one of the feeds and you won't need to check back until I actually post something useful.

tisdag, augusti 24, 2004
 
Custom attributes
Today I got through the section about custom attributes. At first I didn't really understand why you would want to use them, it just seemed like a cumbersome way to declare variables but afterwards I understand more about them, although I'm not completely sure about a practical use for them at the moment. As usual.

The author mentioned that you could use custom attributes in a database connection scenario, declaring the table and columns in attributes, in order to avoid coding up custom logic for each table and column you want to access. Admittely I am a bit tired now but I'm not sure how this would work. Perhaps like this?

[AttributeUsage(AttributeTargets.Property, AllowMultiple = False)]
public class TableNameAttribute : Attribute
{
    private string tableName;
    public TableNameAttribute(string tableName)
    {
        this.tableName = tableName;
    }
}

[AttributeUsage(AttributeTargets.Property, AllowMultiple = True)]
public class ColumnAttribute : Attribute
{
    private string columnName;
    public ColumnAttribute(string columnName)
    {
        this.columnName = columnName;
    }
}

[TableName("Customers")]
[Column("Name")]
[Column("Address")]
[Column("Phone")]
public bool Update()
{
    // What the heck do I do here to use the attributes?
    // Do I need to use GetCustomAttributes()
    // and if so, how do I point it to
    // this class?
}

All in all it seems like a clumsy way of doing things. Why not just do like this:

public bool Update(string tableName, array columns)
{
    // Use the parameters passed to the class to update DB.
}

Or am I missing something?

onsdag, augusti 18, 2004
 
Dictionaries
I've just finished reading about dictionaries, something that might be unique to C#. Then again, I haven't coded in any modern OOP language before this so what do I know?

At first I was unimpressed with dictionaries, all it seemed to be was a way to use strings to index an array. Big deal, I can do that in PHP without breaking a sweat. I changed my mind after reading the chapter though.

Now they seem like something taken out of The Matrix; not only resizing themselves as needed but also using magic prime number based algorithms coded by Microsoft to grab the key, which can be any object of your liking, and search through the load for the actual object stored god knows where. If you screw up your own GetHashCode() and Equals() methods, your data can get lost forever in the vast darkness of cyberspace, never to be found again.

I'm sure they're quite clever and very versatile but right now I have a hard time seeing why they are more powerful than PHP's arrays. Or perhaps PHP is using dictionaries as well?

Still, it's knowing about these kind of things that makes me more confident that I one day will actually be able to write proper C# code.

måndag, augusti 16, 2004
 
Sorry for the lack of updates
There has been other projects taking up my time recently, one of them is C# related but, believe it or not, even more secret than the one I'm about to write for the school I work for so I can't talk about that one at all. At least not yet.

Things are moving along though, I have two of my friends helping out on the schoolrelated project. They too are learning C# as we go along although one of them has studied Java and OOP recently so he's got a leg up on the rest of us.

Hopefully I'll be back tomorrow with a proper update.


Powered by Blogger