Esempio n. 1
0
 private void Save()
 {
     if (openFile.Name != titleBox.Text)
     {
         Library.removeFromLibrary(openFile.Name);
     }
     openFile.Name          = titleBox.Text;
     openFile.Byline        = bylineBox.Text;
     openFile.Copyright     = copyrightBox.Text;
     openFile.LinesPerSlide = Decimal.ToInt32(linesPerSlide.Value);
     openFile.Chorus        = -1;
     openFile.setupTexts(slidePool.Count, slideList.Count);
     for (int x = 0; x < slidePool.Count; x++)
     {
         EditableSlide temp = slidePool[x];
         openFile.addText(temp.Index, temp.Text, temp.LinesPerSlide);
         if (temp.Chorus)
         {
             openFile.Chorus = temp.Index;
         }
     }
     for (int x = 0; x < slideList.Count; x++)
     {
         PlaceholderSlide temp = slideList[x];
         openFile.addOrder(x, temp.Index);
     }
     openFile.Write();
     Library.addToLibrary(openFile.Name);
 }
Esempio n. 2
0
 /// <summary>
 /// Import a SlideSet using the data stored at the RUF Hymnbook website.
 /// </summary>
 /// <param name="url">Either the name of a song to search for or a URL directly to a song page.</param>
 /// <returns>Returns an ErrorCode specifying what went wrong during the import.</returns>
 public static ImporterErrorCode importRHO(string url)
 {
     //http://www.developer.com/net/csharp/article.php/2230091 Try this?
     try
     {
         WebClient client = new WebClient();
         iss = new EditableSlideSet();
         if (!url.Contains(".html"))
         {
             string search = client.DownloadString("http://www.igracemusic.com/hymnbook/hymns.html");
             url    = url.ToLower();
             search = search.ToLower();
             int sindex = search.IndexOf(url);
             if (sindex == -1)
             {
                 return(ImporterErrorCode.SearchTermNotFound);
             }
             string urlfind = "<a href=\"";
             int    uindex  = 0;
             while (true)
             {
                 int utemp = search.IndexOf(urlfind, uindex + 1);
                 if (utemp > sindex)
                 {
                     break;
                 }
                 uindex = utemp;
                 if (uindex == -1)
                 {
                     return(ImporterErrorCode.SearchConstantIncorrect);
                 }
             }
             uindex += urlfind.Length;
             int ulength = (search.IndexOf("\"", uindex) - uindex);
             url = "http://www.igracemusic.com/hymnbook/" + search.Substring(uindex, ulength);
         }
         string titlefind    = " class=\"header1\">";
         string versefind    = " class=\"body\">";
         string endversefind = "<a href=\"#top\">";
         string page         = client.DownloadString(url);
         int    index        = page.IndexOf(titlefind);
         int    length       = (page.IndexOf("</p>", index) - index - titlefind.Length);
         iss.Name = page.Substring((index + titlefind.Length), length);
         iss.Name = stripHTML(iss.Name);
         int    chop   = (page.IndexOf(endversefind, index) - index);
         string verses = page.Substring(index, chop);
         chop = 0;
         int n = 0;
         while (true)
         {
             chop = verses.IndexOf(versefind, chop + 1);
             if (chop == -1)
             {
                 break;
             }
             n++;
         }
         iss.setupTexts(n - 1, 0);
         index = 0;
         for (int x = 0; x < (n - 1); x++)
         {
             index  = verses.IndexOf(versefind, index + 1);
             length = (verses.IndexOf("</p>", index) - index - versefind.Length);
             string verse = verses.Substring((index + versefind.Length), length);
             verse = verse.Replace("&#146;", "'");
             verse = verse.Replace("&quot;", "\"");
             verse = verse.Replace("<br>\n", System.Environment.NewLine);
             verse = verse.Replace("              ", "");
             verse = stripHTML(verse);
             iss.addText(x, verse, 0);
         }
     }
     catch (Exception e)
     {
         //Program.ReportError(e);
         return(ImporterErrorCode.GenericError);
     }
     return(ImporterErrorCode.CompletedSucessfully);
 }
