Show / Hide Table of Contents

Class MigrationManager

Class responsible for migration stuff. It holds migrations, migration types for different versions and can apply them.

Inheritance
System.Object
MigrationManager
Namespace: Eco.Core.Serialization.Migrations
Assembly: Eco.Core.dll
Syntax
public class MigrationManager : Object

Constructors

MigrationManager()

Declaration
public MigrationManager()

Fields

MigrationInfo

Declaration
public InfoBuilder MigrationInfo
Field Value
Type Description
InfoBuilder

MigrationLog

Declaration
public InfoBuilder MigrationLog
Field Value
Type Description
InfoBuilder

Properties

CachedObjectsSerializer

Declaration
public CachedObjectSerializer CachedObjectsSerializer { get; }
Property Value
Type Description
CachedObjectSerializer

HasMigrations

Declaration
public bool HasMigrations { get; }
Property Value
Type Description
System.Boolean

NewVersion

Declaration
public SimpleSerializer NewVersion { get; }
Property Value
Type Description
SimpleSerializer

ObjectSerializer

Declaration
public ObjectSerializer ObjectSerializer { get; }
Property Value
Type Description
ObjectSerializer

OldVersion

Declaration
public SimpleSerializer OldVersion { get; }
Property Value
Type Description
SimpleSerializer

Methods

AddDataStoreMigration(Type, IDataStoreMigration)

Declaration
public void AddDataStoreMigration(Type type, IDataStoreMigration dataStoreMigration)
Parameters
Type Name Description
System.Type type
IDataStoreMigration dataStoreMigration

AddMigratedType(Double, MigratedTypeAttribute)

Adds MigratedTypeAttribute which will be used to access erased information for migrated type (i.e. if it was struct and was changed to class or vice versa).

Declaration
public void AddMigratedType(double sinceVersion, MigratedTypeAttribute migratedType)
Parameters
Type Name Description
System.Double sinceVersion
MigratedTypeAttribute migratedType

AddMigration(Double, IClassMigration)

Declaration
public void AddMigration(double sinceVersion, IClassMigration classMigration)
Parameters
Type Name Description
System.Double sinceVersion
IClassMigration classMigration

AddMigrations(Double, IEnumerable<IClassMigration>)

Adds all migrations from enumerable with same sinceVersion.

Declaration
public void AddMigrations(double sinceVersion, IEnumerable<IClassMigration> migrations)
Parameters
Type Name Description
System.Double sinceVersion
System.Collections.Generic.IEnumerable<IClassMigration> migrations

AddReferencedObjectSerializer(String, Type, Func<Object, Object>)

Adds new ReferencedObjectSerializer created for provided arguments.

Declaration
public ReferencedObjectSerializer AddReferencedObjectSerializer(string keySchemaType, Type type, Func<object, object> referenceResolver)
Parameters
Type Name Description
System.String keySchemaType
System.Type type
System.Func<System.Object, System.Object> referenceResolver
Returns
Type Description
ReferencedObjectSerializer

AddReferencedObjectSerializer<TKey, TReference>(Func<TKey, TReference>)

Shortcut for .

Declaration
public ReferencedObjectSerializer AddReferencedObjectSerializer<TKey, TReference>(Func<TKey, TReference> referenceResolver)
Parameters
Type Name Description
System.Func<TKey, TReference> referenceResolver
Returns
Type Description
ReferencedObjectSerializer
Type Parameters
Name Description
TKey
TReference

AddSchemaMember(ImmutableSerializerSchema, String, String)

Declaration
public ImmutableSerializerSchema AddSchemaMember(ImmutableSerializerSchema schema, string memberName, string memberType)
Parameters
Type Name Description
ImmutableSerializerSchema schema
System.String memberName
System.String memberType
Returns
Type Description
ImmutableSerializerSchema

ChangeSchemaMember(ImmutableSerializerSchema, String, String, String)

