Show / Hide Table of Contents

Class BrainSerializerBase<TState, TBot, TAction>

A helper class for loading and saving bot brains.

Inheritance
object
ResourceHelper
BrainSerializerBase<TState, TBot, TAction>
BrainSerializer<TState, TBot, TAction, TBrain>
Implements
IBrainSerializer
ITitleResourceHelper
IResourceHelper
IMetadataAccess
Inherited Members
ResourceHelper.DefaultParametersFilename
ResourceHelper.JsonFileExtension
ResourceHelper.BaseOutputFolder
ResourceHelper.GetParameters(Assembly, string, string)
ResourceHelper.GetResourcePath(string)
ResourceHelper.WriteResourcesToDisk(Assembly, string, string, Func<string, bool>)
ResourceHelper.WriteNewResourcesToDisk(Assembly, string, string)
ResourceHelper.SafeCombinePath(string, string)
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Microsoft.XboxStudios.BotBrain.Composition
Assembly: BotBrain.Core.dll
Syntax
public abstract class BrainSerializerBase<TState, TBot, TAction> : ResourceHelper, IBrainSerializer, ITitleResourceHelper, IResourceHelper, IMetadataAccess where TBot : IAutomatedBot<TAction>
Type Parameters
Name Description
TState

A title-specific state object.

TBot

A title-specific bot object that implements IAutomatedBot<TAction>.

TAction

The title-specific bot action that implements IEquatable<T>.

Constructors

View Source

BrainSerializerBase(IServiceProvider, ILogger<BrainSerializerBase<TState, TBot, TAction>>?, string?, Assembly?)

Initializes a new instance of the BrainSerializerBase<TState, TBot, TAction> class.

Declaration
protected BrainSerializerBase(IServiceProvider services, ILogger<BrainSerializerBase<TState, TBot, TAction>>? logger = null, string? outputFolder = null, Assembly? brainAssembly = null)
Parameters
Type Name Description
IServiceProvider services

The service provider used for construction.

ILogger<BrainSerializerBase<TState, TBot, TAction>> logger

The logger to use.

string outputFolder

The folder path containing brain resources.

Assembly brainAssembly

The assembly containing brain types to register and resources to extract.

Fields

View Source

DefaultBotBrainOutputFolder

The default output folder for bot brain resources.

Declaration
public const string DefaultBotBrainOutputFolder = "BotBrain"
Field Value
Type Description
string

Properties

View Source

BotBrainFileExtension

Gets the file extension for bot brain files.

Declaration
public virtual string BotBrainFileExtension { get; }
Property Value
Type Description
string
View Source

BrainAssembly

Gets the assembly containing brain types to register and resources to extract.

Declaration
protected Assembly BrainAssembly { get; }
Property Value
Type Description
Assembly
View Source

BrainCoreAssembly

Gets the assembly containing brain core types to register.

Declaration
protected static Assembly BrainCoreAssembly { get; }
Property Value
Type Description
Assembly
View Source

BrainDefaultsFilePath

Gets the absolute path to the default brain parameters file.

Declaration
public virtual string BrainDefaultsFilePath { get; }
Property Value
Type Description
string
View Source

BrainTemplatesFolderPath

Gets the absolute path to the folder containing brain templates.

Declaration
public virtual string BrainTemplatesFolderPath { get; }
Property Value
Type Description
string
View Source

BrainsFolder

Gets or sets the path to the resources folder containing bot brain files.

Declaration
public string BrainsFolder { get; set; }
Property Value
Type Description
string
View Source

JsonConverters

Gets the JSON converters for serializing and deserializing bot brains.

Declaration
protected abstract IEnumerable<JsonConverter> JsonConverters { get; }
Property Value
Type Description
IEnumerable<JsonConverter>
View Source

Logger

Gets the logger to use.

Declaration
public ILogger<BrainSerializerBase<TState, TBot, TAction>> Logger { get; }
Property Value
Type Description
ILogger<BrainSerializerBase<TState, TBot, TAction>>
View Source

ParameterNames

Gets an enumeration of parameter names.

Declaration
public IEnumerable<string> ParameterNames { get; }
Property Value
Type Description
IEnumerable<string>
View Source

Services

Gets the services used for construction.

Declaration
public IServiceProvider? Services { get; }
Property Value
Type Description
IServiceProvider
View Source

TitleOutputFolder

Gets the output folder for title resources.

Declaration
public virtual string TitleOutputFolder { get; }
Property Value
Type Description
string

Methods

View Source

DeserializeBrain(string)

Deserializes a brain from a string.

Declaration
public abstract IBotBrain DeserializeBrain(string contents)
Parameters
Type Name Description
string contents

A string representation of a brain.

Returns
Type Description
IBotBrain

The brain.

View Source

DeserializeBrainFile(string)

Deserializes a brain from a file.

Declaration
public virtual IBotBrain DeserializeBrainFile(string file)
Parameters
Type Name Description
string file

The file containing a brain.

Returns
Type Description
IBotBrain

The brain.

View Source

GetBrainFilePath(string)

Gets the file path for the given bot brain.