Esempio n. 3
0
        /// <summary>
        /// Import a SlideSet using data stored at the Cyber Hymnal website.
        /// </summary>
        /// <param name="url">Either the name of a song to search for or a URL directly to a song page.</param>
        /// <returns>Returns an ErrorCode specifying what went wrong during the import.</returns>
        public static ImporterErrorCode importCH(string url)
        {
            try
            {
                WebClient client = new WebClient();
                iss = new EditableSlideSet();
                if (!url.Contains(".htm"))
                {
                    url = url.ToLower();
                    string search = client.DownloadString("http://www.cyberhymnal.org/ttl/ttl-" + url.ToCharArray()[0] + ".htm");
                    search = search.Replace("&#8217;", "'");
                    search = search.ToLower();
                    int sindex = search.IndexOf(url);
                    if (sindex == -1)
                    {
                        return(ImporterErrorCode.SearchTermNotFound);
                    }
                    string urlfind = "<a href=\"..";
                    int    uindex  = 0;
                    while (true)
                    {
                        int utemp = search.IndexOf(urlfind, uindex + 1);
                        if (utemp > sindex)
                        {
                            break;
                        }
                        uindex = utemp;
                        if (uindex == -1)
                        {
                            return(ImporterErrorCode.SearchConstantIncorrect);
                        }
                    }
                    uindex += urlfind.Length;
                    int ulength = (search.IndexOf("\"", uindex) - uindex);
                    url = "http://www.cyberhymnal.org" + search.Substring(uindex, ulength);
                }
                string titlefind        = "<title>";
                string versefind        = "<p>";
                string chorusfind       = "<p class=\"chorus\">";
                string versesectionfind = "<div class=\"lyrics\">";
                string page             = client.DownloadString(url);
                int    index            = page.IndexOf(titlefind);
                int    length           = (page.IndexOf("</title>", index) - index - titlefind.Length);
                iss.Name = page.Substring((index + titlefind.Length), length);

                index = page.IndexOf(versesectionfind);
                int    chop   = (page.IndexOf("</div>", index) - index);
                string verses = page.Substring(index, chop);
                chop = 0;
                int n = 0;
                while (true)
                {
                    chop = verses.IndexOf(versefind, chop + 1);
                    if (chop == -1)
                    {
                        break;
                    }
                    n++;
                }
                bool haschorus = false;
                if (verses.Contains(chorusfind))
                {
                    n++;
                    haschorus = true;
                }
                iss.setupTexts(n, 0);
                index = 0;
                for (int x = 0; x < (n - (haschorus ? 1 : 0)); x++)
                {
                    index  = verses.IndexOf(versefind, index + 1);
                    length = (verses.IndexOf("</p>", index) - index - versefind.Length);
                    string verse = verses.Substring((index + versefind.Length), length);
                    verse = verse.Replace("<br />", "");
                    verse = verse.Replace("&#8217;", "'");
                    verse = verse.Replace("&#8212;", ";");
                    verse = verse.Replace("&#8220;", "\"");
                    verse = verse.Replace("&#8221;", ",");
                    verse = stripHTML(verse);
                    iss.addText(x, verse, 0);
                }
                if (haschorus)
                {
                    index  = 0;
                    index  = verses.IndexOf(chorusfind, index + 1);
                    index  = verses.IndexOf(chorusfind, index + 1);
                    length = (verses.IndexOf("</p>", index) - index - chorusfind.Length);
                    string chorus = verses.Substring((index + chorusfind.Length), length);
                    chorus = chorus.Replace("<br />", "");
                    chorus = chorus.Replace("&#8217;", "'");
                    chorus = chorus.Replace("&#8212;", ";");
                    chorus = chorus.Replace("&#8220;", "\"");
                    chorus = chorus.Replace("&#8221;", ",");
                    chorus = stripHTML(chorus);
                    iss.addText(n - 1, chorus, 0);
                    iss.Chorus = n - 1;
                }
            }
            catch (Exception e)
            {
                //Program.ReportError(e);
                return(ImporterErrorCode.GenericError);
            }
            return(ImporterErrorCode.CompletedSucessfully);
        }