I got the above mentioned error when i tried to install uTorrent 1.8.4 on Ubuntu Karmic Kola i386, though wine. But this error does not come if you try to install utorrent 1.8.2 or a older version. Hence i installed 1.8.2 and then updated it to 1.8.4 and it works fine. i think the latest versions have some bug in the installer part. installing a old version that doesn’t have this bug and upgrading seems to be a good work around. Note that if you installed 1.8.4 or something newer you will have to uninstall it from wine and then install 1.8.2. even then if you are getting the same error try killing wine and restarting it (wineboot should do the trick according to http://ubuntuforums.org/showthread.php?t=630811. If that doesn’t work for you just kill the two processes that belong to wine and restart it).

Had this ISO around for a while but never really got the chance to try it out. This is a note to self. First go to http://forums.remote-exploit.org/backtrack-4-howto/23652-bt4-usb-installation-noob-proof-tutorial.html. If you are planning to install this on a 4gig or less USB stick, the video (http://www.offensive-security.com/videos/backtrack-usb-install-video/backtrack-usb-install.html) tutorial might be the one that you want to follow. That tutorial is on how to install BT to a usb stick from a booted live cd environment. If you want to just install it to a USB from the ISO it self with out burning it to a CD, you can still follow the same steps with only little modifications applied to the process.

  • Open up a terminal make sure that you are root
    • sudo su (in ubuntu)
  • Mount the ISO to some directory
    • sudo mkdir /media/iso
    • sudo mount -t iso9660 filename.iso /media/iso -o loop
  • When coping files copy them from the mounted ISO (duh….)
  • Follow the rest of the instructions as it is. Even the grub install should work with out any problems (i did this on a ubuntu box btw).

Samsung 2233SWPlus

Its been a very exciting month! After doing more than the average (from my standards :) ) amount of research on the subject of buying a lcd monitor. I settled on the 2233SW. It was one of best options i had, or so i think :) As for now i am very happy with this one. It looks grate, both the finish  and the picture quality. But then its not like i have used a lot of lcd panels. Almost all of the monitors that caught my attention are included in the following spreadsheet, with their key specs and prices in the local markets. Might be helpful to anyone who is looking in to buying a lcd monitor these days.

You won’t be able to see the table here in full because of the layout of the site, so find it here: http://spreadsheets.google.com/pub?key=tN-CeMAoc3qpsQia62azxgQ&output=html

Model Size Wide Screen Price Vendor Cost per Inch Index Brand Resolution Contrast Ratio Responce TIme Cables Brightness

943 SNX 18.5 Yes Rs. 16,950.00 Barclays 1.091 Samsung 1360 x 768 DC 15000:1(1000:1)(Typ.) 5ms ? 250cd/m^2

933sn 18.5 Yes Rs. 16,950.00 Barclays 1.12 1360 x 768 DC 15,000:1 (1,000:1) (Typ.) 5ms N 300 cd/m²

19 LCD Black 19 Yes Rs. 16,400.00 Barclays 1.158 LG 1440 x 900 2000:1 (Typical) 5ms D-Sub, DVI 300 cd/m²

933NW 19 Yes Rs. 16,900.00 Barclays 1.124 Samsung 1440 x 900 DC 15,000:1 (1,000:1) 5ms D-SUB 300 cd/m²

933NW H.G.B.? 19 Yes Rs. 16,950.00 Barclays 1.124 Samsung 1440 x 900 DC 15,000:1 (1,000:1) 5ms D-Sub, DVI 300 cd/m²

X203H 20 Yes Rs. 24,720.00 Techwearhouse 0.809 Acer 1600 x 900 DC 10000:01 5ms D-Sub, DVI 300 cd/m²

V203H 20 Yes Rs. 25,900.00 Metropolitan 0.772 Acer 1600 x 900 DC 10′000:1 5ms D-SUB, DVI-D ? 300 cd/m²

E2009W 20 Yes Rs. 22,000.00 Leaders Dell 1680 x 1050 CR 1000:1 5ms D-Sub, DVI 300 cd/m²

W2243T 21.5 Yes Rs. 24,000.00 EGS 0.895 LG 1920 x 1080 30000:1 DFC 5ms D-SUB, DVI-D 300 cd/m²

2233SW 21.5 Yes Rs. 24,000.00 techgsmsl.com 0.86 Samsung 1920 x 1080 DC 15000:1(1000:1) 5ms D-Sub, DVI 300 cd/m²

2233SW(?) 21.5 Yes Rs. 24,500.00 Tulip 0.86 Samsung 1920 x 1080 DC 15000:1(1000:1) 5ms D-Sub, DVI 300 cd/m²

