Click here to Skip to main content
15,867,921 members
Articles / Programming Languages / C#

CD Beaver - Optical Media Storage Management

Rate me:
Please Sign up or sign in to vote.
4.75/5 (4 votes)
31 Mar 2009CPOL6 min read 31.6K   319   24   9
Solution for Archiving & Managing Optical Media
CD-Beaver

Introduction

CD-Beaver is a simple program for cataloging optical media such as Compact Discs (CD) and Digital Versatile Discs (DVD). The application uses an XML back end as its data store and is a nice partner for disc carrying cases. The purpose of the CD Beaver is to simplify the process of storing and locating discs and the files contained on those discs. In this article, I will demonstrate the various uses of CD Beaver and how it could make archiving your media easier and less stressful.

Background

As with most of my personal projects, this one was born from utter frustration. It all started a few years ago when a colleague of mine who owns a small business was looking for an automated system for storing optical media. He soon came across a solution from Opdicom called Disk Stakka. Below you can see a setup similar to his; five units stacked together providing a storage solution for 500 discs at a reasonable cost of $625 ($125 per unit).

stackka.gif

Following a few months of use, he purchased another 3 units and he insisted this was a solution worth the cost. On his recommendation, I decided to invest in 4 units myself; at a time when I really couldn't justify the expense. The units took a lot of initial overhead getting all the discs into it and cataloging all the files. I was very satisfied initially in having all my DVD movies, video games, backup discs, TV Recordings, Music, and family photos safely stored in the unit.

Within a matter of months, one of the units began to fail and within the year every single unit had failed. The discs consistently got stuck in the unit and ultimately the only way to retrieve a disc from any of the units was to take them apart and guide the disc along its path so it would safely eject from the system. This caused extreme embarrassment as this would always seem to happen when I was entertaining or needed to get access to a disc for some emergency work situation.

What started out as an exciting solution for an old problem for me turned into a nightmare scenario where my media was being held hostage and the only way to get access to my media was to break into this pale beige disc eating beast! I decided several months ago that there was no hope for this ridiculously inept product and I set about creating an alternative.

Design Process

The goals for the project are really simple. I need a solution for storing and retrieving optical media.

The first solution was to use a basic spreadsheet like this:

Image 3

The spreadsheet solution works fine for DVD movies where the file contents are insignificant (AUDIO_TS/VIDEO_TS) but for data discs it poses a problem. Let's take a look at the following work flow:

Image 4

You can see from the above work flow that I have a CD/DVD carrying case named Big Bertha. Contained in sleeve 20C is a disc named PBS Frontline S2004 and contained on that disc are various episodes of the PBS program Frontline. Using the spreadsheet solution, there is no way to relate the files on the disc to the disc itself, or the binder in which it lives without creating a much more sophisticated spreadsheet. If I want to browse the television programs in the collection or search for a specific program, the spreadsheet solution becomes a real hassle. I wanted a solution where I can search disc contents as well as disc titles.

Essentially, entities relate like this: CD-Binders contain Discs and Discs contain Files. Therefore Binders contain Discs as well as Files. Discs have one binder and many files. And Files have one binder and one disc. Refer to the diagram below:

Image 5

With this representation of our physical objects, the original objective can be achieved.

Preparing the Binder for Cataloging

Image 6

The above photograph demonstrates how to setup binders for cataloging. I have added the numbering scheme to the photograph so it's easier to see. Using a black sharpie marker, I number every page starting with 1. If the binder has 4 sleeves per page then each sleeve is labeled from A to D. If the binder only contained 2 sleeves, then the sleeve would be labeled from A to B. So in the photograph above, we are on the 3rd page in the CD-Binder and the sleeve 3A refers to the 3rd page in the binder in the first sleeve (upper-left corner). 3B refers to the 3rd page in the binder in the second sleeve (upper-right corner) and so on.

The binder cover is labeled and the binder is given a name. This binder is named Big-Bertha and has a total capacity of 352 discs (88 pages). Big-Bertha is used to store my family's DVD movie collection. I have another CD-Case named Boob-Tube which stores the family's Tivo Recordings, and various other cases. The CD-Cases are filed safely away in a file cabinet and only the adults have access to them.

The Database

Ok, so I struggle with this choice every time I sit down to startup a project. My choices here may well limit the audience or just be plain inaccessible for some users. MySQL vs MS-SQL vs SQLite, etc, etc. I decided to try something completely crazy this time around and not use a database at all. I have been intrigued by the mass adoption of XML in the last several years and so I decided to try to use it here as my database. Word of caution; the schema I am about to show you is not normalized and violates about every best practice for data storage out there. I'm building a quick and simple solution, not a rocket ship, so please forgive the lack of compliance in that area.

XML
<?xml version="1.0" encoding="utf-8"?>
<database>
  <binders />
  <discs />
  <files />
</database>

Below you can see some sample data:

XML
<?xml version="1.0" encoding="utf-8"?>
<database>
  <binders>
    <binder name="Big-Bertha" />
    <binder name="Boob-Tube" />
  </binders>
  <discs>
    <disc name="BBC Specials 2008 - Disc 01" label="VID01" 
	size="7446 MB" sleeve="1A" binder="Boob-Tube" comments="" />
    <disc name="PBS Battlefield Vietnam" label="BFV" 
	size="7707 MB" sleeve="1B" binder="Boob-Tube" comments="" />
  </discs>
  <files>
    <file name="BBC American Future - A History part 01.avi" 
        size="467 MB" 
        created="10/23/2008 12:00:34 AM" 
        modified="10/23/2008 12:00:34 AM" 
        path="E:\" 
        disc="BBC Specials 2008 - Disc 01" 
        binder="Boob-Tube" />
    <file name="BBC American Future - A History part 02.avi" 
    	size="467 MB" 
        created="10/25/2008 12:10:22 AM" 
        modified="10/25/2008 12:10:22 AM" 
        path="E:\" 
        disc="BBC Specials 2008 - Disc 01" 
        binder="Boob-Tube" />
    <file name="BBC American Future - A History part 03.avi" 
    	size="467 MB" 
        created="10/27/2008 2:44:32 PM" 
        modified="10/27/2008 2:44:32 PM" 
        path="E:\" 
        disc="BBC Specials 2008 - Disc 01" 
        binder="Boob-Tube" />
   ...

