Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
DocumentSystem
DocumentSystem.sln
README.md

README.md

Exam preparation - Document System

A document system holds a list of documents. Documents can be binary or text and have name (mandatory) and can have content. Documents are of two types: text and binary. Text documents can have charset (e.g. utf-8 or windows-1251). Binary documents can have size (in bytes). Binary documents can be of type PDF, Word, Excel, Audio or Video. PDF documents can hold the number of pages they consist of. Word documents can hold the number of characters they consist of. Excel documents can hold the number of rows and the number of columns in the table they hold. Word and Excel documents are both office documents. Office document can have version (e.g. “2007” or “Office97”). A special kind of binary documents are the multimedia documents. All multimedia documents can have length (in seconds). Audio documents and video documents are both multimedia documents. Audio documents can have sample rate (in Hz). Video documents can have frame rate (in fps). PDF, Word and Excel documents are encryptable (can be encrypted and decrypted). Word and text documents are editable (their content could be changed). All document characteristics except their name are non-mandatory. Design the Class Hierarchy Your first task is to design an object-oriented class hierarchy to model the document system and the documents it can hold using the best practices for object-oriented design (OOD) and object-oriented programming (OOP). Additionally you are given few C# interfaces that you should obligatory use: using System.Collections.Generic; public interface IDocument { string Name { get; } string Content { get; } void LoadProperty(string key, string value); void SaveAllProperties(IList<KeyValuePair<string, object>> output); string ToString(); } public interface IEditable { void ChangeContent(string newContent); } public interface IEncryptable { bool IsEncrypted { get; } void Encrypt(); void Decrypt(); } All your documents should implement IDocument. It specifies that documents have immutable Name and Content, can load their properties from key-value pairs through the LoadProperty(key, value) method and save their properties in a list of key-value pairs through the SaveAllProperties(…) method as well as be printed on the console through the ToString() method. All editable documents should implement the IEditable interface. All changes of the document content should pass through this interface (direct content changes are not allowed). All encryptable documents should implement the IEncryptable interface. You do not need to implement encryption algorithm (like AES and Blowfish), just to keep whether a document is encrypted or not in its internal state. You are allowed to encrypt / decrypt a document only though this interface. Write a Program to Execute Commands Your second task is to write a program that executes a sequence of up to 1000 commands. Each command is given in the following format: Command[key1=value1;key2=value2;…] Commands consist of command name and attributes given in square brackets [ ]. Each attribute is given in the form key=value. Keys consist of small English letters. Values consist single line English text and cannot contain the following characters: [, ], =, ; and \n. The sequence of commands ends with an empty line. The valid commands that your program should be able to execute are the following: • AddTextDocument[name=…;charset=…;content=…] – adds a text document to the document system. The name is obligatory, but all other attributes are optional. The order of the attributes can be arbitrary. All attributes will be valid for the type of the document we create. As a result the command prints on the console “Document added: ” in case of success or “Document has no name” in case of missing document name. Multiple documents having the same name are allowed to be added. • AddPDFDocument[name=…;pages=…;size=…;content=…] – works like AddTextDocument. • AddWordDocument[chars=…;name=…;version=…;size=…;content=…] – works like AddTextDocument. • AddExcelDocument[rows=…;cols=…;version=…;size=…;name=…;content=…] – works like AddTextDocument. • AddAudioDocument[name=…;content=…;samplerate=…;length=…;size=…] – works like AddTextDocument. • AddVideoDocument[name=…;content=…;framerate=…;length=…;size=…] – works like AddTextDocument. • EncryptDocument[name] – changes the state of all documents matching the specified name to “encrypted”. Documents that are already encrypted remain in “encrypted” state. For each document matching the specified name, the command prints as a result “Document encrypted: ” on the console or prints “Document does not support encryption: ” if the document is not encryptable. In case of no document is matching the specified name, the message “Document not found: ”. • DecryptDocument[name] – works similarly like EncryptDocument, but changes the state of all matched documents to “not encrypted” and prints as result one of the following messages: “Document decrypted: ”, “Document does not support decryption: ” or “Document not found: ”. • EncryptAllDocuments – changes the state of all documents that support encryption to “encrypted”. As result, if at least one document supports encryption, prints on the console “All documents encrypted”, otherwise prints “No encryptable documents found”. • ListDocuments[] – prints on the console all the documents in the document system in their order of their addition. Each document should be printed alone on a single line in the following form: XXXDocument[key1=value1;key2=value2;…] The XXXDocument is the type of the document, e.g. PDFDocument, VideoDocument, etc. The keys should be ordered alphabetically. Keys with no value should be skipped. If there are no documents, the command prints “No documents found”. Encrypted documents are shown differently, as follows: XXXDocument[encrypted] • ChangeContent[name;new_content] – changes the content of all editable documents matching the specified name with the specified new content. For each document matching the specified name, the command prints as a result “Document content changed: ” on the console or prints “Document is not editable: ” if the document is not editable. In case of no document is matching the specified name, the message “Document not found: ”. The commands are guaranteed to be valid. Only the described above commands will be given as input. The command format will be as described above. The command parameters will also be in the described format. All attributes will be valid for their corresponding command. The commands will be no more than 1000. Each command will be less than 500 characters long. To simplify your work you are given a command parser that provides a skeleton for your solution (see the file DocumentSystem-Skeleton.rar).

You can’t perform that action at this time.