Connecting to Informix in .NET

Imports IBM.Data.Informix

Dim ifxConnection As IfxConnection = New IfxConnection

dbname   = "mydb"
dbserver = "ifx1"
dbhost   = "192.168.1.10"
dbuid    = "dbuser"
dbpwd    = "password"
dbproto  = "onsoctcp"
dbsvc    = "ifx1"

ifxConnection.ConnectionString = "database=" & dbname & ";" & _
				 "server=" & dbserver & ";" & _
				 "host=" & dbhost & ";" & _
				 "uid=" & dbuid & ";" & _
				 "pwd=" & dbpwd & ";" & _
				 "protocol=" & dbproto & ";" & _
				 "service=" & dbsvc & ";"

	Try
		ifxConnection.Open()
		Console.Write("Success!")
		ifxConnection.Close()
	Catch ex As Exception
		Console.Write("Error: " & ex.Message)
	End Try

Windows Uptime Command

I generally use a quick command like net statistics server|more on a Windows machine to quickly grab the uptime.  I decided to put together a small uptime utility that will report the uptime of the system using, you guessed, uptime command.

Drop the uptime.exe into your %PATH%; either something like %WINDIR% or %WINDIR%System32 folder.

The code is available on Github at http://github.com/rjkreider/uptime if you want to take a peek at the code.

Here’s the obligatory screenshot…

I’ll also put a direct download link that is stored on my server.  This is dated 12/19/2016, so check Github to make sure you have the latest.  I may have found a bug, or someone may have found a bug, and things may have changed since I initially published this article.

Download ZIP – uptime.zip

Get File Count Recursively

I’ve been working on a small tool to aid in removing duplicate files and as I’m going back over my roughed in code, I’m trying to optimize it for some performance gains.

This snippet of code works really well for recursively counting files given a specific path.  I originally found it at StackOverflow and slightly modified to suit my needs.

Sub ProcessFile(ByVal path As String)
        fileCounter += 1
    End Sub

    Sub ApplyAllFiles(ByVal folder As String, ByVal extension As String, ByVal fileAction As ProcessFileDelegate)
        For Each file In Directory.GetFiles(folder, extension)
            fileAction.Invoke(file)
        Next
        For Each subDir In Directory.GetDirectories(folder)
            Try
                ApplyAllFiles(subDir, extension, fileAction)
            Catch ex As Exception
            End Try
        Next

    End Sub

It processes about 27k files in 1.5 seconds on my SSD disk.  I have it running against a NAS with considerably larger amount of files, so I’ll see how well it performs.

In my sub, I use the following to kick it off.

        Dim fileCounter as Long = 0L
        Dim path = "z:"
        Dim ext = "*.*"

        ToolStripStatusLabel1.Text = "Calculating files..."

        stpw.Start()

        Dim runProcess As ProcessFileDelegate = AddressOf ProcessFile
        ApplyAllFiles(path, ext, runProcess)

        stpw.Stop()

        Dim rslts3 As String = String.Format("Total files = {0:n0}. Took {1:n0} ms.", fileCounter, stpw.ElapsedMilliseconds)
        ToolStripStatusLabel1.Text = rslts3.ToString

Graphically speaking, this isn’t much to look at – but the important part is in the ToolStripStatus. I have a timer on my form that updates the latest file count every 15 seconds so that a user would know it’s still working. Interestingly enough, if I update the ToolStripStatus with every single file that is found, it exponentially increases the time it takes to go through the files, so I decided to just update every 15 seconds.

Office.com Online using WinForms

This isn’t true API access, just a WebBrowser control. I’m looking into the API though which would require me to register my Application even though it’s not a Windows App.

It has a launcher (I haven’t decided exactly how I’ll integrate this) that will launch the Microsoft Office Online services at the click of a button.

As you can see, you can still access the Navigation provided by Microsoft. I fixed the Winform so it doesn’t launch a new window and keeps everything inside the Winform on the WebBrowser control.

I guess I see this side project being useful for someone who wants to use the free Office.com Online services with their Microsoft account and don’t want the full browser experience.

2014-08-08_141453

2014-08-08_141506

2014-08-08_141519

2014-08-08_141525

Some notes to get this to render properly in the WebBrowser control.

I had to force a User Agent to indicate I was using IE11. I think what I was seeing was that the WebBrowser control was defaulting to MSIE7. Made things look like crap.

VB.NET Code for this:

Private Property uag As String = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko"
     _
    Private Shared Function UrlMkSetSessionOption(ByVal dwOption As Integer, ByVal pBuffer As String, ByVal dwBufferLength As Integer, ByVal dwReserved As Integer) As Integer
    End Function
    Const URLMON_OPTION_USERAGENT As Integer = &H10000001
    Public Function ChangeUserAgent(ByVal Agent As String)
        UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, Agent, Agent.Length, 0)
    End Function

I implemented forcing new windows to the WebBrowser control in the Winform. If you use the top navigation at all, it opened the service in a new Internet Explorer Window.

VB.NET Code for this:

    Private Sub Webbrowser1_NewWindow(sender As Object, e As CancelEventArgs) Handles WebBrowser1.NewWindow
        WebBrowser1.Navigate(WebBrowser1.StatusText)
        e.Cancel = True
    End Sub

Originally, I wanted to just wrap this in a HTA or something simple… but I got errors indicated that I couldn’t pull this in an iFrame. So I tried some Ajax/jQuery stuff in HTA and that was a complete fail (I’m not familiar with ajax/jquery things).