Tuesday, May 27, 2008

GUID Validator

Working with Unique Identifier (known also as GUID) I need to know if a funtion gived or returned string is really a GUID or something else. Since there isn't a predefined funtion to do that, I create my own function using Regular Expressions:


Public Function IsGUID(ByVal guid As String) As Boolean
    Dim rtn As Boolean = False
    If Not String.IsNullOrEmpty(guid) Then
        Dim guidRegEx As Regex = New Regex("^(\{{0,1}" & _
           "([0-9a-fA-F]){8}-([0-9a-fA-F])" & _
           "{4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-" & _
           "([0-9a-fA-F]){12}\}{0,1})$")
        rtn = guidRegEx.IsMatch(guid)
    Else
        rtn = False
    End If

    Return rtn
End Function

Word 2007 OOXML Tags

Developing a program, you may need to save datas in different formats, like excel or word...
Saving text in word format it's quite simple, but do it in word 2007 format (.docx) it's different (it uses xml). Formatting this text is more difficult, 'cause format tags isn't well documented. This is why i put some of them above.

<p>text</p>
<w:p><w:r><w:t>TEXT</w:t></w:r></w:p>

<br />TEXT
</w:t></w:r><w:br /><w:r><w:t>TEXT

Bold
<w:r><w:rPr><w:b /></rPr>TEXT</w:r>

Underline
<w:r><w:rPr><w:u w:val="single"/></rPr>TEXT</w:r>

Italic
<w:r><w:rPr><w:i /></rPr>TEXT</w:r>

Colors
<w:r><w:rPr><w:color w:val="FF0000" /></rPr>TEXT</w:r>

Sunday, May 18, 2008

Unlocking locked files on Team Foundation Server

Some time ago, working on Team Foundation Server 2005, I have to unlock a number of files locked by other users (for example, files locked in an unavailable Work Area). After some search in Microsoft Newsgroups and in technical documents, i can build a working procedure to unlock them:

1. On command prompt, go to C:\Program Files\Microsoft Visual Studio 8\Common7\IDE on TFS server

2. Write:
“tf lock $/ProjectName/LockedFileName /lock:none /workspace:WorkArea;UserThatLocks /server:TFSServerName

4. Write:
“tf undo $/ProjectName/LockedFileName /workspace:WorkArea;UserThatLocks /server:TFSServerName

Friday, May 16, 2008

Ajax - FadeIn and FadeOut Animation

With Microsoft AjaxToolkit you can do a lot oh things but the most complex (for me) is to apply an animation to an object. However, with a small amount of lines, you can create simple animations and effects for a WebForm.

In this example, we wanna show a customized tooltip when the mouse is over a button and then that it disappears when the mouse is out. We use fadeIn and fadeOut animations, 0.5 seconds long and with a framerate of 20fps:


<cc1:AnimationExtender ID="AnimationExtender1" runat="server"
TargetControlID="ImageButton1">
     <Animations>
          <OnMouseOver>
               <sequence>
                    <StyleAction AnimationTarget="info"
                    Attribute="display" Value="block"/>
                    <FadeIn AnimationTarget="info" Duration=".5"
                    Fps="20" />
               </sequence>
          </OnMouseOver>
          <OnMouseOut>
               <sequence>
                    <FadeOut AnimationTarget="info" Duration=".5"
                    Fps="20" />
                    <StyleAction AnimationTarget="info"
                    Attribute="display" Value="none"/>
               </sequence>
          </OnMouseOut>
     </Animations>
</cc1:AnimationExtender>



info is a "div" that contains our tooltip. Must be written in this way:

<div id="info" style="display: none; z-index: 2; opacity: 0;">

Thursday, May 15, 2008

OpenVPN on PFSense: Site to Site

Assume this scenario:

Office1 LAN: 192.168.0.0/24
Office2 LAN: 192.168.1.0/24

We have to configure the PFSense server to connect this two networks.
One office will be the VPN server, the other will be the VPN client

NB: if you also have a VPN access for road warriors configured, don't change the existing configuration but add a new tunnel.

Office1 configuration
Let's configure Office1 as server.
From “VPN à OpenVPN” menu, select “Server” tab and click on “+”.

Use TCP protocole and, if you have other VPN tunnels, set a diffrent port (in this example i use the port 1193). Obviously we have to creat a firewall rule to permit WAN connection on this port.

“Address pool” must be an independent subnetwork, diffrent from both subnetwork in Office1 and Office2.

In “Remote network” area set the subnet of Office2.

Now we have to generate the “Shared key”. Log into the PfSense server of Office1 via SSH, type “8” (shell) and then use this command:

# openvpn --genkey --secret shared.key

This command creates a new shared key for this OpenVPN server. Then copy the content of shared.key file into the Shared Key WebInterface box and press “Save”.

We have to copy this shared key to use it later on the Office2 server.


Office2 configuration

Let's configure Office2 as client.

From “VPN à OpenVPN” menu, select the “Client” tab and click on “+”.

Use the “TCP” protocol.

“Server address” must be the public IP of Office1.

“Server port” is the connection port for the VPN set on the Office1 PfSense (in this example 1193.)

“Interface IP” must be the IP address of local LAN.

“Remote network” must be the IP address of the Office1 LAN dell’Ufficio1.

Paste the previous generated shared key into the shared key box and then click on “Save”.

Now the VPN tunnel between this two offices should be “up and running”.