Ivan Porto Carrero

IO(thoughts) flatMap (_.propagandize)

20

May
2006

ATLAS Cracked the Nut

Ever since i knew about the ATLAS framework it intrigued me because it offers a lot of the features that made me avoid javascript in the past.  The issues that kept me from using javascript are well known to everybody who wrote 7 lines of javascript. Basically it comes down to browser differences in understanding javascript and the differences in the DOM implementation for the two.

Then there was Ajax.NET very nice but a lot of extra programming is involved to get minor ajaxy effects. and still the browser incompatibility.

Actually I wasn’t looking for an ajax framework I wanted  the whole deal. And I stumbled upon ATLAS like many others have of course.  I had been using ajax in intranet applications through the magixajax panel, which still has at least one feature that the update panel from atlas doesn’t have : the ability of a button to cause a regular postback from inside a panel.  It can be implemented in atlas by using a clientside control and have that cause a postback when it’s clicked.

Then Tim Haines told me about the Anthem library. A library of controls that add instant ajax abilities to numerous familiar controls.  The library works well but i found it hard to debug hence it slowed me down a lot. I am not using Anthem anymore.

The atlas framework was exactly what i wanted: extensible, cross-browser and shiny :)
The entry into the atlas world was definitely not the easiest one ever.  It started out with the updatepanels and the server side controls along with the AtlasControlToolkit. And from seeing how things worked in the control toolkit.
The updatepanel is a great tool for enhancing existing apps with instant ajax abilities, that much is certain. A downside I found with the updatepanel was the fact that the response you get back from the server is the full html version for your page and some added lines.  Not really a bandwith saver I would say. Accompanied with the fact that you can’t put a freetextbox inside an updatepanel nor a file upload control made it a close but no cigar kinda tool.  The data exchange is what bugged me the most because more data means slower pages etc…

The next step presented itself, get using webservices and do the processing client-side. Cool let’s take a look at the samples from the documentation. Aha a data service that sounds interesting. Ooops wait a minute xml script. So it took me a some time to get over the fact that it is xml script and to be convinced xml script does save you from writing tons of lines in javascript. Once you get used to the xml script it reads ok and more quickly than javascript.
The dataservice looked very cool.. it takes care of the processing of the datatables returned from my BLL. I tried to get it to work for a very long time but all I could get out of it was that it displays records (that part I had after 5 minutes) but i can’t get it to save my data back to the database (that part cost me 2 days at least). This is through bindings and xml script.  No updating kinda cripples my whole application :( 

A day later i got it working after digging deeper and doing a lot of googling and live searching. I still can’t use the dataservice except for loading data. but I can use regular webmethods to put stuff in the database and use the load method of the dataservice to get the fresh data bound to the listview and itemview controls

So now I can have my somewhat SOA oriented applications and not spend hours trying to resolve browser issues or write thousands lines of javascript to parse my results into the page.

Resources that I found to be very helpful :
http://atlas.asp.net/docs/Client/Browser/jsBrowser.aspx
http://atlas.asp.net/docs/default.aspx
http://atlas.asp.net/docs/Client/default.aspx
http://aspadvice.com/blogs/garbin/archive/2006/03/05/15591.aspx

Javascript transitions and good scripts can also be gotten from script.aculo.us
http://script.aculo.us/

Another problem with an ajax application is that the history button behavour gets broken. Or at least doesn’t work as it is supposed to work. There is a library out there called the Real Simple History Framework that makes that a thing from the past.
A detailed article can be found here :
http://www.onjava.com/pub/a/onjava/2005/10/26/ajax-handling-bookmarks-and-back-button.html?page=1

 

04

May
2006

SqlCommandBuilder .. The One I Forgot to Complete the Puzzel

Basically:.NET 2.0 is too cool :)))

After exploring the smo classes the last part of the afternoon was about creating migrating the data. I hadn’t used the ado api fully but remembered something about the commandbuilder. My conclusion : Worth taking a look at.

I do realise that it isn’t the worlds prettiest sql that gets generated but it gets the job done.  And in the case of my 125 tables that i need to migrate FAST it will save me about 1-2 weeks of writing import procedures etc. Generic datatable updates by writing one sql select command.

   18  public void ImportData(DataTable dt)

   19         {

   20             System.Text.StringBuilder sb = new StringBuilder();

   21             using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[“ConnectionString”].ConnectionString))

   22             {

   23                 SqlCommand cmd = new SqlCommand(string.Format(“Select * from {0}”, dt.TableName),conn);

   24                 SqlDataAdapter da = new SqlDataAdapter(cmd);

   25                 SqlCommandBuilder builder = new SqlCommandBuilder(da);

   26                 //da.UpdateBatchSize = 15;

   27                 da.Update(dt);

   28 

   29             }

   30         }