2233SW 21.5 Yes Rs. 24,700.00 Barclays 0.86 Samsung 1920 x 1080 DC 15000:1(1000:1) 5ms D-Sub, DVI 300 cd/m²

2233SW 21.5 Yes Rs. 25,750.00 Techwearhouse 0.776 Samsung 1920 x 1080 DC 15000:1(1000:1) 5ms D-Sub, DVI 300 cd/m²

2233SW 21.5 Yes Rs. 27,500.00 EGS 0.86 Samsung 1920 x 1080 DC 15000:1(1000:1) 5ms D-Sub, DVI 300 cd/m²

? 22 ? Rs. 27,000.00 Sri 0.814 Dell

2333SW 23 Yes Rs. 26,850.00 Barclays 0.856 Samsung 1920 x 1080 DC 20000:1 (1000:1) 5ms D-SUB, DVI-D 300 cd/m²

X233H 23 Yes Rs. 28,325.00 Techwearhouse 0.812 Acer 1920×1080 DC 40000:01 ACM? 5ms N DVI-D HDMI 300 cd/m²

X233H 23 Yes Rs. 28,900.00 Metropolitan 0.795 Acer 1920×1080 DC 40000:01 ACM? 5ms N DVI-D HDMI 300 cd/m²

T240 24 Yes Rs. 42,500.00 Barclays 0.564 1920×1200 DC 20000:1(1000:1) 5ms N DVI-D HDMI 300 cd/m²

24 Rs. 42,500.00 Winsoft 0.564 Dell

Some pics…

more pics here: http://www.flickr.com/photos/yasi8h/sets/72157622373186619/

My New VGA

After my old vga 8800GTS died on i couldn’t even turn on my desktop. After waiting for month or so and after doing some cost\ benefit analysis i decided on a MSI 9600GT 512. It cost 14,00LKR here in SL. It have been about 2 or 3 weeks since i brought it home. So far its working fine. It doesn’t give any thing more than 25 fps on GTA IV\max settings\1900×1080. But still this is a low end card, you can’t expect wonders from it. I have never overclocked any hardware before but i decided to do some overclocking with this one. As i really needed any extra FPS i can get. The factory settings were: 600\1500\900, i am currently running it at 700\1750\1050. Now i like to think that my system is stable but it is not. It crashed two times within two days. I might have to ajuest the speeds a bit. May be take it back a little. The overclocking gave me some 3 or 4 FPS in GTAIV. Is it worth it? i don’t know. All this time the temps never went pass 60c.

I use computers a lot. like for 11 or 12 hours/day minimum. It’s a very important part of my life. And been a developer my career depends on me been able to use a keyboard. But since lately i have been experiencing some pain in my wrists. Which scared me a bit. I started searching the net for ergonomic keyboards and knowledge related to ergonomics in general. All in all i came in to a decision to pay more attention to ergonomics and to buy any equipment that i needed. Kinesis Advantage seems to be the best ergonomic keyboard out there so i ended up buying one but it was not easy. It was not available in Sri Lanka. And it was very expensive (i live in the third world by the way). Anyway i managed to buy it through amazon and get it to SL through a friend.

First of all here are some pics.

There are more pictures in flickr http://www.flickr.com/photos/yasi8h/sets/72157622050768277/

The first thing i felt when i looked at it was something like ‘oh so this cost me that much…’ . This can be much cheaper. The keys are easy to press and they are all spread across the keyboard. getting used to this thing is hard. At least for me. I am typing this post using it. i have to look at the keyboard while typing and i am using the backspace way too much. i think it will take sometime for me to get used to this. i haven’t still read the manual. i think it has some exercises and stuff to help you get used to the keyboard. it should help me get started. anyways i feel that some keys in the alphabet are harder to access than the others. this may be because i am still getting used to this thing. anyways i am looking forward to learnning and really putting thid to use. it should save my wrists and give me some value for the money i  spent o this.

There are only a few online shopping sites here in lanka that sells computer related stuff. and even within those sites only a very few are actively maintained. i am compiling a list of sites here, as i didn’t find a list anywhere else(i asked google). these consists of sites that actually let you buy online and the ones that only publishes a price list.

If you know any more sites please let me know(put a comment please).

Online Shopping Sites

http://www.memory.lk

As the name sugguest this one sells all things memory related. mostly(if not exclusively) everything they have is kingston.

http://www.laptop.lk/

Has a lot of stuff. looks like a well maintained site. but the web designing is… errr let’s just not talk about that. pricing seems ok.

http://www.slmega.com

This seems to be the only decent online shopping site over here. but then it too can improve a lot. i feel that their prices are a bit high, at least on some items. still have a huge list of products and they will virtually import anything from USA to SL. neat, but expensive.

