Esempio n. 1
0
 public override void Format(InetSongDb xmldb, Stream fw, IWaitDialog wait, object props)
 {
     using (PocketPCExporter exp = new PocketPCExporter(xmldb, fw, wait))
     {
         exp.Run();
     }
 }
Esempio n. 2
0
 public override void DownloadNew(SongDatabase db, int serverid, IWaitDialog dlg)
 {
     InetSongDb xmldb = new InetSongDb();
     object request = null;
     using (Stream fr = Read(ref request))
     {
         xmldb.Load(fr);
     }
     CloseRead(request);
     db.DownloadSongsFromServer(xmldb, serverid, dlg);
 }
Esempio n. 3
0
 public static void AddSongRow(SongData src, InetSongDb db)
 {
     //InetSongDb.songRow dst = db.song.NewsongRow();
     //CopySong(src, dst);
     //dst.title = src.title;
     //dst.groupname = src.groupname;
     //dst.author = src.author;
     //dst.songtext = src.songtext;
     //dst.lang = src.lang;
     //dst.remark = src.remark;
     //db.song.AddsongRow(dst);
 }
Esempio n. 4
0
 //public void Run(SongDatabase db, string filename, int? serverid)
 public override void Parse(Stream fr, InetSongDb xmldb, IWaitDialog wait)
 {
     XslCompiledTransform xslt = new XslCompiledTransform();
     xslt.Load(XmlReader.Create(new StringReader(xsls.zp6_to_zp8)));
     XmlDocument result = new XmlDocument();
     StringBuilder sb = new StringBuilder();
     XmlDocument zp6doc = new XmlDocument();
     zp6doc.Load(fr);
     if (zp6doc.DocumentElement.LocalName != "zpevnik_data" && zp6doc.DocumentElement.LocalName != "zpevnik") throw new Exception("Špatný formát vstupního souboru");
     xslt.Transform(zp6doc, XmlWriter.Create(sb));
     using (StringReader sr = new StringReader(sb.ToString()))
     {
         xmldb.Load(XmlTextReader.Create(sr));
     }
     //db.ImportSongs(sr, serverid);
 }
