コード例 #1
0
        public T Read <T>(BinaryContainer data) where T : Persistable
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            using (var reader = data.AsText().Read())
            {
                var instance = Persistable.Deserialize <T>(data.Identifier, reader, mInstancePool, mConverters);

                return(instance);
            }
        }
コード例 #2
0
        public void Import(IBlobStore source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var container    = source;
            var instancePool = mInstancePool;

            foreach (var keyTypePartition in mSchema.GetPartitionsByDependencyDepth())
            {
                foreach (var keyType in keyTypePartition)
                {
                    foreach (var implementation in keyType.ConcreteTypes)
                    {
                        var section          = PersistedNode.GetContainerKey(implementation);
                        var sectionContainer = container.GetChildStore(section, true);

                        foreach (var leaf in sectionContainer.Keys.Where(x => x.EndsWith(".json", StringComparison.InvariantCultureIgnoreCase)))
                        {
                            using (var reader = sectionContainer.Open(leaf).AsText().Read())
                            {
                                var key = Path.GetFileNameWithoutExtension(leaf);

                                try
                                {
                                    var instance = Persistable.Deserialize(key, implementation, reader, instancePool, mConverters);

                                    mInstancePool.Register(instance);
                                }
                                catch (Exception exception)
                                {
                                    throw new InvalidDataException($"Object \"{key}\" ({section}): {exception.Message}", exception);
                                }
                            }
                        }
                    }
                }
            }
        }