May 2, 2010

Not so long ago I learned about new validation aaproach in MVC 2. It’s realy cool and extensible.

My favorite validation framework is Application Validation Block from Enterprise Library 5.0 from Microsoft’s patterns and practices team. It’s widely adopted and I thought that there is some implementations of validation using this framevork for MVC 2. There were not, and this is realy surprised me.

April 22, 2010

As I’ve found out there were no files for .Net Framework 3.5 SP1 in the Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1 folder. There were only packages.xml and en folder with product.xml and eula.

Today I decided to publish our internal project with ClickOnce technologie on our IIS 7 web site and I’ve got several problems google helped me to solve. But there was one that I had to solve by myself.

I desided, that .Net framework 3.5 sp1 should be located in same location application does, not to download it from vendors server.
After I pressed publish button some files been published, but the process had stop when it tryed to publish dotnetfx35sp1/dotNetFX20/aspnet.msp file and showed error following error

August 8, 2009

Few days ago I had t0 create form, that will just let user to define connection string. I was pretty shure that there I’ll find working example in google, but I could not. So I had to write it by myself.

First of all I’ve created class SimpleConnectionStringBuilder, that implements INotifyPropertyChanged, so I could bind it.

June 10, 2009

Yes, it’s not possible for the service to be restarted for itself. Actualy this could be very handy. I have two servers, with Sql Server on one of them an service, that connects to this sql server on the start. Sometimes electricity shuts down, so both servers goes down, but when they rises up, server with Sql server do it slower then server with services, so servise can’t be started sucessfull. It never starts, nothing ever works. Huge problem. So in my case I needed something that will be starting my service untill connection returns. In my case the problem was, that OnStart event have had initialisation part that had sql connection, and it was realy not so easy to remove this initialisation from OnStart. Actualy I didn’t whant to do this, becouse it’s logicall to do initialisation on start. Why am I tolking about this? Becouse there is an easy way to solve the problem.

May 26, 2009

Once upon a time I’ve decided to install old 32bit ODBC driver on my 64bit Vista and write and run .Net project, that use it. There were not 64bit driver available so I had no choice.

After passing thru installation of driver without any problems surprises have begun. First big surprise was when I had tried to open Data Sources(ODBC) and to create System DSN. There were not such a driver. I tried a lot of things, even writing directly to registry – no result. Finaly I’ve descovered that there is a folder C:\Windows\SysWOW64 and there is a file odbcad32.exe that is for 32 bit. When you open Administration->Data Sources(ODBC) it’s opensC:\Windows\System32\odbcad32.exe wich works only with 64 bit drivers. So first problem was solved. I was able to create datasource with C:\Windows\SysWOW64\odbcad32.exe.

Second surprise was that Visual Studio project was not able to acees this data source. The problem was in build configuration. After changing active solution platform in Build->Configuration manager from Any CPU to x86 everething started working just fine.

April 15, 2009

