Monday, April 2, 2007

ZzzZzzZzz

Hi all,

Just a quick post to insure you that soon I will post a "review" of the DevDays held last week. I'm currently quite busy, but in a week or so most of the work will be done.

C u then ;-)

Grtz

Thursday, February 22, 2007

Remote WMI

Problem: I want to create an application (for God knows what reason) that shows the Event Log-entries for today. How can I do that ?

There are 2 ways the read the event log: one in very few lines and easy code, but not so quick, another one that’s a bit more complicated, but quick.

The easy way:

Dim objLogs() As EventLog
Dim objEntry As EventLogEntry
Dim objLog As EventLog

'this uses local machine
'you can pass machine name to constructor
'to use a different machine
objLogs = EventLog.GetEventLogs()

For Each objLog In objLogs
Debug.WriteLine(objLog.LogDisplayName & " event log")
For Each objEntry In objLog.Entries
With objEntry
Debug.WriteLine("Source: " & .Source & " Time: " & .TimeGenerated.ToString & " Message: " & .Message)
End With
Next
Next



Now, while this is a perfectly good way to read the event log, you’ll notice that it is slooow. It goes through the ENTIRE eventlog, while in this case it only needs to go through the messages of this day.

The second method solves this problem. You can query the eventlog on a very sql-way. Take a look at this code sample .


Imports System
Imports System.Management
Imports System.Diagnostics

Public Class testClass
Public Sub testWQL()
Dim options As New ConnectionOptions
options.Username = "aUsername"
options.Password = "aPassword"

Dim strQuery As String = ""
strQuery = "SELECT TimeGenerated, Message, SourceName, User FROM Win32_NTLogEvent"
strQuery &= " WHERE "
strQuery &= " TimeGenerated='" & ManagementDateTimeConverter.ToDmtfDateTime(Now()) & "'"

Dim scope As New ManagementScope("\\myServer\root\cimv2", options)
Dim searcher As New ManagementObjectSearcher(scope, _
New SelectQuery(strQuery))

Dim result As ManagementObjectCollection = searcher.Get

Dim item As ManagementObject

For Each item In result
Try
Debug.WriteLine(item("message").ToString & " " & item("TimeGenerated").ToString)
Catch ex As Exception
End Try
Next
End Sub
End Class

Some things might need some explaining:

- first of all, you need to define a user/pass combination that you want to use to connect to the server (or any other pc).
- Then, you have to design your query. For more details on the types of query, take a look at these pages :

http://www.databasejournal.com/features/mssql/article.php/3550481

http://www.databasejournal.com/features/mssql/article.php/3552621

- After that, connect to your server, in this syntax. The root\cimV2 is a global collection WMI objects that Microsoft provides. More details are found on MSDN. But I guess that 80% of what you want to monitor/use, is in this collection.
- Execute the query and traverse the results.


My preferred way is the second, because of the speed and efficiency that it gives.

Hope this helps ! ;-)


Gr, K

Sunday, February 18, 2007

Atlas Update Panels - Part 1 (addon)

I always keep my promises, so here's the HTML :



As you can see, the brown line indicates the update panel. Inside the updatepanel, there are basically 2 parts : the ContentTemplate-section and the Triggers-section.

(blue part)
As explained before, the content inside the contenttemplate tags, is the only thing that we will update. We placed 2 items in those tags: the listbox (items being added) and the input textbox (we want to blank this after the insertion is complete).

(red part)
We have 2 kinds of triggers: an event-trigger and a property-trigger. How they work is very straightforward: the event-trigger is fired when a certain event happens (eg "Click") and the property trigger is fired when (you'll never guessed this) a property of a control changes (eg "Text"). In the code example I only used the event-trigger.

One thing you'll have to remember is, that the control that fires the event, can never be in the content template itself!

As you can see the code is quite easy. But giving that VisualStudio is a terrible UI designer, I advise you to add the Atlas code as the last step of your website construction !

Gr, K

Thursday, February 15, 2007

Atlas Update Panels - Part 1

Hi all !

Today, my chief stopped by with a big smile on his face. “Koen, I’ve created a wonderful ASP.NET site. It provides easy update forms, dynamic drop down boxes… Only one thing: it flashes so hard that an epileptic guy would go crazy on it. Can you help me?”

Now it was my turn to smile :-). The reason why it flashes is that asp.net uses postbacks. Those postbacks push and retrieve entire pages to the webserver. As a result, you see the screen “clean up” and a second or so later, you can see it rebuilding.

