コード例 #1
0
        public static DescribedSerializationBase ToDescribedSerializationUsingSpecificFactory <T>(
            this T objectToPackageIntoDescribedSerializationBase,
            SerializerRepresentation serializerRepresentation,
            ISerializerFactory serializerFactory,
            SerializationFormat serializationFormat,
            AssemblyMatchStrategy assemblyMatchStrategy = AssemblyMatchStrategy.AnySingleVersion)
        {
            if (serializerRepresentation == null)
            {
                throw new ArgumentNullException(nameof(serializerRepresentation));
            }

            if (serializerFactory == null)
            {
                throw new ArgumentNullException(nameof(serializerFactory));
            }

            if (serializationFormat == SerializationFormat.Invalid)
            {
                throw new ArgumentOutOfRangeException(Invariant($"'{nameof(serializationFormat)}' == '{SerializationFormat.Invalid}'"), (Exception)null);
            }

            var serializer = serializerFactory.BuildSerializer(serializerRepresentation, assemblyMatchStrategy);

            var ret = objectToPackageIntoDescribedSerializationBase.ToDescribedSerializationUsingSpecificSerializer(serializer, serializationFormat);

            return(ret);
        }
コード例 #2
0
            /// <summary>
            /// Initializes a new instance of the <see cref="For{T}"/> class.
            /// </summary>
            /// <param name="configurationSerializerRepresentation">The configuration serializer representation.</param>
            /// <param name="configurationSerializerFactory">The configuration serializer factory.</param>
            /// <param name="keyOverride">The optional specified key to use; DEFAULT is null and will build a key from the supplied <typeparamref name="T"/>.</param>
            public For(SerializerRepresentation configurationSerializerRepresentation, ISerializerFactory configurationSerializerFactory, string keyOverride = null)
            {
                this.Key = keyOverride ?? BuildKey();
                var configSetting = GetSerializedSetting(this.Key);

                var serializer = configurationSerializerFactory.BuildSerializer(configurationSerializerRepresentation);

                if (!string.IsNullOrWhiteSpace(configSetting))
                {
                    this.Value = serializer.Deserialize <T>(configSetting);
                }
                else
                {
                    throw new FileNotFoundException(FormattableString.Invariant($"Could not find config for: {typeof(T).AssemblyQualifiedName}."));
                }
            }
コード例 #3
0
        public void Serialize(T obj, BinaryWriter writer)
        {
            var idAndSerializer = SerializersCache.GetOrAdd(Tuple.Create(typeof(T), _environment), type =>
            {
                var newSerializer = _serializerFactory.BuildSerializer();
                var schema        = _serializerFactory.GetSchema();
                var newSchemaId   = _registryApi.Register(_subject, schema).Result;
                return(Tuple.Create(newSchemaId, (object)newSerializer));
            });

            var schemaId   = idAndSerializer.Item1;
            var serializer = (Action <Stream, T>)idAndSerializer.Item2;

            writer.Write(MagicByte);
            writer.Write(IPAddress.HostToNetworkOrder(schemaId));
            serializer(writer.BaseStream, obj);
        }
コード例 #4
0
        public PullRequestService(
            IOptions <WebConfiguration> config,
            ISerializerFactory serializerFactory,
            IGitHubClientFactory githubFactory)
        {
            if (serializerFactory is null)
            {
                throw new ArgumentNullException(nameof(serializerFactory));
            }
            if (githubFactory is null)
            {
                throw new ArgumentNullException(nameof(githubFactory));
            }

            _config     = config?.Value ?? throw new ArgumentNullException(nameof(config));
            _serializer = serializerFactory.BuildSerializer();
            _github     = githubFactory.CreateClient();
        }
コード例 #5
0
        public static object DeserializePayloadUsingSpecificFactory(
            this DescribedSerialization describedSerialization,
            ISerializerFactory serializerFactory,
            ICompressorFactory compressorFactory,
            TypeMatchStrategy typeMatchStrategy         = TypeMatchStrategy.NamespaceAndName,
            MultipleMatchStrategy multipleMatchStrategy = MultipleMatchStrategy.ThrowOnMultiple,
            UnregisteredTypeEncounteredStrategy unregisteredTypeEncounteredStrategy = UnregisteredTypeEncounteredStrategy.Default)
        {
            new { describedSerialization }.Must().NotBeNull();
            new { serializerFactory }.Must().NotBeNull();
            new { compressorFactory }.Must().NotBeNull();

            var serializer = serializerFactory.BuildSerializer(describedSerialization.SerializationDescription, typeMatchStrategy, multipleMatchStrategy, unregisteredTypeEncounteredStrategy);
            var compressor = compressorFactory.BuildCompressor(describedSerialization.SerializationDescription.CompressionKind);

            var ret = describedSerialization.DeserializePayloadUsingSpecificSerializer(serializer, compressor, typeMatchStrategy, multipleMatchStrategy);

            return(ret);
        }
コード例 #6
0
        /// <summary>
        /// Converts a self described serialization back into it's object.
        /// </summary>
        /// <param name="describedSerializationBase">Self described serialized object.</param>
        /// <param name="serializerFactory">Implementation of <see cref="ISerializerFactory" /> that can resolve the serializer.</param>
        /// <param name="assemblyMatchStrategy">Optional assembly match strategy for resolving the type of object as well as the configuration type if any; DEFAULT is <see cref="AssemblyMatchStrategy.AnySingleVersion" />.</param>
        /// <returns>
        /// Originally serialized object.
        /// </returns>
        public static object DeserializePayloadUsingSpecificFactory(
            this DescribedSerializationBase describedSerializationBase,
            ISerializerFactory serializerFactory,
            AssemblyMatchStrategy assemblyMatchStrategy = AssemblyMatchStrategy.AnySingleVersion)
        {
            if (describedSerializationBase == null)
            {
                throw new ArgumentNullException(nameof(describedSerializationBase));
            }

            if (serializerFactory == null)
            {
                throw new ArgumentNullException(nameof(serializerFactory));
            }

            var serializer = serializerFactory.BuildSerializer(describedSerializationBase.SerializerRepresentation, assemblyMatchStrategy);

            var result = describedSerializationBase.DeserializePayloadUsingSpecificSerializer(serializer, assemblyMatchStrategy);

            return(result);
        }
コード例 #7
0
        public static DescribedSerialization ToDescribedSerializationUsingSpecificFactory <T>(
            this T objectToPackageIntoDescribedSerialization,
            SerializationDescription serializationDescription,
            ISerializerFactory serializerFactory,
            ICompressorFactory compressorFactory,
            TypeMatchStrategy typeMatchStrategy         = TypeMatchStrategy.NamespaceAndName,
            MultipleMatchStrategy multipleMatchStrategy = MultipleMatchStrategy.ThrowOnMultiple,
            UnregisteredTypeEncounteredStrategy unregisteredTypeEncounteredStrategy = UnregisteredTypeEncounteredStrategy.Default)
        {
            new { serializationDescription }.Must().NotBeNull();
            new { serializerFactory }.Must().NotBeNull();
            new { compressorFactory }.Must().NotBeNull();

            var serializer = serializerFactory.BuildSerializer(serializationDescription, typeMatchStrategy, multipleMatchStrategy, unregisteredTypeEncounteredStrategy);
            var compressor = compressorFactory.BuildCompressor(serializationDescription.CompressionKind);

            var ret = objectToPackageIntoDescribedSerialization.ToDescribedSerializationUsingSpecificSerializer(
                serializationDescription,
                serializer,
                compressor);

            return(ret);
        }