Declaration
public ImmutableSerializerSchema ChangeSchemaMember(ImmutableSerializerSchema schema, string oldMemberName, string newMemberName, string newMemberType)
Parameters
Type Name Description
ImmutableSerializerSchema schema
System.String oldMemberName
System.String newMemberName
System.String newMemberType
Returns
Type Description
ImmutableSerializerSchema

ChangeSchemaType(ImmutableSerializerSchema, String)

Declaration
public ImmutableSerializerSchema ChangeSchemaType(ImmutableSerializerSchema schema, string schemaType)
Parameters
Type Name Description
ImmutableSerializerSchema schema
System.String schemaType
Returns
Type Description
ImmutableSerializerSchema

CopySchemaContent(ImmutableSerializerSchema, BinaryReader, BinaryWriter)

Copies schema content from reader to writer without actually deserializing it.

Declaration
public void CopySchemaContent(ImmutableSerializerSchema schema, BinaryReader reader, BinaryWriter writer)
Parameters
Type Name Description
ImmutableSerializerSchema schema

schema.

System.IO.BinaryReader reader

reader to read from.

System.IO.BinaryWriter writer

writer to write content to.

CreateMemberlessSchema(String)

Declaration
public ImmutableSerializerSchema CreateMemberlessSchema(string schemaType)
Parameters
Type Name Description
System.String schemaType
Returns
Type Description
ImmutableSerializerSchema

CreateSchema(SerializerSchema)

Declaration
public ImmutableSerializerSchema CreateSchema(SerializerSchema schema)
Parameters
Type Name Description
SerializerSchema schema
Returns
Type Description
ImmutableSerializerSchema

CreateSchema(String)

Declaration
public ImmutableSerializerSchema CreateSchema(string schemaType)
Parameters
Type Name Description
System.String schemaType
Returns
Type Description
ImmutableSerializerSchema

CreateSchema(String, ObjectSerializer)

Declaration
public ImmutableSerializerSchema CreateSchema(string schemaType, ObjectSerializer membersSerializer)
Parameters
Type Name Description
System.String schemaType
ObjectSerializer membersSerializer
Returns
Type Description
ImmutableSerializerSchema

DecodeObject(ImmutableSerializerSchema, BinaryReader)

Decodes object using provided schema.

Declaration
public DecodedObject DecodeObject(ImmutableSerializerSchema schema, BinaryReader reader)
Parameters
Type Name Description
ImmutableSerializerSchema schema

schema.

System.IO.BinaryReader reader

reader.

Returns
Type Description
DecodedObject

object instance.

DecodeObject(MigrationContext)

Migrates context and returns DecodedObject (either reference or instance).

Declaration
public DecodedObject DecodeObject(MigrationContext context)
Parameters
Type Name Description
MigrationContext context
Returns
Type Description
DecodedObject

EncodeWith(ISerializer, BinaryWriter, Object, SerializeFlags)

Declaration
public void EncodeWith(ISerializer serializer, BinaryWriter writer, object value, SerializeFlags flags)
Parameters
Type Name Description
ISerializer serializer
System.IO.BinaryWriter writer
System.Object value
SerializeFlags flags

GetOrCreateObjectSerializer(ImmutableSerializerSchema)

Declaration
public ObjectSerializer GetOrCreateObjectSerializer(ImmutableSerializerSchema schema)
Parameters
Type Name Description
ImmutableSerializerSchema schema
Returns
Type Description
ObjectSerializer

GetOrCreateSerializer(ImmutableSerializerSchema)

Declaration
public ISerializer GetOrCreateSerializer(ImmutableSerializerSchema schema)
Parameters
Type Name Description
ImmutableSerializerSchema schema
Returns
Type Description
ISerializer

GetOrCreateSerializerFromSchemaType(String)

Tries to find serializer for schemaType. If not exists then either will try to create new serializer for container types (dictionary or collection) or returns default ObjectSerializer for class schema types.

