How to speed-up generating PDFs via TMS Flexcel

In my current project we needed to generate lot of PDFs from the same excel template.  For this we use TMS Flexcel library. It is a simple library for generating Excel or PDF files in .NET. It loads a xls template from filesystem, populates it with data and that’s it. Quite easy. But generating tons of files in a cycle can be a pain, because the template has to be loaded from file system in every iteration. That can be performance problem. The solution is to read the template into MemoryStream and then in each iteration create new XlsFile object from this memory stream. …

Continue Reading

Handle exceptions in ASP.NET + IIS

Handling exceptions in ASP.NET can be quite tricky. There is lot of ways how to handle them, some are described in the links below (see resources to study). Our solution looks like this Web.config <system.web> <!– MVC Settings –> <compilation debug=”true” targetFramework=”4.5.1″ /> <customErrors mode=”On” /> <!– TODO: Use RemoteOnly for production –> </system.web> <system.webServer> <!– IIS Settings –> <httpErrors errorMode=”Custom” existingResponse=”Auto”> <remove statusCode=”404″ subStatusCode=”-1″ /> <remove statusCode=”500″ subStatusCode=”-1″ /> <error statusCode=”404″ path=”/ErrorPages/404.aspx” responseMode=”ExecuteURL” /> <error statusCode=”500″ path=”/ErrorPages/500.aspx” responseMode=”ExecuteURL” /> </httpErrors> </system.webServer> Because we need to log the exceptions for investigation we added filters. If you do not care what …

Continue Reading

How to call any function as a $filter in AngularJs

Recently I had this little trouble. I had a simple angular controller, which filtered some array of items. I did not want to define the filter in a “global space” because I knew it will be used only by this one controller. So this first thing was to define the custom filter function. Like this $scope.customFilter = (item)=> { return item.someProperty == $scope.filterValue; }; Then call in UI like this. <htmlElement ng-repeat=”item in itemList | filter:customFilter”></htmlElement> So far nothing special, just what is in the angular documentation. But I needed to call that custom filter again, but not from UI …

Continue Reading

Selenium WebDriver can’t start

After a few days of writing tests using Selenium, the WebDriver suddenly stopped working. It did not even start. I tried to restart my machine, check versions of Firefox and Selenium (both were up to date), restart Visual Studio, clean solution. Nothing worked.  There was not even an exception description. All I got was a message “Exception does not have a stack trace”. Not very helpful. After some time I found the cause of this: When Selenium WebDriver starts it creates its own copy of  Firefox profile in Temp folder. If WebDriver is stopped in a standard way, then it …

Continue Reading

How to optimize SQL generated by NHibernate

If we query objects with lot of dependencies NHibernate can (and I believe by default will) load all of them. In many situations this is not necessary. For example all we want is to count objects with some properties or show only 3 properties of some object. The object has lets say 20 properties, some of them pointing to other DB objects and those pointing to another objects. How to optimize this? It is actually quite easy. Use Linq’s SELECT method. NHibernate is clever enough to translate it into optimized SQL. But there is one drawback to consider: NHibernate can …

Continue Reading

How to unit test Angular’s $resource and $http

Unit testing of Angular’s underlying $http can be very tricky. I’ve some spent considerable time to get the unit testing up and running. What was running OK in a live application, was not working at all in a unit test. I was getting error message “No pending request to flush !” all the time. My controller looked something like this //TypeScript Module.controller(“UsersCtrl”, [<any> “$scope”, “$location”, “User”, function ( $scope, $location : ng.ILocationService, User: ng.resource.IResourceClass) { $scope.findUsers = () => { User.query({ email: $scope.searchTerm, showAdHoc: $scope.showAdHoc }, function (data: any) { //data arrived. Do something with them }, function (errorData: any) …

Continue Reading

Function string.format ported from .NET to AngularJS

Have your ever wondered if there something like string.format() method as known in .NET but available in Javascript? And waht about AngularJS? The answer is yes. Guys from Microsoft wrote library Ajax Control Toolkit, containing little this gem String.js (I found it via Stackoverflow). I needed it as a filter in AngularJS, so I have ported it there. The code is available on Github. Example of use <h4 class=”result”> {{‘put values here “{0}” and here “{1}”‘ | stringFormat:[‘1’, ‘2’] }} </h4> Result is put values here “1” and here “2” ONLINE DEMO ON JsFiddle Comments welcome.

Continue Reading

Nebuďte programátory

Překlad eseje: http://alexthunder.livejournal.com/309815.html Už nějakou dobu přemýšlím, jak různým lidem vysvětlit, jak programátoři vlastně pracují. Lidem, kteří nepracují podobným způsobem. Co se děje v geekově mysli, když dlouhou dobu zírá na monitor a občas napíše pár znaků? Přijde mi těžké, téměř nemožné, něco takového vysvětlit v podstatě komukoliv. Vypadá to, jako by celá společnost byla rozdělena na dvě poloviny: Ti, kteří tomu rozumějí, a ti, kteří ne. Ti, kteří tomu rozumějí, žádné vysvětlování nepotřebují, tedy alespoň do té doby, než je někdo o vysvětlení požádá. Ti, kteří netuší, co se v hlavě programátora děje, to možná ani vůbec nezajímá nebo si …

Continue Reading

Dobrodružství s Ask Toolbar

K nové verzi Javy nám Oracle nadělil dáreček v podobě univerzálního kurvítka webových stránek. Jmenuje se Ask Toolbar. Neobjevuje se bohužel jen jako součást instalace Javy, ale je v poslední době přibalován i k užitečným prográmkům zdarma. Chápu, že jejich autoři potřebují peníze, ale přidávat pro to, do svých programů takovouhle sračku… to bych se styděl. Ask Toolbar sám sebe popisuje jako “užitečné rozšíření prohlížeče, aby uživatelé mohli snáze přistupovat ke svým oblíbeným webům”. Pokud si nedáte pozor, tak vám změní nastavení vyhledávače na Ask.com. Tím legrace nekončí, protože Ask Toolbar aktivně mění HTML kód prohlížených stránek. Jednak jejich lišta …

Continue Reading