Example #1
0
        private fsResult InternalSerialize_3_ProcessVersioning(Type overrideConverterType, object instance, out fsData data)
        {
            // note: We do not have to take a Type parameter here, since at this
            //       point in the serialization algorithm inheritance has
            // *always* been handled. If we took a type parameter, it will
            // *always* be equal to instance.GetType(), so why bother taking the
            //  parameter?

            // Check to see if there is versioning information for this type. If
            // so, then we need to serialize it.
            fsOption <fsVersionedType> optionalVersionedType = fsVersionManager.GetVersionedType(instance.GetType());

            if (optionalVersionedType.HasValue)
            {
                fsVersionedType versionedType = optionalVersionedType.Value;

                // Serialize the actual object content; we'll just wrap it with
                // versioning metadata here.
                var result = InternalSerialize_4_Converter(overrideConverterType, instance, out data);
                if (result.Failed)
                {
                    return(result);
                }

                // Add the versioning information
                EnsureDictionary(data);
                data.AsDictionary[Key_Version] = new fsData(versionedType.VersionString);

                return(result);
            }

            // This type has no versioning information -- directly serialize it
            // using the selected converter.
            return(InternalSerialize_4_Converter(overrideConverterType, instance, out data));
        }
Example #2
0
        private fsResult InternalSerialize_3_ProcessVersioning(Type overrideConverterType, object instance, out fsData data)
        {
            // note: We do not have to take a Type parameter here, since at this point in the serialization
            //       algorithm inheritance has *always* been handled. If we took a type parameter, it will
            //       *always* be equal to instance.GetType(), so why bother taking the parameter?
            // 注:ここでは、直列化アルゴリズム継承のこの時点で*常に*処理されているので、ここではTypeパラメータを取る必要はありません。 型パラメータを取った場合、常に* instance * .GetType()と等しくなります。

            // Check to see if there is versioning information for this type. If so, then we need to serialize it.
            //このタイプのバージョニング情報があるかどうかを確認してください。 もしそうなら、それを直列化する必要があります。
            fsOption <fsVersionedType> optionalVersionedType = fsVersionManager.GetVersionedType(instance.GetType());

            if (optionalVersionedType.HasValue)
            {
                fsVersionedType versionedType = optionalVersionedType.Value;

                // Serialize the actual object content; we'll just wrap it with versioning metadata here.
                //実際のオブジェクトの内容をシリアル化する。 ここでバージョン管理のメタデータでラップします。
                var result = InternalSerialize_4_Converter(overrideConverterType, instance, out data);
                if (result.Failed)
                {
                    return(result);
                }

                // Add the versioning information
                //バージョン情報を追加する
                EnsureDictionary(data);
                data.AsDictionary[Key_Version] = new fsData(versionedType.VersionString);

                return(result);
            }

            // This type has no versioning information -- directly serialize it using the selected converter.
            // このタイプにはバージョン管理情報はありません。選択したコンバータを使用して直接シリアル化します。
            return(InternalSerialize_4_Converter(overrideConverterType, instance, out data));
        }
Example #3
0
        private fsResult InternalDeserialize_2_Version(Type overrideConverterType, fsData data, Type storageType, ref object result, out List <fsObjectProcessor> processors)
        {
            if (IsVersioned(data))
            {
                // data is versioned, but we might not need to do a migration
                //データはバージョン管理されていますが、移行は必要ありません
                string version = data.AsDictionary[Key_Version].AsString;

                fsOption <fsVersionedType> versionedType = fsVersionManager.GetVersionedType(storageType);
                if (versionedType.HasValue &&
                    versionedType.Value.VersionString != version)
                {
                    // we have to do a migration
                    //私たちはマイグレーションをしなくてはなりません
                    var deserializeResult = fsResult.Success;

                    List <fsVersionedType> path;
                    deserializeResult += fsVersionManager.GetVersionImportPath(version, versionedType.Value, out path);
                    if (deserializeResult.Failed)
                    {
                        processors = GetProcessors(storageType);
                        return(deserializeResult);
                    }

                    // deserialize as the original type
                    //元の型として非直列化する
                    deserializeResult += InternalDeserialize_3_Inheritance(overrideConverterType, data, path[0].ModelType, ref result, out processors);
                    if (deserializeResult.Failed)
                    {
                        return(deserializeResult);
                    }

                    // TODO: we probably should be invoking object processors all along this pipeline
                    //TODO:おそらくこのパイプラインに沿ってオブジェクトプロセッサを呼び出すべきです
                    for (int i = 1; i < path.Count; ++i)
                    {
                        result = path[i].Migrate(result);
                    }

                    // Our data contained an object definition ($id) that was added to _references in step 4.
                    // However, in case we are doing versioning, it will contain the old version.
                    // To make sure future references to this object end up referencing the migrated version,
                    // we must update the reference.
                    //私たちのデータには、手順4で_referencesに追加されたオブジェクト定義($ id)が含まれていました。
                    //ただし、バージョン管理を行っている場合は古いバージョンが含まれます。このオブジェクトへの今後の参照が移行されたバージョンを参照するようにするには、参照を更新する必要があります。
                    if (IsObjectDefinition(data))
                    {
                        int sourceId = int.Parse(data.AsDictionary[Key_ObjectDefinition].AsString);
                        _references.AddReferenceWithId(sourceId, result);
                    }

                    processors = GetProcessors(deserializeResult.GetType());
                    return(deserializeResult);
                }
            }

            return(InternalDeserialize_3_Inheritance(overrideConverterType, data, storageType, ref result, out processors));
        }