http://www.abc.lk

Has a good set of products. this is a online shop front and it looks pretty ok. They has a lot of Apple products as well so if you are looking for something Apple don’t forget to look here.

http://www.techgsmsl.com

has a limited product range but the site seems to be updated and maintained.

http://www.barclays.lk/

ultra slow site. badly designed(oh well almost every site in this list is badly designed. basically they suck. but still its better than not having a site at all). have a good range of usual products. prices seems ok.

http://www.ibuy.lk

This is an online store run by Dialog. they do have some computer realted stuff for sale. Asian Computer Systems are offering the products. The range of products is pretty limited though.

http://www.computer.lk

have a decent range of products. prices seems to be a bit high… may be they weren’t updated in a while :)

http://www.epsi.lk/

If you want something Asus this would be a good place to look in. but most of their products are not in their web site’s product list. they don’t have a price list their either. but they do have a catalog of products. prices tend to be very high with epsi.

http://www.istore.lk

EPSI’s Apple wing. you can find iPods, iMacs…. with their local prices on this site. it’s usual for Apple products to be high priced :) but when you buy them off epsi its even more high priced. i don’t know may be they are keeping a  huge profit margin.

http://www.bhavik.com/techwarehouse

This is another new site on the block. well it’s domain name looks fishy to me… whatever the products mainly compose of Asus stuff(em… i thought EPSI was the Asus distributor for SL). prices are high… but this one has a decent web application running.

http://www.nunet.lk/

Has some good high end vga cards, memory and foxconn mother boards. you should check them out if you are out to buy something for your gaming rig.

http://www.eglobesl.com

A bit Gamer and Server side hardware supplier. expect the prices to  be higher.

http://www.sh-technologies.com/

This one looks more like web site! :) Have gaming accessories, laptops and laptop skins. Some sections are still under development. its not an online shop, just list the products with their prices.

http://www.salaent.com

Have a decent amount of Chinese/Taiwanese…etc brands. and obviously the prices are cheaper for these goods. these guys do Prolink stuff in SL. they aren’t a online shopping site but they do have a product listing on their (crappy) site.

http://www.digitalhouse.lk

Has a lot of Mercury products. and other stuff. Either this site is not updated as of date or their prices are too high.

http://www.metropolitan.lk

Have some computer related stuff like printers and scanners…etc. this is not an online store just a products listing.

http://www.futureworld.com.lk

All Apple here. looks fine. Just a products listing, no online store.

http://www.buyabans.com/phones_computers.php

yeah it’s Abans. they have a decent set of products, prices aren’t cheap. they do have some logitech gaming gear. worth a look if you are on the lookout for something.

www.lankanet.org

don’t have a lot of products but still worth looking in to. contain a price list no online store.

Junk Sellers

these sites are of companies that sell used computer/parts.

http://www.japansoft.tk/

www.microdevices.lk

http://www.usedcomputer.lk – Caution: You might vomit when you see this site. It has such a horrible look and feel.

Other

http://www.thesrilankantechguide.com

nice site! this site sort of integrates price lists from different sites together and try to provide us a with a unified set of products available in sri lanka. good effort. hope these guys can add more stores.

that’s it. there is a lot of space available for a decent site in this market segment. the ideal site would provide us customers with a wide range of products for decent prices. and also a decent web application that let us sort/search/filter/links to reviews and ratings from other sites…etc. they could do the distribution via some trasnport service, i don’t know. or else they can have a store front in colombo. let’s hope that one day we lankans will have something like newegg or atleast a decent auctioning site like ebay :)

In Short:

if you ever get a exception like “_COMPlusExceptionCode = x” in a .net application while you are debugging it in visual studio, look at the following screenshots.

Long Story:

While working on a asp mvc project i got a exception when the EF was trying to save some changes to the db. so i examined the exception object via visual studio’s visual aids. it said _COMPlusExceptionCode = -532459699 ! now what is that?

complusexception while debugging in visual studio

complusexception while debugging in visual studio

after some googling… i felt a bit lost. but by accident i came across the following error message in the same application, in the same line no, for the same exception. a usual ‘exception icon’ or whatever you call it.

a exception icon displayed in visual studio

a exception icon displayed in visual studio

now when i click on that…

visual studio exception infomation dialog been displayed for a update exception

visual studio exception infomation dialog been displayed for a update exception

viola! there is my exception. it seems that visual studio decodes these COM Plus Exception Codes to meaningful exceptions. but at times its easy to miss this way of viewing the exception.