Interesting XML CRUD Operations

I've not had the pleasure of working much with LINQ yet and I'm extremely pleased with it so far. Below I'm going to show a few interesting CRUD operations I'm using with this XML database (I use the term database in this context very loosely).

SELECT Directly from XML

I prefer to use LINQ to Objects over any other kind of LINQ since it's so simple and elegant but there are a few cases where I need to talk directly to the XML file and below you can see one of them. In this routine, I get the binders directly from the XML file and use it to populate my businessObject entities (Binder, Disc, File, etc.).

C#
XDocument _xdoc = XDocument.Load(Globals.Database);

var bq = from f in _xdoc.Elements("database").Elements("binders").Elements("binder")
         select f;

foreach (var cdcase in bq)
{
   Binder cdbinder = new Binder();
   cdbinder.Name = cdcase.Attribute("name").Value;
   ....
}

SELECT from Entities

Below you can see a member of Binder which determines if there is already a Disc stored in the sleeve entered by the user to store the Disc:

C#
public static bool SleeveOccupied(string sleeve, string binderName)
{
  Disc cd = null;
  try
  {
     cd = (from d in Globals.Discs where d.Sleeve == sleeve && 
           d.Binder.Name == binderName select d).Single();
  }
  catch (InvalidOperationException) { }
  
  return (cd != null) ? true : false;
}

No LIKE Statement?

I could not find a LIKE statement in LINQ similar to what we find in T-SQL syntax. I decided to try RegularExpressions and luckily, they worked perfectly!

C#
List<Disc> m_discs = new List<Disc>();

if (radioButton1.Checked && cbCase.SelectedIndex == 0)
{
   m_discs = (from d in Globals.Discs
              where Regex.IsMatch(d.Name, textBox1.Text, RegexOptions.IgnoreCase)
              orderby d.Name
              select d).ToList();
}

Cascade Delete

This is a ghetto pretend way of cascade deletion (it's not really cascade but I pretend it is!). When the user deletes a disc, all the files in that disc need to be deleted as well.

C#
XDocument xmldoc = XDocument.Load(Globals.Database);
string xpqd = String.Format("database/discs/disc[@name = '{0}']", 
				listView1.SelectedItems[0].Text);
string xpqf = String.Format("database/files/file[@disc = '{0}']", 
				listView1.SelectedItems[0].Text);
xmldoc.XPathSelectElement(xpqd).Remove();
xmldoc.XPathSelectElements(xpqf).Remove();
xmldoc.Save(Globals.Database);
listView1.SelectedItems[0].Remove();
Utility.LoadDb();

Conclusion

Building the system was very fun and simple; a weekend project that actually turned out nicely. Finding discs and archived files is no longer a pain in the ass and because things went so well, I had 30 minutes of pure pleasure pounding my 4 Disk Stakka units with a steel baseball bat and watching them shatter into hundreds of pieces; which I later melted in a bonfire!

History

  • 03/31/2009 - Submitted article

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
I'm a professional .NET software developer and proud military veteran. I've been in the software business for 20+ years now and if there's one lesson I have learned over the years, its that in this industry you have to be prepared to be humbled from time to time and never stop learning!

Comments and Discussions

 
GeneralAccess to the path 'C:\Windows\System32\LogFiles\WMI\RtBackup' is denied. Pin
Infinity82712-Dec-10 5:29
Infinity82712-Dec-10 5:29 
GeneralRe: Access to the path 'C:\Windows\System32\LogFiles\WMI\RtBackup' is denied. Pin
thund3rstruck13-Dec-10 16:52
thund3rstruck13-Dec-10 16:52 
GeneralBuild Error Pin
Spasms24-Sep-09 9:04
Spasms24-Sep-09 9:04 
I am a newbie to programming and came across your program and wanted to run it. However when I load it into VS 2005 pro I get 7 errors and 2 warnings.
Warning 1 The referenced component 'BusinessObjects' could not be found.
Not sure how to fix this, any ideas?

Error 2 The type or namespace name 'BusinessObjects' does not exist in the namespace 'CD_Beaver' (are you missing an assembly reference?) C:\CD-Beaver\frm_properties.cs 9 17 CD-Beaver

Warning 9 The referenced project '..\BusinessObjects\BusinessObjects.csproj' does not exist. CD-Beaver
GeneralRe: Build Error [modified] Pin
thund3rstruck24-Sep-09 10:37
thund3rstruck24-Sep-09 10:37 
GeneralRe: Build Error Pin
Spasms24-Sep-09 17:06
Spasms24-Sep-09 17:06 
GeneralRe: Build Error Pin
Spasms7-Oct-09 13:41
Spasms7-Oct-09 13:41 
GeneralRe: Build Error Pin
thund3rstruck7-Oct-09 14:50
thund3rstruck7-Oct-09 14:50 
GeneralRe: Build Error Pin
Spasms14-Oct-09 12:46
Spasms14-Oct-09 12:46 
GeneralTOTAL SIDETRACK Pin
seeblunt1-Apr-09 0:17
seeblunt1-Apr-09 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.