Example #4
0
        private fsResult InternalDeserialize_2_Version(Type overrideConverterType, fsData data, Type storageType,
                                                       ref object result, out List <fsObjectProcessor> processors)
        {
            if (IsVersioned(data))
            {
                // data is versioned, but we might not need to do a migration
                string version = data.AsDictionary[Key_Version].AsString;

                fsOption <fsVersionedType> versionedType = fsVersionManager.GetVersionedType(storageType);
                if (versionedType.HasValue &&
                    versionedType.Value.VersionString != version)
                {
                    // we have to do a migration
                    fsResult deserializeResult = fsResult.Success;

                    List <fsVersionedType> path;
                    deserializeResult += fsVersionManager.GetVersionImportPath(version, versionedType.Value, out path);
                    if (deserializeResult.Failed)
                    {
                        processors = GetProcessors(storageType);
                        return(deserializeResult);
                    }

                    // deserialize as the original type
                    deserializeResult += InternalDeserialize_3_Inheritance(overrideConverterType, data,
                                                                           path[0].ModelType, ref result, out processors);
                    if (deserializeResult.Failed)
                    {
                        return(deserializeResult);
                    }

                    // TODO: we probably should be invoking object processors all
                    //       along this pipeline
                    for (int i = 1; i < path.Count; ++i)
                    {
                        result = path[i].Migrate(result);
                    }

                    // Our data contained an object definition ($id) that was
                    // added to _references in step 4. However, in case we are
                    // doing versioning, it will contain the old version. To make
                    // sure future references to this object end up referencing
                    // the migrated version, we must update the reference.
                    if (IsObjectDefinition(data))
                    {
                        int sourceId = int.Parse(data.AsDictionary[Key_ObjectDefinition].AsString);
                        _references.AddReferenceWithId(sourceId, result);
                    }

                    processors = GetProcessors(deserializeResult.GetType());
                    return(deserializeResult);
                }
            }

            return(InternalDeserialize_3_Inheritance(overrideConverterType, data, storageType, ref result,
                                                     out processors));
        }
Example #5
0
        private fsResult InternalDeserialize_2_Version(fsData data, Type storageType, ref object result, out List <fsObjectProcessor> processors)
        {
            if (IsVersioned(data))
            {
                // data is versioned, but we might not need to do a migration
                string version = data.AsDictionary[Key_Version].AsString;

                fsOption <fsVersionedType> versionedType = fsVersionManager.GetVersionedType(storageType);
                if (versionedType.HasValue &&
                    versionedType.Value.VersionString != version)
                {
                    // we have to do a migration
                    var deserializeResult = fsResult.Success;

                    List <fsVersionedType> path;
                    deserializeResult += fsVersionManager.GetVersionImportPath(version, versionedType.Value, out path);
                    if (deserializeResult.Failed)
                    {
                        processors = GetProcessors(storageType);
                        return(deserializeResult);
                    }

                    // deserialize as the original type
                    deserializeResult += InternalDeserialize_3_Inheritance(data, path[0].ModelType, ref result, out processors);
                    if (deserializeResult.Failed)
                    {
                        return(deserializeResult);
                    }

                    // TODO: we probably should be invoking object processors all along this pipeline
                    for (int i = 1; i < path.Count; ++i)
                    {
                        result = path[i].Migrate(result);
                    }

                    processors = GetProcessors(deserializeResult.GetType());
                    return(deserializeResult);
                }
            }

            return(InternalDeserialize_3_Inheritance(data, storageType, ref result, out processors));
        }
Example #6
0
        private fsFailure InternalDeserialize_2_Version(fsData data, Type storageType, ref object result)
        {
            if (IsVersioned(data))
            {
                // data is versioned, but we might not need to do a migration
                string version = data.AsDictionary[Key_Version].AsString;

                fsOption <fsVersionedType> versionedType = fsVersionManager.GetVersionedType(storageType);
                if (versionedType.HasValue &&
                    versionedType.Value.VersionString != version)
                {
                    // we have to do a migration

                    List <fsVersionedType> path;
                    fsFailure fail = fsVersionManager.GetVersionImportPath(version, versionedType.Value, out path);
                    if (fail.Failed)
                    {
                        return(fail);
                    }

                    // deserialize as the original type
                    fail = InternalDeserialize_3_Inheritance(data, path[0].ModelType, ref result);
                    if (fail.Failed)
                    {
                        return(fail);
                    }

                    for (int i = 1; i < path.Count; ++i)
                    {
                        result = path[i].Migrate(result);
                    }

                    return(fsFailure.Success);
                }
            }

            return(InternalDeserialize_3_Inheritance(data, storageType, ref result));
        }