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



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



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)



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



Hi again,

I received an comment from David, where he asked on how to create an thumbnail with you own custom size in this control.

So I thought about it and thought it would be the easiest way to create an aspx page that creates an thumbnail,this page could then be used in your website for other thumnail generation aswell.


All you have to do now is to change the imageurl property and pointto the GenerateThumb.aspx webpage and add some properties to the url.

It would look like this.

 <lbn:hyperlink id="img1" runat="server" imageurl="generatethumb.aspx?image=images/image-1.jpg&width=92&height=92" navigateurl="images/image-1.jpg"  tooltip="Picture 1" />

Easy right ?

Attached is the updated site with the generatethumb aspx included.

 /tommy

LightBox.Net_Updated.zip (1.05 mb)



Feb
12

Long time no see..

by Tommy T | Tags: ,

In the last few months I have been pretty busy with a few projects, but at least I managed to finish an earlier project "MailSlots and c#".
I have seen a  bunch of  messages regarding these so I decided to finish it.

The first version I posted was not so very good, it used pointers and thus had to be run as "unsafe", so I rewrote the whole thing and made sure it can be runned as managed code.

To use it is pretty simple, first create an instance of the MailSlotService.Server and feed the contructor your Ootbound file , Inbound file and then what scope to open the mailSlots in.

MailSlotService.Server _svc = new MailSlotService.Serve("MyApp\Out","MyApp\In",".");

The scope is defined like this. * is whole domain and . is local computer.

Then just connect: _svc.Connect();

So now you have created an In and outbound mailslot. To send data just call _svc.SendData(mydata_here) and the data will be sent.

To receive data you will have tosubscripe to the  OnMailSlotReceievedData event. All incoming data will be received through this event.

If you have any questions please message me and I'll try and help.The source will be attached at the end.

  /Tommy


MailSlotService.rar (23.70 kb)



When I am working with Subsonic I usually write an own Domain entity that maps certain fields form the table entity that SubSonic generetes. The reasom I do is that i am trying to Decouple Subsonic form my DomainModel to enable easier testing and making it easier to change the underlying datalayers.

This is a very trivial work writing these mapping methods so I tried to make a generic one using c# generics. I have used it only for my projects and they are working so I though i would post it so anyone else could use it if its needed or at least get a hung or inspiration in creating you own mapping procedure.

Now this method is assuming that fields in both classess are identical, I will expand this Utitlity class later and enable attributes for easier mapping.

So here is the source code:

 

   10 public static void SyncronizeProperties<T, U>(ref T inputObject, ref U returnObject)

   11         {

   12             string propName = string.Empty;

   13             foreach (PropertyInfo info in inputObject.GetType().GetProperties())

   14             {

   15                 if (info.CanWrite)

   16                 {

   17                     propName = info.Name;

   18 

   19                     PropertyInfo remote = returnObject.GetType().GetProperty(propName);

   20                     if (remote != null)

   21                     {

   22                         if (remote.CanWrite)

   23                         {

   24                             if (info.GetType().ToString() == remote.GetType().ToString())

   25                             {

   26                                 remote.SetValue(returnObject, info.GetValue(inputObject, null), null);

   27                             }

   28                         }

   29                     }

   30                 }

   31             }

   32         }

 

  

 

So to call this method I simply call:

SyncronizeProperties<MyEntity, SubSonicEntity>(ref myEntity, ref subonicEntity)

Now the identical PropertyNames will be syncronized.

 Its just an idea but yo might have some need for it.

 /Tommy



I am executing queries against alot of different databases during a ordinary workweek, so I found this superb little application
that does it all.

Its MiniSqlQuery by PK Software

 

Every now and then I need to export the data quickly to send by email or any other way,
now this was missing but thanks to a nice SDK written by Paul it was easy to implement.

So the Exportplugin exports to Html,Csv or Xml, this should be enough for now.

The user interface is quite simple and should be self explanatory:  



Here is the plugin and source code.

  MiniSqlQuery.Exports.Plugin.zip (664.97 kb)

Have a nice day !

/tommy



Well the summer is to an end and its time to get back to work :-),

During this autumn its time to learn the "old" technologies like Linq and WCF and others. I spent most part of my summer learning WCF and think its
time to learn Linq.

While starting to look for information I found two useful tools.

LinqPad

A very simple client for talking and creatin Linq Queries directly agaisbt databases. :-D Yihaa I love the open source community.

 



Visual Linq Query Builder

This is an addin to Visual Studio 2008, wher you design and write Linq Queries directly from within The Visual Studio 2008 IDE



So time to learn.

Have a nice day !

/Tommy



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