tommyt's Blog

the only limit is your imagination
Feb
24

Massive by Rob Conery

by Tommy T | Tags:

Rob Connery has created asmall and simple but yet powerful database wrapper using the new dynamic methods in .Net 4.

Check it out.

 

Massive Git hub

/Tommy



Jun
15

Disabling comments

by Tommy T | Tags:

Hi, I have been getting alot of blog spam lately so I disabled the comments until it is fixex. So if you need to ask me something, please send me a message through contact instead.

/tommy



Recently I have been involved in a project where alot of Importing and Exporting is going on, I just want to recommend a super excellent library that makes

everyhting easier when doing imports and exports and even converting between formats.

http://www.filehelpers.com/

Try it out you wont be dissapointed.

/Tommy



Jun
02

Windows 7 Annoyance

by Tommy T | Tags: ,

Nowadays when you need to take asnapshot of yourself in all the social network sites, it is annoying that there is no easy way to take a snapshot with the builtin webcam in Windows 7.

In Windows Xp it was  builtin wich was great. So I decided to make a small and quick app to do just thet, start the webcam and capture the image.

Started searching for a webcam library in Codeplex and found one with sample and all. http://easywebcam.codeplex.com/.

I created a  clickonce application and published it and now i have a easy way of taking snapshots. :-D

/Tommy



Apr
18

Stuck in China

by Tommy T | Tags:

Fantastic to be stuck in china, thank you island. !!! NOT



Oct
21

Changing Jobs

by Tommy T | Tags:

I am in a process of changing jobs, I am now quitting my position at Ericsson and gonna start working as a Lead Developer

at a company called TrackAndTrace.

 

Please visit at http://www.trackntrace.se

 

Reagards

 

/tommy



Recently I wasn’t allowed to use Subsonic but since I use it all the times I needed to have some kind of similar
functionality so I started building a Mini repository helper.

I wanted to be able to decorate my classes with Meta information telling me what tables they belong to, what fields to map the properties to, stating if it was Primary Keys, Nullables and of course what data types.

So I started creating the Attribute Classes, TableAttribute class and TableFieldAttributes class, the first ones states the Tablename the class belongs to and if Updating,Deleting and Inserting is allowed. This so I can map up Views from the database and make sure no Insert,Updates or Deletes are made.

when decoration a class it can look like this:

   1: [TableAttributes(TableName="TestTable")]
   2:    public class TestTable

and the properties looks like this:

   1: [TableFieldAttributes(IsPrimaryKey = true, DataBaseFieldName = "TestID", DatabaseFieldType = "int")]

2: public int TestID { get; set; }

The functionality I wanted in the this Mini Repository was to be able to do the basic CRUD functionality, Insert,Update,Delete,Get and GetAll, additionally I wanted to be able to send a SqlDataReader to methods and get back either an object or an list of objects. And I wanted only one method of each operations so I hard to use templates and Reflection in order to be able to do that.

The two workhorse methods is CreateObject<T>(SqlDataReader reader,PropertyInfo[] properties), this one takes an reader as an input and the reflected properties from the object, if null is inputed then the actual reflection would be mad in the procedure. The reason I did this was becuase in case i am using multiple iterations I do not want to do reflection every time, but instead input the data in advance.

This method is responsible for setting the property values in the classes, so here is where all work is done, I only handled the following data types (int,string,datetime,decimal,long,bool) but it is rather easy to add more handling.

The second workhorse method is: public static List<T> CreateObjectList<T>(SqlDataReader reader), this one does all the List making, but is directly useing CreateObject building the objects. In this method a reflection is made that is passed down to CreateObject method.

The Get,GetAll,Insert,Update,Delete methods uses reflection to get the fieldnames from the CustomAttributes in the classes and then building the SQL strings, plus alotof other checking, if there is a Primary Key etc..

   1: _properties = typeToInsert.GetProperties();
   2: foreach(PropertyInfo prop in _properties)
   3: {
   4:     TableFieldAttributes attrib = Attribute.GetCustomAttribute(prop, typeof(TableFieldAttributes)) as TableFieldAttributes;
   5:     if (attrib != null)
   6:     {
   7:         if(attrib.IsPrimaryKey)
   8:         {
   9:             PKField = attrib.DataBaseFieldName;
  10:             break;
  11:         }
  12:     }
  13: }

I also included an ExecuteReader method to execute readers, just to simplify the development in the Repositories,
all my new Repositories will inherit this class and thus they will automatically have basic crud functionality.

So an excerpt from the TestTableRepo class would look like this:

   1: public TestTable Get(int PrimaryKey)
   2: {
   3:     return Get<TestTable>(PrimaryKey);
   4: }

 

Pretty nice and elegant code !

In order to get a list all that is need is to create a command, execute it, get a SqlDataReader and then pass it to CreateObjectlist, it could typically look like this.

   1: List<ListItem> _lst = null;
   2: string sql = "SELECT * FROM ListItems WHERE ListTypeID = @ListID";
   3:  
   4: SqlCommand cmd = new SqlCommand();
   5: cmd.CommandText = sql;
   6: cmd.Parameters.AddWithValue("@ListID", listID);
   7:  
   8: SqlDataReader reader = null;
   9:  
  10: reader = ExecuteReader(cmd);
  11: _lst = CreateObjectList<ListItem>(reader);
  12: reader.Close();