While working on this asp.net mvc project at work i couldn’t help notice that there are lots of code that is getting copy-pasted from one controller to the other, when i am adding a new controller. now as you know mvc fm comes with a set of T4 templates that lets you add views and controllers in such a way that some code in these views and controllers are generated for you. this is grate. but you can customize the original templates to your needs and make them generate more of the code for you. (please note that i am talking about controllers that are responsible for mostly CURD on a given single model.)

First of all you will need to identify what code gets repeated from controller to controller in your asp.net mvc project. and then you can get these stuff out in to a template and start working on it.

Locating the T4 Templates

you can find your original templates in [Visual Studio Install Directory]\Common7\IDE\ItemTemplates\[CSharp | VisualBasic]\Web\MVC\CodeTemplates\ and the you can copy them to your project folder. you can start editing these copies and they will be used when you invoke your templates(ex:- by clicking on the Add Controller sub menu within the IDE). for more info please refer to T4 Templates: A Quick-Start Guide for ASP.NET MVC Developers )

Customizing

In my case i wanted my controllers to have all the basic actions like List, Details, Create, Edit and my custom actions like Grid, GridData(take a look at A Grid with Ajax/Pagination/Sorting/Filtering on ASP.net MVC with ExtJS and Enitiy Framework).

i needed to get the type of the model that a given controller is associated with. and then i have to traverse it’s properties(through reflection…etc) and do some string manipulation to generate custom method signatures and custom anonymous types. i also wanted to filter the list of properties that will be used in these parameters and anon types.

Action method signatures

action method signatures can be different from controller to controller. as in…

//Different Properties, in different models
//
//Create action of a Product Controller
public ActionResult Create(string ID, string Name, string Description, string Price)
//
//Create action of a User Controller
public ActionResult Create(string ID, string Name, string Age)

//Different Primary Keys in different models
//
public ActionResult Details(int UID)
//
public ActionResult Details(int UID, int SiteUID)

Method calls to models

//Different Primary Keys
//
public ActionResult Details(int UID)
        {
            return View(Category.GetModelByPrimaryKey(new {UID}));
        }
//
public ActionResult Details(int UID, int SiteUID)
        {
            return View(Category.GetModelByPrimaryKey(new {UID, SiteUID}));
        }

//Different Properties for different models
//
public ActionResult Create(string ID, string Name)
        {
            Category.Create(new {ID,Name}, User.Identity.Name)
            return View();
        }
//
public ActionResult Create(string ID, string Name, int PropOne, string PropTwo)
        {
            Category.Create(new {ID,Name, PropOne, PropTwo}, User.Identity.Name)
            return View();
        }

But unlike in the view here in the controller you can’t just access the model’s type through MvcTextTemplateHost.ViewDataType. when you are generating a controller this property is null. so i thought of using reflection get the model for the current controller. you can use the ControllerRootName property of MvcTextTemplateHost(available through mvcHost variable in the default template) to get the model name(ex: ProductController would give Product).

<#
Type controllerType = Assembly.LoadFile("D:\\path\\to\\your\\model\\assemblys\\dll\\file.dll").GetType("Example.Models." + mvcHost.ControllerRootName);
#>

Following is the full source code of a generated controller and the modified template that was used to generate it. I have reused some methods like IsBindableType and GetEntityKeyProperties(i have modified this a bit) that can be found in some View templates in mvc framework. The generated controller can be used to do CURD operations on the model and provide a backend(providing data to the grid through json) for a ExtJS grid! :) (A Grid with Ajax/Pagination/Sorting/Filtering on ASP.net MVC with ExtJS and Enitiy Framework)

Generated Controller

//
//A Generated Controller
//
using System;
using System.Collections;
using System.Web.Mvc;
using ExampleInc.Filters;
using ExampleInc.Lib.Helpers;
using ExampleInc.Models;
using ExampleInc.Models.UoW;

namespace ExampleInc.Controllers
{
	[Authorize]
    [NavigationFilter]
    public class ExampleModelController : Controller
    {
        //
        // GET: /ExampleModel/
        public ActionResult Index()
        {
            return RedirectToAction("List");
        }

        //
        // GET: /ExampleModel/Details/5
        public ActionResult Details(Int32 SiteUID,Int32 UID)
        {
            return View(ExampleModel.GetModelByPrimaryKey(new {SiteUID,UID}));
        }

