コード例 #1
0
        /// <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 ) );
        }
コード例 #2
0
        /// <summary>
        /// Resolves all tasks defined in a given parsed fragment.
        /// </summary>
        /// <param name="parsedFragment"></param>
        /// <returns></returns>
        /// <exception cref="ParserException">Task has no name!</exception>
        public static List<Task> Resolve( Fragment parsedFragment )
        {
            IEnumerable<Fragment> taskFragments = parsedFragment.Fragments.Where( p => p.Keyword == Keywords.ExtensionDirectives.DeclareTask );
              if( !taskFragments.Any() ) return null;

              List<Task> tasks = new List<Task>();
              foreach( Fragment taskFragment in taskFragments ) {
            // Construct the plugin with the given name
            Task task = new Task {Name = taskFragment.Parameters, SourceFragment = taskFragment};

            // Resolve task
            foreach( Fragment taskParameter in taskFragment.Fragments ) {
              if( taskParameter.Keyword == Keywords.Description ) {
            task.Description = taskParameter.Parameters;

              } else if( taskParameter.Keyword == Keywords.Title ) {
            task.Title = taskParameter.Parameters;

              } else if( taskParameter.Keyword == Keywords.Implementation ) {
            task.Implementation = taskParameter.Parameters;

              } else if( taskParameter.Keyword == Keywords.ServiceDirectives.AdditionalFields ) {
            task.AdditionalFieldsClass = taskParameter.Parameters;
            task.TaskFields = new TaskFields { Implementation = taskParameter.Parameters };
              }
            }

            // If no name was defined, throw
            if( string.IsNullOrEmpty( task.Name ) ) {
              throw new ParserException( "Service has no name!", parsedFragment.SourceDocument );
            }

            if( null != task.TaskFields ) {
              task.TaskFields.Name = task.Name;
            }

            tasks.Add( task );
              }

              return tasks;
        }
コード例 #3
0
 /// <summary>
 /// Generates the task class name for a given task.
 /// </summary>
 /// <param name="extension"></param>
 /// <param name="task"></param>
 /// <returns></returns>
 public static string GetTaskFileName( Extension extension, Task task )
 {
     return String.Format( "{0}Task.php", UpperCamelCase( task.Name ) );
 }
コード例 #4
0
 /// <summary>
 /// Generates the task file name that must be used for the implementation of a task.
 /// </summary>
 /// <param name="extension"></param>
 /// <param name="task"></param>
 /// <returns></returns>
 public static string GetTaskImplementationFileName( Extension extension, Task task )
 {
     return String.Format( "{0}{1}TaskImplementation.php", UpperCamelCase( extension.Key ), UpperCamelCase( task.Name ) );
 }
コード例 #5
0
 /// <summary>
 /// Generates the task class name for a given task.
 /// </summary>
 /// <param name="extension"></param>
 /// <param name="task"></param>
 /// <returns></returns>
 public static string GetTaskClassName( Extension extension, Task task )
 {
     return String.Format( "Tx_{0}_Tasks_{1}Task", UpperCamelCase( extension.Key ), UpperCamelCase( task.Name ) );
 }