Ejemplo n.º 1
0
        /// <summary>
        /// Cancels a Phrase Generation Job thread. If the job isn't canceled before it is completed, the callback that was passed when the job was started may still get invoked.
        /// </summary>
        /// <param name="phraseGenerationJobId">The job id of the job that is being canceled. The id is the number that was returned from calling GeneratePhraseAsync</param>
        public void CancelPhraseGeneration(int phraseGenerationJobId)
        {
            PhraseGenerationJob jobToAbort = jobs.FirstOrDefault(j => j.Id == phraseGenerationJobId);

            if (jobToAbort != null)
            {
                jobToAbort.Abort();
                jobs.Remove(jobToAbort);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates a phrase on a separate thread and sends the generated phrase and the seed used to generate it to a callback once complete.
        /// </summary>
        /// <param name="text">A TextAsset containing the template phrase for the newly generated phrase.</param>
        /// <param name="callback">A callback to which the string phrase and int seed will be passed.</param>
        /// <param name="seed">(Optional) The seed that will be used to generate the phrase.
        /// <para>Use this if you are wanting to recieve a phrase generated previously.</para>
        /// <para>If no seed is passed, a new one will be created and that int is what will be passed to the callback. Otherwise, the seed passed in is the one that will go to the callback.</para></param>
        /// <returns>The Id of the PhraseGenerationJob (thread) generating the phrase, can be passed to CancelGeneration to abort the thread later.</returns>
        public int GeneratePhraseAsyncFromTemplateString(string template, System.Action <string, int> callback, int?seed = null)
        {
            PhraseGenerationJob generationJob = new PhraseGenerationJob();
            TemplateCluster     cluster       = TemplateParser.ParseTemplate(template);

            jobs.Add(generationJob);
            int _seed = seed.HasValue ? seed.Value : System.Environment.TickCount;

            generationJob.Start(_seed, cluster, callback);
            return(generationJob.Id);
        }