CSLA 3.5 Child and Parent Patterns

From this post:
http://forums.lhotka.net/forums/thread/25658.aspx

Child pattern:

[Serializable]
public class Child : BusinessBase<Child>
{
  internal static Child NewChild()
  {
    return DataPortal.CreateChild<Child>();
  }

  internal static Child GetChild()
  {
    return DataPortal.FetchChild<Child>();
  }

  private Child()
  {
    MarkAsChild();
  }

  private void Child_Create()
  {
    // initialize new child here
  }

  private void Child_Fetch()
  {
    // load child data here
  }

  private void Child_Insert()
  {
    // insert child data here
  }

  private void Child_Update()
  {
    // update child data here
  }

  private void Child_DeleteSelf()
  {
    // delete child data here
  }
}

Editable root pattern:

[Serializable]
public class RootParent : BusinessBase<RootParent>
{
  // other class code here ...

  protected override void DataPortal_Insert()
  {
    using (SqlConnection cn = new SqlConnection(...))
    {
      // insert parent data here

      FieldManager.UpdateChildren();
    }
  }

  protected override void DataPortal_Update()
  {
    using (SqlConnection cn = new SqlConnection(...))
    {
      // update parent data here

      FieldManager.UpdateChildren();
    }
  }
}

Editable Root List:

[Serializable]
public class ChildList : BusinessListBase<ChildList, Child>
{
  // other class code here ...

  protected override void DataPortal_Update()
  {
    using (SqlConnection cn = new SqlConnection(...))
    {
      Child_Update();
    }
  }
}

Editable Child List:

[Serializable]
public class ChildList : BusinessListBase<ChildList, Child>
{
  internal ChildList()
  {
    MarkAsChild();
  }

  // other class code here ...
}

If you use the DataPortal methods for creating the child objects (i.e. FetchChild) then you don’t have to bother with the MarkAsChild() stuff.

Turn an Enum into a list in VB.Net with optional CSLA

From time to time you might have an enum that you want to databind to something as if it were a list, so I wrote some classes that turn an Enum into a list that you can databind. 

I created ways to do this in CSLA and also w/o CSLA.  I made the non-CSLA versions 1 work so that you can either use a sub class, or just use generics when defining the type of your list.  You can do the same with the CSLA versions if you want by changing some of the generics, but I didn’t bother.


'*** csla
Dim cslaList As MyTestTypeList = MyTestTypeList.GetList

'*** non-csla with inherited subclass and without
Dim list As New MyTestTypeList2
Dim list2 As New EnumList2(Of MyTestType)


'*** enum we are using
Public Enum MyTestType
something = 1
here = 2
ok = 3
End Enum

'*** csla
<Serializable()> _
Public Class MyTestTypeList
Inherits EnumList(Of mytesttype, MyTestTypeList)

End Class
<Serializable()> _
Public Class EnumList(Of T As Structure, R As EnumList(Of T, R))
Inherits Csla.NameValueListBase(Of String, Integer)

Public Shared Function GetList() As R
Return Csla.DataPortal.Fetch(Of R)()
End Function

Protected Sub New()
' require use of factory method
End Sub

<Csla.RunLocal()> _
Public Overloads Sub DataPortal_Fetch() 'ByVal criteria As Object)
Me.IsReadOnly = False
For Each item As T In [Enum].GetValues(GetType(T))
Dim name As String = [Enum].GetName(GetType(T), item)
Add(New Csla.NameValueListBase(Of String, Integer).NameValuePair(name, [Enum].Parse(GetType(T), name)))
Next
Me.IsReadOnly = True
End Sub
End Class

'*** non-csla
Public Class MyTestTypeList2
Inherits EnumList2(Of MyTestType)

End Class

Public Class EnumList2(Of T As Structure)
Inherits List(Of EnumListItem)

Public Structure EnumListItem
Dim Name As String
Dim Value As Integer
Public Sub New(ByVal name As String, ByVal value As Integer)
Me.Name = name
Me.Value = value
End Sub
End Structure

Public Sub New()
For Each item As T In [Enum].GetValues(GetType(T))
Dim name As String = [Enum].GetName(GetType(T), item)
Add(New EnumListItem(name, [Enum].Parse(GetType(T), name)))
Next
End Sub

End Class

IBM Customer Service

This chat takes place after I have already chatted with a different support group, called the IBM parts divions, and the IBM tech support division:

Mohammed: Thank you for accepting our chat service, how may I assist you?
you: When I customize an x3500, at last screen it says: (5652) Planar Base [$699.00] is required for this configuration and has been added for you.
you: What is Planar Base and what about my configuration makes it a requirement?
Mohammed: Is this for yourself (your company) or a client of yours?
you: mysefl
Mohammed: I see. I’m not too familiar with the planar base. I can have a specialist contact you to further discuss this need of yours
you: ok. How long does that normally take?
Mohammed: our usual turnaround is 48 hours
Mohammed: however we can try to have somebody contact you by end of day tomorrow
Mohammed: but I can’t make any promises
you: ok my number is (630) 708-1234
Mohammed: May I have your full name, telephone number, email address, job title, company name and physical address?
you: Chris May, (630) 708-1234, cmay@RealNameRemoved.com that should be good
Mohammed: unfortunately without all the information requested above, I will not be able to have a specialist contact you
you: ok forget it I’ll just buy a Dell