Simple and nice, that is what I like !

I will attach a sample project below so you can see what it looks like, and in case you want to dabble with it yourself. I only created the bare requirements in this project, but It is not hard to extend it and to build more generic Methods in the base class.

Have a nice day !

/tommy turkijevic

Download File -

MiniRepo.rar (34.29 kb)



Jul
31

Update

Hi everyone,

There is alot of things going on for the moment now and I havent had the time to write any new posts.

I have bought a house so there is alot of activities around that.

I am involved in a secret GPS project, alot more code examples will come out of that as soon as we are official, and of course we also have a little baby at home so things are a little chaotic.

Some of the things I am researching now is Shared Caching, particulary these projects SharedCache.com and MemCached

Subsonic 3 is released with Linq support, take a alook at that, especially at the SimpleRepository.
SimpleRepository is a way to develop by crateing your Entities/Classes/Objects and Subsonic creates the nesccesary tables and saves them. You can also use
migrations, means you can change your classes and this will be updated to your tables (schema and data). Absolutely fantastic, then you query your database
through Linq.

I have a few ideas to write about but they are not formed in the head yet :-D

I wish you alla  nice day !

/tommy



My little daughter Sarah was born on the 2:nd of May. So I am gonna take a timeout for a week or two :-D

and focus on my family :-D

 

Have a nice day  and my best regards

/Tommy



A few days ago I needed to be able to create quick graphs on a website, so I surfed around for a while and I found Fusion Charts, they had a nice flash based one. So I downloaded the trial and started playing around with it.

To create a chart you needed to write xml data och add it to a webpage with some calls back to to code behind page. I didn’t like that at all so I started to write a .Net Wrapper so that I could create my charts in a more object-oriented way, by creating objects and setting properties. And finally when I am done I call the RenderChart() method in my object, assign the output to a literal and “wham” there is the chart.

This wrapper is in really really realy early stages, i still have more to fix and its messy so please bare with me until im done with it. I just though I would post it, in case anyone needs it.

The charts that are working are, Bar,Column, Area, Pie,Doughnut and Line for now (both 2D and 3D), bots singel and multiseries and stacked.

  • Settings that can me modified are:
  • Chart Cosmetics (? yes its like that on their page)
  • Margins and Padding
  • Divisional Lines and grids.
  • Number Settings and formatting.
  • Global Style definitions and map to graph objects.
  • TrendLines
  • Advanced background settings
  • ToolTip and more….

To use the the object its pretty easy, all youhave to do is creata a class of any of the following objects.

  • FusionChartsWrapper.Charts.ColumnChart – All Column variant sof the chart.
  • FusionChartsWrapper.Charts.AreaChart – Area charts
  • FusionChartsWrapper.Charts.LineChart – For Line charts
  • FusionChartsWrapper.Charts.PieChart – For pie an donut charts.
  • FusionChartsWrapper.Charts.BarChart for the Bar charts.
  • FusionChartsWrapper.Charts.CombinationCharts – are combinations, but in very experimental stage.

All the objects have the same constructow where you need to supply the following paramters:

ChartType (the charttypes you can create, enumeration)
Path (Path to the folder where the flash files are.
Width (with of the chart)
Height (Height of the chart)

Thats it now you have a a chart object youh can work with. To add data series you need to create a Series object and add it to the Dataseries list of the object.

Like this:

Serie serie = new Serie("2009");

And start adding DataPoints to the serie you do like this:

serie.Data.Add(new DataPoint("Jan",1100));

When you are finished you just add the series to the DataSeries List:

serie.Data.Add(new DataPoint("Oct", 2055));
serie.Data.Add(new DataPoint("Nov", 2199));
serie.Data.Add(new DataPoint("Dec", 2322));

grf.DataSeries.Add(serie);

If you are doing a Multi series graph, remove the “name” of the data point and create Categories. You can se very tiny example in the included web site example.

For the moment there is no validation of any kind, so If you get an Invalid Data when rendering the graph, please go to the documentation on the FusionCharts website to see how to create each graph, I will add at a later time but for the moment I am concentrating on adding chart types.

Here is some screen dumps of the charts:

gf1 Multiseries Column chart 2D

gfdonut 3D donut chart.

Like I said, this wrapper is a ongoing project and if you have any problems contact me and Ill try and help but do not expect to get my full attention, replies might take a day or two.

I hope it help you a little and good luck.

Tommy

Source Code and Test web App. Fusion Charts Wrapper Source Code



About the me

Im 38 years old and working as a System Architect. I have been woring in the IT field the last 16 years and covered most of the techniques.

In my spare time I train Kyokushin Karate and try to spend as much time as possible with my family.

On this blog I am trying to post things and Code i make or encounter on the www.

RecentComments

Comment RSS

Sign in