It would be great if there was a technique that only postbacks the part which is relevant, the part that changes. But hey, such a thing already exists: AJAX. AJAX stands for Asynchronic JavaScript And Xml. The idea behind AJAX, in a nutshell, is exactly what we described above.

Microsoft wraps this technology in what they call ‘Atlas’. Atlas is eventually a collection of free-to-use javascripts. Those javascripts are shown in visual studio as components, which you can drag&drop.

I’ll discuss all the useful components in later posts, but for now, I want to focus on the UpdatePanel and UpdateProgress.

If you place an update panel on your site, you can tell asp.net that when (eg. ) I click a certain button, only that specific content needs to be updated. The way to tell this, is via a trigger.

Take a look at this example : Open Image

As you van see I created a basic form. Just one list box and one textbox, where I can enter some values. No more, no less. (I’ve put some code behind the button, but that isn’t important for now because we only focus on the ajax-part, which is pure html). If you really want to see the “flashes”, add some color to the background.

When you want to use the Atlas functionallity, you need to add the Atlas control (which you can find in the Microsoft.Web.Atlas.dll), or you can install the Microsoft Atlas pack, available on the microsoft website or via http://ajax.asp.net .

Now for the fun part.

To avoid the postbacks, we need to add an update panel. If you have installed the atlas pack, you’ll see an UpdatePanel component in your toolbox. Drag this on your form and give it a proper name (eg: upnlData). Then, drag your listbox, textbox and “new value”-text in this update panel. Also, you need to add the scriptmanager. This component must appear before the update panel or any other atlas-component in general. I’ll explain this manager later on.

If you have done all this, you should see something like this :
Open Image

Now we need to tell the panel that it should update its content only when I push the button. So when I push the add-button, only the content in the panel is updated, the title or other elements remain untouched.

To teach the panel this update-rule, we need to add a so called “trigger”. I’ll show you the html code later on, but let’s first do it the UI way. If you examine the properies of this updatepanel, you’ll find one called ‘Triggers’. Open this by clicking the triple-point button. You’ll get this window : Open Image

When you click "new trigger", the following appears : Open Image

You can create a trigger the fires when a control throws an event (eg : the click-event for a button) or when some property of a control changes its value (eg : the text-property of a button). In this case, we want to fire the trigger after a user clicks the add-button. So this is what you should enter : Open Image

There is only one thing left to configure. Remember the ScriptManager I told you to add? Well, this scriptmanager does all the work actually. We need to tell it that we want this page partionally rendered. To do this, set the EnablePartialRendering-option to true.

In later posts, I’ll explain in-depth the goal of the scriptmanager, but remember for now that this manager “manages”, delegates and organises all the atlas related things, and that it should always be added to an atlas-enabled page. Also, it must appear before any other atlas-component!

Well, I think we’re ready now. Just run the page and see for yourself! :)

As you can see, it’s not much effort to make a page ajax enabled !


See you at the next post!

Gr, K

Sunday, February 11, 2007

Dev Days 2007

Microsoft Dev Days 2007Next month, the 2007-edition of the Microsoft Dev Days takes place ! Once again, the event will take place in Ghent (Belgium) at the ICC center. Last year I went for the first time. It's a really interesting show, because the Microsoft Dev guys demonstrate what's in the pipeline, but also, some interesting tips about current technologies.

The presentations focus on 2 "kinds" of IT: developping and system. I only saw the dev-part (unfortunately, there's too little time to see everything) and some of their samples were very useful in every day life. It's perfect for practical tips about multiple aspects of .net, in a limited time.

Yes I know, it is a little Microsoft brainwashing (Microsoft's marketing people and partners are very present with all kinds of booths and gadgets), but all in all, if you go, you won't regret it.

Here's the link to their website : http://www.microsoft.com/belux/devitprodays

Hope to see you there!

PS: The food they offer is great !! ;-)

K

Birth of another .NET blog

Hi All!

I know there are a lot of .net blogs already. And you all expect me to say "but mine will be better and more informative". Well, i am not going to do that. It isn't my goal to create a popular blog. The main target is to exchange all .net knowledge. We all encounter other problems, so if everyone creates a blog and shares his .net solution, it'll be easy for a programmer to find a solution to its problem.

Anyway, right now i am going to tweak this blog a little, but soon you can expect the first code snippet ;-)


Gr, K