As a windows user, I realy like to download latest versions of sofware, because they have bugfixes ( and brand new bugs 🙂 I also love everething that is 64bit, and as an ASP.NET developer I love IIS7. So when I decided to install trac to organise our team’s development process, I’ve opened http://trac.edgewall.org/wiki/TracOnWindows and started from the begin. This article is some kind of the step by step tutorial of how to make it 64 bit IIS7 fast cgi.

Simple things

If you are looking for trac, that means that you are already know what svn is. You’ll need subversion client, such as http://tortoisesvn.net/downloads. I’m pretty shure you already have it. Second thing you need is Visual Studio VC++ to cmpile sources. If you don’t have it – you can do the following:

The last thing create folder C:\src4trac\ – for sources. There will by lot of them 🙂 Shourely you can create any folder you like.

Install Python

First, that I’ve read was that I need Python. I was surprised that trac is written on Python. I’ve never used python before, but alway’s whanted to try. So without bothering myself with reading of what I need I went to http://www.python.org and downloaded 64 bit 2.6.2 python installer. I have not noticed

The Subversion project does not provide amd64 or ia64 setup executables, so if you want to use Subversion integration, you’ll need to either compile the bindings yourself, or use the x86 version of Python.

It’s generally hard to find pre-compiled extensions, so you most often have to compile them yourself (e.g. for Genshi, Mercurial, the bindings for the DB backends)

But I realy heapy about not noticed that. I’ve had very intersting week 🙂

So, go ahead, install 64 bit Python 2.6.2 or later.

Install easy_install

The second thing we’ll not be able to enjoy trac without is easy_install. Easy install is cool thing, it’s helps install different python programs easily. So you can type in command line
easy_install trac

and if you get error add C:\Python26\Scripts to the PATH environment variable and reload command line.

Congratulations we’ve overjumped first problem. It was not so hard, and now we can install trac itself 🙂

Install Trac and Genshi

If you have internet connection without proxy server – then simply type

easy_install trac

It will do all the job.

If you have proxy on computer you install trac or if you don’t have internet connection on this computer at all then download from other computer from http://trac.edgewall.org/wiki/TracDownload zip or tar of laterst trac(not the installer) and put it’s unziped/untared content to C:\src4trac\Trac. After that download genshi tar or zip from http://genshi.edgewall.org/wiki/Download and put unziped/untared code to C:\src4trac\Genshi. Now do the following

Running Trac under IIS 7, fast cgi

Standalone server is good, but hard to manage. So it’s much better to use some more powerful server such as IIS. We can run it trac as CGI but it’s not an option – too slow. The very reasonable way to make it run under IIS is it’s new FastCGI module. But here we can read

Note for Windows: Trac’s FCGI does not run under Windows, as Windows does not implement Socket.fromfd, which is used by _fcgi.py. If you want to connect to IIS, your choice may be AJP.

As for me AJP is realy strange thing and not an option – I want FastCGI. So if trac’s fcgi does not support Windows, then we need to find other FCGI module for python. So let’s download http://pypi.python.org/pypi/python-fastcgi and put code to C:\src4trac\PyFCGI folder. Do you think it’s all? No. The most interesting part starts right now.

Download The Development Kit from http://www.fastcgi.com/drupal/node/5 and put the code to the C:\src4trac\FastCgiKit Open C:\src4trac\FastCgiKit\Win32\FastCgi.dsw. If you get error

Connot load project due to a corrupt project file.

on opening projects – you should open dsp files in the text editor that supports conversion between Unix format and windows format. Notepad++ is the right thing. So after the conversion solution will open with all projects.

Visual studio will open. Config_h project will be unavailable – it’s ok. Now you should open Main menu -> Build-> Configuration Manager

Set Active solution configuration: Release. Set Active Solution Platform x64. If there is only win32 option – click on <New> and in Type or select new platform: select x64, Copy settings from Win32.Leave checkbox about creation new platform checked. Cntrl-shift-B. Does not complile. Right.

As you can remember C:/TracProjects/TestProj is the place where we’ve created test environment for trac. Pretty long way 🙂 I’m tired of typing alredy 🙂
There is not much left to do. Now open C:\tracbackup\trac-0.11.4-py2.6.egg\trac\web\fcgi_frontend.py file and replace it’s code with following:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C)2005-2009 Edgewall Software
# Copyright (C) 2005 Matthew Good
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://trac.edgewall.org/wiki/TracLicense.
#
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://trac.edgewall.org/log/.
#
# Author: Matthew Good
import pkg_resources
from trac import __version__ as VERSION
from trac.web.main import dispatch_request
import fastcgi
def run():
s = fastcgi.ThreadedWSGIServer(dispatch_request, workers=1)
s.serve_forever()
if __name__ == '__main__':
run()
pkg_resources.require('Trac==%s' % VERSION)

There is a time for looking if we are on the right way.
Run from command line
python C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\cgi-bin\trac.fcgi

Configure IIS7

Create application pull, named trac and without managed code. Create appliction named trac in the default web site called trac aimed on C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\htdocs in trac application pool.
Create virtual directory in your trac appliction called cgi-bin pointed on C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\cgi-bin.

In trac application open Handler Mappings, click Add module mapping… and fullfill form with the following values:

If it works – you are lucky. If not – set rights on folder c:\Python26 for

NETWORK SERVICES
IUSR_MACHINENAME

There is one more posible bug. Open C:\Python26\Lib\site-packages. There is folders wich ends on .egg. If there is files wich ends with .egg – it’s zip archive. Unzip it to the folder with exactly same name wich have file in the same folder. For example if you have

C:\Python26\Lib\site-packages\genshi-0.5.1-py2.6-win-amd64.egg file – you should inzip it’c content to the C:\Python26\Lib\site-packages\genshi-0.5.1-py2.6-win-amd64.egg folder. This bug is about PYTHON_EGG_CACHE environment variable. Google it if you want:)

So now – it should work. Trac on IIS 7 on fast cgi! Wow! We are greate. Is it the end of our journey? No.

Security

To be completely heappy – we need to be able to login. First of all turn on Basic Authentification for trac application in Autherization in IIS management console.
After that open C:\Python26\Lib\site-packages\trac-0.11.4-py2.6.egg\trac\htdocs\web.config file and add