UPDATE: I did buy a Dell.  Stupid IBM couldn’t have someone take 5 minutes and answer a question for someone who wanted to give them $3000. 

WHS Backup is waiting on cleanup

Today I was trying to do a backup to my WHS and I was getting the message on my client:

Backup is waiting on (cleanup).

After quite a long time, it was still on this message.

I did some investigating on the server and saw that 45 minutes earlier my server had kicked off a backup cleanup process.  This was indicated in the event viewer under “Homeserver”. 

Task Manager also showed whsbackup.exe doing a lot of work.

So, if you run into this, just wait a bit and when the server is done with the cleanup the client backup will start like normal.

PIX ArrayIndexOutofBoundsException

So today I went to make some firewall updates for a client and the Cisco PDM wouldn’t launch from the browser.

After some troubleshooting, I found that the Java VM was indicating an ArrayIndexOutofBoundsException had occurred.

After some checking around I confirmed my suspicion: Java sucks.  Just kidding, well not really, but what I really confirmed was that the PDM wouldn’t work with any new version of Sun Java.  I guess I’m spoiled with .Net being backward compatible. 

Some suggested installing an old version of Java
http://java.sun.com/products/archive/j2se/1.4.2_03/index.html

But lucky for me I was able to just install Java 6 Update 15 and Java 6 Update 7 from Add/Remove programs and everything started working again.

It’s totally true when people accuse MS of copying Java with the .NET framework, but they sure didn’t make it suck like Java.

UPDATE: The version of Java that is working for me is Java 6 Update 6.  You can download it here:
http://java.sun.com/products/archive/j2se/6u6/index.html

Visual Studio type fly out windows in HTML

I’ve been working on a project where I wanted to have a flyout window on the left just like how Visual Studio does their menus.

Maybe “slide out” is more accurate.

I used jQuery, which I am trying to use more in my projects, for the effects.

Anyway, I ended up making it a bit harder than it needed to be by having the tab itself slide out, as well as allow for multiple tabs.

At this point I’m happy enough to move on with a successful proof of concept, but I think if I were doing this from scratch again I wouldn’t bother having the tab slide out as well.  I’d just show the sliding out window.

But, this should be a good starting point.

visualstudioflyoutmenus.htm (17.7 KB)

Update: And of course it completely fails in FF.

I made some changes, removed some things, tweaked others… looks ok in FF now.

visualstudioflyoutmenus2.htm (17.7 KB)

Using XXCopy to clone and compress your files for backup

You can use XXCOPY (www.xxcopy.com) to write simple backup scripts to copy your files to remote storage locations, but you can also use it to compress those files on the NTFS file system.

I have used /CLONE in the past because it’s easy, but a side effect is that all the files will maintain their attributes when copied to the destination.  What this means is that if a file is not compressed at the source, it won’t be compressed at the destination, even if you set the destination folder/drive to be compressed.

To solve this problem you just need to first set the compression attribute of the container of the location you are copying files too, and then use a switch to tell xxcopy to only set the “normal” attribute, which I belive sets the “A” attribute.  Either way, it works.

xxcopy E: /s /ASDC
xxcopy E: /s /AS:C
xXcopy D:FolderRoot*.* E:FolderRoot /CLONE /YY /Z0 /KN

The code here is backing up everything in D:FolderRoot to the E: with compression.

The first step sets the E: to be a compressed drive (this will work for any folder, not just the root of the drive).

The second step sets all files in all folders to be compressed.  This is just to make sure that when this runs at night, no files are missed.

The last step copies all files from the folder we care about, and the /KN swtich allows the destination files to inherit the “C” (compression) attribute from the parent folder.

 

Performing a recursive wildcard delete in TFS

Because I didn’t like the options for integrating SQL Server code into TFS, I wrote an application that scripts all our database objects to text files and then checks those files into TFS every night.  If there is a change in any of the files, those changes are versioned in TFS so we can go back and see when things were changed or recover old code without restoring the entire database.

But recently there was a problem with the server that my app runs on, and during the restore process, the backup process was run twice on a set of folders (at least that is my best guess) leaving thousands of duplciate files in a myriad of folders.

So for example, if there was a file called:

$DatabaseFilessqlserver1SomeDBNameSPsdbo.SomeSP.sql

then the restore process created another file called

$DatabaseFilessqlserver1SomeDBNameSPsCopy of dbo.SomeSP.sql

The problem is that my application does bulk checkins each night of all files under the DatabaseFiles folder.  I didn’t realize that the backup process had been messed up until it was too late, and those thousands of files were already checked into TFS.

So using this page to help with some of the syntax of using the TF.EXE command line too, I was able to perform a recursive wildcard delete.

In the end something like this worked just great:

tf.exe delete /recursive /noprompt "C:TFSrootDatabaseFilesCopy of*"

Notice that the wildcard is applied to all recursive folders under C:TFSrootDatabaseFiles.

Nice.