public static IList<Einsatz> getEinsaetze(string path, Playlist playlist)
        {
            Check.Require( new NHibernateDaoFactory().getPlaylistDao().GetUniqueByExample(playlist,
                Playlist.Property.Description.ToString(),
                Playlist.Property.IsClosed.ToString(),
                Playlist.Property.Sendetermin.ToString()) == null, String.Format(
                "A {0} entity '{1}' does already exist.", playlist.GetType().Name, playlist.Name));

            object template = path;
            object isNewTemplate = false;
            object documentType = WdNewDocumentType.wdNewBlankDocument;
            object isVisible = false;

            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document doc = app.Documents.Add(ref template, ref isNewTemplate, ref documentType, ref isVisible);

            Check.Require(doc.Tables[1].Tables.Count < 2, "Undefined word template.");

            IList<Einsatz> einsaetze = new List<Einsatz>();

            if(doc.Tables[1].Tables.Count == 0 && doc.Tables[1].Rows[1].Cells.Count == 4) {
                einsaetze = FileUpload_Service.readMdrFormat(doc, playlist);
            }
            else if(doc.Tables[1].Tables.Count == 0 && doc.Tables[1].Rows[1].Cells.Count == 7) {
                einsaetze = FileUpload_Service.readOldFormat(doc, playlist);
            }
            else if(doc.Tables[1].Tables.Count == 1) {
                Check.Require(doc.Tables[1].Rows[1].Cells[1].Range.Text.StartsWith("Titel"), String.Format(
                    "New format: row should start with 'Titel' but starts with {0}.",
                    doc.Tables[1].Rows[1].Cells[1].Range.Text.Substring(0, 10)));
                Check.Require(doc.Tables[1].Rows[1].Cells.Count == 1, String.Format(
                    "New format: column number should be 1 but is {0}.",
                    doc.Tables[1].Rows[1].Cells.Count));
                Check.Require(doc.Tables[1].Rows[2].Cells[1].Range.Text.StartsWith("Musiktitel"), String.Format(
                    "New format: row should start with 'Musiktitel' but starts with {0}.",
                    doc.Tables[1].Rows[2].Cells[1].Range.Text.Substring(0, 10)));
                Check.Require(doc.Tables[1].Rows[3].Cells.Count == 7, String.Format(
                    "New format: column number should be 7 but is {0}.",
                    doc.Tables[1].Rows[3].Cells.Count));

                einsaetze = FileUpload_Service.readNewFormat(doc, playlist);
            }
            else if(doc.Tables.Count == 2 && doc.Tables[1].Rows[1].Cells.Count == 3) {
                einsaetze = FileUpload_Service.readShortFormat(doc, playlist);
            }
            else {
                throw new PreconditionException("Unknown playlist format.");
            }

            object SaveChanges = WdSaveOptions.wdDoNotSaveChanges;
            object OriginalFormat = WdOriginalFormat.wdWordDocument;
            object RouteDocument = true;

            ((Microsoft.Office.Interop.Word.Application)app).Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);

            return einsaetze;
        }
        public void can_distinguish_playlist_format()
        {
            string path_oldPlaylist = @"C:\Development\VS2005\projects\Gema.trunk\tanzer.gema.test\service\BB080627.old.format.doc";
            string path_newPlaylist = @"C:\Development\VS2005\projects\Gema.trunk\tanzer.gema.test\service\BB080627.new.format.doc";
            string path_newestPlaylist = @"C:\Development\VS2005\projects\Gema.trunk\tanzer.gema.test\service\BB080711.doc";
            string path_shortList = @"C:\Development\VS2005\projects\Gema.trunk\tanzer.gema.test\service\BB080829.doc";

            object oldTemplate = path_oldPlaylist;
            object newTemplate = path_newPlaylist;
            object newestTemplate = path_newestPlaylist;
            object shortList = path_shortList;
            object isNewTemplate = false;
            object documentType = WdNewDocumentType.wdNewBlankDocument;
            object isVisible = false;

            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document doc = app.Documents.Add(ref oldTemplate, ref isNewTemplate, ref documentType, ref isVisible);
            //Word.Document doc = app.Documents.Add(ref newTemplate, ref isNewTemplate, ref documentType, ref isVisible);
            //Word.Document doc = app.Documents.Add(ref newestTemplate, ref isNewTemplate, ref documentType, ref isVisible);
            //Word.Document doc = app.Documents.Add(ref shortList, ref isNewTemplate, ref documentType, ref isVisible);

            Playlist playlist = new Playlist("BB080627");
            Check.Require(
                new NHibernateDaoFactory().getPlaylistDao().GetUniqueByExample(playlist,
                Playlist.Property.Description.ToString(),
                Playlist.Property.IsClosed.ToString(),
                Playlist.Property.Sendetermin.ToString()) == null,
                String.Format("A {0} entity '{1}' does already exist.", playlist.GetType().Name, playlist.Name));
            Check.Require(doc.Tables[1].Tables.Count < 2, "Undefined word template.");

            IList<Einsatz> einsaetze = new List<Einsatz>();

            if(doc.Tables[1].Tables.Count == 0 && doc.Tables[1].Rows[1].Cells.Count == 4) {
                /*
                 * neuer MDR Vordruck, wie auch immer die Burchen den hergestellt haben...
                 *
                 * Zeilen 1-3 Metadaten
                 * Zeile 4 Column Names
                 * ab Zeile 5 Daten
                 */
                einsaetze = this.readMdrFormat(doc, playlist);
            }
            else if(doc.Tables[1].Tables.Count == 0 && doc.Tables[1].Rows[1].Cells.Count == 7) {
                /*
                 * alter Vordruck
                 *
                 * ab Zeile 1 Daten ( Metadaten und Column Names in separater Kopfzeile)
                 */
                einsaetze = this.readOldFormat(doc, playlist);
            }
            else if(doc.Tables[1].Tables.Count == 1) {
                /*
                 * neues, eigens Format
                 */
                Check.Require(doc.Tables[1].Rows[1].Cells[1].Range.Text.StartsWith("Titel"), String.Format(
                    "New format: row should start with 'Titel' but starts with {0}.",
                    doc.Tables[1].Rows[1].Cells[1].Range.Text.Substring(0, 10)));
                Check.Require(doc.Tables[1].Rows[1].Cells.Count == 1, String.Format(
                    "New format: column number should be 1 but is {0}.",
                    doc.Tables[1].Rows[1].Cells.Count));
                Check.Require(doc.Tables[1].Rows[2].Cells[1].Range.Text.StartsWith("Musiktitel"), String.Format(
                    "New format: row should start with 'Musiktitel' but starts with {0}.",
                    doc.Tables[1].Rows[2].Cells[1].Range.Text.Substring(0, 10)));
                Check.Require(doc.Tables[1].Rows[3].Cells.Count == 7, String.Format(
                    "New format: column number should be 7 but is {0}.",
                    doc.Tables[1].Rows[3].Cells.Count));
                einsaetze = this.readNewFormat(doc, playlist);
            }
            else if( doc.Tables.Count == 2 && doc.Tables[1].Rows[1].Cells.Count == 3) {
                /*
                 * short Format
                 *
                 */
                einsaetze = this.readShortFormat(doc, playlist);
            }
            else {
                throw new PreconditionException("Unknown playlist format.");
            }

            foreach(Einsatz einsatz in einsaetze )
                Console.WriteLine("{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}:{8}:{9}",
                    einsatz.Track.Autor.Name,
                    einsatz.Track.Bpm.ValueAsString,
                    einsatz.Track.Code.Name,
                    einsatz.Track.Interpret.Name,
                    einsatz.Track.Label.Name,
                    einsatz.Track.Laenge.Dauer,
                    einsatz.Track.Titel.Name,
                    einsatz.Track.Verlag.Name,
                    einsatz.Track.Year.ValueAsString,
                    einsatz.Track.Ending.EndingAsString);

            this.persist(playlist, einsaetze);

            object SaveChanges = WdSaveOptions.wdDoNotSaveChanges;
            object OriginalFormat = WdOriginalFormat.wdWordDocument;
            object RouteDocument = true;

            ((Microsoft.Office.Interop.Word.Application)app).Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
        }