Declaration
public ISerializer GetOrCreateSerializerFromSchemaType(string schemaType)
Parameters
Type Name Description
System.String schemaType
Returns
Type Description
ISerializer

GetOrCreateVersionedSerializer(ImmutableSerializerSchema, Double)

Gets or creates versioned serializer. If migration for schema required then it will start from version instead of current schema version. Typical use-case if you have a DataMigration which performs migration on a member which has migrations before and after that data migration. Then you fist migrate the member up-to version compatible with data migration then perform modifications for member from data modification itself and serialize it back with data migration version. When member will be decoded it will apply all migrations after the version of data migration.

Declaration
public ObjectSerializer GetOrCreateVersionedSerializer(ImmutableSerializerSchema schema, double version)
Parameters
Type Name Description
ImmutableSerializerSchema schema
System.Double version
Returns
Type Description
ObjectSerializer

GetSerializerFromId(Int32)

Declaration
public ISerializer GetSerializerFromId(int id)
Parameters
Type Name Description
System.Int32 id
Returns
Type Description
ISerializer

GetSerializerFromSchemaType(String)

Tries to find serializer for schemaType. If not exists then returns default ObjectSerializer for class schema types or throws exception.

Declaration
public ISerializer GetSerializerFromSchemaType(string schemaType)
Parameters
Type Name Description
System.String schemaType
Returns
Type Description
ISerializer

GetTypeBySchemaType(String)

Declaration
public Type GetTypeBySchemaType(string schemaType)
Parameters
Type Name Description
System.String schemaType
Returns
Type Description
System.Type

Init(SimpleSerializer, SimpleSerializer, Double)

Declaration
public void Init(SimpleSerializer oldVersion, SimpleSerializer newVersion, double schemaVersion)
Parameters
Type Name Description
SimpleSerializer oldVersion
SimpleSerializer newVersion
System.Double schemaVersion

IsMigrationOnlyType(Type)

Checks if type is a type which only used during migration. Such a type should be fully serialized instead of CachedObjectsSerializer usage.

Declaration
public bool IsMigrationOnlyType(Type type)
Parameters
Type Name Description
System.Type type
Returns
Type Description
System.Boolean

IsNullableType(String, Double)

Returns if type is nullable in specific schema version.

Declaration
public bool IsNullableType(string schemaType, double version)
Parameters
Type Name Description
System.String schemaType

schema type.

System.Double version

schema version.

Returns
Type Description
System.Boolean

true - if schema type nullable in specified schema version.

LogMigrationInfo()

Declaration
public void LogMigrationInfo()

MigrateDataStore(DataStore.ExclusiveAccess, Type, Action<Object, String>)

Declaration
public void MigrateDataStore(DataStore.ExclusiveAccess dataStoreAccess, Type type, Action<object, string> createFunc)
Parameters
Type Name Description
DataStore.ExclusiveAccess dataStoreAccess
System.Type type
System.Action<System.Object, System.String> createFunc

ReadMembers(BinaryReader, IDictionary<String, MemberDataInput>, ImmutableSerializerSchema, out Dictionary<String, (Int64, Int64)>)

Reads schema, returns decoded data for every requested member and returns member ranges mapping to positions in the stream. Reader positioned at the end of schema data after call to the method.

Declaration
public Dictionary<IDataInput, ReaderDataInput> ReadMembers(BinaryReader reader, IDictionary<string, MemberDataInput> members, ImmutableSerializerSchema schema, out Dictionary<string, (long, long)> memberRanges)
Parameters
Type Name Description
System.IO.BinaryReader reader
System.Collections.Generic.IDictionary<System.String, MemberDataInput> members
ImmutableSerializerSchema schema
System.Collections.Generic.Dictionary<System.String, System.ValueTuple<System.Int64, System.Int64>> memberRanges
Returns
Type Description
System.Collections.Generic.Dictionary<IDataInput, ReaderDataInput>

