Using Visual Studio 2017, we will create a simple Windows Forms App
template project. You can call the application anything you like, but I called mineeBookManager
:
The project will be created and will look as follows:
OurSolution
needs a Class Library
project to contain the classes that drive theeBookManager
application. Add a new Class Library
project to your Solution
and call iteBookManager.Engine
:
A Class Library
project is added to the Solution
with the default class name. Change this class toDocument
:
TheDocument
class will represent a single eBook. Thinking of a book, we can have multiple properties that would represent a single book, but be representative of all books. An example of this would be the author. All books must have an author, otherwise it would not exist.
Note
I know some of you might be thinking that machines could generate documents too, but the information it generates was probably originally written by a person. Take code comments for example. A developer writes the comments in code, and a tool generates a document from that. The developer is still the author.
The properties I have added to the class are merely my interpretation of what might represent a book. Feel free to add additional code to make this your own.
Open the Document.cs
file and add the following code to the class:
namespace eBookManager.Engine { public class Document { public string Title { get; set; } public string FileName { get; set; } public string Extension { get; set; } public DateTime LastAccessed { get; set; } public DateTime Created { get; set; } public string FilePath { get; set; } public string FileSize { get; set; } public string ISBN { get; set; } public string Price { get; set; } public string Publisher { get; set; } public string Author { get; set; } public DateTime PublishDate { get; set; } public DeweyDecimal Classification { get; set; } public string Category { get; set; } } }
You will notice that I have included a property calledClassification
of type DeweyDecimal
. We have not added this class yet, and will do so next.
To the eBookManager.Engine
project, add a class called DeweyDecimal
. If you don't want to go to this level of classification for your eBooks, you can leave this class out. I have included it for the sake of completeness:
Your DeweyDecimal
class must be in the same project as the Document
class added earlier:
The DeweyDecimal
system is quite big. For this reason, I have not catered for every book classification available. I have also only assumed that you would want to be working with programming eBooks. In reality, however, you may want to add in other classifications, such as literature, the sciences, the arts, and so on. It is up to you.
So let's create a class to represent the Dewey Decimal system::
- Open up the
DeweyDecimal
class and add the following code to the class:
namespace eBookManager.Engine { public class DeweyDecimal { public string ComputerScience { get; set; } = "000"; public string DataProcessing { get; set; } = "004"; public string ComputerProgramming { get; set; } = "005"; } }
Word nerds may disagree with me here, but I would like to remind them that I'm a code nerd. The classifications represented here are just so that I can catalog programming and computer science-related eBooks. As mentioned earlier, you can change this to suit your needs.
YoureBookManager.Engine
Solution will now contain the following classes:
DeweyDecimal
Document
DocumentEngine
The eBookManager.Engine
project will be available under the Projects
section in the Reference Manager
screen:
- Before we forget, add an
ImageList
control to theImportBooks
form and call ittvImages
. This will contain the images for the different types of documents we want to catalog.
Note
The ImageList
is a control you add from the Toolbox
on to the ImportBooks
form. You can access the Images Collection Editor
from the ImageList
properties.
The icons can be found in the img
folder in the source code downloadable from GitHub at the following URL—https://github.com/PacktPublishing/CSharp7-and-.NET-Core-2.0-Blueprints.
The icons here are catering for PDF, MS Word, and ePub file types. It also contains folder images:
Note
Please note that if you are running the .NET Framework 4.7, System.ValueTuple
is included in this version of the framework. You will therefore not need to get it from NuGet.
I love making use of extension methods in my projects. I usually add a separate project and/or class for this purpose. In this application, I added an eBookManager.Helper
class library project:
Lastly, I will be using JSON as a simple file store for my eBook catalogue. JSON is really flexible and can be consumed by various programming languages. What makes JSON so nice is the fact that it is relatively light weight and the output it generates is human-readable:
- Go to
Manage the NuGet packages
for yourSolution
and search forNewtonsoft.Json
. Add this then to the projects in yourSolution
and click theInstall
button.
You have now set up the basics needed for your eBookManager
application. Next, we will venture further into the guts of the application by writing some code.