/// <summary> /// Initializes a new instance of the <see cref="CharacterService"/> class. /// </summary> /// <param name="commands">The application's command service.</param> /// <param name="entityService">The application's owned entity service.</param> /// <param name="content">The content service.</param> /// <param name="transformations">The transformation service.</param> public CharacterService(CommandService commands, OwnedEntityService entityService, ContentService content, TransformationService transformations) { this.Commands = commands; this.OwnedEntities = entityService; this.Content = content; this.Transformations = transformations; this.PronounProviders = new Dictionary <string, IPronounProvider>(new CaseInsensitiveStringEqualityComparer()); }
public async Task <RetrieveEntityResult <IReadOnlyList <Transformation> > > DiscoverBundledTransformationsAsync ( [NotNull] GlobalInfoContext db, [NotNull] TransformationService transformation, [NotNull] Species species ) { const string speciesFilename = "Species.yml"; var speciesDir = GetSpeciesDirectory(species); var transformationFiles = Directory.EnumerateFiles(speciesDir).Where(p => !p.EndsWith(speciesFilename)); var transformations = new List <Transformation>(); var deser = new DeserializerBuilder() .WithTypeConverter(new ColourYamlConverter()) .WithTypeConverter(new SpeciesYamlConverter(db, transformation)) .WithNodeDeserializer(i => new ValidatingNodeDeserializer(i), s => s.InsteadOf <ObjectNodeDeserializer>()) .WithNamingConvention(new UnderscoredNamingConvention()) .Build(); foreach (var transformationFile in transformationFiles) { string content = await FileAsync.ReadAllTextAsync(transformationFile); try { transformations.Add(deser.Deserialize <Transformation>(content)); } catch (YamlException yex) { if (yex.InnerException is SerializationException sex) { return(RetrieveEntityResult <IReadOnlyList <Transformation> > .FromError(sex)); } return(RetrieveEntityResult <IReadOnlyList <Transformation> > .FromError(yex)); } } return(RetrieveEntityResult <IReadOnlyList <Transformation> > .FromSuccess(transformations)); }