ReadMembers(BinaryReader, Stream, IDictionary<String, MemberDataInput>, ImmutableSerializerSchema, out Dictionary<String, (Int64, Int64)>)

Reads schema, returns decoded data for every requested member and returns member ranges mapping to positions in the stream. Reader positioned at the end of schema data after call to the method.

Declaration
public Dictionary<IDataInput, ReaderDataInput> ReadMembers(BinaryReader reader, Stream instanceStream, IDictionary<string, MemberDataInput> members, ImmutableSerializerSchema schema, out Dictionary<string, (long, long)> memberRanges)
Parameters
Type Name Description
System.IO.BinaryReader reader

binary reader to read data from.

System.IO.Stream instanceStream

stream with instance data which will advance with reader. It may be reader's base stream or tapped stream from ReadOnlyForkStream.

System.Collections.Generic.IDictionary<System.String, MemberDataInput> members

set of requested member names.

ImmutableSerializerSchema schema

schema describing data to read.

System.Collections.Generic.Dictionary<System.String, System.ValueTuple<System.Int64, System.Int64>> memberRanges

output dictionary with mapping between member names and they reader's positions.

Returns
Type Description
System.Collections.Generic.Dictionary<IDataInput, ReaderDataInput>

dictionary with requested members data.

ReadMembersTo(BinaryReader, Stream, IDictionary<String, MemberDataInput>, ImmutableSerializerSchema, Dictionary<IDataInput, ReaderDataInput>, out Dictionary<String, (Int64, Int64)>)

Reads schema, saves to data decoded data for every requested member and returns member ranges mapping to positions in the stream. Reader positioned at the end of schema data after call to the method.

Declaration
public void ReadMembersTo(BinaryReader reader, Stream instanceStream, IDictionary<string, MemberDataInput> members, ImmutableSerializerSchema schema, Dictionary<IDataInput, ReaderDataInput> data, out Dictionary<string, (long, long)> memberRanges)
Parameters
Type Name Description
System.IO.BinaryReader reader

binary reader to read data from.

System.IO.Stream instanceStream

stream with instance data which will advance with reader. It may be reader's base stream or tapped stream from ReadOnlyForkStream.

System.Collections.Generic.IDictionary<System.String, MemberDataInput> members

set of requested member names.

ImmutableSerializerSchema schema

schema describing data to read.

System.Collections.Generic.Dictionary<IDataInput, ReaderDataInput> data

data dictionary to store requested members data.

System.Collections.Generic.Dictionary<System.String, System.ValueTuple<System.Int64, System.Int64>> memberRanges

output dictionary with mapping between member names and they reader's positions.

RemoveSchemaMember(ImmutableSerializerSchema, String)

Declaration
public ImmutableSerializerSchema RemoveSchemaMember(ImmutableSerializerSchema schema, string memberName)
Parameters
Type Name Description
ImmutableSerializerSchema schema
System.String memberName
Returns
Type Description
ImmutableSerializerSchema

SetMigrationTypes(IEnumerable<MigrationType>)

Declaration
public void SetMigrationTypes(IEnumerable<MigrationType> migrationTypes)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<MigrationType> migrationTypes

SkipSchemaContent(ImmutableSerializerSchema, BinaryReader)

Skips schema content from reader without actually deserializing it.

Declaration
public void SkipSchemaContent(ImmutableSerializerSchema schema, BinaryReader reader)
Parameters
Type Name Description
ImmutableSerializerSchema schema

schema.

System.IO.BinaryReader reader

reader to skip from.

Extension Methods

PropertyChanges.FirePropertyChanged(Object, String)
PropertyChanges.FirePropertyChanged(Object, String, Object, Object)
PropertyChanges.FirePropertyChanged(Object, MemberChangedBeforeAfterEventArgs)
☀
☾
In This Article
Back to top
Copyright (c) Strange Loop Games 2021
☀
☾