as a first level child of <configuration> tag. Actualy you can configure security in any way you like, per user or per role.

Trac and Subversion

Trac and subversion are made for each other 🙂 You can read http://trac.edgewall.org/wiki/TracSubversion about it. This article is for unix. As a Windows user we will do everething in our way :).
Actualy when you need to connect to the subversion repository from trac – you need python bindings of subversion’s dll’s so Trac could do all subversion can. Happyly subversion project include everething you need for such bindings.

Note. When you compile subversion python bindings – you will get subversion + subversion python bindings. Someone can deside to use this compiled subversion binaries not onle for bindings, but for the subversion itself too. I recomend not to do so and do the following – compile subversion bindings for python and use them for trac. But for the subversion functionality itself get subversion binaries from http://subversion.tigris.org/getting.html#windows and instal subversion, create repository and checkin something there and live heapyly. Why? Becouse if you compile them for truck only – you don’t need ssl libraries, berkley db libraries and so on, becouse truck will not use them anyway. You can use minimal number of subversion satellite projects – so the less code you’ll need to compile – the less problems you’ll get 🙂

If you already have subversion 1.x.y. installed then you need to create bindings of 1.x.y. We will make 64bit bindings. Don’t worry – it does not matters how many bits have your installed subversion. If you don’t have subversion yet – download the version you like and install it. Create repository. If you don’t cnow how – read http://svnbook.red-bean.com/en/1.1/ch01s05.html (till the end;))

I have had subversion version 1.5.2 so I had to make my bindings for this version. So let’s do so. First create folder C:\src4trac\svnTheGreate – to show our respect for subversion :). Checkout http://svn.collab.net/repos/svn/tags/1.5.2 Planty of files.
So while you are reading C:\src4trac\svnTheGreate\subversion\bindings\swig\INSTALL – I’ll go get some cofee. It will take you some time 🙂
So welcome back. As you’ve read, you need http://www.swig.org/. Download http://prdownloads.sourceforge.net/swig/swigwin-1.3.39.zip for example and unzip it to C:\src4trac\swig folder. After that download APR from http://apr.apache.org/download.cgi and unzip it to the C:\src4trac\svnTheGreate\apr folder. Download latest APR -util and put it to the C:\src4trac\svnTheGreate\apr-util folder. So let’s compile them. In 64 bit. Let-s start from apr.
It’s simple. Release. x64. Build.
Now open C:\src4trac\svnTheGreate\apr-util\aprutil.dsw. There will be 4 projects that contains iconv in name. They will be unawalable. Never mind. Open C:\src4trac\svnTheGreate\apr-util\include\apu.hw file and set #define APU_HAVE_APR_ICONV 0 instead of 1.
So Release, x64. Build.
Dont worry about _bdb_ projects – you just don’t need them. 6 project’s will fail. Not more.
Now you should do the folowing.

Copy folders Release and LibR from C:\src4trac\svnTheGreate\apr-util\x64 to C:\src4trac\svnTheGreate\apr-util\
Copy folders Release and LibR from C:\src4trac\svnTheGreate\apr-util\x64 to C:\src4trac\svnTheGreate\apr-util\
Copy folder LibR from C:\src4trac\svnTheGreate\apr-util\xml\expat\lib\x64 to C:\src4trac\svnTheGreate\apr-util\xml\expat\lib\

Download Zlib. http://www.zlib.net – and unzip it to the C:\src4trac\svnTheGreate\zlib folder. We do not need to compile it. It will be compiled later with bindings.
Download Neon http://www.webdav.org/neon/ and unzip it to C:\src4trac\svnTheGreate\Neon

All java perl and ruby projects will fail – do not worry, we don’t need them. But if libsvn_fs fails – this is fatal.
If it’s not compile – reread. You must be mised something. Is apr and apr-util compiled in 64 bits? Have you moved folders from x64 and so on.

Now create c:\src4trac\BindingsInstaller.bat

@echo off
SETLOCAL
::Standard commission
SET _svn=C:\src4trac\svnTheGreate\
SET _psb=C:\Python26\Lib\site-packages\

The End

I’ve spent 2 weeks to find the ways. Nothing worked from the first time, and there were no any infomation via google. So I’ve decided to write my experience down in a very detailed way. I know, that it just can’t be too detailed. This article is valuable for the following reasons: Trac on IIS 7 fast cgi – no information in internet at all. Second reason is detailed instructions on subversion python bindings 64 bits. It has it’s tricks like x64 directories. Thank you for spending your time on reading this tutorial. Hope it was usefull. Comment please 🙂