File size: 3,070 Bytes
fab29d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
using System;
using System.IO;
namespace VersOne.Epub.ConsoleDemo
{
internal static class Program
{
private static void Main()
{
char input = '\0';
while (input != 'Q')
{
Console.WriteLine("Select example:");
Console.WriteLine("1. Print book navigation tree (table of contents)");
Console.WriteLine("2. Extract plain text from the whole book");
Console.WriteLine("3. Test the library by reading all EPUB files from a directory");
Console.WriteLine("Q. Exit");
input = Char.ToUpper(Console.ReadKey(true).KeyChar);
Console.WriteLine();
switch (input)
{
case '1':
RunFileExample(PrintNavigation.Run);
break;
case '2':
RunFileExample(ExtractPlainText.Run);
break;
case '3':
RunDirectoryExample(TestDirectory.Run);
break;
case 'Q':
break;
default:
Console.WriteLine("Input is not recognized. Please try again.");
Console.WriteLine();
break;
}
}
}
private static void RunFileExample(Action<string> example)
{
Console.Write("Enter the path to the EPUB file: ");
string filePath = Console.ReadLine();
Console.WriteLine();
if (File.Exists(filePath) && Path.GetExtension(filePath).ToLower() == ".epub")
{
try
{
example(filePath);
}
catch (Exception ex)
{
Console.WriteLine("Exception was thrown:");
Console.WriteLine(ex.ToString());
Console.WriteLine();
}
}
else
{
Console.WriteLine("File doesn't exist.");
Console.WriteLine();
}
}
private static void RunDirectoryExample(Action<string> example)
{
Console.Write("Enter the path to the directory with EPUB files: ");
string directoryPath = Console.ReadLine();
Console.WriteLine();
if (Directory.Exists(directoryPath))
{
try
{
example(directoryPath);
}
catch (Exception ex)
{
Console.WriteLine("Exception was thrown:");
Console.WriteLine(ex.ToString());
Console.WriteLine();
}
}
else
{
Console.WriteLine("Directory doesn't exist.");
Console.WriteLine();
}
}
}
}
|