        //
        // GET: /ExampleModel/Create
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /ExampleModel/Create
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(Int32 SiteUID ,Int32 UID ,String ID ,String Name ,Decimal Turnover ,String StreetAddress ,String City ,String PostalCode ,String Telephone1 ,String Telephone2 ,String Email ,String Fax ,String Notes ,String Capacity ,Int16 NumberOfMealsPerDay ,Decimal SellingPricePerMeal ,Decimal BudgetPricePerMeal ,String BestTimeToCall ,Byte TradingDaysPerWeek ,Byte TradingWeeksPerYear ,Boolean AccountActive ,Int32 PrimaryContact_SiteUID ,Int32 PrimaryContactUID ,DateTime LastCallStartTime ,Boolean IsProfileCall )
        {
            if (ViewData.ModelState.IsValid)
            {
                // Attempt to add the user

                if (ExampleModel.Create(new {SiteUID ,UID ,ID ,Name ,Turnover ,StreetAddress ,City ,PostalCode ,Telephone1 ,Telephone2 ,Email ,Fax ,Notes ,Capacity ,NumberOfMealsPerDay ,SellingPricePerMeal ,BudgetPricePerMeal ,BestTimeToCall ,TradingDaysPerWeek ,TradingWeeksPerYear ,AccountActive ,PrimaryContact_SiteUID ,PrimaryContactUID ,LastCallStartTime ,IsProfileCall }, User.Identity.Name))
                {
                    TempData["StatusBar"] += "ExampleModel '" + ID + "' successfully added.";
                    return RedirectToAction("List");
                }

                ModelState.AddModelError("_FORM", "Error");
            }

            // If we got this far, something failed, redisplay form
            return View();
        }

        //
        // GET: /ExampleModel/Edit/5
        public ActionResult Edit(Int32 SiteUID,Int32 UID)
        {
            return View(ExampleModel.GetModelByPrimaryKey(new {SiteUID,UID}));
        }

        //
        // POST: /ExampleModel/Edit/5
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(Int32 SiteUID ,Int32 UID ,String ID ,String Name ,Decimal Turnover ,String StreetAddress ,String City ,String PostalCode ,String Telephone1 ,String Telephone2 ,String Email ,String Fax ,String Notes ,String Capacity ,Int16 NumberOfMealsPerDay ,Decimal SellingPricePerMeal ,Decimal BudgetPricePerMeal ,String BestTimeToCall ,Byte TradingDaysPerWeek ,Byte TradingWeeksPerYear ,Boolean AccountActive ,Int32 PrimaryContact_SiteUID ,Int32 PrimaryContactUID ,DateTime LastCallStartTime ,Boolean IsProfileCall )
        {
            if (ViewData.ModelState.IsValid)
            {
                if (ExampleModel.Update(new {SiteUID,UID}, new {SiteUID ,UID ,ID ,Name ,Turnover ,StreetAddress ,City ,PostalCode ,Telephone1 ,Telephone2 ,Email ,Fax ,Notes ,Capacity ,NumberOfMealsPerDay ,SellingPricePerMeal ,BudgetPricePerMeal ,BestTimeToCall ,TradingDaysPerWeek ,TradingWeeksPerYear ,AccountActive ,PrimaryContact_SiteUID ,PrimaryContactUID ,LastCallStartTime ,IsProfileCall }, User.Identity.Name))
                {
                    TempData["StatusBar"] += "ExampleModel '" + ID + "' successfully updated.";
                    return RedirectToAction("List");
                }

                ModelState.AddModelError("_FORM", "Error");
            }

            // If we got this far, something failed, redisplay form
            return View(ExampleModel.GetModelByPrimaryKey(new {SiteUID,UID}));
        }

        public ActionResult Delete(Int32 SiteUID,Int32 UID)
        {
            if (ExampleModel.Delete(new {SiteUID,UID}))
            {
                TempData["StatusBar"] += "ExampleModel successfully deleted.";
            }
            else
            {
                TempData["StatusBar"] += "ExampleModel delete operation failed!.";
            }
            return RedirectToAction("List");
        }

        public ViewResult List()
        {
            return View();
        }

        public ViewResult Grid(string RowClickEventHandlerFunctionName)
        {
            ViewData["RowClickEventHandlerFunctionName"] = RowClickEventHandlerFunctionName;
            return View();
        }

        public JsonResult GridData()
        {
            int totalOjectCount;
            var ExampleModelsList = EmExtJSGridFilterHelper.GetResults(Request, DataMan.ObjectContext.ExampleModel, out totalOjectCount);
            var list = new ArrayList();
            foreach (var ExampleModel in ExampleModelsList) //populate data containers with read data
            {
                list.Add(new
                             {
                                 ExampleModel.SiteUID ,ExampleModel.UID ,ExampleModel.ID ,ExampleModel.Name ,ExampleModel.Turnover ,ExampleModel.StreetAddress ,ExampleModel.City ,ExampleModel.PostalCode ,ExampleModel.Telephone1 ,ExampleModel.Telephone2 ,ExampleModel.Email ,ExampleModel.Fax ,ExampleModel.Notes ,ExampleModel.Capacity ,ExampleModel.NumberOfMealsPerDay ,ExampleModel.SellingPricePerMeal ,ExampleModel.BudgetPricePerMeal ,ExampleModel.BestTimeToCall ,ExampleModel.TradingDaysPerWeek ,ExampleModel.TradingWeeksPerYear ,ExampleModel.AccountActive ,ExampleModel.PrimaryContact_SiteUID ,ExampleModel.PrimaryContactUID ,ExampleModel.LastCallStartTime ,ExampleModel.IsProfileCall
                             });
            }
            return Json(new {dataitExampleInc = list.ToArray(), totalItExampleInc = totalOjectCount});
        }
    }
}

