示例#1
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);
                    }
                }
                */
            }
        }
示例#2
0
 public void LoadServers(IWaitDialog dlg)
 {
     using (var reader = ExecuteReader("select id, url from serverlist"))
     {
         while (reader.Read())
         {
             WebRequest req = WebRequest.Create(reader.SafeString(1));
             using (var resp = req.GetResponse())
             {
                 using (var strm = resp.GetResponseStream())
                 {
                     XmlDocument doc = new XmlDocument();
                     doc.Load(strm);
                     foreach (XmlElement elem in doc.SelectNodes("/ServerList/Server/Url"))
                     {
                         string url = elem.InnerText;
                         if ("0" == ExecuteScalar("select count(*) from server where url=@url", "url", url).ToString())
                         {
                             var ss = new XmlSongServer { URL = url };
                             InsertServer(ss);
                             dlg.Message(String.Format("Pøidávám server {0}", ss));
                         }
                     }
                 }
             }
         }
     }
 }
示例#3
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();
     }
 }
示例#4
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));
 }
示例#5
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));
 }
示例#6
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);
                    }
                }
            }
        }
 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();
     }
 }