Well, AJAX is the new buzzword these days in the development world, so I figured I should see what it is all about. Most of the web work I do is in classic ASP, so I figured I should see if I could do some async jscript in classic ASP. I got it working and I do have to say that it is pretty cool. Opens up alot of possiblities and could make the end user experience alot nicer. It should be easy to implement in ASP.Net or PHP too if you so wished.
Tag: Development
· Introduction to the Personal Web Site Starter Kit
· Extending the Personal Web Site Starter Kit
I wanted to see if I could get my blog feed on the main site under the “What’s New Lately� section on the main page (default.aspx). Well first, I took the atom.xml file from my blog, and got the URL. In the process of doing this exercise, I noticed I couldn’t get the Atom feed to work, so I found a site (FeedJumbler) to convert the Atom feed to straight RSS feed, which works.
Then I dragged the XmlDataSource item from the toolbox to the page under the ObjectDataSource that is there by default. If you set the datasource to the URL and the XPath to “rss/channel/item�
In the HTML code for default.aspx, if you add this code
<h4>My Blog Latest Posts</h4>
<asp:DataList ID=”DataList2″ runat=”server”
DataSourceID=”XmlDataSource1″>
<ItemTemplate>
<p>
<h5><%#XPath(“title”)%></h5>
<p>
<%#XPath(“description”)%>
</p>
Posted by <%#XPath(“author”)%> @ <%#XPath(“pubDate”)%>
<a href=”<%#XPath(“link”)%>“><i>Link</i></a>
<hr/>
</ItemTemplate>
</asp:DataList>
Then you should see your blog posts on your PWSK front page!
Visual Studio .NET 2005 Beta 2
I have been playing with VS.NET 2005 Beta 2 all night, the Personal Web Site Starter Kit. I have been modifying it and playing with all the new controls. Pretty sweet so far. Easy to consume RSS feeds, and get data from SQL. The master-detail page relationship is really cool, especially if you use templates for pages.
In networks all over, many devices can send Syslogs to a syslog server. You can download Syslog Servers (like Kiwi) to capture and process the syslogs, or you can create your own server to catch all the syslogs on your network. Then you can parse them to a database and write your own reports of them, having full control of everything.
First, in VB.Net, you need to import some namespaces.
Imports System.IO
Imports System.Net.Sockets
Imports System.Net
Imports System.Text
Then, from you Main procedure, call a procedure called ListenForSyslogs
Private Sub ListenForSyslogs()
Dim ipeRemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Dim udpcUDPClient As New UdpClient(514)
Dim sDataRecieve As String
Dim bBytesRecieved() As Byte
Dim sFromIP As String
Try
While True
bBytesRecieved = udpcUDPClient.Receive(ipeRemoteIpEndPoint)
sDataRecieve = Encoding.ASCII.GetString(bBytesRecieved)
sFromIP = ipeRemoteIpEndPoint.Address.ToString
FillLog(sDataRecieve, sFromIP)
Console.WriteLine(sDataRecieve)
sDataRecieve = ""
End While
Catch e As Exception
' just ignore for now
End Try
End Sub
If you analyze this code, it just sets up a endpoint on the IP you are running the program, and listens on port 514, the default syslog port. It will just run and run, and keep listening. Whenever you recieve data, then call FillLog procedure
Private Sub FillLog(ByVal sSyslog As String, ByVal sFromIp As String)
Dim sPriority As String
Dim sPath As String = System.Environment.CurrentDirectory & "Unprocessed"
sSyslog = sSyslog.Replace(vbCrLf, "")
sSyslog = Mid(sSyslog, InStr(sSyslog, ">") + 1, Len(sSyslog))
sSyslog = Trim(sSyslog)
sPriority = GetSyslogPriority(sSyslog)
Dim swWriter As New StreamWriter(sPath & "syslog" & Now.Month & Now.Day & Now.Year & Now.Minute & ".txt", True)
swWriter.WriteLine(sFromIp & "," & Now & "," & sPriority & "," & sSyslog)
swWriter.Flush()
swWriter.Close()
End Sub
What FillLog does it look at data recieved, and parses it out, removing line feeds, etc.
Then it gets the priority from a function GetSyslogPriority(). Then it writes out the info to a comma seperated txt file (for easy parsing later), that is named pathsyslogmonthdayyearminute.txt so for example, c:unprocessedsyslog0408200529.txt
It will append to that txt for for the minute it gets syslogs for. So you should probably have another process that will consume that txt file before the next hour rolls around.
Finally, the function that gets the priority:
Private Function GetSyslogPriority(ByVal sSyslog As String) As String
Dim sResult As String
If InStr(sSyslog, "-0-") Then
sResult = "Emergency (0)"
End If
If InStr(sSyslog, "-1-") Then
sResult = "Alert (1)"
End If
If InStr(sSyslog, "-2-") Then
sResult = "Critical (2)"
End If
If InStr(sSyslog, "-3-") Then
sResult = "Error (3)"
End If
If InStr(sSyslog, "-4-") Then
sResult = "Warning (4)"
End If
If InStr(sSyslog, "-5-") Then
sResult = "Notice (5)"
End If
If InStr(sSyslog, "-6-") Then
sResult = "Info (6)"
End If
If InStr(sSyslog, "-7-") Then
sResult = "Debug (7)"
End If
If sResult = "" Then
sResult = "UNKNOWN"
End If
Return sResult
End Function
To summarize, you can capture syslogs from your network to text files, and then create another program to read in the text files to a database and write reports. Creating the UDP listener on port 514, you can setup your network devices to dump syslogs to your box where you are running the syslog server you created. To troubleshoot network issues, syslogs will give you a good idea of what is getting denied, etc, and you can create your own homegrown Syslog Server using VB.NET in a few simple steps.
Enjoy!
Coding Slave
Free eBook in PDF format by Bob Reselman. Be forewarned, it is really geeky and for the true geeks to really understand. I downloaded it last week and read it, and it is a pretty good read.
Haven’t posted much up here lately, I have been really busy with PocketBlogger. 4500 hits in less than a week, I never would have thunk it. Between that and being swamped at work, it just seems like there is no time lately. Need to get an oil change, and taxes done, new drivers license, insurance updated, etc.
A lot of cool things have been up lately too, CTIA in New Orleans, tons of new gadgets, the Atom API was finally updated by blogger.com, IE7 Details are leaking out like a sieve, VB Developers want VB 6 to stay (I have no clue why, compared to VB.net it sucks hind t*t)
Last night I was working a project, and a feature was requested to have the program change the screen resolution to 1024×768, and then back to what the user had before they started the program. I figured, hey, .NET, it should be easy, right? First rule of computers…nothing can every be easy.
First order of business. Get the screen size of the screen before changing it, so I know what to change it back to.
  iOrigialScreenWidth = Screen.PrimaryScreen.Bounds.Width()
  iOrigialScreenHeight = Screen.PrimaryScreen.Bounds.Height()