T4 Template used to Generate the Controller

<#@ template language="C#" HostSpecific="True" #>
<#@ output extension="cs" #>
<#@ assembly name="System.Data.Entity" #>
<#@ assembly name="System.Data.Linq" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Data.Objects.DataClasses" #>
<#@ import namespace="System.Data.Linq.Mapping" #>
<#
MvcTextTemplateHost mvcHost = (MvcTextTemplateHost)(Host);
#>
<#
Type controllerType = Assembly.LoadFile("D:\\work_items\\ExampleInc\\ExampleInc-Alt-21\\ExampleInc.Models\\bin\\Debug\\ExampleInc.Models.dll").GetType("ExampleInc.Models." + mvcHost.ControllerRootName);

PropertyInfo[] piArray = controllerType.GetProperties(BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly);

string actionMethodParamerters = "", anonTypePropValString = "", gridDataAnonTypePropValString = "";
foreach (PropertyInfo pi in piArray)
		{
			Type currentPropertyType = GetUnderlyingType(pi.PropertyType);

			if(IsBindableType(currentPropertyType) && IsNeededProp(pi.Name))
			{
				actionMethodParamerters += currentPropertyType.Name + " " + pi.Name + " ,";
				anonTypePropValString += pi.Name + " ,";
				gridDataAnonTypePropValString += mvcHost.ControllerRootName.ToLower() + "." + pi.Name + " ,";
			}
		}
actionMethodParamerters = actionMethodParamerters.Remove(actionMethodParamerters.Length - 1); //remove the last extra ","
anonTypePropValString = anonTypePropValString.Remove(anonTypePropValString.Length - 1); //remove the last extra ","
gridDataAnonTypePropValString = gridDataAnonTypePropValString.Remove(gridDataAnonTypePropValString.Length - 1); //remove the last extra ","
#>
using System;
using System.Collections;
using System.Web.Mvc;
using ExampleInc.Filters;
using ExampleInc.Lib.Helpers;
using ExampleInc.Models;
using ExampleInc.Models.UoW;