Esempio n. 5
0
 private void wizardPage2_ShowFromNext(object sender, EventArgs e)
 {
     try
     {
         ISongParser type = m_types[imptype.SelectedIndex];
         m_xmldb = new InetSongDb();
         using (IWaitDialog wait = WaitForm.Show("Import písní", true))
         {
             type.Parse(m_dynamicProperties, m_xmldb, wait);
         }
     }
     catch (Exception err)
     {
         MessageBox.Show("Pøi importu nastala chyba:\n" + err.Message, "Zpìvníkátor", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     dataGridView1.DataSource = m_xmldb.GetAsTable();
 }
Esempio n. 6
0
        public override void Parse(Stream fr, InetSongDb db, IWaitDialog wait)
        {
            using (StreamReader sr = new StreamReader(fr, m_encoding))
            {
                foreach (string fulltext in SongStreamSplitter.SplitSongs(sr, m_splitProps))
                {
                    if (fulltext.Trim() == "") continue;
                    SongData song = SongDataAnalyser.AnalyseSongData(fulltext, m_dataProps);
                    song.OrigText = SongTextAnalyser.NormalizeSongText(song.SongText, m_textProps);
                    DbTools.AddSongRow(song, db);
                    if (wait.Canceled) return;
                    wait.Message("Zpracována píseò " + song.Title);
                }
                /*
                List<string> lines = new List<string>();
                while (!sr.EndOfStream) lines.Add(sr.ReadLine().TrimEnd());
                int i = 0;
                while (lines.Count > 0 && lines[lines.Count - 1] == "") lines.RemoveAt(lines.Count - 1);

                while (i < lines.Count)
                {
                    List<string> songlines = new List<string>();
                    while (i < lines.Count && lines[i] == "") i++; // preskoc prazdne
                    for (; ; )
                    {
                        if (i + 1 < lines.Count && lines[i] == "" && lines[i + 1] == "") break;
                        if (i >= lines.Count) break;
                        songlines.Add(lines[i]);
                        i++;                      
                    }
                    if (songlines.Count > 0)
                    {
                        InetSongDb.songRow song = db.song.NewsongRow();
                        song.author = song.title = song.groupname = song.songtext = "";
                        song.lang = "cz";
                        SongTextAnalyser.AnalyseSongHeader(songlines, song);
                        song.songtext = SongTextAnalyser.NormalizeSongText(String.Join("\n", songlines.ToArray()));
                        db.song.AddsongRow(song);
                    }
                }
                */
            }
        }
Esempio n. 7
0
        public PocketPCExporter(InetSongDb xmldb, Stream fw, IWaitDialog wait)
        {
            m_filename = Path.Combine(DbManager.DbPath, "tmp" + DateTime.Now.Ticks + ".db3");
            m_xmldb = xmldb;
            m_fw = fw;
            m_wait = wait;
            m_conn = new SQLiteConnection(String.Format("Data Source={0};New=True;Version=3", m_filename));
            m_insertGroup = new SQLiteCommand("INSERT INTO groupnames (groupname) VALUES (@group)", m_conn);
            m_insertGroup.Parameters.Add("@group", DbType.String);

            m_insertSongName = new SQLiteCommand("INSERT INTO songnames (id, songname, groupname) VALUES (@id, @song, @group)", m_conn);
            m_insertSongName.Parameters.Add("@id", DbType.Int32);
            m_insertSongName.Parameters.Add("@song", DbType.String);
            m_insertSongName.Parameters.Add("@group", DbType.String);

            m_insertSongDetail = new SQLiteCommand("INSERT INTO songdetails (id, songtext, author, remark) VALUES (@id, @songtext, @author, @remark)", m_conn);
            m_insertSongDetail.Parameters.Add("@id", DbType.Int32);
            m_insertSongDetail.Parameters.Add("@songtext", DbType.String);
            m_insertSongDetail.Parameters.Add("@author", DbType.String);
            m_insertSongDetail.Parameters.Add("@remark", DbType.String);
        }
Esempio n. 8
0
 public override void UploadChanges(SongDatabase db, int serverid, IWaitDialog dlg)
 {
     InetSongDb xmldb = new InetSongDb();
     object req1 = null;
     using (Stream fr = Read(ref req1)) xmldb.Load(fr);
     CloseRead(req1);
     object request = null;
     using (Stream fw = Write(ref request))
     {
         db.PublishSongsChanges(serverid, xmldb, dlg);
         xmldb.Save(fw);
     }
     CloseWrite(request);
 }
 public void Parse(object props, InetSongDb db, IWaitDialog wait)
 {
     MultipleStreamImporterProperties p = (MultipleStreamImporterProperties)props;
     List<string> files = new List<string>();
     files.AddRange(p.FileNames.Files);
     if (p.FileName != "") files.Add(p.FileName);
     foreach (string filename in files)
     {
         wait.Message("Importuji soubor " + filename);
         if (wait.Canceled) return;
         using (FileStream fr = new FileStream(filename, FileMode.Open))
         {
             if (filename.ToLower().EndsWith(".gz") || filename.ToLower().EndsWith(".xgz"))
             {
                 using (GZipStream gr = new GZipStream(fr, CompressionMode.Decompress))
                 {
                     Parse(gr, db, wait);
                 }
             }
             else
             {
                 Parse(fr, db, wait);
             }
         }
     }
     if (p.URL != "")
     {
         WebRequest req = WebRequest.Create(p.URL);
         WebResponse resp = req.GetResponse();
         using (Stream fr = resp.GetResponseStream())
         {
             Parse(fr, db, wait);
         }
         resp.Close();
     }
 }
Esempio n. 10
0
 public override void UploadWhole(SongDatabase db, int serverid, IWaitDialog dlg)
 {
     InetSongDb xmldb = new InetSongDb();
     object request = null;
     using (Stream fw = Write(ref request))
     {
         db.PublishAllSongs(serverid, xmldb, dlg);
         xmldb.Save(fw);
     }
     CloseWrite(request);
 }
Esempio n. 11
0
 public override void Parse(Stream fr, InetSongDb xmldb, IWaitDialog wait)
 {
     xmldb.Load(fr);
 }
Esempio n. 12
0
 private void button5_Click(object sender, EventArgs e)
 {
     if (SelectedServer != null)
     {
         if (openXML.ShowDialog() == DialogResult.OK)
         {
             InetSongDb xmldb = new InetSongDb();
             using (MessageLogForm dlg = MessageLogForm.Show("Importuji písnì", false))
             {
                 using (FileStream fr = new FileStream(openXML.FileName, FileMode.Open))
                 {
                     xmldb.Load(fr);
                 }
                 m_dbwrap.Database.DownloadSongsFromServer(xmldb, SelectedServer, dlg);
                 dlg.FinishAndWait();
             }
         }
     }
 }
Esempio n. 13
0
 public void PublishSongsChanges(int serverid, InetSongDb xmldb, IWaitDialog dlg)
 {
     var songs = new List<SongData>(this.LoadSongs(null, null, "song.server_id=" + serverid.ToString() + " and song.localmodified=1"));
     using (SQLiteTransaction tran = m_conn.BeginTransaction())
     {
         foreach (var song in songs)
         {
             ProcessPublishSong(tran, xmldb, song, dlg);
         }
         using (var reader = ExecuteReader("select ID, song_netID from deletedsong where server_id=@sid", "sid", serverid))
         {
             while (reader.Read())
             {
                 int id = reader.SafeInt(0);
                 string netid = reader.SafeString(1);
                 xmldb.DeleteSongByNetID(netid);
                 dlg.Message(String.Format("Mažu píseò netID={0}", netid));
             }
         }
         ExecuteNonQuery("delete from deletedsong where server_id=@sid", "sid", serverid);
         tran.Commit();
     }
 }
Esempio n. 14
0
 public void DownloadSongsFromServer(InetSongDb db, int? serverid, IWaitDialog dlg)
 {
     WantOpen();
     int imported = 0;
     ExecuteNonQuery("delete from songdata where song_id = (select song.id from song where song.server_id=@sid and song.localmodified=0)", "sid", serverid);
     ExecuteNonQuery("delete from song where song.server_id=@sid and song.localmodified=0", "sid", serverid);
     List<string> modifiedNetIds = new List<string>();
     using (var reader = ExecuteReader("select netID from song where server_id=@sid and localmodified=1", "sid", serverid))
     {
         while (reader.Read())
         {
             modifiedNetIds.Add(reader.SafeString(0));
         }
         reader.Close();
     }
     foreach (var song in db.Songs)
     {
         if (modifiedNetIds.Contains(song.NetID))
         {
             dlg.Message(String.Format("Ignoruji zmìnìnou píseò {0}, netID={1}", song.Title, song.NetID));
         }
         else
         {
             InsertSong(song, serverid, false);
             imported++;
         }
     }
     dlg.Message(String.Format("Importováno {0} písní", imported));
 }
 public abstract void Parse(Stream fr, InetSongDb db, IWaitDialog wait);
Esempio n. 16
0
        public override void Format(InetSongDb db, Stream fw, IWaitDialog wait, object props)
        {
            TextFileDynamicProperties p = (TextFileDynamicProperties)props;
            List<SongData> songs = new List<SongData>();
            foreach (SongData row in db.Songs)
            {
                songs.Add(row);
            }
            songs.Sort(Sorting.GetComparison(p.Order));

            using (StreamWriter sw = new StreamWriter(fw, m_encoding))
            {
                DumpFileBegin(sw);
                bool wassong = false;
                foreach (SongData row in songs)
                {
                    if (wassong) DumpSongSeparator(sw);
                    DumpSongBegin(row, sw);
                    RunTextFormatting(row.SongText, sw);
                    DumpSongEnd(row, sw);
                    wassong = true;
                }
                DumpFileEnd(sw);
            }
        }
 public void Format(InetSongDb db, object props, IWaitDialog wait)
 {
     string filename = ((SingleFileDynamicProperties)props).FileName;
     using (FileStream fw = new FileStream(filename, FileMode.Create))
     {
         Format(db, fw, wait, props);
     }
 }
 public abstract void Format(InetSongDb db, Stream fw, IWaitDialog wait, object props);
Esempio n. 19
0
 public void ImportNewSongs(InetSongDb db, int? serverid, IWaitDialog dlg)
 {
     WantOpen();
     int imported = 0;
     using (var tran = m_conn.BeginTransaction())
     {
         foreach (var song in db.Songs)
         {
             var scopy = song.Clone();
             scopy.NetID = null;
             InsertSong(tran, scopy, serverid, true);
             imported++;
         }
         tran.Commit();
     }
     dlg.Message(String.Format("Importováno {0} písní", imported));
 }
        public void Format(InetSongDb db, object props, IWaitDialog wait)
        {
            DirectorySongExporterProperties p = (DirectorySongExporterProperties)props;
            IStreamSongFormatter songfmt = GetStreamFormatter();
            string directory = p.FolderName;
            DirectorySongHolder dsh = new DirectorySongHolder(db.Songs);
            // nejdrive zapiseme index
            wait.Message("Zapisuji " + m_indexFileName);
            if (m_writeIndex)
            {
                using (FileStream fsw = new FileStream(Path.Combine(directory, m_indexFileName), FileMode.Create))
                {
                    using (StreamWriter fw = new StreamWriter(fsw, m_encoding))
                    {
                        WriteIndexFile(fw, dsh);
                    }
                }
            }

            // pak skupinove soubory
            if (m_writeGroups)
            {
                foreach (GroupOfSongs grp in dsh.Groups.Values)
                {
                    string path = Path.Combine(directory, MakeTemplate(m_groupFileMask, grp));
                    try { Directory.CreateDirectory(Path.GetDirectoryName(path)); }
                    catch (Exception) { }

                    wait.Message("Zapisuji " + path);
                    if (wait.Canceled) return;

                    using (FileStream fsw = new FileStream(path, FileMode.Create))
                    {
                        using (StreamWriter fw = new StreamWriter(fsw, m_encoding))
                        {
                            WriteGroupFile(fw, grp, dsh);
                        }
                    }
                }
            }

            // pisne - nejdrive zgrupovane
            if (m_writeGroupedSongs)
            {
                foreach (GroupOfSongs grp in dsh.Groups.Values)
                {
                    string path = Path.Combine(directory, MakeTemplate(m_groupedSongsFileMask, grp));
                    try { Directory.CreateDirectory(Path.GetDirectoryName(path)); }
                    catch (Exception) { }

                    wait.Message("Zapisuji " + path);
                    if (wait.Canceled) return;

                    InetSongDb tmp = new InetSongDb();
                    foreach (SongData song in grp.Songs)
                    {
                        DbTools.AddSongRow(song, tmp);
                    }
                    using (FileStream fw = new FileStream(path, FileMode.Create))
                    {
                        songfmt.Format(tmp, fw, wait, props);
                    }
                }
            }

            // pisne - po jedne
            if (m_writeSeparateSongs)
            {
                foreach (SongData song in db.Songs)
                {
                    string path = Path.Combine(directory, MakeTemplate(m_songFileMask, song, dsh));
                    try { Directory.CreateDirectory(Path.GetDirectoryName(path)); }
                    catch (Exception) { }

                    wait.Message("Zapisuji " + path);
                    if (wait.Canceled) return;

                    InetSongDb tmp = new InetSongDb();
                    DbTools.AddSongRow(song, tmp);
                    using (FileStream fw = new FileStream(path, FileMode.Create))
                    {
                        songfmt.Format(tmp, fw, wait, props);
                    }
                }
            }
        }
Esempio n. 21
0
 private void ProcessPublishSong(SQLiteTransaction tran, InetSongDb xmldb, SongData song, IWaitDialog dlg)
 {
     if (song.NetID != null)
     {
         xmldb.UpdateSongByNetID(song);
         ExecuteNonQuery("update song set published=@published, localmodified=0 where id=@id",
             "published", DateTime.UtcNow, "id", song.LocalID);
     }
     else
     {
         xmldb.AddSongWithNewNetID(song);
         ExecuteNonQuery("update song set published=@published, localmodified=0, netID=@netid where id=@id",
             "published", DateTime.UtcNow, "id", song.LocalID, "netid", song.NetID);
     }
     dlg.Message(String.Format("Publikuji píseò {0}, netID={1}", song.Title, song.NetID));
 }
Esempio n. 22
0
 public override void Format(InetSongDb xmldb, Stream fw, IWaitDialog wait, object props)
 {
     xmldb.Save(fw);
 }
Esempio n. 23
0
 public void PublishAllSongs(int serverid, InetSongDb xmldb, IWaitDialog dlg)
 {
     xmldb.Songs.Clear();
     var songs = new List<SongData>(this.LoadSongs(null, null, "song.server_id=" + serverid.ToString()));
     using (SQLiteTransaction tran = m_conn.BeginTransaction())
     {
         foreach (var song in songs)
         {
             ProcessPublishSong(tran, xmldb, song, dlg);
         }
         ExecuteNonQuery("delete from deletedsong where server_id=@sid", "sid", serverid);
         tran.Commit();
     }
 }
Esempio n. 24
0
 private void button6_Click(object sender, EventArgs e)
 {
     if (SelectedServer != null)
     {
         if (saveXML.ShowDialog() == DialogResult.OK)
         {
             InetSongDb xmldb = new InetSongDb();
             xmldb.Songs.AddRange(m_dbwrap.Database.LoadSongs(null, null, "server_id=" + SelectedServer.ToString()));
             using (FileStream fw = new FileStream(saveXML.FileName, FileMode.Create))
             {
                 xmldb.Save(fw);
             }
         }
     }
 }