/// <summary>
        /// Generates a single service
        /// </summary>
        /// <param name="service">The service that should be generated.</param>
        private void GenerateService( Service service )
        {
            ClassProxyGenerator classGenerator = new ClassProxyGenerator( GeneratorContext, Subject );
              ServiceNamingStrategy serviceNamingStrategy = new ServiceNamingStrategy();
              classGenerator.GenerateClassProxy( service, serviceNamingStrategy, "Classes/Service/", false );

              // Autoload services
              WriteVirtual(
            "ext_autoload.php",
            String.Format( "'{0}' => $extensionPath . 'Classes/Service/{1}',", serviceNamingStrategy.GetExtbaseClassName( Subject, service ).ToLower(), serviceNamingStrategy.GetExtbaseFileName( Subject, service ) ) );
        }
        /// <summary>
        /// Generates a single task
        /// </summary>
        /// <param name="task">The task that should be generated.</param>
        private void GenerateTask( Task task )
        {
            ClassProxyGenerator classGenerator = new ClassProxyGenerator( GeneratorContext, Subject );
              TaskNamingStrategy taskNamingStrategy = new TaskNamingStrategy();
              TaskFieldsNamingStrategy taskFieldsNamingStrategy = new TaskFieldsNamingStrategy();

              // Generate the task class itself
              classGenerator.GenerateClassProxy( task, taskNamingStrategy, "Classes/Tasks/", false );

              if( null != task.TaskFields ) {
            classGenerator.GenerateClassProxy( task.TaskFields, taskFieldsNamingStrategy, "Classes/Tasks/", false );

            // Add the autoloader for our fields class
            WriteVirtual(
              "ext_autoload.php",
              String.Format( "'{0}' => $extensionPath . 'Classes/Tasks/{1}',", taskFieldsNamingStrategy.GetExtbaseClassName( Subject, task.TaskFields ).ToLower(), taskFieldsNamingStrategy.GetExtbaseFileName( Subject, task.TaskFields ) ) );
              }

              // Add the autoloader for our class
              WriteVirtual(
            "ext_autoload.php",
            String.Format( "'{0}' => $extensionPath . 'Classes/Tasks/{1}',", taskNamingStrategy.GetExtbaseClassName( Subject, task ).ToLower(), taskNamingStrategy.GetExtbaseFileName( Subject, task ) ) );

              // Register the scheduler task itself
              string registerTaskTemplate = "$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['{_taskClassName}'] = array(" +
                                    "	'extension'        => '{_extensionKey}'," +
                                    "	'title'            => 'LLL:EXT:{_extensionKey}/Resources/Private/Language/locallang_be.xml:{_taskName}'," +
                                    "	'description'      => 'LLL:EXT:{_extensionKey}/Resources/Private/Language/locallang_be.xml:{_taskDescription}'" +
                                    ( ( null != task.TaskFields ) ? ",'additionalFields' => '" + taskFieldsNamingStrategy.GetExtbaseClassName( Subject, task.TaskFields ).ToLower() + "'" : string.Empty ) +
                                    ");";

              string taskName        = String.Format( "{0}.name",        task.Name.ToLower() );
              string taskDescription = String.Format( "{0}.description", task.Name.ToLower() );

              WriteVirtual( "ext_localconf.php", registerTaskTemplate.FormatSmart(
            new {
              _extensionKey     = Subject.Key,
              _taskClassName    = taskNamingStrategy.GetExtbaseClassName( Subject, task ),
              _taskName         = taskName,
              _taskDescription  = taskDescription
            }
              ) );

              // Write language constants
              WriteVirtual( "Resources/Private/Language/locallang_be.xml", string.Format( "<label index=\"{0}\">{1}</label>", taskName, task.Title ) );
              WriteVirtual( "Resources/Private/Language/locallang_be.xml", string.Format( "<label index=\"{0}\">{1}</label>", taskDescription, task.Description ) );
        }
        /// <summary>
        /// Generates the PHP statements to register the modules.
        /// </summary>
        /// <returns></returns>
        private void GenerateModules()
        {
            if( null == Subject.Modules || !Subject.Modules.Any() ) return;

              StringBuilder result = new StringBuilder();

              Log.Info( "Registering modules..." );

              const string template = "if( TYPO3_MODE === 'BE' ) {{\n" +
                              "  Tx_Extbase_Utility_Extension::registerModule(\n" +
                              "    '{_extensionName}',\n" +
                              "    '{_mainModuleName}',\n" +
                              "    '{_subModuleName}',\n" +
                              "    '',\n" +
                              "    array(\n" +
                              "      {_actions}\n" +
                              "    ),\n" +
                              "    array(\n" +
                              "      'access' => 'user,group',\n" +
                              "      'icon'   => 'EXT:{_extensionName}/ext_icon.gif',\n" +
                              "      'labels' => 'LLL:EXT:{_extensionName}/Resources/Private/Language/locallang_{_langFileKey}.xml',\n" +
                              "    )\n" +
                              "  );\n" +
                              "}}";

              for( int moduleIndex = 0; moduleIndex < Subject.Modules.Count; moduleIndex++ ) {
            Typo3ExtensionGenerator.Model.Module module = Subject.Modules[ moduleIndex ];

            Log.InfoFormat( "Registering module '{0}'...", module.Name );

            ActionAggregator.AggregationResult aggregationResult = ActionAggregator.Aggregate( module, true );

            //string subKey = string.Format( "m{0}", moduleIndex + 1 );
            //string moduleKey = string.Format( "tx_{0}_{1}", Subject.Key, subKey );
            string moduleKey = NameHelper.GetModuleSignature( Subject, module );

            result.Append(
              template.FormatSmart(
            new {
                  _extensionName  = Subject.Key,
                  _mainModuleName = module.MainModuleName,
                  _subModuleName  = moduleKey,
                  _langFileKey    = module.Name.ToLower(),
                  _actions        = aggregationResult.Uncachable
                } ) + "\n" );

            // Valid labels that should/could be generated
            // <label index="mlang_tabs_tab">Download Importer</label>
            // <label index="mlang_labels_tabdescr">Import download records from files on the file system.</label>
            // <label index="mlang_labels_tablabel">Create download records from files on the file system.</label>

            WriteVirtual( string.Format( "Resources/Private/Language/locallang_{0}.xml", module.Name.ToLower() ), string.Format( "<label index=\"{0}\">{1}</label>", "mlang_tabs_tab", module.Title ) );

            ClassProxyGenerator classGenerator = new ClassProxyGenerator( GeneratorContext, Subject );
            classGenerator.GenerateClassProxy( module, new ControllerNamingStrategy(), "Classes/Controller/", true );
              }

              string modules = result.ToString().Substring( 0, result.Length - 1 );
              WriteVirtual( "ext_tables.php", modules );
        }
 /// <summary>
 /// Generates the ExtBase controller for the given plugin.
 /// </summary>
 /// <param name="plugin"></param>
 private void GenerateController( Typo3ExtensionGenerator.Model.Plugin.Plugin plugin )
 {
     ClassProxyGenerator classGenerator = new ClassProxyGenerator( GeneratorContext, Subject );
       classGenerator.GenerateClassProxy( plugin, new ControllerNamingStrategy(), "Classes/Controller/", true );
 }