Declaration
protected virtual string GetBrainFilePath(string name)
Parameters
Type Name Description
string name

The brain's name.

Returns
Type Description
string

A file path.

View Source

GetDefaultSerializerSettings(bool)

Gets the default serializer settings for the given options.

Declaration
protected virtual JsonSerializerSettings GetDefaultSerializerSettings(bool indented = true)
Parameters
Type Name Description
bool indented

If true, the JSON output is indented.

Returns
Type Description
JsonSerializerSettings

A settings object.

View Source

GetDeserializerSettings(bool)

Gets the deserializer settings for the given options.

Declaration
protected virtual JsonSerializerSettings GetDeserializerSettings(bool indented = true)
Parameters
Type Name Description
bool indented

If true, the JSON output is indented.

Returns
Type Description
JsonSerializerSettings

A settings object.

View Source

GetJsonConverters<TBrain>()

Gets the JSON converters for serializing bot brains.

Declaration
protected IEnumerable<JsonConverter> GetJsonConverters<TBrain>() where TBrain : IBotBrain
Returns
Type Description
IEnumerable<JsonConverter>

An enumeration of converters.

Type Parameters
Name Description
TBrain

The brain type.

View Source

GetParameterMetadata(string)

Gets the metadata for a parameter.

Declaration
public ParameterMetadata? GetParameterMetadata(string parameterName)
Parameters
Type Name Description
string parameterName

The parameter name.

Returns
Type Description
ParameterMetadata

The metadata, if it exists.

View Source

GetSerializerSettings(bool)

Gets the serializer settings for the given options.

Declaration
protected virtual JsonSerializerSettings GetSerializerSettings(bool indented = true)
Parameters
Type Name Description
bool indented

If true, the JSON output is indented.

Returns
Type Description
JsonSerializerSettings

A settings object.

View Source

GetTitleResourcePath(string?)

Gets the output file path for the given title resource.

Declaration
public string GetTitleResourcePath(string? filepath = null)
Parameters
Type Name Description
string filepath

The resource file path.

Returns
Type Description
string

A file path.

View Source

Initialize()

Initializes the brain helper.

Declaration
public virtual void Initialize()
View Source

IsReservedBrainFilename(string)

Determines if the given filename is reserved for brain metadata like defaults or parameters.

Declaration
public virtual bool IsReservedBrainFilename(string filename)
Parameters
Type Name Description
string filename

The filename.

Returns
Type Description
bool

True if it is reserved.

View Source

LoadBrain(string)

Loads a brain file.

Declaration
public virtual IBotBrain? LoadBrain(string name)
Parameters
Type Name Description
string name

The name of the brain.

Returns
Type Description
IBotBrain

The brain, or null if it couldn't be loaded.

View Source

LoadDefaultBrainParameters()

Loads the default brain parameters.

Declaration
public virtual IParameterManager? LoadDefaultBrainParameters()
Returns
Type Description
IParameterManager

The default parameters, or null if they don't exist.

View Source

LoadFileItem<T>(string, Func<string, T>, string)

Loads an object from a file.

Declaration
protected T LoadFileItem<T>(string filePath, Func<string, T> deserializeFunc, string itemType)
Parameters
Type Name Description
string filePath

The file to load.

Func<string, T> deserializeFunc

The deserialization function.

string itemType

The item type name.

Returns
Type Description
T

The object, or a default value if it failed to load.

Type Parameters
Name Description
T

The object type.

View Source

LoadParameterMetadata()

Loads parameter metadata embedded within assemblies.

Declaration
protected virtual MetadataContainer LoadParameterMetadata()
Returns
Type Description
MetadataContainer

A metadata container.

View Source

LoadTemplates<T>(string, JsonSerializerSettings, Func<string, bool>?)

Loads templates from a folder.

Declaration
protected void LoadTemplates<T>(string folder, JsonSerializerSettings serializerSettings, Func<string, bool>? ignore = null)
Parameters
Type Name Description
string folder

The folder to search.

JsonSerializerSettings serializerSettings

The JSON serializer settings.

Func<string, bool> ignore

An optional function specifying which files to ignore.

Type Parameters
Name Description
T

The object type.

View Source

RegisterBrainAssemblyTypes(Assembly)

Registers brain-related types for deserialization.

Declaration
protected static void RegisterBrainAssemblyTypes(Assembly a)
Parameters
Type Name Description
Assembly a

The assembly to index.

View Source

SerializeBrain(IBotBrain, bool)

Serializes a brain to a string.

Declaration
public virtual string SerializeBrain(IBotBrain brain, bool indented = true)
Parameters
Type Name Description
IBotBrain brain

The brain.

bool indented

If true, the output is indented.

Returns
Type Description
string

A string representation of a brain.

View Source

WriteCoreResources()

Writes the embedded bot brain core resources to disk.

Declaration
protected void WriteCoreResources()
View Source

WriteTitleResources()

Writes the embedded bot brain title-specific resources to disk.

Declaration
protected virtual void WriteTitleResources()

Implements

IBrainSerializer
ITitleResourceHelper
IResourceHelper
IMetadataAccess
  • View Source
In this article
Back to top Generated by DocFX