Exemplo n.º 1
0
        static void Main(string[] args)
        {
            System.Collections.Stack stack = new System.Collections.Stack();
            stack.Push(1);
            stack.Push(2);
            stack.Push(3);

            Console.WriteLine("1 in stack:{0}", stack.Contains(1));
            Console.WriteLine("Remove 1:{0}", stack.Pop());
            Console.WriteLine("Peek1:{0}", stack.Peek());

            object[] numArray = stack.ToArray();
            Console.WriteLine(string.Join(", ", numArray));
        }
Exemplo n.º 2
0
        private void createOPFAuto(string strPath)
        {
            //fbdSplit.ShowDialog();
            string strSavePath = strPath;
            System.Collections.Stack stkImgs;
            stkImgs = new System.Collections.Stack();
            stkImgs.Clear();
            MatchCollection mc;

            if (strSavePath.Length > 2)
            {

                try
                {

                    Application.UseWaitCursor = true;
                    toolStripStatusLabel1.Text = "Creating .OPF File... Please Wait";
                    this.Refresh();
                    string strContent = "";

                    string[] strLines;

                    strContent = rtbContent.Text;
                    strLines = strContent.Split('\n');
                    long i = strLines.Length;

                    toolStripProgressBar1.Maximum = Convert.ToInt32(i) + 1;
                    toolStripProgressBar1.Minimum = 1;
                    toolStripProgressBar1.Value = 1;
                    this.Refresh();

                    StreamWriter swFiles;
                    string strFileNames = "";
                    string strChapterTitle = "";
                    bool blSplitStart = false;
                    bool blIdFound = false;
                    bool blSrcFound = false;
                    bool blTitleFound = false;
                    bool blATitleFound = false;
                    string strWrite = "";

                    string strIdFound = "";
                    string strSrcFound = "";
                    string strTitleFound = "";
                    string strATitleFound = "";
                    long lnImgIDCount = 1;

                    swFiles = new StreamWriter(strSavePath + "\\content.opf");

                    swFiles.WriteLine("<?xml version=\"1.0\"?>\n" +
                        "<package version=\"2.0\" xmlns=\"http://www.idpf.org/2007/opf\"\n" +
                        "         unique-identifier=\"isbn\">\n" +
                        " <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n" +
                        "           xmlns:opf=\"http://www.idpf.org/2007/opf\">\n" +
                        "   <dc:title>***Book Name***</dc:title> \n" +
                        "   <dc:creator>***Author Name***</dc:creator>\n" +
                        "   <dc:language>en-US</dc:language> \n" +
                        "   <dc:rights>***Copyright***</dc:rights>\n" +
                        "   <dc:publisher>***Publisher***</dc:publisher>\n" +
                        "   <dc:identifier id=\"isbn\">****</dc:identifier>\n" +
                        "   <meta name=\"cover\" content=\"cover-image\"/>  \n" +
                        " </metadata>\n" +
                        " <manifest>\n" +
                        "\n" +
                        "<!-- Images -->\n");

                    for (int j = 0; j < i; j++)
                    {

                        mc = Regex.Matches(strLines[j], "<img src=\"([^\"]+)\"");

                        foreach (Match singleMc in mc)
                        {

                            if (stkImgs.Contains(singleMc.Result("$1")) == false)
                            {
                                stkImgs.Push(singleMc.Result("$1"));
                                swFiles.WriteLine("  <item href=\"" + singleMc.Result("$1") + "\" id=\"img_" + lnImgIDCount.ToString() + "\" media-type=\"image/jpeg\"/>");
                                lnImgIDCount++;
                            }

                        }

                        toolStripProgressBar1.Value = j + 1;

                    }

                    swFiles.WriteLine("<!-- NCX -->\n" +
                        "\n" +
                        "<item id=\"ncx\" href=\"toc.ncx\" media-type=\"application/x-dtbncx+xml\"/>\n" +
                        "\n" +
                        " <!-- CSS Style Sheets -->\n" +
                        "\n" +
                        "<item id=\"style_bv\" href=\"bv_ebook_style.css\" media-type=\"text/css\"/>\n" +
                        "<item id=\"style_basic\" href=\"stylesheet.css\" media-type=\"text/css\"/>\n" +
                        "<item id=\"pagetemplate\" href=\"page-template.xpgt\" media-type=\"application/vnd.adobe-page-template+xml\"/>\n" +
                        "<!-- Content Documents -->\n" +
                        "\n");

                    string strIDRef = " <spine toc=\"ncx\">";

                    for (int j = 0; j < i; j++)
                    {

                        if (strLines[j].StartsWith("<split"))
                        {
                            strFileNames = Regex.Replace(strLines[j], "^<split filename=\"([^<>]+)\">$", "$1");
                            blSplitStart = true;
                            //swFiles.WriteLine("      <content src=\"" + strFileNames + "\"/>");
                            blSrcFound = true;
                            strSrcFound = strFileNames;

                        }

                        if (strLines[j].StartsWith("<div>") == true)
                        {
                            j++;
                            if (strLines[j].StartsWith("<a id=") == true)
                            {
                                strChapterTitle = Regex.Replace(strLines[j], "^<a id=\"([^<]*)\"></a>(.*)$", "$1");
                                //swFiles.WriteLine("    <navPoint class=\"chapter\" id=\"" + strChapterTitle + "\" playOrder=\"1\">");
                                blIdFound = true;
                                strIdFound = strChapterTitle;

                            }

                        }

                        if (strLines[j].StartsWith("</split"))
                        {
                            strWrite = "";
                            if (blIdFound == true)
                            {

                                if (blSrcFound == true)
                                {
                                    strWrite = "  <item id=\"" + strIdFound + "\" href=\"" + strSrcFound + "\" media-type=\"application/xhtml+xml\"/>";
                                    swFiles.WriteLine(strWrite);

                                    strIDRef = strIDRef + "\n" + "  <itemref idref=\"" + strIdFound + "\" linear=\"yes\" />";

                                }

                            }

                            blIdFound = false;
                            blSrcFound = false;
                            blTitleFound = false;
                            blATitleFound = false;

                            strIdFound = "";
                            strSrcFound = "";
                            strTitleFound = "";
                            strATitleFound = "";

                            blSplitStart = false;
                        }

                        toolStripProgressBar1.Value = j + 1;

                    }

                    swFiles.WriteLine("  </manifest>\n");

                    swFiles.WriteLine(strIDRef);

                    swFiles.WriteLine("<guide>");

                    for (int j = 0; j < i; j++)
                    {

                        if (strLines[j].StartsWith("<split"))
                        {
                            strFileNames = Regex.Replace(strLines[j], "^<split filename=\"([^<>]+)\">$", "$1");
                            blSplitStart = true;
                            //swFiles.WriteLine("      <content src=\"" + strFileNames + "\"/>");
                            blSrcFound = true;
                            strSrcFound = strFileNames;

                        }

                        if (strLines[j].StartsWith("<head>") == true)
                        {
                            j++;
                            if (strLines[j].StartsWith("<title>") == true)
                            {
                                strChapterTitle = Regex.Replace(strLines[j], "^<title>(.*)</title>$", "$1");
                                //swFiles.WriteLine("        <text>" + strChapterTitle + "</text>");
                                blTitleFound = true;
                                strTitleFound = strChapterTitle;
                            }

                        }

                        if (strLines[j].StartsWith("<h2 class=\"chaptertitle\">") == true)
                        {

                            strChapterTitle = Regex.Replace(strLines[j], "^<h2 class=\"chaptertitle\">(.*)</h2>$", "$1");
                            strChapterTitle = RemoveTag(strChapterTitle);
                            blATitleFound = true;
                            strATitleFound = strChapterTitle;

                        }

                        if (strLines[j].StartsWith("<div>") == true)
                        {
                            j++;
                            if (strLines[j].StartsWith("<a id=") == true)
                            {
                                strChapterTitle = Regex.Replace(strLines[j], "^<a id=\"([^<]*)\"></a>(.*)$", "$1");
                                //swFiles.WriteLine("    <navPoint class=\"chapter\" id=\"" + strChapterTitle + "\" playOrder=\"1\">");
                                blIdFound = true;
                                strIdFound = strChapterTitle;

                            }

                        }

                        if (strLines[j].StartsWith("</split"))
                        {
                            strWrite = "";
                            if (blIdFound == true)
                            {
                                strWrite = strIdFound;
                                if (blATitleFound == true)
                                {
                                    //strATitleFound
                                }
                                else
                                {
                                    if (blTitleFound == true)
                                    {
                                        strATitleFound = strTitleFound;
                                    }

                                }

                                strWrite = "<reference type=\"text\"\n" +
                                "		   title=\"" + strATitleFound + "\"\n" +
                                "          href=\"" + strSrcFound + "\"/>";

                                swFiles.WriteLine(strWrite);
                            }

                            blIdFound = false;
                            blSrcFound = false;
                            blTitleFound = false;
                            blATitleFound = false;

                            strIdFound = "";
                            strSrcFound = "";
                            strTitleFound = "";
                            strATitleFound = "";

                            blSplitStart = false;
                        }

                        toolStripProgressBar1.Value = j + 1;

                    }

                    swFiles.WriteLine("</guide>\n</package>");

                    swFiles.Flush();
                    swFiles.Close();

                    this.Refresh();

                    rtbContent.Text = string.Join("\n", strLines);
                    toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;

                    toolStripStatusLabel1.Text = "Ready";
                    Application.UseWaitCursor = false;
                }
                catch
                {
                    MessageBox.Show("Unexpected Error", "ERR", MessageBoxButtons.OK);

                }
            }
        }