namespace <#= mvcHost.Namespace #>
{
	[Authorize]
    [NavigationFilter]
    public class <#= mvcHost.ControllerName #> : Controller
    {
        //
        // GET: /<#= mvcHost.ControllerRootName #>/
        public ActionResult Index()
        {
            return RedirectToAction("List");
        }

<#
if(mvcHost.AddActionMethods) {
#>
        //
        // GET: /<#= mvcHost.ControllerRootName #>/Details/5
        public ActionResult Details(<#= GetMethodParamertersString(controllerType) #>)
        {
            return View(<#= mvcHost.ControllerRootName #>.GetModelByPrimaryKey(new {<#= GetDataAnonTypePropValString(controllerType) #>}));
        }

        //
        // GET: /<#= mvcHost.ControllerRootName #>/Create
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /<#= mvcHost.ControllerRootName #>/Create
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(<#= actionMethodParamerters #>)
        {
            if (ViewData.ModelState.IsValid)
            {
                // Attempt to add the user

                if (<#= mvcHost.ControllerRootName #>.Create(new {<#= anonTypePropValString #>}, User.Identity.Name))
                {
                    TempData["StatusBar"] += "<#= mvcHost.ControllerRootName #> '" + ID + "' successfully added.";
                    return RedirectToAction("List");
                }

                ModelState.AddModelError("_FORM", "Error");
            }

            // If we got this far, something failed, redisplay form
            return View();
        }

        //
        // GET: /<#= mvcHost.ControllerRootName #>/Edit/5
        public ActionResult Edit(<#= GetMethodParamertersString(controllerType) #>)
        {
            return View(<#= mvcHost.ControllerRootName #>.GetModelByPrimaryKey(new {<#= GetDataAnonTypePropValString(controllerType) #>}));
        }

        //
        // POST: /<#= mvcHost.ControllerRootName #>/Edit/5
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(<#= actionMethodParamerters #>)
        {
            if (ViewData.ModelState.IsValid)
            {
                if (<#= mvcHost.ControllerRootName #>.Update(new {<#= GetDataAnonTypePropValString(controllerType) #>}, new {<#= anonTypePropValString #>}, User.Identity.Name))
                {
                    TempData["StatusBar"] += "<#= mvcHost.ControllerRootName #> '" + ID + "' successfully updated.";
                    return RedirectToAction("List");
                }

                ModelState.AddModelError("_FORM", "Error");
            }

            // If we got this far, something failed, redisplay form
            return View(<#= mvcHost.ControllerRootName #>.GetModelByPrimaryKey(new {<#= GetDataAnonTypePropValString(controllerType) #>}));
        }

        public ActionResult Delete(<#= GetMethodParamertersString(controllerType) #>)
        {
            if (<#= mvcHost.ControllerRootName #>.Delete(new {<#= GetDataAnonTypePropValString(controllerType) #>}))
            {
                TempData["StatusBar"] += "<#= mvcHost.ControllerRootName #> successfully deleted.";
            }
            else
            {
                TempData["StatusBar"] += "<#= mvcHost.ControllerRootName #> delete operation failed!.";
            }
            return RedirectToAction("List");
        }

        public ViewResult List()
        {
            return View();
        }

        public ViewResult Grid(string RowClickEventHandlerFunctionName)
        {
            ViewData["RowClickEventHandlerFunctionName"] = RowClickEventHandlerFunctionName;
            return View();
        }

        public JsonResult GridData()
        {
            int totalOjectCount;
            var <#= mvcHost.ControllerRootName.ToLower() #>sList = EmExtJSGridFilterHelper.GetResults(Request, DataMan.ObjectContext.<#= mvcHost.ControllerRootName #>, out totalOjectCount);
            var list = new ArrayList();
            foreach (var <#= mvcHost.ControllerRootName.ToLower() #> in <#= mvcHost.ControllerRootName.ToLower() #>sList) //populate data containers with read data
            {
                list.Add(new
                             {
                                 <#= gridDataAnonTypePropValString #>
                             });
            }
            return Json(new {dataitems = list.ToArray(), totalItems = totalOjectCount});
        }
<#
}
#>
    }
}
<#+
public static List<PropertyInfo> GetEntityKeyProperties(Type type)
{
	List<PropertyInfo> keyProperties = new List<PropertyInfo>();

	PropertyInfo[] properties = type.GetProperties();

	foreach (PropertyInfo pi in properties)
	{
		System.Object[] attributes = pi.GetCustomAttributes(true);

		foreach (object attribute in attributes)
		{
			if (attribute is EdmScalarPropertyAttribute)
			{
				if ((attribute as EdmScalarPropertyAttribute).EntityKeyProperty == true)
				{
					keyProperties.Add(pi);
				}
			} else if(attribute is ColumnAttribute) {
				if ((attribute as ColumnAttribute).IsPrimaryKey == true)
				{
					keyProperties.Add(pi);
				}
			}
		}
	}

	return keyProperties;
}

public bool IsBindableType(Type type)
{
	bool isBindable = false;

	if (type.IsPrimitive || type.Equals(typeof(string)) || type.Equals(typeof(DateTime)) || type.Equals(typeof(decimal)) || type.Equals(typeof(Guid)) || type.Equals(typeof(DateTimeOffset)) || type.Equals(typeof(TimeSpan)))
	{
		isBindable = true;
	}

	return isBindable;
}

public bool IsNeededProp(string propName)
        {
            switch (propName)
            {
                case "CreationDate":
                case "LastModifiedDate":
                case "LastModifiedBy":
                case "EffectiveDate":
                case "ExpiryDate":
                case "ServerEntryDate":
                    return false;
            }
            return true;
        }

public string GetMethodParamertersString(Type viewDataType)
        {
			List<PropertyInfo> primaryKeys = GetEntityKeyProperties(viewDataType);

			if(primaryKeys.Count > 0) {
				string result = "";
				foreach(PropertyInfo pk in primaryKeys)
				{
					result += String.Format("{0} {1},", GetUnderlyingType(pk.PropertyType).Name , pk.Name);
				}

				return result.Remove(result.Length - 1); //remove the last extra ","
			} else {
				return "UID=Model.PrimaryKey";
			}
        }

public string GetDataAnonTypePropValString(Type viewDataType)
        {
			List<PropertyInfo> primaryKeys = GetEntityKeyProperties(viewDataType);

			if(primaryKeys.Count > 0) {
				string result = "";
				foreach(PropertyInfo pk in primaryKeys)
				{
					result += String.Format("{0},", pk.Name);
				}

				return result.Remove(result.Length - 1); //remove the last extra ","
			} else {
				return "UID=Model.PrimaryKey";
			}
        }

public Type GetUnderlyingType(Type type)
{
	Type currentPropertyType = type;
			Type currentUnderlyingType = System.Nullable.GetUnderlyingType(currentPropertyType);
			if(currentUnderlyingType != null) {
				currentPropertyType = currentUnderlyingType;
			}

			return currentPropertyType;
}
#>

hope this will help someone/myself in the feuture :)

a bit too complex title eh? sorry about that. i am finally blogging about something after a long while. its a good idea to use the revision number of your source tree in thee release versions of your software. because it will enable you to ‘connect and identify’ your release versions with your source tree’s different revisions. this is how i went about ‘automating’ it. note that I use svn as my source control system, and VS(2008) as my IDE at work.

What we are trying to do

Read the AssemblyInfo.cs file in a project and replace the(/a part of the) version number for that project with it’s svn revision number.

What you need

Code

<!-- Import of the MSBuildCommunityTask targets -->
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />

  <!-- to AssemblyInfo to include svn revision number -->
<Target Name="BeforeBuild">
	<SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="$(ProgramFiles)\VisualSVN\bin">
	   <Output TaskParameter="Revision" PropertyName="Revision" />
        </SvnVersion>

	<FileUpdate Files="Properties\AssemblyInfo.cs"
                Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
                ReplacementText="$1.$2.$3.$(Revision)" />
</Target>

Steps

  • Locate and open your project file. ex:- exampleProject.csproj in a editor.
  • Edit(SvnVersion node’s ToolPath attribute) the path of the svn bin folder, where you find the executables(ex: svn.exe, svnversion.exe…).
  • go the very end and add the following code to the file. be sure to add this code before the </project> tag closing. so that your code is still inside the <project> node.
  • Save the exampleProject.csproj file.
  • it’s done! now every time you build your project, it’s AssemblyInfo.cs file’s version will contain the svn revision number as it’s last part(x.x.x.svn-revison)

How

Let me start by saying that I am no expert in MSBuild(reffer MSDN for more info). MSBuild is the build system used by VS to build your projects. when you create a project file it is basically a MSBuild file. the build file tell MSBuild how your project should be build/compiled and about any other actions that needs to taken to insure a succesful build. when we needed to include the svn revision number of our project in the AssemblyInfo.cs file we simply added a build target called AssenblyInfo. inside that we uses two MSBuild CommunityTasks(“The MSBuild Community Tasks Project is an open source project for MSBuild tasks. The goal of the project is to provide a collection of open source tasks for MSBuild.“).

  • SvnVersion – “Summarize the local revision(s) of a working copy.” – we use this to get the svn revision of our project. the result(revision) is stroed in a property called Revision.
  • FileUpdate – “Replace text in file(s) using a Regular Expression.” – we use this task to replace the revision portion of the version string(x.x.x.revision) with the content of the Revision property.

and that’s it. pretty simple eh!

References

i recently needed to use Enum.GetValues on a .netcf project. but unfortunately it is not there in .netcf. googling gives a lot of solutions that we can use in .netcf. but i couldn’t find one that worked exactly as Enum.GetValue did.

Retrieves an array of the values of the constants in a specified enumeration.

is the method description for the Enum.GetValue, taken from msdn.com. most of the solutions online returned only an array of the constants. not their values. so i came up with the following. now of course this is inspired from lot of smart people’s code that i took from around the net sometime back. ;)


private static string EnumValuesToString(object e)
        {
            var eVal = (int) e;
            var allValues = GetValues(typeof (Testnum));
            var strings = new List<string>();

            foreach (var value in allValues)
            {
                if (value > eVal)
                {
                    break;
                }
                if ((eVal & value) != value)
                {
                    continue;
                }
                strings.Add(value.ToString());
            }

            return string.Join(",", strings.ToArray());
        }

        private static int[] GetValues(Type enumType)
        {
            if (enumType.BaseType ==
                typeof (Enum))
            {
                //get the public static fields (members of the enum)
                var fi = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);
                //create a new enum array
                var values = new int[fi.Length];
                //populate with the values
                for (var iEnum = 0; iEnum < fi.Length; iEnum++)
                {
                    values[iEnum] = (int) fi[iEnum].GetValue(null);
                }
                //return the array
                return values;
            }

            //the type supplied does not derive from enum
            throw new ArgumentException("enumType parameter is not a System.Enum");
        }

usage would go like


        [Flags]
        public enum Testenum
        {
            fld1 = 1,
            fld2 = 2,
            fld3 = 4,
            fld4 = 8,
            fld5 = 16
        }

        #endregion

        public ClassTest()
        {
            EnumValuesToString(Testenum.fld1 | Testenum.fld2 | Testenum.fld4);
        }

may this help me/you/him or her in the future :)

Next Page »