# Changeset 1181 for trunk/Documentation

Ignore:
Timestamp:
Feb 24, 2010, 4:51:08 PM (12 years ago)
Message:

HowTo: small changes and revisions over the first 18 pages

Location:
trunk/Documentation/Developer/PluginHowTo
Files:
4 edited

### Legend:

Unmodified
 r1156 \item Getting all prerequisites and installing them \item Accessing and downloading the source code with SVN \item Compiling the source code for the first time \item Compiling the current source code for the first time \end{itemize} Since CrypTool 2.0 is based on Microsoft .NET 3.5, you will need a Microsoft Windows environment. (Currently no plans exist for porting this project to mono or to other platforms.) We have successfully tested with \textbf{Windows XP}, \textbf{Windows Vista} and \textbf{Windows 7}. Since you are reading the developer guidlines, you probably want to develop something. Hence, you will need a development environment. In order to compile our sources you need \textbf{Microsoft Visual Studio 2008 Professional}. Please always install the latest service packs for Visual Studio. Unfortunately, our sources do not work (smoothly) with the freely available Visual Studio Express (C\#) versions. This is due to the fact that CrypWin uses a commercial component and is therefore distributed only as binary. However, the C\# Express version cannot handle a binary as a start project, and thus debugging becomes cumbersome. Since you are reading the developer guidelines, you probably want to develop something. Hence, you will need a development environment. In order to compile our sources you need \textbf{Microsoft Visual Studio 2008 Professional}. Please always install the latest service packs for Visual Studio. Unfortunately, our sources do not work (smoothly) with the freely available Visual Studio Express (C\#) versions. This is due to the fact that CrypWin uses a commercial component and is therefore distributed only as binary, and the current version of C\# Express cannot handle a binary as a start project, which makes debugging cumbersome. This will be resolved later in 2010 when the project is moved to Visual Studio 2010. Usually the installation of Visual Studio also installs the .NET framework. In order to run or compile our source code you will need (at the time of writing) at least \textbf{Microsoft .NET 3.5 with Service Pack 1 (SP1)}. You can get this for free from Microsoft's \href{http://download.microsoft.com/download/2/0/e/20e90413-712f-438c-988e-fdaa79a8ac3d/dotnetfx35.exe}{webpage}. After the last step, your development environment should be ready for our source code. Now you will need a way of accessing and downloading the entire sources. In the CrypTool 2.0 project we use Subversion (SVN) for version control, and hence you need an \textbf{SVN client}, e.g. \textbf{TortoiseSVN} or the \textbf{svn commandline from cygwin}. It does not matter which one you use, but if you have never worked with SVN before, we suggest using \href{http://www.tortoisesvn.net/}{TortoiseSVN}, since it offers a nice Windows Explorer integration of SVN. Usually the installation of Visual Studio also installs the .NET framework. In order to run or compile our source code you will need (at the time of writing) at least \textbf{Microsoft .NET 3.5 with Service Pack 1 (SP1)}. You can get this for free from Microsoft's \href{http://download.microsoft.com/download/2/0/e/20e90413-712f-438c-988e-fdaa79a8ac3d/dotnetfx35.exe}{webpage}. Once that has been installed, your development environment should be ready for our source code. \section{Accessing Subversion (SVN)} \label{AccessingSubversion} This section describes how to access our SVN repository and how to configure the basic settings. Now you will need a way of accessing and downloading the source code. In the CrypTool 2.0 project we use Subversion (SVN) for version control, and hence you need an \textbf{SVN client}, e.g.\ \textbf{TortoiseSVN} or the \textbf{svn commandline from cygwin}. It does not matter which client you use, but if you have never worked with SVN before, we suggest using \href{http://www.tortoisesvn.net/}{TortoiseSVN}, since it offers a nice Windows Explorer integration of SVN. \subsection*{The CrypTool2 SVN URL} \url{https://www.cryptool.org/svn/CrypTool2/} To access the repository, you must provide a username and password. If you are a guest and just want to download our source code, you can use anonymous" as the username and an empty password. If you are a registered developer, just use your provided username and password (which is the same as for the wiki). To access the repository, you must provide a username and password. If you are a guest and just want to download our source code, you can use anonymous" as the username and an empty password. If you are a registered developer, just use your provided username and password (which should be the same as for the wiki). \subsection*{Accessing the repository with TortoiseSVN} As mentioned above, in order to access the SVN repository one of the best options is \href{http://www.tortoisesvn.net/}{TortoiseSVN}. We will describe here how to use the basics of the program, although you should be able to use any SVN client in a similar fashion. First install TortoiseSVN (which unfortunately requires you to reboot your computer) and then create a directory (for instance CrypTool2") for storing the local working files somewhere on your computer. Right-click on this directory and select SVN Checkout" from the context menu. A window will appear in which you will be asked for the URL of the repository as given above. The Checkout directory" should already be filled in correctly with your new folder. Then just hit ok, accept the certificate (if necessary), and enter your login information as described above. Mark the checkbox for saving your credentials if you don't want to enter them every time you work with the repository. Then hit ok, and now the whole CrypTool2 repository should be checked out into your chosen directory. First install TortoiseSVN (which unfortunately requires you to reboot your computer) and then create a directory (for instance CrypTool2") for storing the local working files somewhere on your computer. Right-click on this directory and select SVN Checkout" from the context menu. A window will appear in which you will be asked for the URL of the repository as given above. The Checkout directory" should already be filled in correctly with your new folder. Then just hit OK", accept the certificate (if necessary), and enter your login information as described above. Mark the checkbox for saving your credentials if you don't want to enter them every time you work with the repository. Then hit OK", and now the whole CrypTool2 repository should be checked out into your chosen directory. Later on, if changes have been made in the repository and you want to update your working copy, you can do this by right-clicking on any directory within the working files and choosing SVN Update" from the context menu. If you are a registered developer, have changed a file, and want your changes to be reflected in the repository, you should choose SVN Commit" from the context menu to upload your changes. Please always provide \textit{meaningful descriptions} of your updates. You should commit your sources to our SVN repository as often as you can. This will ensure your interoperability with the rest of the project for further development. Later on, if changes have been made in the repository and you want to update your working copy, you can do this by right-clicking on any directory within the working files and choosing SVN Update" from the context menu. You should do this often to maintain a current version of the files. A TortoiseSVN tutorial can be found \href{http://www.mind.ilstu.edu/research/robots/iris4/developers/svntutorial}{here}. \subsection*{Ignore patterns} \label{IgnorePatterns} \subsection*{Committing your changes} \label{CommitingYourChanges} Please only check in clean code by using the following \textbf{ignore patterns}: \begin{center} \textit{obj bin debug release *.pdb *.suo *.exe *.dll} \end{center} This basically means that you should never check in compiled and user-generated files. For example, please do not check in the entire \textit{bin/} and \textit{obj/} directories that Visual Studio generates. Note that the server will reject your commits if you try to do so. If you want to submit a component (binary file) despite the ignore patterns you can still add \textit{*.dll} files by using the context menu and add that file explicitly - but please be absolutely sure, that you know what you are doing. Additionally you need to explicitly provide a list of file names respectively directory names which shall override the ignore pattern. Example, you want to check in a file named someLib.dll, you must write a comment which looks like this: \begin{center} \fbox{\parbox{15cm} {\tt The lib is required by all developers, so I'm adding it explicitly to the repository. override-bad-extension: someLib.dll }} \end{center} Please note that any text after the colon and the whitespace will be treated as the file name. Please do not use quotes and do not write any text after the name. \subsection*{Committing your changes} \label{CommitingChanges} If you have an SVN account (not anonymous access), you can commit your file changes to the public CrypTool2 repository. Choose ''SVN Commit'' from the context menu in order to upload your changes. Please always provide meaningful descriptions of your updates. If you are a registered developer, you can commit your file changes to the public CrypTool2 repository. Right-click on the directory within the working files that contains your changes and select SVN Commit" from the context menu to upload your changes. Please always provide \textit{meaningful descriptions} of your updates. You should commit your sources to our SVN repository as often as you can to ensure your interoperability with the rest of the project, but only commit code that successfully compiles and runs! You can use command words in the SVN comment to link your changes to a particular ticket. The command syntax is as follows: }} \end{center} You can have more than one command in a message. The following commands are supported. There is more than one spelling for each command, to make this as user-friendly as possible. \fbox{\parbox{15cm} {\tt Changed blah and foo to do this or that. Fixes \#10 and \#12, and refs \#12. Changed blah and foo to do this or that.\ Fixes \#10 and \#12, and refs \#12. }} \end{center} This will close \#10 and \#12, and add a note to \#12. \subsection*{Ignore patterns} \label{IgnorePatterns} Please only check in proper source code by using the following \textbf{ignore patterns}: \begin{center} \textit{obj bin debug release *.pdb *.suo *.exe *.dll *.aux *.dvi *.log *.bak *.bbl *.blg *.user} \end{center} This basically means that you should never check in compiled and automatically generated files. For example, please do not check in the entire \textit{bin/} and \textit{obj/} directories that Visual Studio generates. Note that the server will reject your commits if you try to do so. If you want to submit a component (binary file) despite the ignore patterns you can still add \textit{*.dll} files by using the context menu and adding the file explicitly - but please be absolutely sure that you know what you are doing. Additionally, you need to provide an explicit list of file and directory names which should override the ignore pattern. For example, if you want to check in a file named someLib.dll, you must write a comment which looks like this: \begin{center} \fbox{\parbox{15cm} {\tt The lib is required by all developers, so I am adding it explicitly to the repository. override-bad-extension:\ someLib.dll }} \end{center} Please note that any text after the colon and the whitespace will be treated as the file name. Therefore, do not use quotation marks and do not write any text after the file name. \section{Compiling the sources} \label{CompilingTheSources} By this point you should have checked out a copy of the entire CrypTool repository. Compiling is pretty easy; just go to the \textit{trunk/} directory and open the \textbf{\textit{CrypTool 2.0.sln}} Visual Studio solution. The Visual Studio IDE should open with all the working plugins components nicely arranged. In case you are now starting Visual Studio for the first time, you will have to choose your settings. Just select either most common" or C\#" --- you can change this at any time later. On the right side is the project explorer, where you can see all the subprojects included in the solution. Look for the project \textbf{\textit{CrypWin.exe}} there. Once you have found it, right-click on it and select Set as StartUp-Project" from the context menu. Next, go to the menu bar and select Build" $\rightarrow$ Build Solution". Then go to Debug" and select Start Debugging" --- now CrypTool 2.0 should start for the first time with your own compiled code. Presumably you have not changed anything yet, but you now have your own build of all the components (with the exception of CrypWin and AnotherEditor, since they are available only as binaries). If the program does not compile or start correctly, please consult our \href{https://www.cryptool.org/trac/CrypTool2/wiki/FAQ}{FAQ} and let us know if you found a bug. By this point you should have checked out a copy of the entire CrypTool repository. Compiling is pretty easy; just go to the \textit{trunk/} directory and open the \textbf{\textit{CrypTool 2.0.sln}} Visual Studio solution. The Visual Studio IDE should open with all the working plugins components nicely arranged. In case you are now starting Visual Studio for the first time, you will have to choose your settings. Just select either most common" or C\#" --- you can change this at any time later. On the right side is the project explorer, where you can see all the subprojects included in the solution. Look for the project \textbf{\textit{CrypWin.exe}} there. Once you have found it, right-click on it and select Set as StartUp-Project" from the context menu. Next, go to the menu bar and select Build" $\rightarrow$ Build Solution". If you are a core developer, hence somebody who can also compile CryWin and AnotherEditor, you should use the \textbf{\textit{CrypTool 2.0.sln}} solution from the \textit{trunk/CoreDeveloper/} directory (which will \textit{not} be visible to you if you are not a core developer). As a core developer, be aware that when you compile, you \textbf{change the \textit{CryWin.exe}} which is visible to everybody else. Thus, when doing a check-in, please make sure you \textit{really} want to check in a new binary. As core developer you can also build a new setup and publish it as beta release on the website. This process is explained in the wiki: \url{https://www.cryptool.org/trac/CrypTool2/wiki/BuildSetup}. Then go to Debug" and select Start Debugging". CrypTool 2.0 should now start for the first time with your own compiled code. Presumably you have not changed anything yet, but you now have your own build of all the components (with the exception of CrypWin and AnotherEditor, since they are available only as binaries). If the program does not compile or start correctly, please consult our \href{https://www.cryptool.org/trac/CrypTool2/wiki/FAQ}{FAQ} and let us know if you found a bug. If you are a \textbf{core developer}, hence somebody who can also compile CryWin and AnotherEditor, you should use the \textbf{\textit{CrypTool 2.0.sln}} solution from the \textit{trunk/CoreDeveloper/} directory (which will \textit{not} be visible to you if you are not a core developer). As a core developer, be aware that when you compile, you \textbf{change the \textit{CryWin.exe}} that is visible to everybody else. Thus, when doing a check-in, please make sure you \textit{really} want to check in a new binary. Core developers can also build a new setup and publish it as beta release on the website. This process is explained in the wiki at \url{https://www.cryptool.org/trac/CrypTool2/wiki/BuildSetup}.
 r1145 \chapter{Plugin Implementation} \label{sec:PluginImplementation} In this chapter we provide step-by-step instructions for implementing your own CrypTool 2.0 plugin. The given instructions refer mostly to the usage of MS Visual C\# 2008 Express Edition, hence before starting you should have a copy of \textbf{Microsoft Visual Studio 2008} or \textbf{Microsoft Visual C\# 2008 Express Edition} installed on your computer. We will use the \textbf{Caesar cipher} (also known as the \textbf{shift cipher}) for our example implemenation. In this chapter we provide step-by-step instructions for implementing your own CrypTool 2.0 plugin. The given instructions refer mostly to the usage of the Visual C\# Express and Visual Studio Professional 2008 editions, so before starting you should have a copy of \textbf{Microsoft Visual Studio 2008} (or \textbf{Microsoft Visual C\# 2008 Express Edition}) installed on your computer. We will use the \textbf{Caesar cipher} (also known as the \textbf{shift cipher}) for our example implemenation. \section{Creating a new project} \label{sec:CreatingANewProject} To begin, open Visual Studio 2008 or C\# 2008 Express Edition, go to the menu bar and select File"~$\rightarrow$ New" $\rightarrow$ Project\ldots ". The following window will appear: To begin, open Visual Studio, go to the menu bar and select File"~$\rightarrow$ New" $\rightarrow$ Project\ldots ". The following window will appear: \begin{figure}[h!] \centering \includegraphics[width=1.00\textwidth]{figures/vs_create_new_project.jpg} \caption{Creating a new Visual Studio/C\# Express project.} \caption{Creating a new Visual Studio project.} \label{fig:vs_create_new_project} \end{figure} If you are using Visual Studio 2008, select \textbf{.NET-Framework 3.5"} as the target framework; the Express Edition will automatically choose the target framework. Then choose \textbf{Class Library"} as the default template, as this will build the project as a DLL file. Give the project a unique and meaningful name (such as Caesar" in our case), and choose a location to save it to. (The Express Edition will ask for a save location later when you close your project or environment). Select the subdirectory CrypPlugins" from your SVN trunk as the location. Finally, confirm by pressing the OK" button. Note that creating a new project in this manner also creates a new solution into which the project is placed. \noindent If you are using Visual Studio 2008, select \textbf{.NET-Framework 3.5"} as the target framework; the Express Edition will automatically choose the target framework. Then choose \textbf{Class Library"} as the default template, as this will build the project for your plugin as a DLL file. Give the project a unique and meaningful name (such as Caesar" in our case), and choose a location to save it to. (The Express Edition will ask for a save location later when you close your project or environment). Select the subdirectory CrypPlugins" from your SVN trunk as the location. Finally, confirm by pressing the OK" button. Note that creating a new project in this manner also creates a new solution into which the project is placed. \begin{figure}[h!] \centering \includegraphics[width=0.80\textwidth]{figures/save_solution_csharp_express.JPG} \caption{The Microsoft C\# Express Edition Save Project dialog window.} \caption{The Microsoft C\# Express Edition Save Project" dialog window.} \label{fig:save_solution_csharp_express} \end{figure} At this point, your Visual Studio\slash C\# Express solution should look like this: \noindent At this point, your Visual Studio\slash C\# Express solution should look like this: \begin{figure}[h!] \label{sec:InterfaceSelection} First we must add a reference to the CrypTool library, \textbf{\textit{CrypPluginBase.dll}}, where all the necessary CrypTool plugin interfaces are declared. To include our new plugin in the CrypTool program, we must first add a reference to the CrypTool library, \textbf{\textit{CrypPluginBase.dll}}, where all the necessary CrypTool plugin interfaces are declared. \begin{figure}[h!] \end{figure} Right-click in the Solution Explorer on the Reference" item and choose Add Reference". A window like the following should appear: \noindent Right-click in the Solution Explorer on the Reference" item and choose Add Reference". A window like the following should appear: \begin{figure}[h!] \clearpage Select the project CrypPluginBase". If you do not have the CrypPluginBase" source code, it is also possible to add a reference the the binary DLL. In this case browse to the path where the library file \textit{CrypPluginBase.dll} is located, e.g.\ \textit{C:\textbackslash Documents and Settings\textbackslash $<$Username$>$\textbackslash My Documents\textbackslash Visual Studio 2008\textbackslash Projects\textbackslash CrypPluginBase\textbackslash bin\textbackslash Debug} and select the library by double clicking the file or pressing the OK" button. (You can also select the binary DLL located in the folder where \textit{CrypWin.exe} was placed when you downloaded CrypTool2.) \noindent Select the project CrypPluginBase". If you do not have the CrypPluginBase" source code, it is also possible to add a reference the binary DLL. In this case browse to the path where the library file \textit{CrypPluginBase.dll} is located, e.g.\ \textit{C:\textbackslash Documents and Settings\textbackslash $<$Username$>$\textbackslash My Documents\textbackslash Visual Studio 2008\textbackslash Projects\textbackslash CrypPluginBase\textbackslash bin\textbackslash Debug} and select the library by double clicking the file or pressing the OK" button. (You can also select the binary DLL located in the folder where \textit{CrypWin.exe} was placed when you downloaded CrypTool2.) \begin{figure}[h!] \end{figure} Besides CrypPluginBase you will need to add three assembly references to provide the necessary Windows" namespaces for the \textbf{user control} functions Presentation" and QuickWatchPresentation". This can be done in the same manner as before with the CrypPluginBase" but by selecting the .NET" tab. Select the following .NET components: \noindent Besides CrypPluginBase you will need to add three assembly references to provide the necessary Windows" namespaces for the \textbf{user control} functions Presentation" and QuickWatchPresentation". This can be done in the same manner as before with the CrypPluginBase" but by selecting the .NET" tab. Select the following .NET components: \begin{itemize} \clearpage Afterwards your reference tree view should look like this: \noindent Afterwards your reference tree view should look like this: \begin{figure}[h!] \end{figure} If your plugin will be based on other additional libraries, you can add them in the same way. \noindent If your plugin will be based on other additional libraries, you can add them in the same way. \section{Modifing the project properties} \end{itemize} This section of your assembly file should now look something like this: \noindent This section of your assembly file should now look something like this: \begin{lstlisting} %\clearpage Both options will achieve the same results. We will guide you through the second method. First, delete Class1.cs". \noindent Both options will achieve the same results. We will guide you through the second method. First, delete Class1.cs". \begin{figure}[h!] \clearpage Then right-click on the project item (in our case, Caesar") and select Add $\rightarrow$ Class\ldots ": \noindent Then right-click on the project item (in our case, Caesar") and select Add $\rightarrow$ Class\ldots ": \begin{figure}[h] \clearpage Finally, give your class a unique name. We will call our class Caesar.cs" and define it as public so that it will be available to other classes. \noindent Finally, give your class a unique name. We will call our class Caesar.cs" and define it as public so that it will be available to other classes. \begin{figure}[h!] \end{figure} \noindent Visual Studio will automatically generate a basic code outline for the new class. In our example, we will not use the all the namespaces that are automatically imported, so you can delete the lines \texttt{using System;} and \texttt{using System.Linq;}. \subsection{Creating a settings class} \label{sec:CreatingASettingsClass} \clearpage Below is an example of what a completed TaskPane for the existing Caesar plugin in CrypTool 2 looks like: \noindent Below is an example of what a completed TaskPane for the existing Caesar plugin in CrypTool 2 looks like: \begin{figure}[h!] \end{itemize} In our example, the Caesar algorithm necessitates the inclusion of the following namespaces: \noindent In our example, the Caesar algorithm necessitates the inclusion of the following namespaces: \begin{itemize} \item ''Cryptool.PluginBase'' --- to provide ''ISettings'' for the CaesarSettings class \item ''Cryptool.PluginBase.Cryptography'' --- to provide ''IEncryption'' for the Caesar class \item ''Cryptool.PluginBase.IO'' --- to provide CryptoolStream for the input and output Data \item ''Cryptool.PluginBase.Miscellaneous'' --- to use the entire CrypTool event handler \item Cryptool.PluginBase --- to implement ISettings in the CaesarSettings class. \item Cryptool.PluginBase.Cryptography --- to implement IEncryption in the Caesar class. \item Cryptool.PluginBase.IO --- to use CryptoolStream for data input and output. \item Cryptool.PluginBase.Miscellaneous --- to use the CrypTool event handler. \end{itemize} It is important to define a new default namespace of our public class (''Caesar''). In CrypTool the default namespace is presented by ''Cryptool.[name of class]''. Therefore our namespace has to be defined as follows: ''Cryptool.Caesar''.\clearpage Up to now the source code should look as you can see below: \noindent It is important to define a new default namespace for our public class (Caesar"). In CrypTool 2.0  the standard namespace convention is \textit{Cryptool.[name of class]}. Therefore our namespace will be defined as \textit{Cryptool.Caesar}.\clearpage \noindent At this point, the source code should look like the following: \begin{lstlisting} using System.Text; //needed CrypTool namespaces //required CrypTool namespaces using Cryptool.PluginBase; using Cryptool.PluginBase.Cryptography; } \end{lstlisting} Next let your class ''Caesar'' inherit from IEncryption by inserting of the following statement: \ \\ % ugly but functional \noindent Next we should let the Caesar" class inherit from IEncryption by making the following alteration: \begin{lstlisting} namespace Cryptool.Caesar { public class Caesar: IEncryption public class Caesar : IEncryption { } } \end{lstlisting} \subsection{Add the interface functions for the class Caesar} \label{sec:AddTheInterfaceFunctionsForTheClassCaesar} \subsection{Adding interface functions for the Caesar class} \label{sec:AddingInterfaceFunctionsForTheCaesarClass} There is an underscore at the ''I'' in IEncryption statement. Move your mouse over it or place the cursor at it and press ''Shift+Alt+F10'' and you will see the following submenu: \begin{figure}[h!]