Gorgo.Live.ToString()

Mariusz, Gorzoch tech Blog

Archive for October 2013

TFS 2012 Code review how to start

leave a comment »

Most common question when it comes to „code review” process is „how to start” ? In nut shell there are two approaches to do code review in TFS 2012 and Visual Studio 2012:

A. Not blocking approach (recommended for now)

In that approach you first check-in the code and then request review (post code review). Going for that way you ask for an feedback on things with you already placed in TFS.

clip_image002

How to do it :

1. Complete work around work item and check-in your changes

2. Go to history and find changeset associated with check-in from point 1

clip_image003

clip_image004

3. Request review

clip_image006

A: Enter people with you would like to do review of your code

The best people to choice to do code review are team members of your own project. Anyway if they are too busy then you can try to ask people from outside your project to do it for you. Not being member of your team project is not blocking code reviewers for proving you feedback.

B: Provide description of the change

C: Submit request

4. Done

Your request review should now be submitted to the reviewer and they should :

– Get email with information that review is pending for them

– They should see it in “My work” tab

clip_image007

B. Blocking approach

In that approach you don’t check in your changes but instead of that you request for review of changes with are pending.

clip_image009

In nut shell this process looks like this:

1. You complete your work and when you are ready to check-in then instead of using option “Check-in” you use “Request review”

2. You fill the “request review” form in similar way as described in point A.3 and submit your review

3. You suspend your work (all current changed) with help of new “suspend” feature in “My work” panel.

4. Now you can start working on new feature/work item

5. After a while you get feedback around code review.

6. You suspend your current work

7. Now you need to resume changes suspended in point 3

8. You review changes, adjust your code and check-in code or go for the next code review round

9. Once changes are check-in you resume your work from point 6

As you can see that approach is much more tricky and complex. This is the reason why I recommend to start from option A. Moreover that approach strongly relay on quick feedback around code review as it block your check-in and exposes you to long and boring marge process.

So, to do or not to do code review ? If you are still not sure if it is worth to go for it let me give you few proven reasons:

1. Finding bugs early, when they are cheap to fix.

2. Coding standards compliance. Code review helps to maintain consistent coding style across the company.

3. Teaching and sharing knowledge. During review team members gain better understanding of the code base and learn from each other.

4. Consistent design and implementation. Peer review helps to maintain a level of consistency in software design and implementation.

5. Higher software security. Applications that require a high level of security benefit from targeted security reviews.

6. Team cohesion. Review discussions save team members from isolation and bring them closer to each other.

7. Confidence of stakeholders. You build confidence of stakeholders about the technical quality of the execution.

Written by Mariusz Gorzoch

17 October 2013 at 18:55

Posted in TFS

Tagged with ,

Do backup of SQL database and ftp / ftps it to remote location

leave a comment »

Here is the problem : you have SQL server with some production databases and you need to secure backups of those databases in some remote location. In our case this remote location is accessible only thru FTPS.

To do that you have at least two option:

1. You can go and use SqlBackupAndFTP application http://sqlbackupandftp.com/ . In case of that option you can use that tool for free to do backup and ftp of max 2 databases and you are limited to FTP. If you are force to use FTPS like we are, then you need to either buy full version of find some other way.

2. You can build peace of PowerShell script and run it as part of database maintenance plan. And that is the approach I went for.

Below you can find peace of PowerShell script I wrote to achieve that task:

[Net.ServicePointManager]::ServerCertificateValidationCallback={$true}
$Dir = "c:\temp"
foreach($item in (dir $dir))
{
    $content = [System.IO.File]::ReadAllBytes($item.FullName)
    $ftp = [System.Net.FtpWebRequest]::Create("ftp://{FtpServer}/{HomeFolder}/"+$item.Name)
    $ftp = [System.Net.FtpWebRequest]$ftp
    $ftp.UsePassive = $true
    $ftp.UseBinary = $true
    $ftp.EnableSsl = $true
    $ftp.Credentials = new-object System.Net.NetworkCredential("{UserName}","{Password}")
    $ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
    $rs = $ftp.GetRequestStream()
    $rs.Write($content,0,$content.Length)
    $rs.Close()
    $item.Delete();
}

First line of the scripts resolve problem with missing SSL certificate on your SQL server. Without that you will not be able to use above script as system will not trust remote FTP server (unless FTP SSL certificate is in your trusted store)

Next we iterate thru each file in folder pointed in line two and for each of it we open FTPS ($ftp.EnableSsl = $true) connection and upload our file.

Please note that above approach has one disadvantage : to send file, we load it into memory. If you will have bigger files then this can be a problem. Anyway I’ll leave to solve that problem to you (if you know .net then it shouldn’t be a big deal)

happy PowerShelling.

Written by Mariusz Gorzoch

15 October 2013 at 22:03

Posted in Powershell, SQL

Tagged with ,