Been busy

by tommyt25. May 2012 13:29

Hello,

 

Have bene busy with my company, its called Trackntrace and we do GPS Tracking.

 

Will start writing these blogs again, this time about things I learned during these ast two years i have been building Trackntrace backend.

 

/Tommy

Tags:

Massive by Rob Conery

by tommyt24. February 2011 11:21

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

Tags:

C#

Disabling comments

by tommyt15. June 2010 12:55

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

Tags:

Filehelpers

by tommyt2. June 2010 16:41

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

Tags:

C#

Windows 7 Annoyance

by tommyt2. June 2010 16:36

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

Tags: ,

C#

Stuck in China

by tommyt18. April 2010 05:14

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

Tags:

Changing Jobs

by tommyt21. October 2009 11:18

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

Tags:

Mini Repository using Reflection

by tommyt2. September 2009 17:27

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)

Tags:

C# | Vs2008

Update

by tommyt31. July 2009 13:42

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

Tags: ,

Portable

My Little daughter is here

by tommyt3. May 2009 21:37

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

Tags:

Other

About the author

Something about the author

Page List