03

May
2006

Woohoo… Microsoft.SqlServer.Management.Smo

The problem I was facing is that I need to keep an accounting database in sync with the “real” application this company uses.

I don’t need all the tables but about 125 need to be imported with data and the whole shabang.

In my mind the best way to do that is to have something iterate the whole database, fill up a dataset and start creating the tables in sql if they don’t exist. Next step is to import all the data from the dataset into the new database.

Obviously this can be done if you just look at the dataset generator. It reads schema’s and creates .net objects from database tables.
But how do i create tables ? And how do i do it without having to write long sql strings ?

The answer is : Microsoft.SqlServer.Management.Smo
A managed library to manipulate sql 2005 :)

You can create any number of items with this library including databases, tables, functions, views, stored procedures ….
Hence woohoo.

To support just the simple types (no objects) I now have a class that does exactly what I want it to do import a database and it took me about 70 lines of code :)

All you need to know to get started can be found on the microsoft website or on david haydens website, that’s where I learned of the existence of this namespace.

http://davidhayden.com/blog/dave/archive/2006/01/27/2775.aspx

http://msdn2.microsoft.com/en-US/library/ms162203.aspx

I won’t be putting up any code with this post because it’s too easy.  If you do run into problems, i can provide you with a snippet :)

15

Mar
2006

Generics Are Great

Today I explored generics properly and I must admit that I’m very sorry i did not take the time earlier

Bottom line : GENERICS ARE GREAT

01

Mar
2006

Multi-Threading in asp.net

I got a question asked just recently about multi threading and async execution of a page.

About async execution I am a little bit biased because for asp.net I don’t really see a huge benefit most of the time and I really believe it should be used very wisely.

Spawning threads on the other hand is more convient for lengthy operations that are not essential to the execution of the page.  I will just copy paste the mail I’ve sent to the other guy. It came with a question on what about cleaning of the objects afterwards

If you use it async asp.net should take care of the cleaning.

I haven’t used the async scenario yet because I jump to separate threads more quickly that way my page isn’t blocked ever and I can update the interface through a timed ajax call to a webservice.

I use the multi threading to send mass emails with progress bar etc.

Once you’ve done it you will see that it is pretty easy to implement and has IMHO more advantages than simply executing a page async because you don’t have to wait for the execution to end.

 

You start by making a worker class with a parameterised constructor that implements at least the following interface

 

    4     interface IAggregatorWorker

    5     {

    6         void ExecuteTask();

    7         bool KeepRunning { get; set; }

    8     }

 

The execute task method is the method where you do your work as long as KeepRunning is set to true.  I believe that sessionstate is unavailable in a spawned thread so you will have to find a way to persist your session objects differently if you are needing them at all.

If you want to add properties for the worker thread to work with you that is no problem it behaves as a normal class as far as i can tell

 

In your page you start a thread by instantiating your workerclass and setting the properties

 

   45         BLL.MailThreadWorker mtc = new BLL.MailThreadWorker();

   46         mtc.Body = tbBody.Text;

   47         mtc.Subject = tbSubject.Text;

   48         Guid id = Guid.NewGuid();

   49         mtc.BaseUrl = Request.Url.DnsSafeHost;

   50         mtc.SessionId = id;

   51         System.Threading.Thread thread = new System.Threading.Thread( new System.Threading.ThreadStart(mtc.MailingStart));

   52         thread.Name = “MailingThread” ;

   53         thread.Start();

 

You can stop or suspend the thread at any time and then you can dispose of your objects that are still hanging around. By setting the property of KeepRunning property of the worker instance to false.

and there you should do your clean-up.  The code from the mailingthread is taken from the code beside (i believe is the new word for the file) of my aspx page.

 

This is a link to an article on msdn that explains it probably a lot cleaner than I ever can. Other good examples to look at what you can do with threading is to look after articles about windows services there are a few that explain the concept really clearly

 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchUsingThreads.asp

01

Mar
2006

FTP Server With Sql Acces

I have the need to run an ftp server for one of my applications. It is to complement a web application where there is a pretty big datatransfer.  Users need to be able to register and upon activation they need to be able to upload movies (20-70MB) to a folder online. These movies need to be made available online and proposed for review to somebody in the company.

So far so good. Were it not that we are running IIS Ftp server for the moment who stores it’s users in the AD of the server. That is not the place where I want to store credentials for my users. Also I wanted to make only one folder available for a user and to accomplish this IIS is just too difficult to manage.  Thus again time for an internet hunt and yessss there is is Blackmoon FTP server who allows to do the entire configuration in a sql database or an access database. 

