Showing posts with label nuget. Show all posts
Showing posts with label nuget. Show all posts

Thursday, 3 December 2015

How to access TeamCity REST API from C#?

If you work with JetBrains TeamCity as your Continuous Integration server, you probably know that it has rich REST API that allows querying builds, their configuration, builds queue and also perform CRUD operation on them. It might be extremely useful for building custom monitor, triggering builds, cleaning builds queue and many other activities.

In this post I would like to present FluentTc: an easy to use library for all the above operations. When I started working on this library, I had in mind, that it should has fluent, easy to discover API. That's what I like in libraries I consume, so I developed a library that looks like I like it and I hope that you r will find it also usable and easy to use.

In order to get started to use it, you need to install the recent package from Manage Nuget packages -> Search FluentTc

or typing the below in your Package Manager Console of

install-package FluentTc 

So now, having the reference, let's get to the code.

In order to get all the build of specific Build Configuration, you can simply use:


If you are familiar with TeamCity REST API you might know that when retrieving list of entities, it returns only some basic properties of those entities, Id, Name and some Href. It also provides an option to retrieve additional properties. And this is how it can be done using FluentTc:



The above methods return default amount of builds as retrieved from TeamCity REST API. If there is large amount of builds, you'd probably prefer retrieving them with paging, i.e. a few builds each time. This is how it can be achieved with FluentTc:



Of course you can apply different query filters when retrieving your builds. For example, in order to retrieve not personal, pinned, successful builds, that ran during the recent day under specific build configuration, use this:


Credits:
FluentTc was inspired by Paul Stack's TeamCitySharp library.

For questions/suggestions feel free to comment below.

Thursday, 20 February 2014

How to follow best practices of NHibernate with WCF integration?

If you work with NHibernate, you are probably familiar with its best practices. When working with WCF we need to maintain UnitOfWork and transactions. There is a library that makes this integration seamless: NHJump by James Lanng and Richard Penrose.

Marking your service class with an attribute will do the magic:
  • will create a unit of work per request
  • will open a transaction
  • will commit it at the end of the request or rollback it if an exception was thrown
 [ServiceContract] 
public interface IPersistenceService  {  ...  }  
[UnitOfWork]
public class PersistenceService : IPersistenceService  {  ...  }

Sounds nice? It has also ASP.NET MVC integration.

Samples can be found on SVN repository:

Available on nuget:

PM> Install-Package NhJump.Persistence

Tuesday, 20 August 2013

How to install a development machine for .NET development

Recently I had to install a development machine from scratch. Like many developers I hate doing things twice, thus I summarized my experience in a few lines of command-line script. The script is divided to three logical parts:

  1. .NET Development environment
  2. Repositories
  3. Database

Let me introduce Chocolatey: the magical command-line installer that made my life much easier since I was introduced to it. You need to install it once by pasting  the magical piece of code to command-line console:
C:\>@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin - See more at: http://chocolatey.org/#sthash.6Kd97faR.dpuf

.NET Development contains 
  1. VS2012 Professional. From my experience Professional edition is good enough for most of the development tasks. The Express edition is not supported by Resharper, so it is not acceptable for me. 
  2. Resharper - needless to explain its importance here.
  3. Nuget Package Manager - same
  4. Resharper Nuget plugin - a very nice plugin for Resharper, that significantly made my life easier: when I type a class ,which is not referenced in my project, the plugin looks whether a corresponding package is already referenced is adds reference to that package (instead of adding reference to bin\Debug\some_package.dll )
cinst VisualStudio2012Professional
cinst resharper
cinst NugetPackageManager
cinst resharper-nuget

Repositories:
These command-line lines install Tortoise SVN and VisualSVN.
cinst tortoisesvn
cinst visualsvn

Database:
You may choose any database, I chosen MySql for the small project I am working on. These lines of code would install MySQL server. Please note that root has empty password after the installation. It would also install a free SQL Client tool: HeidiSQL
cinst mysql
cinst HeidiSQL


P.S. A few last words about licensing. I do not encourage anyone working with illegal software, the opposite. All the above programs, except Visual Studio and Resharper, are free. They were especially chosen for the small development projects and are free of charge. Visual Studio license can be acquired by applying to BizSpark program of Microsft, for more details . Resharper license can be provided for free by JetBrains for open source projects.

Tuesday, 16 July 2013

Automatic Deployment :: Choosing the magic tool

About a year ago I was asked to automate the deployment process. Actually it has some level of automation, but it should be significantly improved. When my boss says "significantly improve", he means "completely rewrite". In the beginning I was looking for that magic tool, that click-and-relax solutions that will do the work. Polling at StackOverflow and googling around resulted with a list of tools. This post will focus on advantages and disadvantages of these tools. In the next post I will try to explain what solution was chosen and why.

eyeShare by Ayehu http://www.ayehu.com/

eyeShare is a descent UI based tool for deployment automation and monitoring. I was interested only in the automation part. It provides and drag and drop user interface with different kinds of actions: Copy, Stop Service, Start Service etc. It has many cool features, such as email and SMS notifications and listeners. The listeners allow the user to respond to some failure in some action. For example, deployment of the database failed, eyeShare will send email/SMS with notification and will wait for reply: proceed or rollback database changes. This might be extremely useful. However it has some major drawbacks for our basic scenario:

  1. deployment processes stored by eyeShare are not version controlled, they are stored in SQL Server database with no history tracking; 
  2. it requires installation of the UI management on each machine and there is no web UI accessible from all the machines; 
  3. something that took me sometime to understand and I had to talk to their support: let say I have action A and then action B. I assume that until action A is finished, action B does not start. Basic serial processing. However eyeShare executes action in parallel, even of they are organized serially in the deployment workflow. There are some workaround that need to be done using timers and timeout in order to overcome this behavior. 
Octopus Deploy http://octopusdeploy.com/

Octopus Deploy is a cool deployment project for ASP.NET and Windows Service projects. Actually I did not dive too much into it, since it requires any software component will be delivered as a nuget package. Since our product has many dependent components, it was decided that it would be too much work to package every component as nuget package.


Puppet http://puppetlabs.com/

Puppet, puppet, puppet! Everybody in the DevOps world talk about Puppet. If your want automatic deployment you have to use Puppet. 

I was curious when starting to learn about Puppet. I have to admit, that the learning curve was steep, but at the end we had automatic deployment POC using Puppet. After the POC was completed it was decided not to proceed with it. Here are some of the reasons. My feeling was that Puppet it more Linux/Unix oriented, that Windows. Since our main product is developed in .NET and should be deployed to Windows servers, the whole overhead with Linux style paths and Linux style commands is ridiculous. Some of the operations are not supported in Puppet agent on Windows and I had to write scripts in Powershell. At the end it resulted that most of the things are written in Powershell, so there was no reason to use Puppet as a manager of these scripts.

For the actual selected and working solution wait for the next post:
http://borismod.blogspot.co.il/2013/07/automatic-deployment-final-solution.html





Wednesday, 8 February 2012

How to update references to a 3rd party assembly in all the projects in the solution?

Let's say you have a 3rd party assembly referenced in many projects in your solution. Once a new version of the 3rd party assembly is released, you probably would like to update the references in all your projects in a solution to the new version.

Are you using NuGet to update 3rd party libraries?
If the answer no, install Extension for Visual Studio RIGHT NOW from NuGet

Copy the following script to the root directory of your solution


Navigate to View -> Other Windows -> Package Management Console

Run the following command

PM> .\Upgrade-Package.ps1 -PackageID:log4net