Sunday, November 24, 2013

Getting Citrix Receiver Working on Fedora 19

  1. Download the Citrix Receiver in RPM format here: http://www.citrix.com/downloads/citrix-receiver/linux.html
  2. As sudo or root, issue a `yum install ICAClient*.rpm`.
  3. Click on the .ica link in your xenapp citrix website. When prompted to open or download the .ica file, select download.
  4. Run `/opt/Citrix/ICAClient/wfica.sh launch.ica` in the directory where launch.ica was downloaded to.
  5. If you see error messages like, "Error while loading shared library : libpng12.so.0 : can not open shared object file", issue a ` yum install libpng12.i686 libpng12-devel.i686`. 
  6. Go back to your Citrix website, and click on the .ica link again. This time instead of downloading it, select open with, and choose, "/opt/Citrix/ICAClient/wfica.sh".
  7.  The Citrix receiver will now complain about  you not having a trusted certificate. You will need to find the certificate needed and place it in the following folder, "/opt/Citrix/ICAClient/keystore/cacerts/". For example if you need the Go Daddy Class 2 certificate, go to the following site and download it into the cacerts folder; https://certs.godaddy.com/anonymous/repository.pki. You can also export the certificate from Firefox (Preference -> Advanced -> View Certificates) or if you have a working Windows computer export it following these instructions.
  8. Citrix Receiver should now work. (If you encounter issues with sound try `yum install alsa-lib.i686` however I haven't bothered with sound yet)

Tuesday, September 24, 2013

VB.Net Cross Thread Events in WinForms

Today I quickly did a proof of concept on integrating a third part component into a winforms application and had to figure out how to raise events on the Windows Forms UI thread from a different one. There are plenty of examples of doing this in C# but they didn't quite translate to VB.Net.

Although a BackgroundWorker may have worked I had some more complex requirements. Therefore I slightly tweaked a C# cross thread example on stackoverflow and combined it with another example of building a custom event. Here is what I came out with. I have to investigate better ways of doing this but since there is a lack of any VB.Net examples I thought I would post one.

Imports System.ComponentModel
Imports System.Threading

Public Class CrossThreadingExample

    Private dummyThread As Thread

    Private ReadOnly crossThreadEventList As New List(Of CrossThreadEventHandler)

    Public Delegate Sub CrossThreadEventHandler(sender As Object, e As CrossThreadEventArgs)

    Public Custom Event CrossThreadNotification As CrossThreadEventHandler

        AddHandler(handler As CrossThreadEventHandler)
            Me.crossThreadEventList.Add(handler)
        End AddHandler

        RemoveHandler(handler As CrossThreadEventHandler)
            Me.crossThreadEventList.Remove(handler)
        End RemoveHandler

        RaiseEvent(sender As Object, e As CrossThreadEventArgs)
            For Each del In Me.crossThreadEventList
                Dim synchronizedInvoke As ISynchronizeInvoke = DirectCast(del.Target, ISynchronizeInvoke)

                If synchronizedInvoke IsNot Nothing AndAlso synchronizedInvoke.InvokeRequired Then
                    synchronizedInvoke.Invoke(del, New Object() {sender, e})
                Else
                    del.DynamicInvoke(New Object() {sender, e})
                End If

            Next
        End RaiseEvent

    End Event

    Public Sub Start()
        Me.dummyThread = New Thread(AddressOf DoWork)
        Me.dummyThread.IsBackground = True
        Me.dummyThread.Start()
    End Sub

    Public Sub Cancel()
        Me.dummyThread.Abort()
    End Sub

    Private Sub DoWork()
        Dim i As Integer = 0
        While i < Integer.MaxValue
            i += 1
            If i Mod 10 = 0 Then
                RaiseEvent CrossThreadNotification(Me, New CrossThreadEventArgs(i))
            End If

            Thread.Sleep(100)
        End While
    End Sub

End Class

Public Class CrossThreadEventArgs
    Inherits EventArgs

    Public Property NumberDivisibleBy10 As Integer

    Public Sub New(number As Integer)
        MyBase.New()
        Me.NumberDivisibleBy10 = number
    End Sub

End Class

And here is an example of using it on a Windows Form where a label gets updated with values divisible by 10.

Public Class ExampleForm

    Private WithEvents crossThreadingExample As CrossThreadingExample

    Public Sub New()
        Me.InitializeComponent()
        Me.crossThreadingExample = New CrossThreadingExample()
        Me.crossThreadingExample.Start()
    End Sub

    Public Sub ChangeLabel(sender As Object, e As CrossThreadEventArgs) Handles crossThreadingExample.CrossThreadNotification
        Me.LabelCounter.Text = e.NumberDivisibleBy10.ToString()
    End Sub

    Protected Overrides Sub OnClosing(e As System.ComponentModel.CancelEventArgs)
        MyBase.OnClosing(e)
        Me.crossThreadingExample.Cancel()
    End Sub

End Class

Sunday, July 28, 2013

Querying IIS Log File Information Easily

Microsoft has a command line tool called LogParser that can easily be used to execute SQL statements against log files. The tool is extremely handy when there is problem with a web service or site hosted by IIS.

For example to see if a rogue consumer of your web service is doing something silly like looping through and flooding it with calls you can query the most called web service by IP address by issuing:

.\LogParser.exe -i:W3C "
select
    count(*),    
    date as date,  
    cs-uri-stem,    
    c-ip     
from 
    \\servername\logs\current\* 
group by
    date,  
    cs-uri-stem,    
    c-ip   
having
   count(*) > 500000
" -rtp:-1
This will return a nicely formatted result like so:
COUNT(ALL *) date         cs-uri-stem                   c-ip    
------------ ----------   ----------------------------- ------------- 
510832       2013-07-11   /ExampleServices/Test.asmx    10.1.1.1  
535199       2013-07-11   /ExampleServices/Example.asmx 10.1.1.2 
Log parser is typically installed in: C:\Program Files (x86)\Log Parser 2.2

Sunday, June 9, 2013

Getting the Lenovo Yoga wireless driver working in Fedora 18

If you are like me you installed Fedora 18 off the live CD only to find that you can't do anything because the wireless card does not work by default.

To get wireless working the first step is to install the build tools needed to install the driver. The easiest way to do this is to download the install DVD to a USB thumb drive. Once you plug it into the Yoga, Fedora will mount the drive automatically. Figure out where it mounted by going to Dolphin or whatever file manager you use and viewing the path to the drive.

Now go into your yum repos and temporary change the yum repository to point to the live dvd image.
[richie@localhost ~]$ su -
Password:
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# gedit fedora.repo

change from
[fedora]
name=Fedora $releasever - $basearch
failovermethod=priority
#baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch
enabled=1
#metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
to
[fedora]
name=Fedora $releasever - $basearch
failovermethod=priority
baseurl=file:///run/media/.....PATH_TO_BASE_DVD_ISO_DIR
enabled=1
#metadata_expire=7d
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
Next disable the Fedora updates repo by setting enabled to 0 in the fedora-updates.repo file. You can also just issue a yum --disablerepo command. Remember to re-enable it once you are done.
fedora-updates.repo
[updates]
name=Fedora $releasever - $basearch - Updates
failovermethod=priority
#baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/$basearch/
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

Now issue a `yum install make gcc kernel-header kernel-devel cpp perl`

Once yum has installed all the packages needed we can finally download the Realtek driver and copy it over to the Lenovo Yoga via a USB thumb drive. The driver is located here:

http://dl.dropbox.com/u/57056576/DRIVERS/REALTEK/rtl_92ce_92se_92de_8723ae_linux_mac80211_0006.0514.2012.tar.gz

After extracting the driver go into the driver folder and issue the command, `make && make install`. If all goes well restart your Yoga and wireless should automatically work.

Make sure to re-enable the fedora-updates.repo by setting enabled=1.

Update 11/17/2013: Please note that whenever you perform a yum update and a new kernel is installed you will need to re-perform a `make && make install` on the wireless driver. Also, the last time I updated my kernel, the make failed. I fixed the failure by downloading a more recent version of the driver: https://github.com/lwfinger/rtl8723au