Well you think you would be able to set those values as well as get them? Come on, that would be to easy.
The only way I could figure out how to change it was to revisit the good ol’ API. I found a class that someone has wrapped around the API calls to change the resolution, so I referenced that in my project, and was ready to go. At the top of the code “Imports Resolution” – Resolution was the name of the class.
  ‘ change to 1024×768 so the program fills screen
  Dim ChangeRes As CResolution
  ChangeRes = New Resolution.CResolution(1024, 768)
and to change it back again, on close of the program:
  ‘ change to original resolution
  Dim ChangeRes As CResolution
  ChangeRes = New Resolution.CResolution(iOrigialScreenWidth , iOrigialScreenHeight)
Well, anyway, here is the API Class (in C#). You would need to reference the Assembly in your project.
So, the moral of the story, instead of using 6 lines of code to change the resolution back and forth, it takes 6 lines and referencing the API. Fun!
SQL Exception Handling in .NET
In .NET , Microsoft introduced the Try, Catch, Finally exception handling. In all books and examples I have seen, you catch an exception like so:
Try
…some code
Catch ex as Exception
…some error handling code
End Try
Well, what happens when you are catching a SQL Exception?
Try
…some code
Catch sEx as SqlException
…some error handling code
End Try
Is Microsoft trying to tell us something here??
Microsoft Office and .NET
I know Microsoft is trying to make everything .NET, and they have there is a Visual Studio .NET for Microsoft Office thing, but I mean, it is a PITA if you want to try to make managed code work with MS Office. I would like to make some add-in’s for Outlook, but I want it to be totally managed code, and you can’t do that because you have to add in the COM objects for outlook. I have a book that I have been reading for my own edification titled “Programming Microsoft Outlook and Microsoft Exchange 2003“, by Thomas Rizzo, and it is a good read, but I just wish I could use all .NET assemblies and stuff instead of the the COM Objects. Maybe in the next version of Office you will be able to use totally managed code to create add-ins. I know in Whidbey, they added in the WebBrowser control, a managed code version of the Browser Control in VB 6.0.
Saint Cloud Times RSS Feed
Well, the other day, I wrote into the St. Cloud Times and asked them if they had RSS feeds for the news headlines. I got a reply that pretty much said “what do you want them for?” “go to hell”, so I did a little thinking, and just created a program to scrape the headlines and put them into a rss formatted XML file, so I can read them with my aggregator. I have it done, and I am testing it now, works like a champ. I will probably test it some more, then maybe put it up so other people can use it. 🙂