Friday, May 16, 2008

generic property classes

Recently I needed an object that could compare the before and after values of fields and if there was a difference certain actions would be taken. This logic was soon applied to most of the fields in my class (business entity (BE)). This isn't feasible to continue for all BEs in the future. So I was trying to develop a way to create a single property that could meet the needs of any data type without having to recode the object for each datatype. After some searching I found a site that showed how to create a generic class. Not a class that uses a generic list, but an actual class that accepts a datatype when you instanciate it.

That little gem made the class easy to build and it was off to the races after that.
Example:

Imports System.Collections.Generic
'''
''' this is a generic class that can be used to contain properties for an object.
''' The class supports serialization. The class has before and current values and can tell if the vales are different.
'''

'''
'''
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True), _
System.Xml.Serialization.XmlRootAttribute([Namespace]:="", IsNullable:=False)> _
Public Class Generic_Property(Of T)

Private _B As T = Nothing
Private _V As T = Nothing

end class



notes: the objects inside the class get the type of 'T' and all references to the objects properties etc... use 'T' also.


example:
_
Public Property CV() As T
Get
Return _V
End Get
Set(ByVal value As T)
_V = value
End Set
End Property

notes: this example is serializable so it can be converted to xml and stored where ever. The values then convert back from xml to the class without any issue. It looks like all of the attributes for making the object serializable to xml are not displayed. If anyone needs help post a comment and I'll try to get you the code.

have fun.

~Lost

Wednesday, December 19, 2007

scrolling numbers with javascript

I needed a javascript based list that could scroll numbers. Additionaly, the list needed to have a min and max values.

I found one list that created an initial set of information and then shifted the div around - after spending a large amount of time trying to figure out the position I decided to create a list based on clock cycle.

The new list would compute values based on a global tracker and spin new values based on a clock ticker. At this point I went and found a clock ticker and used that as the base.

Next I wrote functions to create a list of values and pushed the values to a div.
see code below.
This could be modified to work with an array of strings...












Tuesday, December 11, 2007

Design Patterns

I have started taking a serious look at design patterns. If you google Design Patterns check out the wiki - there is loads of info contained in there and it is a good starting place. I started a book group at work and we are slated to start reading "Head First Design Patterns". So far myself and a couple of other developers are reading ahead - most seem excited.

A friend of mine went to a c# course taught by Jean-Paul S. Boodhoo (Blog at:http://www.jpboodhoo.com/blog/). The course taught my friend a great deal about test driven development and design patterns. In just a week I saw his programming ability skyrocket.

I have started trying to use design patterns in my applications - all I can say is spend most of your time thinking. The design patterns require extra effort in forethought and minimal effort for implementation.

thats all for now ~ peace

Saturday, December 8, 2007

asp.net 2.0 - disable web site with caching

So,
we have been trying to get our website to be disabled using the application state. Makes sense, it is very easy, cheap, and maintainable. Imagine my surprise when it failed on its second live use. Not sure why it failed, but I figure some point in the future I'll have to fix it. I started thinking about how this could be done.

requirements:
no database
easy to implement
potentially deployed in a web farm so must be able to hit all servers at once
does not switch users to alternate server
potentially initiated by file push (only if possible)

An additional request came to mind. One co-worker wanted to disable the site when he initiates a site update. So a file based approach would be warranted, but no one wants to check a file setting every time a post back occurs.

Then I remembered hearing that you can set cache dependency to files. I started trying to build a cache dependency against a file and guess what, it worked.

By setting the cache dependency to a file when the file changes to have settings that disable the site the cache fires the dependency method and sets the site to disabled with the appropriate message. I'll post code later.

More over, by implementing design patterns (factory/structure) I can create two separate classes with the same interfaces. Each class is used to disable the site but one class will use application state while the other will use cache. The call to the code is the same (and the type is the same (interface type)) and switching between the two is handled by the factory method.

Needless to say, this could make disabling sites during database updates easier than ever before.