Fits like a glove in my opinion :)
I downloaded it, installed it end yes it just works. I can now do the full configuration through the generated DAL from ORM.NET. All it took to integrate an FTP server in my application was one afternoon and that’s it.

You can download blackmoon from their site. They offer a free version for personal use. But even from the enterprise edition with domain license you won’t become  poor man :)
http://www.blackmoonftpserver.com

01

Mar
2006

A Poor Man’s Code Generation

There has been a lot of talk about code generation and ORM software around where I was.

I got curious and embarked on a free codegeneration exploration. Being new to the concept of codegeneration my requirements were the following :

  • It needs to be faster then the dataset generator of visual studio 2005

  • It needs to support relations

  • It needs to support stored procedures or at the very least use dynamic query language that uses parameters to set up queries to the database.

  • It needs to be with a very very fast learning curve.

  • It needs to be free (although I also looked at the wilson O/R mapper which is practically free and LLBL codegen which is definetely not free)

These are my findings :

The one that is most easily found is mygeneration with the dOOdads architecture out of the box. Of course you can create your own templates to customize the generated code to you your specific needs and architecture.
my generation can be found at : http://www.mygenerationsoftware.com/portal/default.aspx
It does work fine but the dOOdads architecture does not support relations and these you have to make yourself again.  I found it all a bit too much fiddling about and it didn’t meet my 2 of my requirements, thus the search went on.

Next I found ORM.NET, which is the one I am using for the moment. Total setup time of a DAL that is easily queried 1,5 min flat. I was impressed, and best of all it is completely free. Apparently it is written by a consulting firm that used it for their internal needs. They no longer support it and it turned open source.
ORM.NET gets my stars. And I will be using it a lot in simpler scenario’s like websites etc.
ORM.NET can be found at : http://www.olero.com/OrmWeb/index.aspx?p=ORM.ascx

While looking for some documentation on ORM.NET I came across a link to ntiergen.net which can handle about any job. It generates stored procedures for you, along the DAL and the needed classes. You get to configure all your stored procedures beforehand and get the opportunity to create views and complicated queries through their interface.  Normally it is priced at $449 but the link I found offers a fully functional licensed version open for the public. I downloaded it and just gave it a brief look as I am very pressed for time at the moment.
nTierGen.NET can be found at http://weblogs.asp.net/gavinjoyce/archive/2004/08/28/222017.aspx

Happy code generating !!!

 

28

Feb
2006

Quirky IE Behaviour for Add Event Listener

Today I had to build something so I needed to add multiple functions to the window.onload event

So what I discovered today is when you use the following snippet for attaching events .. They don’t get loaded in the right order by this I mean Firefox fires the one that says yay first and then the again one… IE fires first the latter and then the first.  Nothing to be worried about for the moment,in my case at least, but when you need it to initialise some functions.. it can get you into a lot of head scratching.

function myAddEvent(obj, event, listener, useCapture) {
  // Non-IE
  if(obj.addEventListener) {
    if(!useCapture) useCapture = false;

    obj.addEventListener(event, listener, useCapture);
    return true;
  }

  // IE
  else if(obj.attachEvent) {
    return obj.attachEvent(‘on’+event, listener);
  }
}

function myListener() {
  alert(‘yay’);
}

function myListener2() {
  alert(‘yay again’);
}

myAddEvent(window, ‘load’, myListener);
myAddEvent(window, ‘load’, myListener2);

26

Feb
2006

Seems Like Work Isn’t Slowing Down for the Moment

I thought I was busy before I got this thing on my hand.   Now it’s even worse. 
I don’t know where to crawl first.

I got my MYOB professional partner subscription last week and am trying to integrate it now in the program I’m writing.  And I have to say.. It’s not all that hard.. just open the docs and you’re good to go.

But what annoys the hell out of me, apart from not being able to run myob on a win2k3 server, is that myob is slow as a dog.  A request can easily take up to 30 seconds to complete. This gives me an excuse to delve into the async pattern. It appeals a lot to me.. but seens as I ‘m always pressed for time I don’t get to experiment all that often.. But this problem does give me the necessity to do it.

Maybe I will post my findings later.  If the async pattern doesn’t give me a good viable solution to my problem I have another way of going about it.  SQL server 2005 supports managed code, which we are all very aware off, so  I can reference and consume a webservice and stick all the myob datatable queries in a sql db as xml, index it and it is also searchable.

But first let’s get to the async pattern..

To top